|
| 1 | +package li.songe.gkd.ui |
| 2 | + |
| 3 | +import androidx.compose.foundation.layout.Arrangement |
| 4 | +import androidx.compose.foundation.layout.Column |
| 5 | +import androidx.compose.foundation.layout.Spacer |
| 6 | +import androidx.compose.foundation.layout.fillMaxSize |
| 7 | +import androidx.compose.foundation.layout.height |
| 8 | +import androidx.compose.foundation.layout.padding |
| 9 | +import androidx.compose.foundation.layout.width |
| 10 | +import androidx.compose.foundation.verticalScroll |
| 11 | +import androidx.compose.material3.BottomAppBar |
| 12 | +import androidx.compose.material3.Scaffold |
| 13 | +import androidx.compose.material3.Text |
| 14 | +import androidx.compose.material3.TextButton |
| 15 | +import androidx.compose.runtime.Composable |
| 16 | +import androidx.compose.runtime.mutableIntStateOf |
| 17 | +import androidx.compose.runtime.saveable.rememberSaveable |
| 18 | +import androidx.compose.ui.Modifier |
| 19 | +import androidx.compose.ui.input.nestedscroll.nestedScroll |
| 20 | +import androidx.compose.ui.unit.dp |
| 21 | +import androidx.lifecycle.viewmodel.compose.viewModel |
| 22 | +import androidx.navigation3.runtime.NavKey |
| 23 | +import kotlinx.serialization.Serializable |
| 24 | +import li.songe.gkd.ui.component.CopyTextCard |
| 25 | +import li.songe.gkd.ui.component.EmptyText |
| 26 | +import li.songe.gkd.ui.component.PerfIcon |
| 27 | +import li.songe.gkd.ui.component.PerfIconButton |
| 28 | +import li.songe.gkd.ui.component.PerfTopAppBar |
| 29 | +import li.songe.gkd.ui.component.useScrollBehaviorState |
| 30 | +import li.songe.gkd.ui.share.LocalMainViewModel |
| 31 | +import li.songe.gkd.ui.share.noRippleClickable |
| 32 | +import li.songe.gkd.ui.style.EmptyHeight |
| 33 | +import li.songe.gkd.ui.style.itemHorizontalPadding |
| 34 | +import li.songe.gkd.ui.style.itemVerticalPadding |
| 35 | +import li.songe.gkd.util.ISSUES_URL |
| 36 | +import li.songe.gkd.util.throttle |
| 37 | + |
| 38 | + |
| 39 | +@Serializable |
| 40 | +data object CrashReportRoute : NavKey |
| 41 | + |
| 42 | +@Composable |
| 43 | +fun CrashReportPage() { |
| 44 | + val mainVm = LocalMainViewModel.current |
| 45 | + val vm = viewModel<CrashReportVm>() |
| 46 | + val scrollKey = rememberSaveable { mutableIntStateOf(0) } |
| 47 | + val (scrollBehavior, scrollState) = useScrollBehaviorState(scrollKey) |
| 48 | + Scaffold( |
| 49 | + modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), |
| 50 | + topBar = { |
| 51 | + PerfTopAppBar( |
| 52 | + scrollBehavior = scrollBehavior, |
| 53 | + navigationIcon = { |
| 54 | + PerfIconButton( |
| 55 | + imageVector = PerfIcon.ArrowBack, |
| 56 | + onClick = mainVm::popPage, |
| 57 | + ) |
| 58 | + }, |
| 59 | + title = { |
| 60 | + Text( |
| 61 | + text = "崩溃记录", |
| 62 | + modifier = Modifier.noRippleClickable(onClick = throttle { scrollKey.intValue++ }) |
| 63 | + ) |
| 64 | + }, |
| 65 | + ) |
| 66 | + }, |
| 67 | + bottomBar = { |
| 68 | + if (vm.crashDataList.isNotEmpty()) { |
| 69 | + BottomAppBar { |
| 70 | + Spacer(modifier = Modifier.weight(1f)) |
| 71 | + TextButton( |
| 72 | + onClick = throttle { mainVm.openUrl(ISSUES_URL) }, |
| 73 | + ) { |
| 74 | + Text(text = "问题反馈") |
| 75 | + } |
| 76 | + Spacer(modifier = Modifier.width(itemHorizontalPadding)) |
| 77 | + TextButton( |
| 78 | + onClick = { mainVm.showShareLogDlgFlow.value = true }, |
| 79 | + ) { |
| 80 | + Text(text = "导出日志") |
| 81 | + } |
| 82 | + Spacer(modifier = Modifier.width(itemHorizontalPadding)) |
| 83 | + } |
| 84 | + } |
| 85 | + }, |
| 86 | + ) { contentPadding -> |
| 87 | + Column( |
| 88 | + modifier = Modifier |
| 89 | + .verticalScroll(scrollState) |
| 90 | + .fillMaxSize() |
| 91 | + .padding(contentPadding), |
| 92 | + verticalArrangement = Arrangement.spacedBy(itemVerticalPadding) |
| 93 | + ) { |
| 94 | + if (vm.crashDataList.isNotEmpty()) { |
| 95 | + vm.crashDataList.forEach { crashData -> |
| 96 | + CopyTextCard( |
| 97 | + text = crashData.stackTrace, |
| 98 | + modifier = Modifier.padding(horizontal = 8.dp), |
| 99 | + ) |
| 100 | + } |
| 101 | + } else { |
| 102 | + Spacer(modifier = Modifier.height(EmptyHeight)) |
| 103 | + EmptyText() |
| 104 | + } |
| 105 | + Spacer(modifier = Modifier.height(EmptyHeight)) |
| 106 | + } |
| 107 | + } |
| 108 | +} |
0 commit comments