Compare commits
No commits in common. "dec620a40947d699914804fbc218605a0a6dddd3" and "33333ca9982b303a6815dfb7ce1a4ddfe8d265bb" have entirely different histories.
dec620a409
...
33333ca998
@ -1074,7 +1074,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
|
|
||||||
if (this@HomeActivity.isNetworkAvailable(null, offlineShortcut)) {
|
if (this@HomeActivity.isNetworkAvailable(null, offlineShortcut)) {
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
val success = repository.markAllAsRead(items)
|
val success = repository.markAllAsRead(items.map { it.id })
|
||||||
if (success) {
|
if (success) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
this@HomeActivity,
|
this@HomeActivity,
|
||||||
@ -1153,10 +1153,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
|
|
||||||
actions.forEach { action ->
|
actions.forEach { action ->
|
||||||
when {
|
when {
|
||||||
action.read -> doAndReportOnFail(repository.markAsReadById(action.articleId.toInt()), action)
|
action.read -> doAndReportOnFail(repository.markAsRead(action.articleId.toInt()), action)
|
||||||
action.unread -> doAndReportOnFail(repository.unmarkAsReadById(action.articleId.toInt()), action)
|
action.unread -> doAndReportOnFail(repository.markAsRead(action.articleId.toInt()), action)
|
||||||
action.starred -> doAndReportOnFail(repository.starrById(action.articleId.toInt()), action)
|
action.starred -> doAndReportOnFail(repository.markAsRead(action.articleId.toInt()), action)
|
||||||
action.unstarred -> doAndReportOnFail(repository.unstarrById(action.articleId.toInt()), action)
|
action.unstarred -> doAndReportOnFail(repository.markAsRead(action.articleId.toInt()), action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ class ReaderActivity : AppCompatActivity(), DIAware {
|
|||||||
private fun readItem(item: SelfossModel.Item) {
|
private fun readItem(item: SelfossModel.Item) {
|
||||||
if (markOnScroll) {
|
if (markOnScroll) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.markAsRead(item)
|
repository.markAsRead(item.id)
|
||||||
// TODO: Handle failure
|
// TODO: Handle failure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,13 +207,13 @@ class ReaderActivity : AppCompatActivity(), DIAware {
|
|||||||
R.id.star -> {
|
R.id.star -> {
|
||||||
if (allItems[binding.pager.currentItem].starred) {
|
if (allItems[binding.pager.currentItem].starred) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.unstarr(allItems[binding.pager.currentItem])
|
repository.unstarr(allItems[binding.pager.currentItem].id)
|
||||||
// TODO: Handle failure
|
// TODO: Handle failure
|
||||||
}
|
}
|
||||||
afterUnsave()
|
afterUnsave()
|
||||||
} else {
|
} else {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.starr(allItems[binding.pager.currentItem])
|
repository.starr(allItems[binding.pager.currentItem].id)
|
||||||
// TODO: Handle failure
|
// TODO: Handle failure
|
||||||
}
|
}
|
||||||
afterSave()
|
afterSave()
|
||||||
|
@ -113,14 +113,14 @@ class ItemCardAdapter(
|
|||||||
if (c.isNetworkAvailable()) {
|
if (c.isNetworkAvailable()) {
|
||||||
if (item.starred) {
|
if (item.starred) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.unstarr(item)
|
repository.unstarr(item.id)
|
||||||
// TODO: Handle failure
|
// TODO: Handle failure
|
||||||
}
|
}
|
||||||
item.starred = false
|
item.starred = false
|
||||||
binding.favButton.isSelected = false
|
binding.favButton.isSelected = false
|
||||||
} else {
|
} else {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.starr(item)
|
repository.starr(item.id)
|
||||||
// TODO: Handle failure
|
// TODO: Handle failure
|
||||||
}
|
}
|
||||||
item.starred = true
|
item.starred = true
|
||||||
|
@ -79,7 +79,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
private fun readItemAtIndex(position: Int, showSnackbar: Boolean = true) {
|
private fun readItemAtIndex(position: Int, showSnackbar: Boolean = true) {
|
||||||
val i = items[position]
|
val i = items[position]
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.markAsRead(i)
|
repository.markAsRead(i.id)
|
||||||
}
|
}
|
||||||
if (repository.displayedItems == ItemType.UNREAD) {
|
if (repository.displayedItems == ItemType.UNREAD) {
|
||||||
items.remove(i)
|
items.remove(i)
|
||||||
@ -95,7 +95,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
|
|||||||
|
|
||||||
private fun unreadItemAtIndex(position: Int, showSnackbar: Boolean = true) {
|
private fun unreadItemAtIndex(position: Int, showSnackbar: Boolean = true) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.unmarkAsRead(items[position])
|
repository.unmarkAsRead(items[position].id)
|
||||||
// Todo: SharedItems.unreadItem(app, api, db, items[position])
|
// Todo: SharedItems.unreadItem(app, api, db, items[position])
|
||||||
// TODO: update db
|
// TODO: update db
|
||||||
|
|
||||||
|
@ -76,19 +76,19 @@ override fun doWork(): Result {
|
|||||||
actions.forEach { action ->
|
actions.forEach { action ->
|
||||||
when {
|
when {
|
||||||
action.read -> doAndReportOnFail(
|
action.read -> doAndReportOnFail(
|
||||||
repository.markAsReadById(action.articleId.toInt()),
|
repository.markAsRead(action.articleId.toInt()),
|
||||||
action
|
action
|
||||||
)
|
)
|
||||||
action.unread -> doAndReportOnFail(
|
action.unread -> doAndReportOnFail(
|
||||||
repository.unmarkAsReadById(action.articleId.toInt()),
|
repository.unmarkAsRead(action.articleId.toInt()),
|
||||||
action
|
action
|
||||||
)
|
)
|
||||||
action.starred -> doAndReportOnFail(
|
action.starred -> doAndReportOnFail(
|
||||||
repository.starrById(action.articleId.toInt()),
|
repository.starr(action.articleId.toInt()),
|
||||||
action
|
action
|
||||||
)
|
)
|
||||||
action.unstarred -> doAndReportOnFail(
|
action.unstarred -> doAndReportOnFail(
|
||||||
repository.unstarrById(action.articleId.toInt()),
|
repository.unstarr(action.articleId.toInt()),
|
||||||
action
|
action
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
R.id.unread_action -> if (context != null) {
|
R.id.unread_action -> if (context != null) {
|
||||||
if (this@ArticleFragment.item.unread) {
|
if (this@ArticleFragment.item.unread) {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.markAsRead(this@ArticleFragment.item)
|
repository.markAsRead(this@ArticleFragment.item.id)
|
||||||
}
|
}
|
||||||
this@ArticleFragment.item.unread = false
|
this@ArticleFragment.item.unread = false
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
@ -179,7 +179,7 @@ class ArticleFragment : Fragment(), DIAware {
|
|||||||
).show()
|
).show()
|
||||||
} else {
|
} else {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
repository.unmarkAsRead(this@ArticleFragment.item)
|
repository.unmarkAsRead(this@ArticleFragment.item.id)
|
||||||
}
|
}
|
||||||
this@ArticleFragment.item.unread = true
|
this@ArticleFragment.item.unread = true
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
|
@ -121,70 +121,54 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
|||||||
return api.sources()
|
return api.sources()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun markAsRead(item: SelfossModel.Item): Boolean {
|
suspend fun markAsRead(id: Int): Boolean {
|
||||||
// TODO: Check internet connection
|
// TODO: Check internet connection
|
||||||
val success = markAsReadById(item.id)
|
val success = api.markAsRead(id.toString())?.isSuccess == true
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
markAsReadLocally(item)
|
markAsReadLocally(items.first {it.id == id})
|
||||||
}
|
}
|
||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun markAsReadById(id: Int): Boolean {
|
suspend fun unmarkAsRead(id: Int): Boolean {
|
||||||
// TODO: Check internet connection
|
// TODO: Check internet connection
|
||||||
return api.markAsRead(id.toString())?.isSuccess == true
|
val success = api.unmarkAsRead(id.toString())?.isSuccess == true
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun unmarkAsRead(item: SelfossModel.Item): Boolean {
|
|
||||||
val success = unmarkAsReadById(item.id)
|
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
unmarkAsReadLocally(item)
|
unmarkAsReadLocally(items.first {it.id == id})
|
||||||
}
|
}
|
||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun unmarkAsReadById(id: Int): Boolean {
|
suspend fun starr(id: Int): Boolean {
|
||||||
// TODO: Check internet connection
|
|
||||||
return api.unmarkAsRead(id.toString())?.isSuccess == true
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun starr(item: SelfossModel.Item): Boolean {
|
|
||||||
val success = starrById(item.id)
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
starrLocally(item)
|
|
||||||
}
|
|
||||||
return success
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun starrById(id: Int): Boolean {
|
|
||||||
// TODO: Check success, store in DB
|
// TODO: Check success, store in DB
|
||||||
return api.starr(id.toString())?.isSuccess == true
|
val success = api.starr(id.toString())?.isSuccess == true
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun unstarr(item: SelfossModel.Item): Boolean {
|
|
||||||
val success = unstarrById(item.id)
|
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
unstarrLocally(item)
|
starrLocally(items.first {it.id == id})
|
||||||
}
|
}
|
||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun unstarrById(id: Int): Boolean {
|
suspend fun unstarr(id: Int): Boolean {
|
||||||
// TODO: Check internet connection
|
// TODO: Check internet connection
|
||||||
return api.unstarr(id.toString())?.isSuccess == true
|
val success = api.unstarr(id.toString())?.isSuccess == true
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
unstarrLocally(items.first {it.id == id})
|
||||||
|
}
|
||||||
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun markAllAsRead(items: ArrayList<SelfossModel.Item>): Boolean {
|
suspend fun markAllAsRead(ids: List<Int>): Boolean {
|
||||||
// TODO: Check Internet connectivity, store in DB
|
// TODO: Check Internet connectivity, store in DB
|
||||||
|
|
||||||
val success = api.markAllAsRead(items.map { it.id.toString() })?.isSuccess == true
|
val success = api.markAllAsRead(ids.map { it.toString() })?.isSuccess == true
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
for (item in items) {
|
val itemsToMark = items.filter { it.id in ids }
|
||||||
|
for (item in itemsToMark) {
|
||||||
markAsReadLocally(item)
|
markAsReadLocally(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user