Commit 1716bcb5 authored by Christophe Henry's avatar Christophe Henry Committed by Christophe Henry

I didn't come here to tell you how this is going to end. I came here to tell...

I didn't come here to tell you how this is going to end. I came here to tell you how it's going to begin.
parents
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
### Android template
# Built application files
*.apk
*.ap_
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches
# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks
# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
# Google Services (e.g. APIs or Firebase)
google-services.json
# Freeline
freeline.py
freeline/
freeline_project_description.json
# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
Supprimerait .gitignore
Supprimerait app/.gitignore
Supprimerait app/build.gradle
Supprimerait app/libs/
Supprimerait app/proguard-rules.pro
Supprimerait app/src/
Supprimerait build.gradle
Supprimerait gradle.properties
Supprimerait gradle/
Supprimerait gradlew
Supprimerait gradlew.bat
Supprimerait settings.gradle
/build
/src/main/assets/*.properties
apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply plugin: "kotlinx-serialization"
apply plugin: "kotlin-kapt"
android {
compileSdkVersion 28
defaultConfig {
applicationId "fr.chenry.android.freshrss"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
}
}
dataBinding {
enabled = true
}
}
dependencies {
def lifecycle_version = "2.0.0"
def room_version = "2.1.0-alpha03"
def fuel_version = "1.16.0"
def espresso_version = "3.1.1"
def test_runnner_version = "1.1.1"
def promise_version = "3.3.0"
def android_support_version = "28.0.0"
implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-beta01'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "com.android.support:appcompat-v7:$android_support_version"
implementation "com.android.support:preference-v7:$android_support_version"
implementation "com.android.support:support-core-utils:$android_support_version"
implementation "com.android.support:support-fragment:$android_support_version"
implementation "androidx.appcompat:appcompat:1.0.0-beta01"
implementation "androidx.core:core-ktx:1.1.0-alpha03"
implementation "com.google.android.material:material:1.0.0-beta01"
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
implementation "androidx.recyclerview:recyclerview:1.0.0"
testImplementation "junit:junit:4.12"
androidTestImplementation "androidx.test:runner:$test_runnner_version"
androidTestImplementation "androidx.test.espresso:espresso-core:$espresso_version"
// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version"
testImplementation "androidx.arch.core:core-testing:$lifecycle_version"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
implementation "androidx.room:room-guava:$room_version"
implementation "androidx.room:room-coroutines:$room_version"
testImplementation "androidx.room:room-testing:$room_version"
implementation "com.github.kittinunf.fuel:fuel:$fuel_version"
implementation "com.github.kittinunf.fuel:fuel-android:$fuel_version"
implementation "com.github.kittinunf.fuel:fuel-kotlinx-serialization:$fuel_version"
implementation "nl.komponents.kovenant:kovenant:$promise_version"
implementation "nl.komponents.kovenant:kovenant-android:$promise_version"
implementation "org.apache.commons:commons-text:1.4"
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package fr.chenry.android.freshrss
import androidx.test.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTestActivity {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("fr.chenry.android.freshrss", appContext.packageName)
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
xmlns:tools="http://schemas.android.com/tools"
package="fr.chenry.android.freshrss">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_PROFILE"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<dist:module dist:instant="true"/>
<application
android:name="fr.chenry.android.freshrss.FreshRSSApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:resizeableActivity="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsPictureInPicture="false"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="fr.chenry.android.freshrss.activities.TestActivity">
</activity>
<activity
android:name="fr.chenry.android.freshrss.activities.LoginActivity"
android:label="@string/title_activity_login">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="fr.chenry.android.freshrss.activities.MainActivity"
android:label="@string/app_name">
</activity>
</application>
</manifest>
\ No newline at end of file
package fr.chenry.android.freshrss
import android.app.Application
import fr.chenry.android.freshrss.store.Store
import nl.komponents.kovenant.android.startKovenant
import nl.komponents.kovenant.android.stopKovenant
import java.util.*
class FreshRSSApplication: Application() {
override fun onCreate() {
super.onCreate()
startKovenant()
Store.debugMode = try {
val properties = Properties()
properties.load(baseContext.assets.open("config.properties"))
properties.getProperty("debug", "false")!!.toBoolean()
} catch (_: Throwable) { false }
}
override fun onTerminate() {
super.onTerminate()
stopKovenant()
}
}
\ No newline at end of file
package fr.chenry.android.freshrss.activities
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.app.LoaderManager.LoaderCallbacks
import android.content.*
import android.database.Cursor
import android.os.Bundle
import android.view.View
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.addTextChangedListener
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.store.Store
import fr.chenry.android.freshrss.store.api.Endpoints
import fr.chenry.android.freshrss.utils.cleanUrlSlashes
import fr.chenry.android.freshrss.utils.e
import kotlinx.android.synthetic.main.activity_login.*
import nl.komponents.kovenant.ui.failUi
import nl.komponents.kovenant.ui.successUi
import java.util.*
/**
* A login screen that offers login via email/password.
*/
class LoginActivity: AppCompatActivity(), LoaderCallbacks<Cursor> {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
// Set up the login form.
password.setOnEditorActionListener(TextView.OnEditorActionListener {_, id, _ ->
if(id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) {
attemptLogin()
return@OnEditorActionListener true
}
false
})
email_sign_in_button.setOnClickListener {attemptLogin()}
try {
val properties = Properties()
properties.load(baseContext.assets.open("config.properties"))
instance.setText(properties.getProperty("instance"))
login.setText(properties.getProperty("login"))
password.setText(properties.getProperty("password"))
} catch(_: Throwable) {
}
computeHint()
instance.addTextChangedListener {computeHint()}
resetErrors()
instance.requestFocus()
}
private fun attemptLogin() {
resetErrors()
// Store values at the time of the login attempt.
val instanceStr = instance.text.toString()
val loginStr = login.text.toString()
val passwordStr = password.text.toString()
var cancel = false
var focusView: View? = null
// Check for a valid password, if the user entered one.
if(passwordStr.isBlank()) {
password.error = getString(R.string.error_invalid_password)
focusView = password
cancel = true
}
// Check for a valid email address.
if(loginStr.isBlank()) {
login.error = getString(R.string.error_field_required)
focusView = login
cancel = true
}
if(cancel) {
focusView?.requestFocus()
} else {
showProgress(true)
Store.login(instanceStr, loginStr, passwordStr) successUi {
startActivity(Intent(this, MainActivity::class.java))
//startActivity(Intent(this, TestActivity::class.java))
} failUi {
this.e(it)
instance.error = getString(R.string.error_instance)
showProgress(false)
}
}
}
private fun computeHint() {
val instanceStr = instance.text.toString().let {
if(it.isBlank()) resources.getString(R.string.instance_exemple) else it
}
reified_instance_url.text = instanceStr.cleanUrlSlashes().replace("/$".toRegex(), "")
if(!Endpoints.hasProtocol(instanceStr)) {
protocol_default.text = Endpoints.defaultProtocol
protocol_default.visibility = View.VISIBLE
} else {
protocol_default.visibility = View.GONE
}
if(!Endpoints.hasApiEndpoint(instanceStr)) {
api_endpoint.text = Endpoints.apiEndpoint
api_endpoint.visibility = View.VISIBLE
} else {
api_endpoint.visibility = View.GONE
}
}
private fun resetErrors() {
listOf(login, password, instance).forEach {
it.error = null
it.clearFocus()
}
hideKeyboard()
}
private fun hideKeyboard() {
val view = this.currentFocus
view?.let {
val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(it.windowToken, 0)
}
}
private fun showProgress(show: Boolean) {
login_progress_text.text = resources.getString(
R.string.login_progress_text,
Endpoints.computeApiUrl(instance.text.toString())
)
val shortAnimTime = resources.getInteger(android.R.integer.config_shortAnimTime).toLong()
login_form.visibility = if(show) View.GONE else View.VISIBLE
login_form.animate()
.setDuration(shortAnimTime)
.alpha((if(show) 0 else 1).toFloat())
.setListener(object: AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
login_form.visibility = if(show) View.GONE else View.VISIBLE
}
})
login_progress.visibility = if(show) View.VISIBLE else View.GONE
}
override fun onLoaderReset(cursorLoader: Loader<Cursor>) {
}
override fun onLoadFinished(p0: Loader<Cursor>?, p1: Cursor?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onCreateLoader(p0: Int, p1: Bundle?): Loader<Cursor> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
package fr.chenry.android.freshrss.activities
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.components.waiting.WaitingFragment
import fr.chenry.android.freshrss.store.*
import fr.chenry.android.freshrss.utils.e
import nl.komponents.kovenant.*
import nl.komponents.kovenant.ui.failUi
import nl.komponents.kovenant.ui.successUi
class MainActivity: AppCompatActivity() {
private val deferred = deferred<Unit, Throwable>()
init {
Store.getSubscriptions() then {
Store.getUnreadCount().get()
} then {
val promises = Store.subscriptions.value!!.keys.map {key -> Store.getStreamContents(key)}
all(promises, cancelOthersOnError = false).get()
} then {
Store.getUnreadItems().get()
} success { deferred.resolve() } fail (deferred::reject)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Router.observe(::onRouteChanged)
setupActionBar()
}
override fun onStart() {
super.onStart()
deferred.promise successUi {Router.navigate(RouteName.SUBSCRIPTIONS, pushHistory = false)} failUi {this.e(it)}
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
return super.onCreateOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
if(item == null) return super.onOptionsItemSelected(item)
return when(item.itemId) {
android.R.id.home -> {
onBackPressed()
true
}
else -> super.onOptionsItemSelected(item)
}
}
override fun onBackPressed() {
if(supportFragmentManager.backStackEntryCount > 0)
supportFragmentManager.popBackStackImmediate()
}
private fun onRouteChanged(to: Router.Route) {
val bundle = if(to.parameters.isEmpty()) Bundle.EMPTY else Bundle(to.parameters.entries.size).apply {
to.parameters.entries.forEach {(k, v) -> this.putString(k, v)}
}
val fragmentTransaction = supportFragmentManager?.beginTransaction()
?.replace(R.id.fragment_container, Fragment.instantiate(this, to.fragment.qualifiedName, bundle))
if(to.pushHistory)
fragmentTransaction?.addToBackStack(null)
fragmentTransaction?.commit()
}
private fun setupActionBar() {
supportFragmentManager.addOnBackStackChangedListener {
if(supportFragmentManager.backStackEntryCount > 0) supportActionBar?.setDisplayHomeAsUpEnabled(true)
else supportActionBar?.setDisplayHomeAsUpEnabled(false)
}
supportFragmentManager?.beginTransaction()?.add(R.id.fragment_container, WaitingFragment())?.commit()
}
}
package fr.chenry.android.freshrss.activities
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.store.Store
import kotlinx.android.synthetic.main.activity_test.*
import nl.komponents.kovenant.ui.successUi
class TestActivity: AppCompatActivity() {
val promise = Store.api.getUnreadItems(0)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test)
}
override fun onStart() {
super.onStart()
promise.successUi { test_text.text = "" }
}
}
package fr.chenry.android.freshrss.components.subscriptioncontents
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.*
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.ShareActionProvider
import androidx.core.view.MenuItemCompat
import androidx.fragment.app.Fragment
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.store.Store
import fr.chenry.android.freshrss.store.dao.store.ContentItem
import fr.chenry.android.freshrss.utils.capitalizeFull
import kotlinx.android.synthetic.main.fragment_subscription_content_detail.*
import java.util.regex.Pattern
import kotlin.text.RegexOption.IGNORE_CASE
class SubscriptionContentDetailFragment: Fragment() {
private lateinit var subscriptionContentsId: String
private lateinit var subscriptionArticleId: String
private lateinit var article: ContentItem
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
subscriptionContentsId = arguments?.getString("streamId")!!
subscriptionArticleId = arguments?.getString("articleId")!!
article = Store.getArticle(subscriptionContentsId, subscriptionArticleId).get()
activity.let {it as AppCompatActivity}.supportActionBar?.apply {subtitle = article.title}
return inflater.inflate(R.layout.fragment_subscription_content_detail, container, false)
}
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
inflater?.inflate(R.menu.actionbar, menu)
menu?.findItem(R.id.action_share)
.let {MenuItemCompat.getActionProvider(it) as ShareActionProvider}
.setShareIntent(
Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
val regex = "\\s*[^\\p{L}]*\\s*${Pattern.quote(article.author)}\\s*\\W*\\s*".toRegex(IGNORE_CASE)
val computedTitle = regex.replace(article.title, "")
val computedAuthor = if(article.author.isBlank()) "" else " — ${article.author}"
val comutedUrl = if(article.href.isBlank()) "" else "\n${article.href}"
putExtra(Intent.EXTRA_TEXT, "${computedTitle.capitalize()}${computedAuthor.capitalizeFull()}$comutedUrl")
})
val url = try { Uri.parse(article.href) } catch(_: Throwable) {null}
if(url != null) {
val actionOrigin = menu?.findItem(R.id.action_origin)
actionOrigin?.isVisible = true
actionOrigin?.setOnMenuItemClickListener {
val intent = Intent(Intent.ACTION_VIEW).apply {data = url}
startActivity(intent)
true
}
}
super.onCreateOptionsMenu(menu, inflater)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
val content = "<h1>${article.title}</h1>${article.content}"
content_detail.settings.javaScriptEnabled = false
content_detail.loadData(content, "text/html", "UTF-8")
}
override fun onDestroyView() {
activity.let {it as AppCompatActivity}.supportActionBar?.subtitle = null
super.onDestroyView()
}
}
package fr.chenry.android.freshrss.components.subscriptioncontents
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import fr.chenry.android.freshrss.R
class SubscriptionContentsFragment: Fragment() {