From 860338fc5f5feaa9ba50ffab5bc1823990f90afd Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Wed, 20 Feb 2019 22:48:53 +0530 Subject: [PATCH 1/2] Force clean deleted logs from disk - clean up job may not run on devices due to factors mentioned in https://github.com/evernote/android-job/wiki/FAQ#what-happens-with-jobs-after-the-app-was-forced-killed This option hence powrs the user to run the job at the exact moment Signed-off-by: Arka Prava Basu --- src/main/java/org/havenapp/main/ListActivity.java | 7 +++++++ .../org/havenapp/main/service/RemoveDeletedFilesJob.kt | 7 +++++++ src/main/res/menu/menu_main.xml | 7 +++++++ src/main/res/values/strings.xml | 1 + 4 files changed, 22 insertions(+) diff --git a/src/main/java/org/havenapp/main/ListActivity.java b/src/main/java/org/havenapp/main/ListActivity.java index 5bef658d..dc69c1d9 100644 --- a/src/main/java/org/havenapp/main/ListActivity.java +++ b/src/main/java/org/havenapp/main/ListActivity.java @@ -321,6 +321,9 @@ public boolean onOptionsItemSelected (MenuItem item) { case R.id.action_test_notification: testNotifications(); break; + case R.id.action_run_cleanup_job: + runCleanUpJob(); + break; } return true; } @@ -337,6 +340,10 @@ private void removeAllEvents() new EventDeleteAllAsync(() -> onAllEventsRemoved(removedEvents)).execute(removedEvents); } + private void runCleanUpJob() { + RemoveDeletedFilesJob.Companion.runNow(); + } + private void onAllEventsRemoved(List removedEvents) { Snackbar.make(recyclerView, resourceManager.getString(R.string.events_deleted), Snackbar.LENGTH_SHORT) .setAction(resourceManager.getString(R.string.undo), diff --git a/src/main/java/org/havenapp/main/service/RemoveDeletedFilesJob.kt b/src/main/java/org/havenapp/main/service/RemoveDeletedFilesJob.kt index 58f9b65e..c0d69078 100644 --- a/src/main/java/org/havenapp/main/service/RemoveDeletedFilesJob.kt +++ b/src/main/java/org/havenapp/main/service/RemoveDeletedFilesJob.kt @@ -28,6 +28,13 @@ class RemoveDeletedFilesJob: Job() { .build() .schedule() } + + fun runNow(): Int { + return JobRequest.Builder(SERVICE_TAG) + .startNow() + .build() + .schedule() + } } override fun onRunJob(params: Params): Result { diff --git a/src/main/res/menu/menu_main.xml b/src/main/res/menu/menu_main.xml index 32c9caa3..b31f12a1 100644 --- a/src/main/res/menu/menu_main.xml +++ b/src/main/res/menu/menu_main.xml @@ -24,6 +24,13 @@ android:orderInCategory="100" android:title="@string/menu_licenses" app:showAsAction="never" /> + + + Recording... LIGHT DETECTED + Clean deleted logs from disk From d7b725e7fff153bda4230d29681b88d9fc3c02ff Mon Sep 17 00:00:00 2001 From: Arka Prava Basu Date: Wed, 20 Feb 2019 23:07:47 +0530 Subject: [PATCH 2/2] Bug Fix: Fix no files deleted from disk on successful job run - the null check was wrongly implemented Signed-off-by: Arka Prava Basu --- .../java/org/havenapp/main/service/RemoveDeletedFilesJob.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/havenapp/main/service/RemoveDeletedFilesJob.kt b/src/main/java/org/havenapp/main/service/RemoveDeletedFilesJob.kt index c0d69078..f2c3c954 100644 --- a/src/main/java/org/havenapp/main/service/RemoveDeletedFilesJob.kt +++ b/src/main/java/org/havenapp/main/service/RemoveDeletedFilesJob.kt @@ -117,7 +117,9 @@ class RemoveDeletedFilesJob: Job() { if (!storageDir.exists() || !storageDir.isDirectory) return - storageDir.listFiles() ?: currentFileList.addAll(storageDir.listFiles()) + storageDir.listFiles()?.let { + currentFileList.addAll(it) + } val subDir = storageDir.list { dir, name -> File(dir, name).isDirectory } subDir.filter { it != null }.forEach { getAllFileInStorageDir(File(storageDir, it), currentFileList) }