Skip to content

Commit

Permalink
style: Fix codestyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyKunitsky committed Nov 29, 2022
1 parent e52b424 commit d54e41d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 70 deletions.
142 changes: 76 additions & 66 deletions sample/src/main/java/ru/bartwell/exfilepickersample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
Expand Down Expand Up @@ -40,6 +43,7 @@ class MainActivity : ComponentActivity() {
}
}

@Suppress("LongMethod")
@Composable
private fun ScreenContent() {
val radioOptions = listOf(
Expand Down Expand Up @@ -74,43 +78,53 @@ private fun ScreenContent() {
.verticalScroll(scrollState),
) {
CheckBoxItem(
title = stringResource(R.string.only_one_item), onCheckedChange = { onlyOneCheckboxState.value = it },
title = stringResource(R.string.only_one_item),
onCheckedChange = { onlyOneCheckboxState.value = it },
isChecked = onlyOneCheckboxState.value
)
CheckBoxItem(
title = stringResource(R.string.filter_listed), onCheckedChange = { filterListedCheckboxState.value = it },
title = stringResource(R.string.filter_listed),
onCheckedChange = { filterListedCheckboxState.value = it },
isChecked = filterListedCheckboxState.value
)
CheckBoxItem(
title = stringResource(R.string.filter_exclude), onCheckedChange = { filterExcludeCheckboxState.value = it },
title = stringResource(R.string.filter_exclude),
onCheckedChange = { filterExcludeCheckboxState.value = it },
isChecked = filterExcludeCheckboxState.value
)
CheckBoxItem(
title = stringResource(R.string.disable_new_folder_button), onCheckedChange = { newFolderCheckboxState.value = it },
title = stringResource(R.string.disable_new_folder_button),
onCheckedChange = { newFolderCheckboxState.value = it },
isChecked = newFolderCheckboxState.value
)
CheckBoxItem(
title = stringResource(R.string.disable_sort_button), onCheckedChange = { disableSortCheckboxState.value = it },
title = stringResource(R.string.disable_sort_button),
onCheckedChange = { disableSortCheckboxState.value = it },
isChecked = disableSortCheckboxState.value
)
CheckBoxItem(
title = stringResource(R.string.enable_quit_button), onCheckedChange = { enableQuitCheckboxState.value = it },
title = stringResource(R.string.enable_quit_button),
onCheckedChange = { enableQuitCheckboxState.value = it },
isChecked = enableQuitCheckboxState.value
)
CheckBoxItem(
title = stringResource(R.string.reverse_sorting), onCheckedChange = { reverseSortingCheckboxState.value = it },
title = stringResource(R.string.reverse_sorting),
onCheckedChange = { reverseSortingCheckboxState.value = it },
isChecked = reverseSortingCheckboxState.value
)
CheckBoxItem(
title = stringResource(R.string.start_from_root), onCheckedChange = { startFromRootCheckboxState.value = it },
title = stringResource(R.string.start_from_root),
onCheckedChange = { startFromRootCheckboxState.value = it },
isChecked = startFromRootCheckboxState.value
)
CheckBoxItem(
title = stringResource(R.string.first_item_as_up), onCheckedChange = { firstItemAsUpCheckboxState.value = it },
title = stringResource(R.string.first_item_as_up),
onCheckedChange = { firstItemAsUpCheckboxState.value = it },
isChecked = firstItemAsUpCheckboxState.value
)
CheckBoxItem(
title = stringResource(R.string.hide_hidden_files), onCheckedChange = { hideHiddenFilesCheckboxState.value = it },
title = stringResource(R.string.hide_hidden_files),
onCheckedChange = { hideHiddenFilesCheckboxState.value = it },
isChecked = hideHiddenFilesCheckboxState.value
)

Expand All @@ -120,73 +134,69 @@ private fun ScreenContent() {
)
radioOptions.forEach { text ->
RadioButtonItem(
selected = (text == selectedOption),
selected = text == selectedOption,
title = text,
onSelectedChange = {
onOptionSelected(text)
}
)
}

Box(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 20.dp, vertical = 20.dp)
Button(
onClick = { showPickerState.value = true },
Modifier.padding(horizontal = 20.dp, vertical = 0.dp)
) {
Button(onClick = { showPickerState.value = true }) {
Text(text = stringResource(R.string.choose_files))
Text(text = stringResource(R.string.choose_files))
}
if (showPickerState.value) {
val onlyExtensions = if (filterListedCheckboxState.value) {
arrayOf("*.jpeg", "*.jpg")
} else {
emptyArray()
}
if (showPickerState.value) {
val onlyExtensions = if (filterListedCheckboxState.value) {
arrayOf("*.jpeg", "*.jpg")
} else {
emptyArray()
}
val exceptExtensions = if (filterExcludeCheckboxState.value) {
arrayOf("*.jpg")
} else {
emptyArray()
}
val sortingType = if (reverseSortingCheckboxState.value) {
SortingType.NAME_DESC
} else {
SortingType.NAME_ASC
val exceptExtensions = if (filterExcludeCheckboxState.value) {
arrayOf("*.jpg")
} else {
emptyArray()
}
val sortingType = if (reverseSortingCheckboxState.value) {
SortingType.NAME_DESC
} else {
SortingType.NAME_ASC
}
val startDirectory = if (startFromRootCheckboxState.value) {
"/"
} else {
null
}
val choiceType = when (selectedOption) {
stringResource(R.string.choice_type_all) -> {
ChoiceType.ALL
}
val startDirectory = if (startFromRootCheckboxState.value) {
"/"
} else {
null
stringResource(R.string.choice_type_files) -> {
ChoiceType.FILES
}
val choiceType = when (selectedOption) {
stringResource(R.string.choice_type_all) -> {
ChoiceType.ALL
}
stringResource(R.string.choice_type_files) -> {
ChoiceType.FILES
}
else -> {
ChoiceType.DIRECTORIES
}
else -> {
ChoiceType.DIRECTORIES
}
val config = Config(
canChooseOnlyOneItem = onlyOneCheckboxState.value,
showOnlyExtensions = onlyExtensions,
exceptExtensions = exceptExtensions,
isNewFolderButtonDisabled = newFolderCheckboxState.value,
isSortButtonDisabled = disableSortCheckboxState.value,
isQuitButtonEnabled = enableQuitCheckboxState.value,
sortingType = sortingType,
startDirectory = startDirectory,
useFirstItemAsUpEnabled = firstItemAsUpCheckboxState.value,
hideHiddenFilesEnabled = hideHiddenFilesCheckboxState.value,
choiceType = choiceType,
uiConfig = UiConfig(
darkMode = DarkMode.DARK
)
)
val intent = exFilePicker.createIntent(context, config)
launcher.launch(intent)
}
val config = Config(
canChooseOnlyOneItem = onlyOneCheckboxState.value,
showOnlyExtensions = onlyExtensions,
exceptExtensions = exceptExtensions,
isNewFolderButtonDisabled = newFolderCheckboxState.value,
isSortButtonDisabled = disableSortCheckboxState.value,
isQuitButtonEnabled = enableQuitCheckboxState.value,
sortingType = sortingType,
startDirectory = startDirectory,
useFirstItemAsUpEnabled = firstItemAsUpCheckboxState.value,
hideHiddenFilesEnabled = hideHiddenFilesCheckboxState.value,
choiceType = choiceType,
uiConfig = UiConfig(
darkMode = DarkMode.DARK
)
)
val intent = exFilePicker.createIntent(context, config)
launcher.launch(intent)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@Composable
fun CheckBoxItem(modifier: Modifier = Modifier, title: String, onCheckedChange: (Boolean) -> Unit, isChecked: Boolean) {
fun CheckBoxItem(title: String, isChecked: Boolean, onCheckedChange: (Boolean) -> Unit) {
Row(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -21,7 +21,7 @@ fun CheckBoxItem(modifier: Modifier = Modifier, title: String, onCheckedChange:
onCheckedChange = onCheckedChange,
)
Text(
modifier = modifier.align(Alignment.CenterVertically),
modifier = Modifier.align(Alignment.CenterVertically),
text = title,
style = MaterialTheme.typography.bodyLarge
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@Composable
fun RadioButtonItem(modifier: Modifier = Modifier, title: String, onSelectedChange: () -> Unit, selected: Boolean) {
fun RadioButtonItem(selected: Boolean, title: String, onSelectedChange: () -> Unit) {
Row(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -20,7 +20,7 @@ fun RadioButtonItem(modifier: Modifier = Modifier, title: String, onSelectedChan
onClick = onSelectedChange
)
Text(
modifier = modifier.align(Alignment.CenterVertically),
modifier = Modifier.align(Alignment.CenterVertically),
text = title,
style = MaterialTheme.typography.bodyLarge
)
Expand Down

0 comments on commit d54e41d

Please sign in to comment.