Skip to content

Commit ec57fec

Browse files
Merge pull request #16133 from nextcloud/fix/cancel-gallery-thumbnail-generation-when-leave-media-tab
fix: stop running gallery background job when user leave
2 parents a8f66d8 + a1fc5d8 commit ec57fec

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

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

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

43+
fun cancelAllActiveJobs() {
44+
for ((_, job) in activeJobs) {
45+
job.cancel()
46+
}
47+
activeJobs.clear()
48+
}
49+
4350
fun removeActiveJob(imageView: ImageView, job: CoroutineScope) {
4451
if (isActiveJob(imageView, job)) {
4552
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,13 @@ class OCFileListDelegate(
413413

414414
fun cleanup() {
415415
ioScope.cancel()
416+
417+
GalleryImageGenerationJob.cancelAllActiveJobs()
418+
419+
// cancel async tasks from ThumbnailsCacheManager
420+
cancelAllPendingTasks()
421+
422+
Log_OC.d(TAG, "background jobs cancelled")
416423
}
417424

418425
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)