Closes #269.
This commit is contained in:
parent
f1757937a4
commit
6ede718a9f
@ -227,7 +227,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
|||||||
recyclerView: RecyclerView,
|
recyclerView: RecyclerView,
|
||||||
viewHolder: RecyclerView.ViewHolder
|
viewHolder: RecyclerView.ViewHolder
|
||||||
): Int =
|
): Int =
|
||||||
if (elementsShown != UNREAD_SHOWN) {
|
if (elementsShown != UNREAD_SHOWN && elementsShown != READ_SHOWN) {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
super.getSwipeDirs(
|
super.getSwipeDirs(
|
||||||
@ -250,8 +250,8 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
|||||||
val adapter = recyclerView.adapter
|
val adapter = recyclerView.adapter
|
||||||
|
|
||||||
when (adapter) {
|
when (adapter) {
|
||||||
is ItemCardAdapter -> adapter.removeItemAtIndex(position)
|
is ItemCardAdapter -> adapter.handleItemAtIndex(position)
|
||||||
is ItemListAdapter -> adapter.removeItemAtIndex(position)
|
is ItemListAdapter -> adapter.handleItemAtIndex(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
badgeNew--
|
badgeNew--
|
||||||
|
@ -41,7 +41,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
updateItems(items)
|
updateItems(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doUnmark(i: Item, position: Int) {
|
private fun unmarkSnackbar(i: Item, position: Int) {
|
||||||
val s = Snackbar
|
val s = Snackbar
|
||||||
.make(
|
.make(
|
||||||
app.findViewById(R.id.coordLayout),
|
app.findViewById(R.id.coordLayout),
|
||||||
@ -71,12 +71,11 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
}
|
}
|
||||||
notifyItemRemoved(position)
|
notifyItemRemoved(position)
|
||||||
updateItems(items)
|
updateItems(items)
|
||||||
doUnmark(i, position)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
thread {
|
thread {
|
||||||
db.actionsDao().deleteReadActionForArticle(i.id)
|
db.actionsDao().insertAllActions(ActionEntity(i.id, false, true, false, false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,7 +86,62 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
s.show()
|
s.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeItemAtIndex(position: Int) {
|
private fun markSnackbar(i: Item, position: Int) {
|
||||||
|
val s = Snackbar
|
||||||
|
.make(
|
||||||
|
app.findViewById(R.id.coordLayout),
|
||||||
|
R.string.marked_as_unread,
|
||||||
|
Snackbar.LENGTH_LONG
|
||||||
|
)
|
||||||
|
.setAction(R.string.undo_string) {
|
||||||
|
items.add(position, i)
|
||||||
|
thread {
|
||||||
|
db.itemsDao().delete(i.toEntity())
|
||||||
|
}
|
||||||
|
notifyItemInserted(position)
|
||||||
|
updateItems(items)
|
||||||
|
|
||||||
|
if (app.isNetworkAccessible(null)) {
|
||||||
|
api.markItem(i.id).enqueue(object : Callback<SuccessResponse> {
|
||||||
|
override fun onResponse(
|
||||||
|
call: Call<SuccessResponse>,
|
||||||
|
response: Response<SuccessResponse>
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
|
||||||
|
items.remove(i)
|
||||||
|
thread {
|
||||||
|
db.itemsDao().insertAllItems(i.toEntity())
|
||||||
|
}
|
||||||
|
notifyItemRemoved(position)
|
||||||
|
updateItems(items)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
thread {
|
||||||
|
db.actionsDao().insertAllActions(ActionEntity(i.id, true, false, false, false))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val view = s.view
|
||||||
|
val tv: TextView = view.findViewById(com.google.android.material.R.id.snackbar_text)
|
||||||
|
tv.setTextColor(Color.WHITE)
|
||||||
|
s.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun handleItemAtIndex(position: Int) {
|
||||||
|
val i = items[position]
|
||||||
|
|
||||||
|
if (i.unread) {
|
||||||
|
readItemAtIndex(position)
|
||||||
|
} else {
|
||||||
|
unreadItemAtIndex(position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun readItemAtIndex(position: Int) {
|
||||||
val i = items[position]
|
val i = items[position]
|
||||||
items.remove(i)
|
items.remove(i)
|
||||||
notifyItemRemoved(position)
|
notifyItemRemoved(position)
|
||||||
@ -105,7 +159,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
) {
|
) {
|
||||||
if (!response.succeeded() && debugReadingItems) {
|
if (!response.succeeded() && debugReadingItems) {
|
||||||
val message =
|
val message =
|
||||||
"message: ${response.message()} " +
|
"MARK message: ${response.message()} " +
|
||||||
"response isSuccess: ${response.isSuccessful} " +
|
"response isSuccess: ${response.isSuccessful} " +
|
||||||
"response code: ${response.code()} " +
|
"response code: ${response.code()} " +
|
||||||
"response message: ${response.message()} " +
|
"response message: ${response.message()} " +
|
||||||
@ -116,7 +170,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
Toast.makeText(app.baseContext, message, Toast.LENGTH_LONG).show()
|
Toast.makeText(app.baseContext, message, Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
doUnmark(i, position)
|
unmarkSnackbar(i, position)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
|
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
|
||||||
@ -129,7 +183,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
app.getString(R.string.cant_mark_read),
|
app.getString(R.string.cant_mark_read),
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
items.add(i)
|
items.add(position, i)
|
||||||
notifyItemInserted(position)
|
notifyItemInserted(position)
|
||||||
updateItems(items)
|
updateItems(items)
|
||||||
|
|
||||||
@ -141,7 +195,64 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
} else {
|
} else {
|
||||||
thread {
|
thread {
|
||||||
db.actionsDao().insertAllActions(ActionEntity(i.id, true, false, false, false))
|
db.actionsDao().insertAllActions(ActionEntity(i.id, true, false, false, false))
|
||||||
doUnmark(i, position)
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun unreadItemAtIndex(position: Int) {
|
||||||
|
val i = items[position]
|
||||||
|
items.remove(i)
|
||||||
|
notifyItemRemoved(position)
|
||||||
|
updateItems(items)
|
||||||
|
|
||||||
|
thread {
|
||||||
|
db.itemsDao().insertAllItems(i.toEntity())
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app.isNetworkAccessible(null)) {
|
||||||
|
api.unmarkItem(i.id).enqueue(object : Callback<SuccessResponse> {
|
||||||
|
override fun onResponse(
|
||||||
|
call: Call<SuccessResponse>,
|
||||||
|
response: Response<SuccessResponse>
|
||||||
|
) {
|
||||||
|
if (!response.succeeded() && debugReadingItems) {
|
||||||
|
val message =
|
||||||
|
"UNMARK message: ${response.message()} " +
|
||||||
|
"response isSuccess: ${response.isSuccessful} " +
|
||||||
|
"response code: ${response.code()} " +
|
||||||
|
"response message: ${response.message()} " +
|
||||||
|
"response errorBody: ${response.errorBody()?.string()} " +
|
||||||
|
"body success: ${response.body()?.success} " +
|
||||||
|
"body isSuccess: ${response.body()?.isSuccess}"
|
||||||
|
ACRA.getErrorReporter().maybeHandleSilentException(Exception(message), app)
|
||||||
|
Toast.makeText(app.baseContext, message, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
markSnackbar(i, position)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(call: Call<SuccessResponse>, t: Throwable) {
|
||||||
|
if (debugReadingItems) {
|
||||||
|
ACRA.getErrorReporter().maybeHandleSilentException(t, app)
|
||||||
|
Toast.makeText(app.baseContext, t.message, Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
Toast.makeText(
|
||||||
|
app,
|
||||||
|
app.getString(R.string.cant_mark_unread),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
items.add(i)
|
||||||
|
notifyItemInserted(position)
|
||||||
|
updateItems(items)
|
||||||
|
|
||||||
|
thread {
|
||||||
|
db.itemsDao().delete(i.toEntity())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
thread {
|
||||||
|
db.actionsDao().insertAllActions(ActionEntity(i.id, false, true, false, false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
<string name="tab_favs">"Favorites"</string>
|
<string name="tab_favs">"Favorites"</string>
|
||||||
<string name="action_about">"About"</string>
|
<string name="action_about">"About"</string>
|
||||||
<string name="marked_as_read">"Item read"</string>
|
<string name="marked_as_read">"Item read"</string>
|
||||||
|
<string name="marked_as_unread">"Item unread"</string>
|
||||||
<string name="undo_string">"Undo"</string>
|
<string name="undo_string">"Undo"</string>
|
||||||
<string name="addStringNoUrl">"Log in to add sources."</string>
|
<string name="addStringNoUrl">"Log in to add sources."</string>
|
||||||
<string name="cant_get_sources">"Can't get sources list."</string>
|
<string name="cant_get_sources">"Can't get sources list."</string>
|
||||||
@ -82,6 +83,7 @@
|
|||||||
<string name="card_height_off">Card height will be fixed</string>
|
<string name="card_height_off">Card height will be fixed</string>
|
||||||
<string name="source_code">Source code</string>
|
<string name="source_code">Source code</string>
|
||||||
<string name="cant_mark_read">Can\'t mark article as read</string>
|
<string name="cant_mark_read">Can\'t mark article as read</string>
|
||||||
|
<string name="cant_mark_unread">Can\'t mark article as unread</string>
|
||||||
<string name="drawer_error_loading_tags">Error loading tags…</string>
|
<string name="drawer_error_loading_tags">Error loading tags…</string>
|
||||||
<string name="drawer_error_loading_sources">Error loading sources…</string>
|
<string name="drawer_error_loading_sources">Error loading sources…</string>
|
||||||
<string name="drawer_item_filters">Filters</string>
|
<string name="drawer_item_filters">Filters</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user