chore/sonarqube-fixes #35

Merged
AmineB merged 8 commits from chore/sonarqube-fixes into master 2022-08-24 12:37:37 +00:00
3 changed files with 36 additions and 50 deletions
Showing only changes of commit fb572dbb27 - Show all commits

View File

@ -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)
}
}
}
}
}

View File

@ -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)
}
}
}
}

View File

@ -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)
}
}
}