chore/sonarqube-fixes #35
@ -318,7 +318,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
||||
|
||||
handleRecurringTask()
|
||||
|
||||
handleOfflineActions()
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
repository.handleDBActions()
|
||||
}
|
||||
|
||||
getElementsAccordingToTab()
|
||||
}
|
||||
@ -1082,26 +1084,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,28 +56,7 @@ override fun doWork(): Result {
|
||||
|
||||
val notifyNewItems = settings.getBoolean("notify_new_items", false)
|
||||
|
||||
val actions: List<ACTION> = 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
|
||||
)
|
||||
}
|
||||
}
|
||||
repository.handleDBActions()
|
||||
|
||||
launch {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -434,4 +434,36 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
||||
} catch (e: Throwable) {}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user