Skip to content

Commit

Permalink
feat(abcdecoder):优化搜索界面,资源列表界面支持直接展示图片
Browse files Browse the repository at this point in the history
  • Loading branch information
Yricky committed Dec 19, 2024
1 parent 16f6d36 commit e1a2e02
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 49 deletions.
4 changes: 2 additions & 2 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/AppState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AppState {
}
var opened = false
when(file){
is SelectedAbcFile -> AbcView(file.abcBuf).also {
is SelectedAbcFile -> AbcView(file.abcBuf,stubHapSession).also {
session.openPage(it)
currHapSession = session
opened = true
Expand All @@ -44,7 +44,7 @@ class AppState {
}
opened = true
}
is SelectedIndexFile -> ResIndexView(file.resBuf, file.tag).also{
is SelectedIndexFile -> ResIndexView(file.resBuf, file.tag, stubHapSession).also{
session.openPage(it)
currHapSession = session
opened = true
Expand Down
18 changes: 10 additions & 8 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/HapSession.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package me.yricky.abcde

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.runtime.*
import androidx.compose.ui.graphics.painter.Painter
import me.yricky.abcde.page.*
import me.yricky.oh.abcd.cfm.AbcClass
import me.yricky.oh.abcd.cfm.AbcMethod
Expand Down Expand Up @@ -36,18 +34,18 @@ class HapSession(
}
}

fun openClass(page:HapView?,classItem: AbcClass){
ClassView(classItem,page).also {
fun openClass(classItem: AbcClass){
ClassView(classItem,this).also {
navPage(it)
if(!pageStack.contains(it)){
pageStack.add(it)
}
}
}

fun openCode(page:HapView?,method: AbcMethod){
fun openCode(method: AbcMethod){
method.codeItem?.let {
CodeView(it,page).also {
CodeView(it,this).also {
navPage(it)
if(!pageStack.contains(it)){
pageStack.add(it)
Expand Down Expand Up @@ -76,4 +74,8 @@ class HapSession(
navPage(page)
}
}

@Composable
fun loadPainterInZip(entryName:String):Painter? = hapView?.loadPainterInZip(entryName)
val hapConfig = hapView?.config
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package me.yricky.abcde.content

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -115,8 +117,9 @@ fun AbcUniSearchStateView(
){
Column {
Row(
Modifier.fillMaxWidth().height(40.dp)
.border(1.dp,MaterialTheme.colorScheme.surfaceVariant),
Modifier.fillMaxWidth().padding(top = 4.dp, end = 4.dp).height(28.dp)
.clip(RoundedCornerShape(16.dp))
.background(MaterialTheme.colorScheme.surfaceVariant),
verticalAlignment = Alignment.CenterVertically
) {
BasicTextField(
Expand All @@ -125,19 +128,21 @@ fun AbcUniSearchStateView(
singleLine = true,
maxLines = 1,
cursorBrush = SolidColor(MaterialTheme.colorScheme.onSecondaryContainer),
modifier = Modifier.weight(1f)
modifier = Modifier.weight(1f).padding(horizontal = 12.dp),
)
Button(onClick = {
state.session?.job?.cancel()
state.session = state.startSearch(setOf(AbcUniSearchState.MethodName,AbcUniSearchState.ASM))
}, enabled = state.filterText.isNotBlank()){
}, enabled = state.filterText.isNotBlank(),
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 4.dp)
){
Text("查询")
}
}

state.session?.let {
AnimatedVisibility(!it.finished.value) {
LinearProgressIndicator(progress = { it.progress.value }, modifier = Modifier.fillMaxWidth())
LinearProgressIndicator(progress = { it.progress.value }, modifier = Modifier.fillMaxWidth().padding(start = 16.dp, end = 20.dp))
}
var tabIndex by remember { mutableStateOf(0) }
TabRow(
Expand All @@ -146,12 +151,14 @@ fun AbcUniSearchStateView(
Tab(
selected = tabIndex == 0,
onClick = { tabIndex = 0 },
text = { Text("在方法名中查找") }
text = { Text("在方法名中查找") },
modifier = Modifier.height(32.dp)
)
Tab(
selected = tabIndex == 1,
onClick = { tabIndex = 1 },
text = { Text("在方法引用的字符串中查找") }
text = { Text("在方法引用的字符串中查找") },
modifier = Modifier.height(32.dp)
)
}
LazyColumnWithScrollBar {
Expand All @@ -167,7 +174,7 @@ fun AbcUniSearchStateView(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clickable {
if (it.classItem is AbcClass) {
hapSession.openClass(abc.hap, it.classItem)
hapSession.openClass(it.classItem)
}
}
) {
Expand All @@ -179,7 +186,7 @@ fun AbcUniSearchStateView(
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clickable {
hapSession.openCode(abc.hap, it.method)
hapSession.openCode(it.method)
}
) {
Image(Icons.method(),null,modifier = Modifier.padding(8.dp))
Expand All @@ -190,7 +197,7 @@ fun AbcUniSearchStateView(
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clickable {
hapSession.openCode(abc.hap,it.method)
hapSession.openCode(it.method)
}
) {
Image(Icons.asm(),null,modifier = Modifier.padding(8.dp))
Expand Down
14 changes: 8 additions & 6 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/page/AbcView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ import me.yricky.oh.abcd.cfm.AbcClass
import me.yricky.oh.abcd.cfm.exportName
import me.yricky.oh.utils.Adler32

class AbcView(val abc: AbcBuf,override val hap:HapView? = null):AttachHapPage() {
class AbcView(val abc: AbcBuf,override val hap:HapSession):AttachHapPage() {

override val navString: String = "${hap?.navString ?: ""}${asNavString("ABC", abc.tag)}"
override val name: String = if(hap == null){
override val navString: String = "${hap.hapView?.navString ?: ""}${asNavString("ABC", abc.tag)}"
override val name: String = if(hap.hapView == null){
abc.tag
} else "${hap.name}/${abc.tag}"
} else "${hap.hapView.name}/${abc.tag}"

private val tabState = mutableIntStateOf(0)

@Composable
override fun Page(modifier: Modifier, hapSession: HapSession, appState: AppState) {
val scope = rememberCoroutineScope()
VerticalTabAndContent(modifier, listOfNotNull(composeSelectContent{ _: Boolean ->
VerticalTabAndContent(modifier, tabState, listOfNotNull(composeSelectContent{ _: Boolean ->
Image(Icons.clazz(), null, Modifier.fillMaxSize(), colorFilter = grayColorFilter)
} to composeContent{
Column(Modifier.fillMaxSize().padding(end = 4.dp)) {
Expand Down Expand Up @@ -71,7 +73,7 @@ class AbcView(val abc: AbcBuf,override val hap:HapView? = null):AttachHapPage()
if (it is TreeStruct.LeafNode) {
val clazz = it.value
if(clazz is AbcClass){
hapSession.openClass(hap,clazz)
hapSession.openClass(clazz)
}
} else if(it is TreeStruct.TreeNode){
toggleExpand(it)
Expand Down
12 changes: 7 additions & 5 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/page/ClassView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ import me.yricky.abcde.content.ModuleInfoContent
import me.yricky.abcde.ui.*
import me.yricky.oh.abcd.cfm.*

class ClassView(val classItem: AbcClass,override val hap:HapView? = null):AttachHapPage() {
override val navString: String = "${hap?.navString ?: ""}${asNavString("CLZ", classItem.name)}"
override val name: String = "${hap?.name?:""}/${classItem.abc.tag}/${classItem.name}"
class ClassView(val classItem: AbcClass,override val hap:HapSession):AttachHapPage() {
override val navString: String = "${hap.hapView?.navString ?: ""}${asNavString("CLZ", classItem.name)}"
override val name: String = "${hap.hapView?.name?:""}/${classItem.abc.tag}/${classItem.name}"

private val sourceCodeString by lazy {
classItem.entryFunction()?.debugInfo?.state?.sourceCodeString
}

private val tabState = mutableIntStateOf(0)

@OptIn(ExperimentalFoundationApi::class)
@Composable
override fun Page(modifier: Modifier, hapSession: HapSession, appState: AppState) {
VerticalTabAndContent(modifier, listOfNotNull(
VerticalTabAndContent(modifier, tabState, listOfNotNull(
composeSelectContent{ _:Boolean ->
Image(classItem.icon(), null, Modifier.fillMaxSize(), colorFilter = grayColorFilter)
} to composeContent{
Expand Down Expand Up @@ -129,7 +131,7 @@ class ClassView(val classItem: AbcClass,override val hap:HapView? = null):Attach
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clearFocusWhenEnter(focus)
.fillMaxWidth().clickable { hapSession.openCode(hap,it) }
.fillMaxWidth().clickable { hapSession.openCode(it) }
) {
Image(it.icon(), null)
it.codeItem?.let { c ->
Expand Down
14 changes: 8 additions & 6 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/page/CodeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ import me.yricky.oh.abcd.isa.*
import me.yricky.oh.abcd.isa.util.ExternModuleParser
import me.yricky.oh.abcd.isa.util.V2AInstParser

class CodeView(val code: Code,override val hap:HapView? = null):AttachHapPage() {
class CodeView(val code: Code,override val hap:HapSession):AttachHapPage() {
companion object{
const val ANNO_TAG = "ANNO_TAG"
const val ANNO_ASM_NAME = "ANNO_ASM_NAME"

val operandParser = listOf(V2AInstParser,ExternModuleParser)
fun tryBlockString(tb:TryBlock):String = "TryBlock[0x${tb.startPc.toString(16)},0x${(tb.startPc + tb.length).toString(16)})"
}
override val navString: String = "${hap?.navString ?: ""}${asNavString("ASM", code.method.defineStr(true))}"
override val name: String = "${hap?.name ?: ""}/${code.method.abc.tag}/${code.method.clazz.name}/${code.method.name}"
override val navString: String = "${hap.hapView?.navString ?: ""}${asNavString("ASM", code.method.defineStr(true))}"
override val name: String = "${hap.hapView?.name ?: ""}/${code.method.abc.tag}/${code.method.clazz.name}/${code.method.name}"

private fun genAsmViewInfo():List<Pair<Asm.AsmItem, AnnotatedString>> {
return code.asm.list.map {
Expand Down Expand Up @@ -84,11 +84,13 @@ class CodeView(val code: Code,override val hap:HapView? = null):AttachHapPage()
private var asmViewInfo:List<Pair<Asm.AsmItem, AnnotatedString>> by mutableStateOf(genAsmViewInfo())
private var showLabel:Boolean by mutableStateOf(false)

private val tabState = mutableIntStateOf(0)

@OptIn(ExperimentalFoundationApi::class)
@Composable
override fun Page(modifier: Modifier, hapSession: HapSession, appState: AppState) {
val clipboardManager = LocalClipboardManager.current
VerticalTabAndContent(modifier, listOfNotNull(
VerticalTabAndContent(modifier, tabState, listOfNotNull(
composeSelectContent { _: Boolean ->
Image(Icons.asm(), null, Modifier.fillMaxSize())
} to composeContent {
Expand All @@ -101,7 +103,7 @@ class CodeView(val code: Code,override val hap:HapView? = null):AttachHapPage()
is FieldType.ClassType -> Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.clickable {
hapSession.openClass(hap, clz.clazz as AbcClass)
hapSession.openClass(clz.clazz as AbcClass)
}
){
Image(Icons.clazz(), null)
Expand Down Expand Up @@ -183,7 +185,7 @@ class CodeView(val code: Code,override val hap:HapView? = null):AttachHapPage()
buildList {
item.calledMethods.forEach {
add(ContextMenuItem("跳转到${it.name}"){
hapSession.openCode(hap,it)
hapSession.openCode(it)
})
}
}
Expand Down
13 changes: 7 additions & 6 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/page/HapView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class HapView(val hapFile:SelectedHapFile):Page() {
private val thumbnailCache = mutableStateMapOf<String,Painter>()
private val thumbnailCacheMutex = Mutex()
@Composable
private fun loadPainterInZip(entryName:String):Painter {
fun loadPainterInZip(entryName:String):Painter {
val node = tree.tree.pathMap[entryName] ?: return Icons.image()
val density = LocalDensity.current
return thumbnailCache[node.value.name] ?: produceState(Icons.image()) {
Expand All @@ -127,8 +127,7 @@ class HapView(val hapFile:SelectedHapFile):Page() {
}else BitmapPainter(loadImageBitmap(it))
}
}.onFailure {
println("load failed: ${node.value.name}")
it.printStackTrace()
println("load failed: ${node.value.name} \nmsg:${it.message}")
}.onSuccess {
thumbnailCache[node.value.name] = it
value = it
Expand Down Expand Up @@ -168,9 +167,11 @@ class HapView(val hapFile:SelectedHapFile):Page() {
}
}

private val tabState = mutableIntStateOf(0)

@Composable
override fun Page(modifier: Modifier, hapSession: HapSession, appState: AppState) {
VerticalTabAndContent(modifier,
VerticalTabAndContent(modifier, tabState,
listOfNotNull(
composeSelectContent {
Image(Icons.showAsTree(), null, Modifier.fillMaxSize(), colorFilter = grayColorFilter)
Expand Down Expand Up @@ -302,7 +303,7 @@ class HapView(val hapFile:SelectedHapFile):Page() {
kotlin.runCatching {
hapSession.openPage(AbcView(
getEntryFile(it.value.name){ f ->SelectedAbcFile(f,it.value.name) }!!.abcBuf,
this@HapView
hapSession
))
}.onFailure {
it.printStackTrace()
Expand All @@ -313,7 +314,7 @@ class HapView(val hapFile:SelectedHapFile):Page() {
hapSession.openPage(ResIndexView(
getEntryFile(it.value.name){ f -> SelectedIndexFile(f,it.value.name) }!!.resBuf,
it.value.name,
this@HapView
hapSession
))
}
}
Expand Down
2 changes: 1 addition & 1 deletion abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/page/Page.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sealed class Page{
}

sealed class AttachHapPage:Page(){
abstract val hap:HapView?
abstract val hap:HapSession
}

val Page.shortName get() = name.short(35)
17 changes: 13 additions & 4 deletions abcdecoder/src/jvmMain/kotlin/me/yricky/abcde/page/ResIndexView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand Down Expand Up @@ -37,13 +38,13 @@ import me.yricky.oh.resde.ResIndexBuf
import me.yricky.oh.resde.ResType
import me.yricky.oh.resde.ResourceItem

class ResIndexView(val res:ResIndexBuf, name: String,override val hap:HapView? = null):AttachHapPage() {
class ResIndexView(val res:ResIndexBuf, name: String,override val hap:HapSession):AttachHapPage() {
companion object{
val emptyTable = ResTable()
}
private val scope = CoroutineScope(Dispatchers.Default)
override val navString: String = "${hap?.navString ?: ""}${asNavString("REI", name)}"
override val name: String = if(hap == null){ name } else "${hap?.name ?: ""}/$name"
override val navString: String = "${hap.hapView?.navString ?: ""}${asNavString("REI", name)}"
override val name: String = if(hap.hapView == null){ name } else "${hap.hapView.name}/$name"

private val filterFlow = MutableStateFlow("")
private val mapFlow: StateFlow<Map<ResType,ResTable>> = filterFlow.map { f ->
Expand Down Expand Up @@ -188,10 +189,18 @@ class ResIndexView(val res:ResIndexBuf, name: String,override val hap:HapView? =
var namePop by remember { mutableStateOf(false) }
Text(
txt,
modifier = Modifier.fillMaxSize().clickable { namePop = !namePop },
modifier = Modifier.fillMaxHeight().weight(1f).clickable { namePop = !namePop },
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
if(currKey == ResType.MEDIA && hap.hapConfig!= null){
val prefix = remember(hap.hapConfig) { "${hap.hapConfig.module.name}/" }
if(txt.startsWith(prefix)){
hap.loadPainterInZip(txt.removePrefix(prefix))?.let {
Image(it, null,Modifier.aspectRatio(1f).padding(1.dp))
}
}
}
if(namePop) Popup(
onDismissRequest = { namePop = false },
properties = PopupProperties(focusable = true)
Expand Down

0 comments on commit e1a2e02

Please sign in to comment.