From 2781ad3307a0961465be1155c80a2993c73f314b Mon Sep 17 00:00:00 2001 From: Mateus Rodrigues Costa Date: Tue, 12 Nov 2024 18:46:00 -0300 Subject: [PATCH] Disable "Show File Preview" switch when "Skip File Details" is enabled --- .../apps/share2storage/DetailsActivity.kt | 6 ++--- .../share2storage/screens/SettingsScreen.kt | 26 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/DetailsActivity.kt b/app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/DetailsActivity.kt index 5b4f5c0..a468cfc 100644 --- a/app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/DetailsActivity.kt +++ b/app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/DetailsActivity.kt @@ -53,7 +53,7 @@ class DetailsActivity : ComponentActivity() { private var skipFileDetails: Boolean = false private var defaultSaveLocation: Uri? = null - private var showFilePreview: Boolean = true + private var shouldShowFilePreview: Boolean = true private var shouldSkipFilePicker: Boolean = false @@ -116,7 +116,7 @@ class DetailsActivity : ComponentActivity() { val showFilePreview = sharedPreferences.getBoolean(SharedPreferenceKeys.SHOW_FILE_PREVIEW_KEY, true) Log.d("details] showFilePreview", showFilePreview.toString()) - this.showFilePreview = showFilePreview + this.shouldShowFilePreview = !skipFileDetails && showFilePreview val skipFilePicker = sharedPreferences.getBoolean(SharedPreferenceKeys.SKIP_FILE_PICKER, false) @@ -137,7 +137,7 @@ class DetailsActivity : ComponentActivity() { if (fileUri == null) return this.fileUri = fileUri - val uriData = getUriData(contentResolver, fileUri, getPreview = showFilePreview) + val uriData = getUriData(contentResolver, fileUri, getPreview = shouldShowFilePreview) if (uriData == null) return this.uriData = uriData diff --git a/app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/screens/SettingsScreen.kt b/app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/screens/SettingsScreen.kt index 087cb31..f9ce4c2 100644 --- a/app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/screens/SettingsScreen.kt +++ b/app/src/main/kotlin/com/mateusrodcosta/apps/share2storage/screens/SettingsScreen.kt @@ -173,6 +173,7 @@ fun SettingsScreenContent( ShowFilePreviewSetting( updateShowFilePreview = updateShowFilePreview, spShowFilePreview = spShowFilePreview, + spSkipFileDetails = spSkipFileDetails, ) AppBasicDivider() AppListHeader(title = stringResource(R.string.settings_category_intents)) @@ -271,23 +272,26 @@ fun SkipFileDetailsSetting( @Composable fun ShowFilePreviewSetting( + spSkipFileDetails: StateFlow, updateShowFilePreview: (Boolean) -> Unit, spShowFilePreview: StateFlow, ) { + val skipFileDetails by spSkipFileDetails.collectAsState() val showFilePreview by spShowFilePreview.collectAsState() - ListItem(modifier = Modifier.clickable { updateShowFilePreview(!showFilePreview) }, - headlineContent = { - Text(stringResource(R.string.settings_show_file_preview)) - }, - supportingContent = { - Text(stringResource(R.string.settings_show_file_preview_info)) - }, - trailingContent = { - Switch(checked = showFilePreview, onCheckedChange = { value -> - updateShowFilePreview(value) - }) + ListItem(modifier = if (skipFileDetails) Modifier.alpha(Utils.CONTENT_ALPHA_DISABLED) else Modifier.clickable { + updateShowFilePreview( + !showFilePreview + ) + }, headlineContent = { + Text(stringResource(R.string.settings_show_file_preview)) + }, supportingContent = { + Text(stringResource(R.string.settings_show_file_preview_info)) + }, trailingContent = { + Switch(enabled = !skipFileDetails, checked = showFilePreview, onCheckedChange = { value -> + updateShowFilePreview(value) }) + }) } @Composable