Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Crash when calling get storage volumes on some devices #1072

Merged
merged 3 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ suspend fun Context.convertToUTF8(uri: Uri, charset: Charset? = null): Uri = wit
convertNetworkUriToUTF8(url = url, sourceCharset = detectedCharset)
}
}

else -> {
val detectedCharset = charset ?: detectCharset(uri = uri, context = this@convertToUTF8)
if (detectedCharset == StandardCharsets.UTF_8) {
Expand Down Expand Up @@ -398,5 +399,10 @@ suspend fun ContentResolver.deleteMedia(
}
}

fun Context.getStorageVolumes() = getExternalFilesDirs(null)
.map { File(it.path.substringBefore("/Android")) }
fun Context.getStorageVolumes() = try {
getExternalFilesDirs(null)?.mapNotNull {
File(it.path.substringBefore("/Android")).takeIf { file -> file.exists() }
} ?: listOf(Environment.getExternalStorageDirectory())
} catch (e: Exception) {
listOf(Environment.getExternalStorageDirectory())
}
1 change: 1 addition & 0 deletions core/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,5 @@
<string name="folders">Folders</string>
<string name="tree">Tree</string>
<string name="played_progress">Played progress</string>
<string name="media_view_mode">Media view mode</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fun QuickSettingsDialog(
Column(
modifier = Modifier.verticalScroll(rememberScrollState()),
) {
DialogSectionTitle(text = "Media view mode")
DialogSectionTitle(text = stringResource(R.string.media_view_mode))
SingleChoiceSegmentedButtonRow(
modifier = Modifier.fillMaxWidth(),
) {
Expand Down