-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47885db
commit a0f385e
Showing
9 changed files
with
214 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/src/main/kotlin/cn/super12138/todo/logic/model/SortingMethod.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cn.super12138.todo.logic.model | ||
|
||
import android.content.Context | ||
import cn.super12138.todo.R | ||
|
||
enum class SortingMethod(val id: Int) { | ||
Date(1), | ||
Priority(2), | ||
Completion(3), | ||
AlphabeticalAscending(4), | ||
AlphabeticalDescending(5); | ||
|
||
fun getDisplayName(context: Context): String { | ||
val resId = when (this) { | ||
Date -> R.string.sorting_date | ||
Priority -> R.string.sorting_priority | ||
Completion -> R.string.sorting_completion | ||
AlphabeticalAscending -> R.string.sorting_alphabetical_ascending | ||
AlphabeticalDescending -> R.string.sorting_alphabetical_descending | ||
} | ||
return context.getString(resId) | ||
} | ||
|
||
companion object { | ||
fun fromId(id: Int): SortingMethod { | ||
return SortingMethod.entries.find { it.id == id } ?: Date | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
app/src/main/kotlin/cn/super12138/todo/ui/pages/settings/components/SettingsDialogs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package cn.super12138.todo.ui.pages.settings.components | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.selection.selectable | ||
import androidx.compose.foundation.selection.selectableGroup | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.RadioButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.semantics.Role | ||
import androidx.compose.ui.unit.dp | ||
import cn.super12138.todo.ui.components.BasicDialog | ||
import cn.super12138.todo.ui.pages.settings.state.rememberPrefIntState | ||
|
||
@Composable | ||
fun SettingsRadioDialog( | ||
key: String, | ||
defaultIndex: Int, | ||
visible: Boolean, | ||
title: String, | ||
options: List<SettingsRadioOptions>, | ||
onSelect: (id: Int) -> Unit, | ||
onDismiss: () -> Unit, | ||
modifier: Modifier = Modifier, | ||
) { | ||
SettingsDialog( | ||
visible = visible, | ||
title = title, | ||
text = { | ||
var selectedItemIndex by rememberPrefIntState(key, defaultIndex) | ||
// Modifier.selectableGroup() 用来确保无障碍功能运行正确 | ||
Column(Modifier.selectableGroup()) { | ||
options.forEach { option -> | ||
Row( | ||
Modifier | ||
.fillMaxWidth() | ||
.height(56.dp) | ||
.selectable( | ||
selected = option.id == selectedItemIndex, | ||
onClick = { | ||
selectedItemIndex = option.id | ||
onSelect(option.id) | ||
onDismiss() | ||
}, | ||
role = Role.RadioButton | ||
) | ||
.padding(horizontal = 16.dp), | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
RadioButton( | ||
selected = option.id == selectedItemIndex, | ||
onClick = null // 设置为 null 有利于屏幕阅读器 | ||
) | ||
Text( | ||
text = option.text, | ||
style = MaterialTheme.typography.bodyLarge, | ||
modifier = Modifier.padding(start = 16.dp) | ||
) | ||
} | ||
} | ||
} | ||
}, | ||
onDismissRequest = onDismiss, | ||
modifier = modifier | ||
) | ||
} | ||
|
||
data class SettingsRadioOptions( | ||
val id: Int, | ||
val text: String, | ||
) | ||
|
||
@Composable | ||
fun SettingsDialog( | ||
visible: Boolean, | ||
title: String, | ||
text: @Composable (() -> Unit)? = null, | ||
onDismissRequest: () -> Unit = {}, | ||
modifier: Modifier = Modifier | ||
) { | ||
BasicDialog( | ||
visible = visible, | ||
title = { Text(title) }, | ||
text = text, | ||
confirmButton = {}, | ||
dismissButton = {}, | ||
onDismissRequest = onDismissRequest, | ||
modifier = modifier | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters