Skip to content

Commit 6e13c49

Browse files
committed
resource id popup
1 parent 8abe8a9 commit 6e13c49

5 files changed

Lines changed: 30 additions & 13 deletions

File tree

composeApp/src/commonMain/composeResources/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
<string name="deploy">Deploy</string>
8282
<string name="sign_deploy_app">Sign and deploy %1$s</string>
83-
<string name="open">"Open</string>
83+
<string name="open">Open</string>
8484
<string name="close">Close</string>
8585
<string name="select">Select</string>
8686
<string name="cancel">Cancel</string>

composeApp/src/commonMain/kotlin/me/lkl/dalvikus/tree/archive/ApkNode.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import me.lkl.dalvikus.snackbarManager
1111
import me.lkl.dalvikus.tree.ContainerNode
1212
import me.lkl.dalvikus.tree.Node
1313
import java.io.File
14+
import java.math.BigInteger
1415

1516
class ApkNode(
1617
override val name: String,
@@ -47,6 +48,13 @@ class ApkNode(
4748
override fun readEntry(path: String): ByteArray {
4849
return super.readEntry(path)
4950
}
51+
52+
fun getResourceById(unsignedValue: Int): ResResSpec? {
53+
if (!resTable.isMainPackageLoaded) return null
54+
val resId = ResID(unsignedValue)
55+
val resSpec = resTable.mainPackage.getResSpec(resId)
56+
return resSpec
57+
}
5058
}
5159

5260
fun getApkToolConfig(): Config {

composeApp/src/commonMain/kotlin/me/lkl/dalvikus/ui/editor/EditorViewModel.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.lkl.dalvikus.ui.editor
22

3+
import androidx.compose.runtime.collectAsState
34
import androidx.compose.runtime.getValue
45
import androidx.compose.runtime.mutableStateOf
56
import androidx.compose.runtime.setValue
@@ -9,15 +10,19 @@ import androidx.compose.ui.text.AnnotatedString
910
import androidx.compose.ui.text.TextRange
1011
import androidx.compose.ui.text.input.TextFieldValue
1112
import androidx.compose.ui.unit.sp
13+
import brut.androlib.res.data.ResResSpec
1214
import kotlinx.coroutines.CoroutineScope
1315
import kotlinx.coroutines.Dispatchers
1416
import kotlinx.coroutines.launch
1517
import kotlinx.coroutines.withContext
1618
import me.lkl.dalvikus.dalvikusSettings
1719
import me.lkl.dalvikus.tabs.TabElement
20+
import me.lkl.dalvikus.tree.archive.ApkNode
1821
import me.lkl.dalvikus.ui.editor.highlight.CodeHighlightColors
1922
import me.lkl.dalvikus.ui.editor.highlight.highlightCode
2023
import me.lkl.dalvikus.ui.editor.suggestions.AssistPopupState
24+
import me.lkl.dalvikus.ui.uiTreeRoot
25+
import java.math.BigInteger
2126

2227
const val maxEditorFileSize = 128 * 1024 // 128 KiB
2328
const val maxEditorLines = 10000 // 10,000 lines
@@ -221,4 +226,17 @@ class EditorViewModel(private val tab: TabElement) {
221226
)
222227
changeContent(newTextFieldValue, coroutineScope)
223228
}
229+
230+
fun tryResolveResIdText(unsignedValue: BigInteger): String {
231+
val apks = uiTreeRoot.childrenFlow.value.filterIsInstance<ApkNode>()
232+
val resIds = mutableListOf<ResResSpec>()
233+
for (apk in apks) {
234+
val resResSpec = apk.getResourceById(unsignedValue.toInt())
235+
if (resResSpec != null) {
236+
resIds.add(resResSpec)
237+
}
238+
}
239+
return if (resIds.isEmpty()) "Resource not found"
240+
else resIds.joinToString(", ") { "R.${it.type.name}.${it.name}" }
241+
}
224242
}

composeApp/src/commonMain/kotlin/me/lkl/dalvikus/ui/editor/suggestions/Popups.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package me.lkl.dalvikus.ui.editor.suggestions
22

33
import androidx.compose.material.icons.Icons
44
import androidx.compose.material.icons.filled.ContentCopy
5-
import androidx.compose.material.icons.filled.Error
65
import androidx.compose.material.icons.filled.ErrorOutline
76
import androidx.compose.material.icons.outlined.ArrowCircleRight
8-
import androidx.compose.material.icons.outlined.Code
97
import androidx.compose.material.icons.outlined.Info
108
import androidx.compose.material.icons.outlined.Search
119
import androidx.compose.material3.MaterialTheme
@@ -134,14 +132,7 @@ fun HexPopup(
134132
8 -> {
135133
println(cleanedHex)
136134
if(cleanedHex.startsWith("7e") || cleanedHex.startsWith("7f")) {
137-
val intValue = signedValue.toInt()
138-
val typeId = (intValue shr 16) and 0xFF
139-
val entryId = intValue and 0xFFFF
140-
val typeNames = mapOf(
141-
1 to "anim", 2 to "drawable", 3 to "layout", 4 to "string", 5 to "style", 6 to "id"
142-
)
143-
val typeName = typeNames[typeId] ?: "unknown"
144-
"$typeName:$entryId (resource ID)"
135+
"$cleanedHex (resource ID) = ${viewModel.tryResolveResIdText(unsignedValue)} (resolved) "
145136
} else {
146137
val floatValue = Float.fromBits(signedValue.toInt())
147138
"$signedValue (base 10) = $floatValue (float)"

composeApp/src/commonMain/kotlin/me/lkl/dalvikus/ui/resources/ResourcesView.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ val resourceTypesIcons = mapOf(
6464

6565
@Composable
6666
private fun ApkResourceCards() {
67+
// TODO add search bar for resource ids in base 16, base 10, and resource name.
6768
val treeRootChildren by uiTreeRoot.childrenFlow.collectAsState()
68-
val apks = treeRootChildren
69-
.filterIsInstance<ApkNode>()
69+
val apks = treeRootChildren.filterIsInstance<ApkNode>()
7070

7171
val gridState = rememberLazyGridState()
7272
var selectedResType by remember { mutableStateOf("all") }

0 commit comments

Comments
 (0)