Fixes #180.
This commit is contained in:
parent
403ecc4521
commit
320924b4ed
@ -117,7 +117,7 @@ dependencies {
|
|||||||
|
|
||||||
|
|
||||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
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
|
// Android Support
|
||||||
compile 'com.android.support:appcompat-v7:27.0.2'
|
compile 'com.android.support:appcompat-v7:27.0.2'
|
||||||
|
@ -2,6 +2,7 @@ package apps.amine.bou.readerforselfoss
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.DialogInterface
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
@ -10,6 +11,7 @@ import android.net.Uri
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.preference.PreferenceManager
|
import android.preference.PreferenceManager
|
||||||
import android.support.v4.view.MenuItemCompat
|
import android.support.v4.view.MenuItemCompat
|
||||||
|
import android.support.v7.app.AlertDialog
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.support.v7.widget.DividerItemDecoration
|
import android.support.v7.widget.DividerItemDecoration
|
||||||
import android.support.v7.widget.GridLayoutManager
|
import android.support.v7.widget.GridLayoutManager
|
||||||
@ -1006,78 +1008,92 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
|||||||
return true
|
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 {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.refresh -> {
|
R.id.refresh -> {
|
||||||
api.update().enqueue(object : Callback<String> {
|
needsConfirmation(R.string.menu_home_refresh, R.string.refresh_dialog_message, {
|
||||||
override fun onResponse(
|
api.update().enqueue(object : Callback<String> {
|
||||||
call: Call<String>,
|
override fun onResponse(
|
||||||
response: Response<String>
|
call: Call<String>,
|
||||||
) {
|
response: Response<String>
|
||||||
Toast.makeText(
|
) {
|
||||||
this@HomeActivity,
|
Toast.makeText(
|
||||||
R.string.refresh_success_response, Toast.LENGTH_LONG
|
this@HomeActivity,
|
||||||
)
|
R.string.refresh_success_response, Toast.LENGTH_LONG
|
||||||
.show()
|
)
|
||||||
}
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onFailure(call: Call<String>, t: Throwable) {
|
override fun onFailure(call: Call<String>, t: Throwable) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this@HomeActivity,
|
this@HomeActivity,
|
||||||
R.string.refresh_failer_message,
|
R.string.refresh_failer_message,
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).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
|
return true
|
||||||
}
|
}
|
||||||
R.id.readAll -> {
|
R.id.readAll -> {
|
||||||
if (elementsShown == UNREAD_SHOWN) {
|
if (elementsShown == UNREAD_SHOWN) {
|
||||||
swipeRefreshLayout.isRefreshing = false
|
needsConfirmation(R.string.readAll, R.string.markall_dialog_message, {
|
||||||
val ids = items.map { it.id }
|
swipeRefreshLayout.isRefreshing = false
|
||||||
|
val ids = items.map { it.id }
|
||||||
|
|
||||||
api.readAll(ids).enqueue(object : Callback<SuccessResponse> {
|
api.readAll(ids).enqueue(object : Callback<SuccessResponse> {
|
||||||
override fun onResponse(
|
override fun onResponse(
|
||||||
call: Call<SuccessResponse>,
|
call: Call<SuccessResponse>,
|
||||||
response: Response<SuccessResponse>
|
response: Response<SuccessResponse>
|
||||||
) {
|
) {
|
||||||
if (response.body() != null && response.body()!!.isSuccess) {
|
if (response.body() != null && response.body()!!.isSuccess) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this@HomeActivity,
|
this@HomeActivity,
|
||||||
R.string.all_posts_read,
|
R.string.all_posts_read,
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
tabNewBadge.removeBadge()
|
tabNewBadge.removeBadge()
|
||||||
} else {
|
} else {
|
||||||
|
Toast.makeText(
|
||||||
|
this@HomeActivity,
|
||||||
|
R.string.all_posts_not_read,
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
swipeRefreshLayout.isRefreshing = false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this@HomeActivity,
|
this@HomeActivity,
|
||||||
R.string.all_posts_not_read,
|
R.string.all_posts_not_read,
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
|
swipeRefreshLayout.isRefreshing = false
|
||||||
}
|
}
|
||||||
|
})
|
||||||
swipeRefreshLayout.isRefreshing = false
|
items = ArrayList()
|
||||||
}
|
if (items.isEmpty()) {
|
||||||
|
|
||||||
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
|
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this@HomeActivity,
|
this@HomeActivity,
|
||||||
R.string.all_posts_not_read,
|
R.string.nothing_here,
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).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
|
return true
|
||||||
}
|
}
|
||||||
|
@ -163,4 +163,6 @@
|
|||||||
<string name="remove_to_favs_reader">Supprimer des favoris</string>
|
<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_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="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>
|
</resources>
|
||||||
|
@ -166,4 +166,6 @@
|
|||||||
<string name="remove_to_favs_reader">Remove from favorites</string>
|
<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_content_reader_font_size">Article reader content font size</string>
|
||||||
<string name="pref_header_viewer">Article viewer</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>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user