You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-07-17 15:47:54 +02:00
fix deletion handling
This commit is contained in:
@ -5,6 +5,7 @@ import android.graphics.Bitmap
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.datastore.preferences.core.Preferences
|
import androidx.datastore.preferences.core.Preferences
|
||||||
import androidx.glance.*
|
import androidx.glance.*
|
||||||
|
import androidx.glance.appwidget.AppWidgetId
|
||||||
import androidx.glance.appwidget.GlanceAppWidgetManager
|
import androidx.glance.appwidget.GlanceAppWidgetManager
|
||||||
import androidx.glance.appwidget.state.updateAppWidgetState
|
import androidx.glance.appwidget.state.updateAppWidgetState
|
||||||
import androidx.work.*
|
import androidx.work.*
|
||||||
@ -74,9 +75,18 @@ class ImageDownloadWorker(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cancel(context: Context, glanceId: GlanceId) {
|
suspend fun cancel(context: Context, appWidgetId: Int) {
|
||||||
val appWidgetId = GlanceAppWidgetManager(context).getAppWidgetId(glanceId)
|
WorkManager.getInstance(context).cancelAllWorkByTag("$uniqueWorkName-$appWidgetId")
|
||||||
WorkManager.getInstance(context).cancelAllWorkByTag(appWidgetId.toString())
|
|
||||||
|
// 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)
|
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)
|
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