You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-07-17 10:57:44 +02:00
fix deletion handling
This commit is contained in:
@ -5,6 +5,7 @@ import android.graphics.Bitmap
|
||||
import android.util.Log
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.glance.*
|
||||
import androidx.glance.appwidget.AppWidgetId
|
||||
import androidx.glance.appwidget.GlanceAppWidgetManager
|
||||
import androidx.glance.appwidget.state.updateAppWidgetState
|
||||
import androidx.work.*
|
||||
@ -74,9 +75,18 @@ class ImageDownloadWorker(
|
||||
)
|
||||
}
|
||||
|
||||
fun cancel(context: Context, glanceId: GlanceId) {
|
||||
val appWidgetId = GlanceAppWidgetManager(context).getAppWidgetId(glanceId)
|
||||
WorkManager.getInstance(context).cancelAllWorkByTag(appWidgetId.toString())
|
||||
suspend fun cancel(context: Context, appWidgetId: Int) {
|
||||
WorkManager.getInstance(context).cancelAllWorkByTag("$uniqueWorkName-$appWidgetId")
|
||||
|
||||
// delete cached image
|
||||
val glanceId = GlanceAppWidgetManager(context).getGlanceIdBy(appWidgetId)
|
||||
val widgetConfig = getAppWidgetState(context, PreferencesGlanceStateDefinition, glanceId)
|
||||
val currentImgUUID = widgetConfig[kImageUUID]
|
||||
|
||||
if (!currentImgUUID.isNullOrEmpty()) {
|
||||
val file = File(context.cacheDir, imageFilename(currentImgUUID))
|
||||
file.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,5 +42,14 @@ class MemoryReceiver : GlanceAppWidgetReceiver() {
|
||||
|
||||
super.onReceive(context, intent)
|
||||
}
|
||||
|
||||
override fun onDeleted(context: Context, appWidgetIds: IntArray) {
|
||||
super.onDeleted(context, appWidgetIds)
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
appWidgetIds.forEach { id ->
|
||||
ImageDownloadWorker.cancel(context, id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,9 +120,4 @@ class PhotoWidget : GlanceAppWidget() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun onDelete(context: Context, glanceId: GlanceId) {
|
||||
super.onDelete(context, glanceId)
|
||||
ImageDownloadWorker.cancel(context, glanceId)
|
||||
}
|
||||
}
|
||||
|
@ -42,5 +42,13 @@ class RandomReceiver : GlanceAppWidgetReceiver() {
|
||||
|
||||
super.onReceive(context, intent)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDeleted(context: Context, appWidgetIds: IntArray) {
|
||||
super.onDeleted(context, appWidgetIds)
|
||||
CoroutineScope(Dispatchers.Default).launch {
|
||||
appWidgetIds.forEach { id ->
|
||||
ImageDownloadWorker.cancel(context, id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user