Skip to content

Commit

Permalink
Merge pull request #378 from archie94/force_cleanup
Browse files Browse the repository at this point in the history
 Force clean deleted logs from disk & Bug Fix
  • Loading branch information
n8fr8 authored Mar 8, 2019
2 parents 9e06319 + d7b725e commit 8910374
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/java/org/havenapp/main/ListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -337,6 +340,10 @@ private void removeAllEvents()
new EventDeleteAllAsync(() -> onAllEventsRemoved(removedEvents)).execute(removedEvents);
}

private void runCleanUpJob() {
RemoveDeletedFilesJob.Companion.runNow();
}

private void onAllEventsRemoved(List<Event> removedEvents) {
Snackbar.make(recyclerView, resourceManager.getString(R.string.events_deleted), Snackbar.LENGTH_SHORT)
.setAction(resourceManager.getString(R.string.undo),
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/havenapp/main/service/RemoveDeletedFilesJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -110,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) }
Expand Down
7 changes: 7 additions & 0 deletions src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
android:orderInCategory="100"
android:title="@string/menu_licenses"
app:showAsAction="never" />

<item
android:id="@+id/action_run_cleanup_job"
android:title="@string/run_disk_cleanup"
android:orderInCategory="2"
app:showAsAction="never"/>

<item
android:id="@+id/action_remove_all_events"
android:title="@string/remove_all_logs"
Expand Down
1 change: 1 addition & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,6 @@

<string name="status_recording_video">Recording…</string>
<string name="status_light">LIGHT DETECTED</string>
<string name="run_disk_cleanup">Clean deleted logs from disk</string>

</resources>

0 comments on commit 8910374

Please sign in to comment.