Skip to content

Commit

Permalink
perf: 优化输入弹窗样式
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Oct 20, 2023
1 parent 265c9f2 commit d1c04e2
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 146 deletions.
3 changes: 0 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ dependencies {
implementation(libs.androidx.lifecycle.runtime.ktx)

implementation(libs.compose.ui)
// implementation(libs.compose.material)
implementation(libs.compose.material3)
implementation(libs.compose.preview)
debugImplementation(libs.compose.tooling)
Expand Down Expand Up @@ -155,8 +154,6 @@ dependencies {
implementation(libs.ktor.serialization.kotlinx.json)

implementation(libs.google.accompanist.drawablepainter)
implementation(libs.google.accompanist.placeholder.material)
implementation(libs.google.accompanist.systemuicontroller)

implementation(libs.kotlinx.serialization.json)
implementation(libs.kotlinx.collections.immutable)
Expand Down
113 changes: 61 additions & 52 deletions app/src/main/java/li/songe/gkd/ui/DebugPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.core.app.NotificationManagerCompat
Expand Down Expand Up @@ -93,41 +94,42 @@ fun DebugPage() {
val shizukuIsOk by usePollState { shizukuIsSafeOK() }
if (!shizukuIsOk) {
AuthCard(title = "Shizuku授权",
desc = "高级运行模式,能更准确识别界面活动ID",
onAuthClick = {
try {
Shizuku.requestPermission(Activity.RESULT_OK)
} catch (e: Exception) {
ToastUtils.showShort("Shizuku可能没有运行")
}
})
desc = "高级运行模式,能更准确识别界面活动ID",
onAuthClick = {
try {
Shizuku.requestPermission(Activity.RESULT_OK)
} catch (e: Exception) {
ToastUtils.showShort("Shizuku可能没有运行")
}
})
Divider()
} else {
TextSwitch(name = "Shizuku模式",
desc = "高级运行模式,能更准确识别界面活动ID",
checked = store.enableShizuku,
onCheckedChange = { enableShizuku ->
if (enableShizuku) {
appScope.launchTry(Dispatchers.IO) {
// 检验方法是否适配, 再允许使用 shizuku
val tasks = newActivityTaskManager()?.safeGetTasks()?.firstOrNull()
if (tasks != null) {
updateStorage(
storeFlow, store.copy(
enableShizuku = true
)
)
}
}
} else {
updateStorage(
storeFlow, store.copy(
enableShizuku = false
)
)
}
desc = "高级运行模式,能更准确识别界面活动ID",
checked = store.enableShizuku,
onCheckedChange = { enableShizuku ->
if (enableShizuku) {
appScope.launchTry(Dispatchers.IO) {
// 检验方法是否适配, 再允许使用 shizuku
val tasks =
newActivityTaskManager()?.safeGetTasks()?.firstOrNull()
if (tasks != null) {
updateStorage(
storeFlow, store.copy(
enableShizuku = true
)
)
}
}
} else {
updateStorage(
storeFlow, store.copy(
enableShizuku = false
)
)
}

})
})
Divider()
}

Expand Down Expand Up @@ -176,25 +178,25 @@ fun DebugPage() {
// Build.VERSION.SDK_INT < Build.VERSION_CODES.R
val screenshotRunning by usePollState { ScreenshotService.isRunning() }
TextSwitch(name = "截屏服务",
desc = "生成快照需要获取屏幕截图,Android11无需开启",
checked = screenshotRunning,
onCheckedChange = appScope.launchAsFn<Boolean> {
if (!NotificationManagerCompat.from(context).areNotificationsEnabled()) {
ToastUtils.showShort("需要通知权限")
return@launchAsFn
}
if (it) {
val mediaProjectionManager =
context.getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
val activityResult =
launcher.launchForResult(mediaProjectionManager.createScreenCaptureIntent())
if (activityResult.resultCode == Activity.RESULT_OK && activityResult.data != null) {
ScreenshotService.start(intent = activityResult.data!!)
}
} else {
ScreenshotService.stop()
}
})
desc = "生成快照需要获取屏幕截图,Android11无需开启",
checked = screenshotRunning,
onCheckedChange = appScope.launchAsFn<Boolean> {
if (!NotificationManagerCompat.from(context).areNotificationsEnabled()) {
ToastUtils.showShort("需要通知权限")
return@launchAsFn
}
if (it) {
val mediaProjectionManager =
context.getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
val activityResult =
launcher.launchForResult(mediaProjectionManager.createScreenCaptureIntent())
if (activityResult.resultCode == Activity.RESULT_OK && activityResult.data != null) {
ScreenshotService.start(intent = activityResult.data!!)
}
} else {
ScreenshotService.stop()
}
})
Divider()


Expand Down Expand Up @@ -263,11 +265,18 @@ fun DebugPage() {
OutlinedTextField(
value = value,
onValueChange = {
value = it.trim().let { s -> if (s.length > 5) s.substring(0..4) else s }
value = it.filter { c -> c.isDigit() }.take(5)
},
singleLine = true,
modifier = Modifier.fillMaxWidth(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number)
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
supportingText = {
Text(
text = "${value.length} / 5",
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.End,
)
},
)
}, onDismissRequest = { showPortDlg = false }, confirmButton = {
TextButton(onClick = {
Expand Down
126 changes: 58 additions & 68 deletions app/src/main/java/li/songe/gkd/ui/SettingsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import android.content.Intent
import android.net.Uri
import android.provider.Settings
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.shape.RoundedCornerShape
Expand Down Expand Up @@ -39,6 +37,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
Expand Down Expand Up @@ -224,18 +223,19 @@ fun SettingsPage() {
})
Divider()

TextSwitch(name = "保存日志",
desc = "保存最近7天的日志",
checked = store.log2FileSwitch,
onCheckedChange = {
updateStorage(
storeFlow, store.copy(
log2FileSwitch = it
)
)
if (!it) {
appScope.launchTry(Dispatchers.IO) {
val logFiles = LogUtils.getLogFiles()
TextSwitch(
name = "保存日志",
desc = "保存最近7天的日志,大概占用您5M的空间",
checked = store.log2FileSwitch,
onCheckedChange = {
updateStorage(
storeFlow, store.copy(
log2FileSwitch = it
)
)
if (!it) {
appScope.launchTry(Dispatchers.IO) {
val logFiles = LogUtils.getLogFiles()
if (logFiles.isNotEmpty()) {
logFiles.forEach { f ->
f.delete()
Expand Down Expand Up @@ -327,14 +327,13 @@ fun SettingsPage() {
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.selectable(
selected = (option.second == store.enableDarkTheme),
onClick = {
updateStorage(
storeFlow,
storeFlow.value.copy(enableDarkTheme = option.second)
)
})
.selectable(selected = (option.second == store.enableDarkTheme),
onClick = {
updateStorage(
storeFlow,
storeFlow.value.copy(enableDarkTheme = option.second)
)
})
.padding(horizontal = 16.dp)
) {
RadioButton(
Expand All @@ -356,54 +355,45 @@ fun SettingsPage() {
}

if (showToastInputDlg) {
Dialog(onDismissRequest = { showToastInputDlg = false }) {
var value by remember {
mutableStateOf(store.clickToast)
}
Card(
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
.padding(16.dp),
shape = RoundedCornerShape(16.dp),
) {
Column(
modifier = Modifier.padding(10.dp)
) {
Text(text = "请输入提示文字")
Spacer(modifier = Modifier.height(10.dp))

OutlinedTextField(
value = value,
onValueChange = { value = it },
singleLine = true,
modifier = Modifier,
var value by remember {
mutableStateOf(store.clickToast)
}
val maxCharLen = 32
AlertDialog(title = { Text(text = "请输入提示文字") }, text = {
OutlinedTextField(
value = value,
onValueChange = {
value = it.take(maxCharLen)
},
singleLine = true,
supportingText = {
Text(
text = "${value.length} / $maxCharLen",
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.End,
)
Row(
horizontalArrangement = Arrangement.End, modifier = Modifier.fillMaxWidth()
) {
TextButton(onClick = { showToastInputDlg = false }) {
Text(
text = "取消", modifier = Modifier
)
}
Spacer(modifier = Modifier.width(5.dp))
TextButton(onClick = {
updateStorage(
storeFlow, store.copy(
clickToast = value
)
)
showToastInputDlg = false
}) {
Text(
text = "确认", modifier = Modifier
)
}
}
}
},
)
}, onDismissRequest = { showToastInputDlg = false }, confirmButton = {
TextButton(onClick = {
updateStorage(
storeFlow, store.copy(
clickToast = value
)
)
showToastInputDlg = false
}) {
Text(
text = "确认", modifier = Modifier
)
}
}
}, dismissButton = {
TextButton(onClick = { showToastInputDlg = false }) {
Text(
text = "取消", modifier = Modifier
)
}
})
}

if (showShareLogDlg) {
Expand Down
Loading

0 comments on commit d1c04e2

Please sign in to comment.