Skip to content

Commit

Permalink
优化逻辑,调整UI
Browse files Browse the repository at this point in the history
优化逻辑,调整UI
  • Loading branch information
GangJust committed Sep 8, 2022
1 parent 7eeabb6 commit 89e2ca5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 57 deletions.
10 changes: 8 additions & 2 deletions src/jvmMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
import androidx.compose.ui.Alignment
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.application
import ui.App
import ui.mApp

fun main() = application {
Window(
state = WindowState(size = DpSize(580.dp, 620.dp), position = WindowPosition(Alignment.Center)),
onCloseRequest = ::exitApplication,
title = "AdbHelper",
resizable = false,
content = {
App()
mApp()
},
)
}
97 changes: 52 additions & 45 deletions src/jvmMain/kotlin/ui/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package ui

import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.shape.AbsoluteCutCornerShape
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Refresh
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import ui.kitview.ScrollableContainer
Expand All @@ -23,104 +25,109 @@ fun mItemView(
modifier: Modifier,
style: TextStyle,
) {
Box(
val titleModifier = modifier.then(Modifier.widthIn(min = 120.dp))
Column(
modifier = modifier,
content = {
Text(
modifier = titleModifier,
text = title,
style = style.copy(fontWeight = FontWeight.Bold),
)
Card(
elevation = 6.dp,
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(4),
shape = AbsoluteCutCornerShape(4.dp),
content = {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = modifier,
content = {
Text(
modifier = modifier,
text = title,
style = style,
)
Text(
modifier = modifier,
text = value,
style = style,
)
},
)
SelectionContainer {
Text(
text = value,
style = style,
modifier = modifier.then(
Modifier.heightIn(min = 34.dp)
.wrapContentHeight(Alignment.CenterVertically, false),//最小高度垂直居中对齐
),
)
}
},
)
},
}
)
}

@Composable
fun mScrollItemView(
title: String,
value: String,
value: List<String>,
modifier: Modifier,
style: TextStyle,
) {
Box(
val titleModifier = modifier.then(Modifier.widthIn(min = 120.dp))
Column(
modifier = modifier,
content = {
Text(
modifier = titleModifier,
text = title,
style = style.copy(fontWeight = FontWeight.Bold),
)
Card(
elevation = 6.dp,
modifier = Modifier.fillMaxWidth().height(200.dp),
shape = RoundedCornerShape(4),
modifier = Modifier.fillMaxWidth().height(150.dp),
shape = AbsoluteCutCornerShape(4.dp),
content = {
Row(
verticalAlignment = Alignment.Top,
modifier = modifier,
content = {
Text(
modifier = modifier,
text = title,
style = style,
)
ScrollableContainer {
ScrollableContainer {
Column(modifier = modifier) {
value.forEach {
SelectionContainer {
Text(
modifier = modifier.then(Modifier.fillMaxWidth()),
text = value,
modifier = Modifier.padding(vertical = 4.dp).fillMaxWidth(),
text = it,
style = style,
)
}
}
},
)
}
}
},
)
},
}
)
}


@Composable
@Preview
fun App() {
fun mApp() {
val viewModel = MainViewModel()
val paddingValues = PaddingValues(vertical = 8.dp, horizontal = 12.dp)
val modifier = Modifier.padding(paddingValues)
val textStyle = TextStyle.Default.copy(fontSize = 16.sp)

//首次加载
viewModel.onRefresh()

//脚手架构建
Scaffold(
backgroundColor = Color.White,
content = {
Column {
mItemView("PackageName", viewModel.getFinalData().mPackageName, modifier, textStyle)
mItemView("CurrentActivity", viewModel.getFinalData().mResumedActivity, modifier, textStyle)
mItemView("LastActivity", viewModel.getFinalData().mLastPausedActivity, modifier, textStyle)
mScrollItemView("Activity Stack", viewModel.getFinalData().mActivityRecordList, modifier, textStyle)
mItemView("当前包名", viewModel.getFinalData().mPackageName, modifier, textStyle)
mItemView("当前活动", viewModel.getFinalData().mResumedActivity, modifier, textStyle)
mItemView("历史活动", viewModel.getFinalData().mLastPausedActivity, modifier, textStyle)
mScrollItemView("活动栈信息", viewModel.getFinalData().mActivityRecordList, modifier, textStyle)
}
},
floatingActionButton = {
FloatingActionButton(
content = {
Icon(Icons.Rounded.Refresh, "重新加载")
Icon(Icons.Rounded.Refresh, "刷新")
},
onClick = {
viewModel.onRefresh()
},
)
},
isFloatingActionButtonDocked = true,
)
}
4 changes: 2 additions & 2 deletions src/jvmMain/kotlin/ui/data/MainData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class MainData : ViewData<MainData.FinalMainData>() {
var mPackageName = mutableStateOf("")
var mResumedActivity = mutableStateOf("")
var mLastPausedActivity = mutableStateOf("")
var mActivityRecordList = mutableStateOf("")
var mActivityRecordList = mutableStateOf(listOf(""))

override fun finalData() = FinalMainData(
mPackageName.value,
Expand All @@ -20,6 +20,6 @@ class MainData : ViewData<MainData.FinalMainData>() {
val mPackageName: String,
val mResumedActivity: String,
val mLastPausedActivity: String,
val mActivityRecordList: String,
val mActivityRecordList: List<String>,
) : FinalViewData()
}
17 changes: 9 additions & 8 deletions src/jvmMain/kotlin/ui/model/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import base.viewmodel.ViewModel
import ui.data.MainData
import utils.GTextUtils
import utils.ShellUtils
import java.io.BufferedInputStream
import java.io.BufferedReader
import java.io.InputStreamReader

class MainViewModel : ViewModel<MainData, MainData.FinalMainData>() {
private var charsetName = ShellUtils.CHAR_SET_GBK
Expand Down Expand Up @@ -62,16 +65,16 @@ class MainViewModel : ViewModel<MainData, MainData.FinalMainData>() {
val process = ShellUtils.adbShell(null, "dumpsys activity | grep -i run | grep ${viewData.mPackageName.value}")
val contents = getCommonResultAll(process)
if (contents.contains("获取失败")) {
viewData.mActivityRecordList.value = GTextUtils.to(contents)
viewData.mActivityRecordList.value = listOf(GTextUtils.to(contents))
return
}
val stringList = contents.split("\n")
var content: String = ""
val contentList: MutableList<String> = mutableListOf()
for (s in stringList) {
val s1 = s.substring(s.indexOf("u0") + 2, s.lastIndexOf(" t"))
content = "$content\n${GTextUtils.to(s1)}"
contentList.add(GTextUtils.to(s1))
}
viewData.mActivityRecordList.value = GTextUtils.to(content)
viewData.mActivityRecordList.value = contentList
}

/**
Expand All @@ -86,10 +89,7 @@ class MainViewModel : ViewModel<MainData, MainData.FinalMainData>() {
resultContents.indexOf(startText) + startText.length,
resultContents.lastIndexOf(endText)
)

//println("resultContents: $resultContents")
//println("resultContent: $resultContent")

process.destroy()
return resultContent
}

Expand All @@ -101,6 +101,7 @@ class MainViewModel : ViewModel<MainData, MainData.FinalMainData>() {
if (GTextUtils.isEmpty(resultContents)) {
return "获取失败,可能存在以下情况(如:锁屏、黑屏等)"
}
process.destroy()
return resultContents
}
}

0 comments on commit 89e2ca5

Please sign in to comment.