Skip to content

Commit

Permalink
Disable FFMPEG option, if no plugin installed
Browse files Browse the repository at this point in the history
  • Loading branch information
reocat committed Jan 6, 2025
1 parent 5809f53 commit a8f3d92
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
17 changes: 12 additions & 5 deletions app/src/main/java/com/dd3boh/outertune/ui/component/Preference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ fun <T> ListPreference(
valueText: @Composable (T) -> String,
onValueSelected: (T) -> Unit,
isEnabled: Boolean = true,
disabled: (T) -> Boolean = { false }
) {
var showDialog by remember {
mutableStateOf(false)
Expand All @@ -105,25 +106,29 @@ fun <T> ListPreference(
onDismiss = { showDialog = false }
) {
items(values) { value ->
val isDisabled = disabled(value)
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.clickable {
.clickable(enabled = !isDisabled) {
showDialog = false
onValueSelected(value)
}
.padding(horizontal = 16.dp, vertical = 12.dp)
) {
RadioButton(
selected = value == selectedValue,
onClick = null
onClick = null,
enabled = !isDisabled
)

Text(
text = valueText(value),
style = MaterialTheme.typography.bodyLarge,
modifier = Modifier.padding(start = 16.dp)
modifier = Modifier
.padding(start = 16.dp)
.alpha(if (isDisabled) 0.5f else 1f)
)
}
}
Expand All @@ -149,7 +154,8 @@ inline fun <reified T : Enum<T>> EnumListPreference(
noinline valueText: @Composable (T) -> String,
noinline onValueSelected: (T) -> Unit,
isEnabled: Boolean = true,
values: List<T> = enumValues<T>().toList()
values: List<T> = enumValues<T>().toList(),
noinline disabled: (T) -> Boolean = { false }
) {
ListPreference(
modifier = modifier,
Expand All @@ -159,7 +165,8 @@ inline fun <reified T : Enum<T>> EnumListPreference(
values = values,
valueText = valueText,
onValueSelected = onValueSelected,
isEnabled = isEnabled
isEnabled = isEnabled,
disabled = disabled
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ import kotlinx.coroutines.launch
import java.time.LocalDateTime
import java.time.ZoneOffset

private fun isPackageInstalled(packageName: String, packageManager: PackageManager): Boolean {
return try {
packageManager.getPackageInfo(packageName, 0)
true
} catch (e: PackageManager.NameNotFoundException) {
false
}
}

val MEDIA_PERMISSION_LEVEL =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) Manifest.permission.READ_MEDIA_AUDIO
else Manifest.permission.READ_EXTERNAL_STORAGE
Expand Down Expand Up @@ -536,24 +545,25 @@ fun LocalPlayerSettings(
onCheckedChange = onStrictExtensionsChange
)
// scanner type
if (true) { // todo: detect if ext library is installed
EnumListPreference(
title = { Text(stringResource(R.string.scanner_type_title)) },
icon = { Icon(Icons.Rounded.Speed, null) },
selectedValue = scannerImpl,
onValueSelected = onScannerImplChange,
valueText = {
when (it) {
ScannerImpl.TAGLIB -> stringResource(R.string.scanner_type_taglib)
ScannerImpl.FFMPEG_EXT -> stringResource(R.string.scanner_type_ffmpeg_ext)
}
}
)
val isFFmpegInstalled = remember {
isPackageInstalled("wah.mikooomich.ffMetadataEx", context.packageManager)
}
}



EnumListPreference(
title = { Text(stringResource(R.string.scanner_type_title)) },
icon = { Icon(Icons.Rounded.Speed, null) },
selectedValue = scannerImpl,
onValueSelected = onScannerImplChange,
valueText = {
when (it) {
ScannerImpl.TAGLIB -> stringResource(R.string.scanner_type_taglib)
ScannerImpl.FFMPEG_EXT -> stringResource(R.string.scanner_type_ffmpeg_ext)
}
},
values = ScannerImpl.entries,
disabled = { it == ScannerImpl.FFMPEG_EXT && !isFFmpegInstalled }
)
}

TopAppBar(
title = { Text(stringResource(R.string.local_player_settings_title)) },
Expand Down

0 comments on commit a8f3d92

Please sign in to comment.