From 320924b4ed076c5356f534648f964269cf3bfda4 Mon Sep 17 00:00:00 2001 From: Amine Bou Date: Sat, 3 Mar 2018 16:00:56 +0100 Subject: [PATCH] Fixes #180. --- app/build.gradle | 2 +- .../bou/readerforselfoss/HomeActivity.kt | 116 ++++++++++-------- app/src/main/res/values-fr-rFR/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 4 files changed, 71 insertions(+), 51 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 48bb22d..dcd093f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -117,7 +117,7 @@ dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // Android Support compile 'com.android.support:appcompat-v7:27.0.2' diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt index 973245c..d07c62e 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -2,6 +2,7 @@ package apps.amine.bou.readerforselfoss import android.app.Activity import android.content.Context +import android.content.DialogInterface import android.content.Intent import android.content.SharedPreferences import android.graphics.Color @@ -10,6 +11,7 @@ import android.net.Uri import android.os.Bundle import android.preference.PreferenceManager import android.support.v4.view.MenuItemCompat +import android.support.v7.app.AlertDialog import android.support.v7.app.AppCompatActivity import android.support.v7.widget.DividerItemDecoration import android.support.v7.widget.GridLayoutManager @@ -1006,78 +1008,92 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { return true } + private fun needsConfirmation(titleRes: Int, messageRes: Int, doFn: () -> Unit) { + AlertDialog.Builder(this@HomeActivity) + .setMessage(messageRes) + .setTitle(titleRes) + .setPositiveButton(android.R.string.ok) { _, _ -> doFn() } + .setNegativeButton(android.R.string.cancel) { _, _ -> } + .create() + .show() + } + override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.refresh -> { - api.update().enqueue(object : Callback { - override fun onResponse( - call: Call, - response: Response - ) { - Toast.makeText( - this@HomeActivity, - R.string.refresh_success_response, Toast.LENGTH_LONG - ) - .show() - } + needsConfirmation(R.string.menu_home_refresh, R.string.refresh_dialog_message, { + api.update().enqueue(object : Callback { + override fun onResponse( + call: Call, + response: Response + ) { + Toast.makeText( + this@HomeActivity, + R.string.refresh_success_response, Toast.LENGTH_LONG + ) + .show() + } - override fun onFailure(call: Call, t: Throwable) { - Toast.makeText( - this@HomeActivity, - R.string.refresh_failer_message, - Toast.LENGTH_SHORT - ).show() - } + override fun onFailure(call: Call, t: Throwable) { + Toast.makeText( + this@HomeActivity, + R.string.refresh_failer_message, + Toast.LENGTH_SHORT + ).show() + } + }) + Toast.makeText(this, R.string.refresh_in_progress, Toast.LENGTH_SHORT).show() }) - Toast.makeText(this, R.string.refresh_in_progress, Toast.LENGTH_SHORT).show() return true } R.id.readAll -> { if (elementsShown == UNREAD_SHOWN) { - swipeRefreshLayout.isRefreshing = false - val ids = items.map { it.id } + needsConfirmation(R.string.readAll, R.string.markall_dialog_message, { + swipeRefreshLayout.isRefreshing = false + val ids = items.map { it.id } - api.readAll(ids).enqueue(object : Callback { - override fun onResponse( - call: Call, - response: Response - ) { - if (response.body() != null && response.body()!!.isSuccess) { - Toast.makeText( - this@HomeActivity, - R.string.all_posts_read, - Toast.LENGTH_SHORT - ).show() - tabNewBadge.removeBadge() - } else { + api.readAll(ids).enqueue(object : Callback { + override fun onResponse( + call: Call, + response: Response + ) { + if (response.body() != null && response.body()!!.isSuccess) { + Toast.makeText( + this@HomeActivity, + R.string.all_posts_read, + Toast.LENGTH_SHORT + ).show() + tabNewBadge.removeBadge() + } else { + Toast.makeText( + this@HomeActivity, + R.string.all_posts_not_read, + Toast.LENGTH_SHORT + ).show() + } + + swipeRefreshLayout.isRefreshing = false + } + + override fun onFailure(call: Call, t: Throwable) { Toast.makeText( this@HomeActivity, R.string.all_posts_not_read, Toast.LENGTH_SHORT ).show() + swipeRefreshLayout.isRefreshing = false } - - swipeRefreshLayout.isRefreshing = false - } - - override fun onFailure(call: Call, t: Throwable) { + }) + items = ArrayList() + if (items.isEmpty()) { Toast.makeText( this@HomeActivity, - R.string.all_posts_not_read, + R.string.nothing_here, Toast.LENGTH_SHORT ).show() - swipeRefreshLayout.isRefreshing = false } + handleListResult() }) - items = ArrayList() - if (items.isEmpty()) { - Toast.makeText( - this@HomeActivity, - R.string.nothing_here, - Toast.LENGTH_SHORT - ).show() - } - handleListResult() } return true } diff --git a/app/src/main/res/values-fr-rFR/strings.xml b/app/src/main/res/values-fr-rFR/strings.xml index e9d429d..ed736ac 100644 --- a/app/src/main/res/values-fr-rFR/strings.xml +++ b/app/src/main/res/values-fr-rFR/strings.xml @@ -163,4 +163,6 @@ Supprimer des favoris Taille du texte du contenu du lecteur d\'articles Lecteur d\'articles + En validant, votre instance Selfoss sera mise à jour. + Marquer tous les éléments comme lus ? diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8b7cc0f..39f16ab 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -166,4 +166,6 @@ Remove from favorites Article reader content font size Article viewer + This will refresh your Selfoss instance. + This will mark all the items as read.