Skip to content

Commit

Permalink
Fixed app crashing when deleting cache/download
Browse files Browse the repository at this point in the history
  • Loading branch information
tom5079 committed Aug 4, 2020
1 parent 3e657bd commit 6ebc386
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {
minSdkVersion 16
targetSdkVersion 29
versionCode 57
versionName "4.20"
versionName "4.20-hotfix1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
Expand Down
2 changes: 1 addition & 1 deletion app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"filters": [],
"properties": [],
"versionCode": 57,
"versionName": "4.20",
"versionName": "4.20-hotfix1",
"enabled": true,
"outputFile": "app-release.apk"
}
Expand Down
22 changes: 13 additions & 9 deletions app/src/main/java/xyz/quaver/pupil/ui/fragment/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SettingsFragment :
return getString(R.string.settings_storage_usage,
Runtime.getRuntime().exec("du -hs " + dir.absolutePath).let {
BufferedReader(InputStreamReader(it.inputStream)).use { reader ->
reader.readLine().split('\t').firstOrNull() ?: "0"
reader.readLine()?.split('\t')?.firstOrNull() ?: "0"
}
}
)
Expand All @@ -106,11 +106,13 @@ class SettingsFragment :
if (dir.exists())
dir.deleteRecursively()

CoroutineScope(Dispatchers.IO).launch {
summary = getString(R.string.settings_storage_usage_loading)
summary = getString(R.string.settings_storage_usage_loading)

launch(Dispatchers.Main) {
this@with.summary = getDirSize(dir)
CoroutineScope(Dispatchers.IO).launch {
getDirSize(dir).let {
launch(Dispatchers.Main) {
this@with.summary = getDirSize(dir)
}
}
}
}
Expand All @@ -127,11 +129,13 @@ class SettingsFragment :
if (dir.exists())
dir.deleteRecursively()

CoroutineScope(Dispatchers.IO).launch {
summary = getString(R.string.settings_storage_usage_loading)
summary = getString(R.string.settings_storage_usage_loading)

launch(Dispatchers.Main) {
this@with.summary = getDirSize(dir)
CoroutineScope(Dispatchers.IO).launch {
getDirSize(dir).let {
launch(Dispatchers.Main) {
this@with.summary = getDirSize(dir)
}
}
}
}
Expand Down

0 comments on commit 6ebc386

Please sign in to comment.