160 lines
6.4 KiB
Kotlin
160 lines
6.4 KiB
Kotlin
package com.power.ops.pages
|
|
|
|
import androidx.compose.foundation.background
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.fillMaxHeight
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.rounded.AccountCircle
|
|
import androidx.compose.material.icons.rounded.AirplanemodeActive
|
|
import androidx.compose.material.icons.rounded.ListAlt
|
|
import androidx.compose.material.icons.rounded.Logout
|
|
import androidx.compose.material.icons.rounded.NetworkCheck
|
|
import androidx.compose.material.icons.rounded.PrivacyTip
|
|
import androidx.compose.material.icons.rounded.Upload
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.draw.clip
|
|
import androidx.compose.ui.platform.LocalContext
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.navigation.NavController
|
|
import com.power.ops.components.BottomBar
|
|
import com.power.ops.components.Dialog
|
|
import com.power.ops.components.Divider
|
|
import com.power.ops.components.Header
|
|
import com.power.ops.components.HeaderType
|
|
import com.power.ops.components.RichItem
|
|
import com.power.ops.components.Tip
|
|
import com.power.ops.managers.HttpManager
|
|
import com.power.ops.managers.LogManager
|
|
import com.power.ops.theme.Main400
|
|
import com.power.ops.theme.PowerTheme
|
|
import com.power.ops.theme.Secondary500
|
|
import com.power.ops.theme.Typography
|
|
import com.power.ops.utils.getVersionName
|
|
import com.power.ops.utils.openUrl
|
|
import kotlinx.coroutines.launch
|
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
@Composable
|
|
fun SettingPage(navController: NavController) {
|
|
var isShowDialog by remember { mutableStateOf(false) }
|
|
|
|
var isShowTip by remember { mutableStateOf(false) }
|
|
var tipText by remember { mutableStateOf("成功") }
|
|
|
|
|
|
//val settingDao: SettingDao = SettingDatabase.getDatabase(LocalContext.current).settingDao()
|
|
// SettingVM.singleton(LocalContext.current).setSetting()
|
|
// val settings by settingDao.querySettings().collectAsState(initial = emptyList())
|
|
// var settings by object : SettingVM()
|
|
|
|
val context = LocalContext.current
|
|
val coroutineScope = rememberCoroutineScope()
|
|
|
|
Column(modifier = Modifier
|
|
.fillMaxHeight()
|
|
.background(color = Secondary500)) {
|
|
Header(
|
|
navController = navController,
|
|
headerType = HeaderType.CONFIRM,
|
|
title = "设置"
|
|
) {
|
|
navController.popBackStack()
|
|
}
|
|
LazyColumn(
|
|
modifier = Modifier
|
|
.fillMaxHeight()
|
|
.weight(1f)
|
|
) {
|
|
this.item {
|
|
Column(modifier = Modifier
|
|
.padding(start = 14.dp, end = 14.dp, top = 14.dp)
|
|
.clip(shape = RoundedCornerShape(10.dp))
|
|
.background(Main400)
|
|
) {
|
|
RichItem(imageVector = Icons.Rounded.AccountCircle, text = "修改资料") {
|
|
tipText = "未开放"
|
|
isShowTip = true
|
|
}
|
|
Divider()
|
|
RichItem(imageVector = Icons.Rounded.NetworkCheck, text = "网络设置") {
|
|
tipText = "开发中"
|
|
isShowTip = true
|
|
}
|
|
Dialog(defaultValue = "http://", showDialog = isShowDialog, onDismiss = {
|
|
isShowDialog = false
|
|
}, onConfirm = {
|
|
LogManager.i(it)
|
|
})
|
|
Divider()
|
|
RichItem(imageVector = Icons.Rounded.AirplanemodeActive, text = "飞控设置") {
|
|
navController.navigate("AircraftSettingPage")
|
|
}
|
|
}
|
|
|
|
Column(modifier = Modifier
|
|
.padding(start = 14.dp, end = 14.dp, top = 14.dp)
|
|
.clip(shape = RoundedCornerShape(10.dp))
|
|
.background(Main400)
|
|
) {
|
|
RichItem(imageVector = Icons.Rounded.ListAlt, text = "上传日志") {
|
|
coroutineScope.launch {
|
|
tipText = "上传成功"
|
|
HttpManager.singleton.reqSendLogs(LogManager.logs)
|
|
isShowTip = true
|
|
}
|
|
}
|
|
Divider()
|
|
RichItem(imageVector = Icons.Rounded.PrivacyTip, text = "隐私政策") {
|
|
openUrl(context, "http://power.nofee.fun/privacy")
|
|
}
|
|
Divider()
|
|
RichItem(imageVector = Icons.Rounded.Upload, text = "版本更新", intro = "内测版:${getVersionName(context)}") {
|
|
openUrl(context, "http://power.nofee.fun/android")
|
|
}
|
|
}
|
|
|
|
Column(modifier = Modifier
|
|
.padding(start = 14.dp, end = 14.dp, top = 14.dp)
|
|
.clip(shape = RoundedCornerShape(10.dp))
|
|
.background(Main400)
|
|
) {
|
|
RichItem(imageVector = Icons.Rounded.Logout, text = "退出登录") {
|
|
navController.navigate("LoginPage")
|
|
}
|
|
}
|
|
|
|
Text(
|
|
text = "© 2023 新能源智能",
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.padding(20.dp),
|
|
textAlign = TextAlign.Center,
|
|
style = Typography.bodySmall
|
|
)
|
|
}
|
|
}
|
|
Tip(showTip = isShowTip, text = tipText) { isShowTip = false }
|
|
}
|
|
}
|
|
|
|
@Preview
|
|
@Composable
|
|
fun PreviewSettingPage() {
|
|
PowerTheme {
|
|
SettingPage(navController = NavController(LocalContext.current))
|
|
}
|
|
} |