Skip to content

Commit 1ba8b80

Browse files
committed
fix: stop running gallery background job when user leave
Signed-off-by: alperozturk <[email protected]>
1 parent a8f66d8 commit 1ba8b80

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

app/src/main/java/com/nextcloud/client/jobs/gallery/GalleryImageGenerationJob.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class GalleryImageGenerationJob(private val user: User, private val storageManag
4040
)
4141
private val activeJobs = WeakHashMap<ImageView, Job>()
4242

43+
fun getActiveJobs(): WeakHashMap<ImageView, Job> = activeJobs
44+
4345
fun removeActiveJob(imageView: ImageView, job: CoroutineScope) {
4446
if (isActiveJob(imageView, job)) {
4547
removeJob(imageView)

app/src/main/java/com/owncloud/android/ui/adapter/GalleryAdapter.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,8 @@ class GalleryAdapter(
372372
override fun setHighlightedItem(file: OCFile) = Unit
373373

374374
override fun setSortOrder(mFile: OCFile, sortOrder: FileSortOrder) = Unit
375+
376+
fun cleanup() {
377+
ocFileListDelegate.cleanup()
378+
}
375379
}

app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,19 @@ class OCFileListDelegate(
413413

414414
fun cleanup() {
415415
ioScope.cancel()
416+
417+
val activeJobs = GalleryImageGenerationJob.getActiveJobs()
418+
419+
// Cancel all pending thumbnail/generation jobs for gallery images
420+
for ((_, job) in activeJobs) {
421+
job.cancel()
422+
}
423+
activeJobs.clear()
424+
425+
// cancel async tasks from ThumbnailsCacheManager
426+
cancelAllPendingTasks()
427+
428+
Log_OC.d(TAG, "background jobs cancelled")
416429
}
417430

418431
companion object {

app/src/main/java/com/owncloud/android/ui/fragment/GalleryFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public static void setLastMediaItemPosition(Integer position) {
120120
public void onDestroyView() {
121121
LocalBroadcastManager.getInstance(requireContext()).unregisterReceiver(refreshSearchEventReceiver);
122122
setLastMediaItemPosition(null);
123+
mAdapter.cleanup();
123124
super.onDestroyView();
124125
}
125126

0 commit comments

Comments
 (0)