Update unread widgets from a background thread
This commit is contained in:
parent
664e444d79
commit
8b5055ec40
4 changed files with 18 additions and 6 deletions
|
@ -22,6 +22,7 @@ dependencies {
|
|||
implementation "androidx.core:core-ktx:${versions.coreKtx}"
|
||||
implementation "com.takisoft.preferencex:preferencex:${versions.preferencesFix}"
|
||||
implementation "com.jakewharton.timber:timber:${versions.timber}"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.kotlinCoroutines}"
|
||||
|
||||
testImplementation "org.robolectric:robolectric:${versions.robolectric}"
|
||||
testImplementation "junit:junit:${versions.junit}"
|
||||
|
|
|
@ -14,6 +14,9 @@ import com.fsck.k9.inject
|
|||
import com.fsck.k9.widget.unread.UnreadWidgetConfigurationActivity
|
||||
import com.fsck.k9.widget.unread.UnreadWidgetData
|
||||
import com.fsck.k9.widget.unread.UnreadWidgetRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
|
@ -28,11 +31,18 @@ class UnreadWidgetProvider : AppWidgetProvider(), EarlyInit {
|
|||
private val repository: UnreadWidgetRepository by inject()
|
||||
|
||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||
val pendingResult = goAsync()
|
||||
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
updateWidgets(context, appWidgetManager, appWidgetIds)
|
||||
pendingResult.finish()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateWidgets(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||
for (widgetId in appWidgetIds) {
|
||||
val widgetData = repository.getWidgetData(widgetId)
|
||||
widgetData?.let {
|
||||
updateWidget(context, appWidgetManager, it)
|
||||
}
|
||||
val widgetData = repository.getWidgetData(widgetId) ?: continue
|
||||
updateWidget(context, appWidgetManager, widgetData)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ dependencies {
|
|||
implementation "net.jcip:jcip-annotations:1.0"
|
||||
implementation "com.jakewharton.timber:timber:${versions.timber}"
|
||||
implementation "org.apache.james:apache-mime4j-core:${versions.mime4j}"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.kotlinCoroutines}"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${versions.kotlinCoroutines}"
|
||||
|
||||
testImplementation project(':mail:testing')
|
||||
testImplementation project(':app:storage')
|
||||
|
|
|
@ -10,6 +10,7 @@ buildscript {
|
|||
|
||||
versions = [
|
||||
'kotlin': '1.3.72',
|
||||
'kotlinCoroutines': '1.3.5',
|
||||
'androidxAppCompat': '1.2.0-beta01',
|
||||
'androidxRecyclerView': '1.1.0',
|
||||
'androidxLifecycle': '2.2.0',
|
||||
|
|
Loading…
Reference in a new issue