Closes #36
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
aminecmi 2022-08-24 13:34:05 +02:00
parent 34028949d7
commit fb572dbb27
3 changed files with 36 additions and 50 deletions

View File

@ -318,7 +318,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
handleRecurringTask() handleRecurringTask()
handleOfflineActions() CoroutineScope(Dispatchers.Main).launch {
repository.handleDBActions()
}
getElementsAccordingToTab() getElementsAccordingToTab()
} }
@ -1082,26 +1084,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
} }
private fun handleOfflineActions() { private fun handleOfflineActions() {
fun doAndReportOnFail(success: Boolean, action: ACTION) {
if (success) {
thread {
repository.deleteDBAction(action)
}
}
}
CoroutineScope(Dispatchers.Main).launch {
val actions = repository.getDBActions()
actions.forEach { action ->
when {
action.read -> doAndReportOnFail(repository.markAsReadById(action.articleid.toInt()), action)
action.unread -> doAndReportOnFail(repository.unmarkAsReadById(action.articleid.toInt()), action)
action.starred -> doAndReportOnFail(repository.starrById(action.articleid.toInt()), action)
action.unstarred -> doAndReportOnFail(repository.unstarrById(action.articleid.toInt()), action)
}
}
}
} }
} }

View File

@ -56,28 +56,7 @@ override fun doWork(): Result {
val notifyNewItems = settings.getBoolean("notify_new_items", false) val notifyNewItems = settings.getBoolean("notify_new_items", false)
val actions: List<ACTION> = repository.getDBActions() repository.handleDBActions()
actions.forEach { action ->
when {
action.read -> doAndReportOnFail(
repository.markAsReadById(action.articleid.toInt()),
action
)
action.unread -> doAndReportOnFail(
repository.unmarkAsReadById(action.articleid.toInt()),
action
)
action.starred -> doAndReportOnFail(
repository.starrById(action.articleid.toInt()),
action
)
action.unstarred -> doAndReportOnFail(
repository.unstarrById(action.articleid.toInt()),
action
)
}
}
launch { launch {
handleNewItemsNotification(repository.tryToCacheItemsAndGetNewOnes(), notifyNewItems, notificationManager) handleNewItemsNotification(repository.tryToCacheItemsAndGetNewOnes(), notifyNewItems, notificationManager)
@ -134,12 +113,4 @@ override fun doWork(): Result {
} }
} }
} }
private fun doAndReportOnFail(result: Boolean, action: ACTION) {
if (result) {
thread {
repository.deleteDBAction(action)
}
}
}
} }

View File

@ -434,4 +434,36 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
} catch (e: Throwable) {} } catch (e: Throwable) {}
return emptyList() return emptyList()
} }
suspend fun handleDBActions() {
val actions: List<ACTION> = getDBActions()
actions.forEach { action ->
when {
action.read -> doAndReportOnFail(
markAsReadById(action.articleid.toInt()),
action
)
action.unread -> doAndReportOnFail(
unmarkAsReadById(action.articleid.toInt()),
action
)
action.starred -> doAndReportOnFail(
starrById(action.articleid.toInt()),
action
)
action.unstarred -> doAndReportOnFail(
unstarrById(action.articleid.toInt()),
action
)
}
}
}
private fun doAndReportOnFail(result: Boolean, action: ACTION) {
if (result) {
deleteDBAction(action)
}
}
} }