11package com.github.purofle.nmsl.pages
22
3- import androidx.compose.foundation.background
4- import androidx.compose.foundation.clickable
5- import androidx.compose.foundation.layout.*
6- import androidx.compose.foundation.lazy.LazyColumn
7- import androidx.compose.foundation.shape.RoundedCornerShape
8- import androidx.compose.material.icons.Icons
9- import androidx.compose.material.icons.filled.ArrowDropDown
10- import androidx.compose.material3.*
3+ import androidx.compose.foundation.layout.Column
4+ import androidx.compose.foundation.layout.Row
5+ import androidx.compose.material3.RadioButton
6+ import androidx.compose.material3.Scaffold
7+ import androidx.compose.material3.Text
118import androidx.compose.runtime.*
129import androidx.compose.ui.Alignment
13- import androidx.compose.ui.Modifier
14- import androidx.compose.ui.unit.DpOffset
15- import androidx.compose.ui.unit.dp
1610import com.github.purofle.nmsl.config.Config
1711import com.github.purofle.nmsl.config.LauncherConfig
1812import com.github.purofle.nmsl.download.DownloadProvider
@@ -25,69 +19,23 @@ class SettingPage : Page {
2519 var gameSource by remember { mutableStateOf(" ${config.launcherConfig.provider} 源" ) }
2620
2721 Scaffold {
28- LazyColumn {
29- item {
30- SettingSelectItem (
31- title = " 游戏资源下载源" ,
32- items = DownloadProvider .providers.keys.map {
33- SettingItem (" ${it} 源" ) {
34- gameSource = " ${it} 源"
35- config = config.copy(launcherConfig = LauncherConfig (provider = it))
36- }
37- },
38- defaultItem = gameSource
39- )
22+ Column {
23+ Text (" 游戏下载源" )
24+ Row {
25+ DownloadProvider .providers.keys.forEach {
26+ Row (verticalAlignment = Alignment .CenterVertically ) {
27+ Text (" ${it} 源" )
28+ RadioButton (
29+ selected = gameSource == " ${it} 源" ,
30+ onClick = {
31+ gameSource = " ${it} 源"
32+ config = config.copy(launcherConfig = LauncherConfig (provider = it))
33+ },
34+ )
35+ }
36+ }
4037 }
4138 }
4239 }
4340 }
44- }
45-
46- data class SettingItem (
47- val title : String ,
48- val onClick : () -> Unit
49- )
50-
51- @Composable
52- fun SettingSelectItem (
53- title : String ,
54- items : List <SettingItem >,
55- defaultItem : String
56- ) {
57-
58- var expanded by remember { mutableStateOf(false ) }
59-
60- Column (modifier = Modifier .padding(12 .dp)) {
61- Text (title)
62- Spacer (modifier = Modifier .height(6 .dp))
63- Row (
64- modifier = Modifier
65- .height(32 .dp)
66- .background(MaterialTheme .colorScheme.secondaryContainer, RoundedCornerShape (2 .dp))
67- .clickable { expanded = ! expanded },
68- verticalAlignment = Alignment .CenterVertically
69- ) {
70- Text (defaultItem, modifier = Modifier .padding(start = 12 .dp))
71- Icon (
72- imageVector = Icons .Default .ArrowDropDown ,
73- contentDescription = null ,
74- modifier = Modifier .padding(start = 48 .dp, end = 12 .dp)
75- )
76- }
77- }
78- DropdownMenu (
79- expanded = expanded,
80- onDismissRequest = { expanded = false },
81- offset = DpOffset (12 .dp, 0 .dp)
82- ) {
83- items.forEach {
84- DropdownMenuItem (
85- text = { Text (it.title) },
86- onClick = {
87- expanded = false
88- it.onClick()
89- }
90- )
91- }
92- }
9341}
0 commit comments