This commit is contained in:
Amine Bou 2018-03-03 16:00:56 +01:00
parent 403ecc4521
commit 320924b4ed
4 changed files with 71 additions and 51 deletions

View File

@ -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'

View File

@ -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,9 +1008,20 @@ 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 -> {
needsConfirmation(R.string.menu_home_refresh, R.string.refresh_dialog_message, {
api.update().enqueue(object : Callback<String> {
override fun onResponse(
call: Call<String>,
@ -1030,10 +1043,12 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
}
})
Toast.makeText(this, R.string.refresh_in_progress, Toast.LENGTH_SHORT).show()
})
return true
}
R.id.readAll -> {
if (elementsShown == UNREAD_SHOWN) {
needsConfirmation(R.string.readAll, R.string.markall_dialog_message, {
swipeRefreshLayout.isRefreshing = false
val ids = items.map { it.id }
@ -1078,6 +1093,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
).show()
}
handleListResult()
})
}
return true
}

View File

@ -163,4 +163,6 @@
<string name="remove_to_favs_reader">Supprimer des favoris</string>
<string name="pref_content_reader_font_size">Taille du texte du contenu du lecteur d\'articles</string>
<string name="pref_header_viewer">Lecteur d\'articles</string>
<string name="refresh_dialog_message">En validant, votre instance Selfoss sera mise à jour.</string>
<string name="markall_dialog_message">Marquer tous les éléments comme lus ?</string>
</resources>

View File

@ -166,4 +166,6 @@
<string name="remove_to_favs_reader">Remove from favorites</string>
<string name="pref_content_reader_font_size">Article reader content font size</string>
<string name="pref_header_viewer">Article viewer</string>
<string name="refresh_dialog_message">This will refresh your Selfoss instance.</string>
<string name="markall_dialog_message">This will mark all the items as read.</string>
</resources>