Skip to content

Commit

Permalink
Disable "Show File Preview" switch when "Skip File Details" is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
MateusRodCosta committed Nov 12, 2024
1 parent 06a5f57 commit 2781ad3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ fun SettingsScreenContent(
ShowFilePreviewSetting(
updateShowFilePreview = updateShowFilePreview,
spShowFilePreview = spShowFilePreview,
spSkipFileDetails = spSkipFileDetails,
)
AppBasicDivider()
AppListHeader(title = stringResource(R.string.settings_category_intents))
Expand Down Expand Up @@ -271,23 +272,26 @@ fun SkipFileDetailsSetting(

@Composable
fun ShowFilePreviewSetting(
spSkipFileDetails: StateFlow<Boolean>,
updateShowFilePreview: (Boolean) -> Unit,
spShowFilePreview: StateFlow<Boolean>,
) {
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
Expand Down

0 comments on commit 2781ad3

Please sign in to comment.