ui: migrate toggle buttons to m3 expressive
This commit is contained in:
@@ -22,7 +22,6 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.button.MaterialButtonToggleGroup
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.DialogSortBinding
|
||||
import org.oxycblt.auxio.list.ClickableListListener
|
||||
@@ -32,8 +31,7 @@ import org.oxycblt.auxio.util.systemBarInsetsCompat
|
||||
|
||||
abstract class SortDialog :
|
||||
ViewBindingBottomSheetDialogFragment<DialogSortBinding>(),
|
||||
ClickableListListener<Sort.Mode>,
|
||||
MaterialButtonToggleGroup.OnButtonCheckedListener {
|
||||
ClickableListListener<Sort.Mode> {
|
||||
private val modeAdapter = SortModeAdapter(@Suppress("LeakingThis") this)
|
||||
|
||||
abstract fun getInitialSort(): Sort?
|
||||
@@ -53,12 +51,17 @@ abstract class SortDialog :
|
||||
insets
|
||||
}
|
||||
binding.sortModeRecycler.adapter = modeAdapter
|
||||
binding.sortDirectionGroup.addOnButtonCheckedListener(this)
|
||||
binding.sortCancel.setOnClickListener { dismiss() }
|
||||
binding.sortSave.setOnClickListener {
|
||||
applyChosenSort(requireNotNull(getCurrentSort()))
|
||||
dismiss()
|
||||
}
|
||||
binding.sortDirectionAsc.setOnClickListener {
|
||||
updateDirection(Sort.Direction.ASCENDING)
|
||||
}
|
||||
binding.sortDirectionDsc.setOnClickListener {
|
||||
updateDirection(Sort.Direction.DESCENDING)
|
||||
}
|
||||
|
||||
// --- STATE SETUP ---
|
||||
modeAdapter.update(getModeChoices(), UpdateInstructions.Diff)
|
||||
@@ -66,31 +69,20 @@ abstract class SortDialog :
|
||||
val initial = getInitialSort()
|
||||
if (initial != null) {
|
||||
modeAdapter.setSelected(initial.mode)
|
||||
val directionId =
|
||||
when (initial.direction) {
|
||||
Sort.Direction.ASCENDING -> R.id.sort_direction_asc
|
||||
Sort.Direction.DESCENDING -> R.id.sort_direction_dsc
|
||||
}
|
||||
binding.sortDirectionGroup.check(directionId)
|
||||
updateDirection(initial.direction)
|
||||
}
|
||||
updateButtons()
|
||||
}
|
||||
|
||||
override fun onDestroyBinding(binding: DialogSortBinding) {
|
||||
super.onDestroyBinding(binding)
|
||||
binding.sortDirectionGroup.removeOnButtonCheckedListener(this)
|
||||
}
|
||||
|
||||
override fun onClick(item: Sort.Mode, viewHolder: RecyclerView.ViewHolder) {
|
||||
modeAdapter.setSelected(item)
|
||||
updateButtons()
|
||||
}
|
||||
|
||||
override fun onButtonChecked(
|
||||
group: MaterialButtonToggleGroup?,
|
||||
checkedId: Int,
|
||||
isChecked: Boolean,
|
||||
) {
|
||||
private fun updateDirection(direction: Sort.Direction) {
|
||||
val binding = requireBinding()
|
||||
binding.sortDirectionAsc.isChecked = direction == Sort.Direction.ASCENDING
|
||||
binding.sortDirectionDsc.isChecked = direction == Sort.Direction.DESCENDING
|
||||
updateButtons()
|
||||
}
|
||||
|
||||
@@ -100,14 +92,10 @@ abstract class SortDialog :
|
||||
}
|
||||
|
||||
private fun getCurrentSort(): Sort? {
|
||||
val binding = requireBinding()
|
||||
val initial = getInitialSort()
|
||||
val mode = modeAdapter.currentMode ?: return null
|
||||
val direction =
|
||||
when (requireBinding().sortDirectionGroup.checkedButtonId) {
|
||||
R.id.sort_direction_asc -> Sort.Direction.ASCENDING
|
||||
R.id.sort_direction_dsc -> Sort.Direction.DESCENDING
|
||||
else -> return null
|
||||
}
|
||||
val direction = if (binding.sortDirectionAsc.isChecked) Sort.Direction.ASCENDING else Sort.Direction.DESCENDING
|
||||
return Sort(mode, direction)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,12 +89,17 @@ class ExportPlaylistDialog : ViewBindingMaterialDialogFragment<DialogPlaylistExp
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
binding.exportPathsGroup.addOnButtonCheckedListener { group, checkedId, isChecked ->
|
||||
if (!isChecked) return@addOnButtonCheckedListener
|
||||
binding.exportRelativePaths.setOnClickListener {
|
||||
// Enforce "selection required" behavior even if the config value doesn't change.
|
||||
val current = pickerModel.currentExportConfig.value
|
||||
pickerModel.setExportConfig(
|
||||
current.copy(absolute = checkedId == R.id.export_absolute_paths)
|
||||
)
|
||||
updateExportConfig(current.copy(absolute = false))
|
||||
pickerModel.setExportConfig(current.copy(absolute = false))
|
||||
}
|
||||
binding.exportAbsolutePaths.setOnClickListener {
|
||||
// Enforce "selection required" behavior even if the config value doesn't change.
|
||||
val current = pickerModel.currentExportConfig.value
|
||||
updateExportConfig(current.copy(absolute = true))
|
||||
pickerModel.setExportConfig(current.copy(absolute = true))
|
||||
}
|
||||
|
||||
binding.exportWindowsPaths.setOnClickListener { _ ->
|
||||
@@ -138,13 +143,8 @@ class ExportPlaylistDialog : ViewBindingMaterialDialogFragment<DialogPlaylistExp
|
||||
|
||||
private fun updateExportConfig(config: ExportConfig) {
|
||||
val binding = requireBinding()
|
||||
binding.exportPathsGroup.check(
|
||||
if (config.absolute) {
|
||||
R.id.export_absolute_paths
|
||||
} else {
|
||||
R.id.export_relative_paths
|
||||
}
|
||||
)
|
||||
binding.exportRelativePaths.isChecked = !config.absolute
|
||||
binding.exportAbsolutePaths.isChecked = config.absolute
|
||||
if (config.absolute) {
|
||||
binding.exportRelativePaths.icon = null
|
||||
binding.exportAbsolutePaths.setIconResource(R.drawable.ic_check_24)
|
||||
|
||||
@@ -163,39 +163,17 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
|
||||
updateExtrasVisibility(binding)
|
||||
}
|
||||
|
||||
// Set up mode toggle listener
|
||||
binding.folderModeGroup.addOnButtonCheckedListener { group, checkedId, isChecked ->
|
||||
if (!isChecked) return@addOnButtonCheckedListener
|
||||
|
||||
when (checkedId) {
|
||||
R.id.locations_mode_exclude -> {
|
||||
isFilePickerMode = true
|
||||
updateModeUI(binding)
|
||||
updateSaveButtonState()
|
||||
}
|
||||
R.id.locations_mode_include -> {
|
||||
isFilePickerMode = false
|
||||
updateModeUI(binding)
|
||||
updateSaveButtonState()
|
||||
}
|
||||
}
|
||||
binding.locationsModeExclude.setOnClickListener {
|
||||
updateLocationMode(binding, filePicker = true)
|
||||
}
|
||||
|
||||
// Set up exclude/include mode toggle listener for System Database mode
|
||||
binding.locationsExcludeModeGroup.addOnButtonCheckedListener { group, checkedId, isChecked
|
||||
->
|
||||
if (!isChecked) return@addOnButtonCheckedListener
|
||||
|
||||
when (checkedId) {
|
||||
R.id.locations_exclude_mode_exclude -> {
|
||||
isIncludeMode = true
|
||||
updateExcludeModeUI(binding)
|
||||
}
|
||||
R.id.locations_exclude_mode_include -> {
|
||||
isIncludeMode = false
|
||||
updateExcludeModeUI(binding)
|
||||
}
|
||||
}
|
||||
binding.locationsModeInclude.setOnClickListener {
|
||||
updateLocationMode(binding, filePicker = false)
|
||||
}
|
||||
binding.locationsExcludeModeExclude.setOnClickListener {
|
||||
updateFilterMode(binding, include = true)
|
||||
}
|
||||
binding.locationsExcludeModeInclude.setOnClickListener {
|
||||
updateFilterMode(binding, include = false)
|
||||
}
|
||||
|
||||
// Set up add folder buttons
|
||||
@@ -239,12 +217,9 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
|
||||
// Load data for the initial mode
|
||||
loadModeData(binding)
|
||||
|
||||
// Set the initial toggle button selection
|
||||
if (isFilePickerMode) {
|
||||
binding.folderModeGroup.check(R.id.locations_mode_exclude)
|
||||
} else {
|
||||
binding.folderModeGroup.check(R.id.locations_mode_include)
|
||||
}
|
||||
// Set initial selection state (no group logic; we manage checked state ourselves)
|
||||
binding.locationsModeExclude.isChecked = isFilePickerMode
|
||||
binding.locationsModeInclude.isChecked = !isFilePickerMode
|
||||
|
||||
// Check storage permission status
|
||||
hasStoragePermission = checkStoragePermission()
|
||||
@@ -263,13 +238,30 @@ class LocationsDialog : ViewBindingMaterialDialogFragment<DialogMusicLocationsBi
|
||||
binding.locationsExcludeNonMusicSwitch.isChecked = query.excludeNonMusic
|
||||
|
||||
isIncludeMode = query.mode == MediaStore.FilterMode.INCLUDE
|
||||
binding.locationsExcludeModeGroup.check(
|
||||
if (isIncludeMode) R.id.locations_exclude_mode_exclude
|
||||
else R.id.locations_exclude_mode_include
|
||||
)
|
||||
binding.locationsExcludeModeExclude.isChecked = isIncludeMode
|
||||
binding.locationsExcludeModeInclude.isChecked = !isIncludeMode
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateLocationMode(binding: DialogMusicLocationsBinding, filePicker: Boolean) {
|
||||
// Enforce "selection required" behavior.
|
||||
binding.locationsModeExclude.isChecked = filePicker
|
||||
binding.locationsModeInclude.isChecked = !filePicker
|
||||
|
||||
isFilePickerMode = filePicker
|
||||
updateModeUI(binding)
|
||||
updateSaveButtonState()
|
||||
}
|
||||
|
||||
private fun updateFilterMode(binding: DialogMusicLocationsBinding, include: Boolean) {
|
||||
// Enforce "selection required" behavior.
|
||||
binding.locationsExcludeModeExclude.isChecked = include
|
||||
binding.locationsExcludeModeInclude.isChecked = !include
|
||||
|
||||
isIncludeMode = include
|
||||
updateExcludeModeUI(binding)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
// Update save button state after dialog is shown
|
||||
|
||||
Reference in New Issue
Block a user