Skip to content

Commit

Permalink
feat(abcdecoder):完善Hap页面的展示效果
Browse files Browse the repository at this point in the history
  • Loading branch information
Yricky committed Nov 25, 2024
1 parent 4b1abe3 commit 48069fa
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 39 deletions.
40 changes: 10 additions & 30 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/page/HapView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive
import me.yricky.abcde.AppState
import me.yricky.abcde.HapSession
import me.yricky.abcde.desktop.DesktopUtils
import me.yricky.abcde.ui.*
import me.yricky.abcde.util.*
import me.yricky.oh.abcd.cfm.ClassItem
import me.yricky.oh.common.TreeStruct
import me.yricky.oh.common.toByteArray
import me.yricky.oh.hapde.Constant.DIR_ETS
Expand All @@ -39,7 +37,6 @@ import me.yricky.oh.hapde.Constant.ENTRY_MODULE_JSON
import me.yricky.oh.hapde.Constant.ENTRY_PACK_INFO
import me.yricky.oh.hapde.Constant.ENTRY_RES_INDEX
import me.yricky.oh.hapde.HapConfig
import me.yricky.oh.hapde.HapFileInfo
import me.yricky.oh.hapde.HapSignBlocks
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter
import org.bouncycastle.cms.CMSSignedData
Expand All @@ -58,7 +55,7 @@ class HapView(val hapFile:SelectedHapFile):Page() {
override val name: String = hap.name

val tree by lazy {
TreeModel(TreeStruct(hap.stream().asSequence().asIterable(), pathOf = { it.name }))
TreeModel(TreeStruct(hap.stream().asSequence().asIterable(), pathOf = { it.name })).apply { }
}
var list by mutableStateOf(tree.buildFlattenList())
private set
Expand Down Expand Up @@ -249,28 +246,7 @@ class HapView(val hapFile:SelectedHapFile):Page() {
TreeStruct(emptyList())
).let { TreeModel(it) }
}
TreeItemList(
modifier = Modifier.fillMaxSize(),
list = profile.buildFlattenList { true },
expand = { true },
withTreeHeader = false
){
when (val node = it) {
is TreeStruct.LeafNode<JsonPrimitive> -> {
Column {
Row(verticalAlignment = Alignment.CenterVertically){
Image(Icons.info(), null, modifier = Modifier.padding(end = 2.dp).size(20.dp))
Text(it.pathSeg, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
Text(node.value.toString().replace("\\n","\n"), style = codeStyle)
}
}
is TreeStruct.TreeNode<JsonPrimitive> -> {
Image(Icons.pkg(), null, modifier = Modifier.padding(end = 2.dp).size(20.dp))
Text(it.pathSeg, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}
}
JsonTree(Modifier.fillMaxSize(), profile)
}
Spacer(Modifier.size(12.dp))
TitleCard(Modifier.weight(2f),"Certificates"){
Expand All @@ -281,7 +257,6 @@ class HapView(val hapFile:SelectedHapFile):Page() {
?.let { CMSSignedData(it) }
?.certificates?.getMatches(null)
?.map { conv.getCertificate(it) } ?: emptyList()

}
LazyColumnWithScrollBar {
itemsIndexed(certs){ i,c ->
Expand Down Expand Up @@ -341,8 +316,6 @@ class HapView(val hapFile:SelectedHapFile):Page() {
this@HapView
))
}
} else if(it.path == ENTRY_MODULE_JSON){

}
} else if(it is TreeStruct.TreeNode){
toggleExpand(it)
Expand All @@ -351,12 +324,19 @@ class HapView(val hapFile:SelectedHapFile):Page() {
when (val node = it) {
is TreeStruct.LeafNode<ZipEntry> -> {
Image(iconOf(node), null, modifier = Modifier.padding(end = 2.dp).size(18.dp))
Text(it.pathSeg, maxLines = 1, overflow = TextOverflow.Ellipsis,modifier = Modifier.weight(1f))
Text(
remember { node.value.size.toByteSizeFormat() },
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.bodySmall
)
}
is TreeStruct.TreeNode<ZipEntry> -> {
Image(iconOf(node), null, modifier = Modifier.padding(end = 2.dp).size(18.dp))
Text(it.pathSeg, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}
Text(it.pathSeg, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}

Expand Down
46 changes: 46 additions & 0 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/ui/JsonTree.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package me.yricky.abcde.ui

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import kotlinx.serialization.json.JsonPrimitive
import me.yricky.abcde.util.TreeModel
import me.yricky.oh.common.TreeStruct

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun JsonTree(
modifier: Modifier = Modifier,
json:TreeModel<JsonPrimitive>
){

val list = remember(json) { json.buildFlattenList { true } }
TreeItemList(
modifier = modifier,
list = list,
expand = { true },
withTreeHeader = false
){
when (val node = it) {
is TreeStruct.LeafNode<JsonPrimitive> -> {
FlowRow{
Image(Icons.info(), null, modifier = Modifier.padding(end = 2.dp).size(18.dp))
Text("${it.pathSeg}: ", maxLines = 1, overflow = TextOverflow.Ellipsis, style = codeStyle)
SelectionContainer {
Text(node.value.toString().replace("\\n","\n"), style = codeStyle)
}
}
}
is TreeStruct.TreeNode<JsonPrimitive> -> {
Image(Icons.pkg(), null, modifier = Modifier.padding(end = 2.dp).size(20.dp))
Text(it.pathSeg, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}
}
}
13 changes: 8 additions & 5 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/ui/TreeItemList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fun <T> TreeItemList(
modifier: Modifier,
list: List<Pair<Int, TreeStruct.Node<T>>>,
expand: (TreeStruct.TreeNode<T>) -> Boolean,
onClick: (TreeStruct.Node<T>) -> Unit = {},
onClick: ((TreeStruct.Node<T>) -> Unit)? = null,
applyContent: LazyListScope.(LazyListScope.() -> Unit) -> Unit = { it() },
withTreeHeader: Boolean = true,
content: @Composable RowScope.(TreeStruct.Node<T>) -> Unit
Expand All @@ -38,15 +38,17 @@ fun <T> TreeItemList(
items(list, key = { "${it.first}/${it.second.path}${it.second.javaClass}" }, contentType = { 1 }) { item ->
Row(
Modifier.fillMaxWidth()
.clickable { onClick(item.second) }.drawBehind {
.let { m ->
onClick?.let { m.clickable{ it(item.second) } } ?: m
}.drawBehind {
repeat(item.first){
drawRect(
Color.hsv(((it * 40)%360).toFloat() ,1f,0.5f),
topLeft = Offset(density.density * (it * 12 + 7),0f),
size = Size(density.density * 2,size.height)
)
}
}.padding(start = (12*item.first).dp),
}.padding(start = (12*item.first).dp, end = LocalScrollbarStyle.current.thickness),
verticalAlignment = Alignment.CenterVertically
) {
when (val node = item.second) {
Expand Down Expand Up @@ -98,8 +100,9 @@ fun <T> TreeItemList(
) {
headerItems.forEach { item ->
Row(
Modifier.fillMaxWidth()
.clickable { onClick(item.second) }.drawBehind {
Modifier.fillMaxWidth().let { m ->
onClick?.let { m.clickable{ it(item.second) } } ?: m
}.drawBehind {
repeat(item.first){
drawRect(
Color.hsv(((it * 40)%360).toFloat() ,1f,0.5f),
Expand Down
8 changes: 5 additions & 3 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/ui/theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,15 @@ fun AbcField.defineStr():String = run {
if(isModuleRecordIdx()){
val moduleRecordOffset = getIntValue()
sb.append("= 0x${moduleRecordOffset?.toString(16)}")
}
if(isScopeNames()){
} else if(isScopeNames()){
getIntValue()?.let {
LiteralArray(abc,it)
}?.let {
sb.append("= ${it}")
sb.append("= $it")
}
} else {
val moduleRecordOffset = getIntValue()
sb.append("= 0x${moduleRecordOffset?.toString(16)}")
}
sb.toString()
}
Expand Down
12 changes: 11 additions & 1 deletion abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/ui/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,14 @@ fun VerticalTabAndContent(
}

fun composeSelectContent(content:@Composable (Boolean)->Unit) = content
fun composeContent(content:@Composable ()->Unit) = content
fun composeContent(content:@Composable ()->Unit) = content

fun Long.toByteSizeFormat():String = kotlin.run {
if(this > 1048576){
"${String.format("%.2f",this/1048576.0)}MiB"
} else if(this > 1024){
"${String.format("%.2f",this/1024.0)}KiB"
} else {
"${this}B"
}
}

0 comments on commit 48069fa

Please sign in to comment.