sendSyncWorkerCompletionBroadcast

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-12-12 15:29:54 +01:00 committed by Alper Öztürk
parent fe30406964
commit a474948118
2 changed files with 24 additions and 1 deletions

View file

@ -32,6 +32,8 @@ class SyncWorker(
const val FILE_PATHS = "FILE_PATHS"
const val TOP_PARENT_PATH = "TOP_PARENT_PATH"
const val SYNC_WORKER_COMPLETION_BROADCAST = "SYNC_WORKER_COMPLETION_BROADCAST"
const val FILE_DOWNLOAD_COMPLETION_BROADCAST = "FILE_DOWNLOAD_COMPLETION_BROADCAST"
const val FILE_PATH = "FILE_PATH"
@ -94,13 +96,13 @@ class SyncWorker(
}
}
// TODO add cancel only one file download
withContext(Dispatchers.Main) {
notificationManager.showCompletionMessage(result)
}
if (result) {
downloadingFilePaths.remove(topParentPath)
sendSyncWorkerCompletionBroadcast()
Log_OC.d(TAG, "SyncWorker completed")
Result.success()
} else {
@ -117,4 +119,9 @@ class SyncWorker(
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
}
private fun sendSyncWorkerCompletionBroadcast() {
val intent = Intent(SYNC_WORKER_COMPLETION_BROADCAST)
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
}
}

View file

@ -200,12 +200,28 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
setHasStableIds(true);
registerSyncWorkerCompletionReceiver();
registerFileDownloadCompletionReceiver();
// initialise thumbnails cache on background thread
new ThumbnailsCacheManager.InitDiskCacheTask().execute();
}
private void registerSyncWorkerCompletionReceiver() {
LocalBroadcastManager
.getInstance(activity)
.registerReceiver(syncWorkerCompletionReceiver, new IntentFilter(SyncWorker.SYNC_WORKER_COMPLETION_BROADCAST));
}
private final BroadcastReceiver syncWorkerCompletionReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (activity instanceof FileDisplayActivity fda) {
fda.refreshList();
}
}
};
private void registerFileDownloadCompletionReceiver() {
LocalBroadcastManager
.getInstance(activity)