Skip to content

Commit 7c433fc

Browse files
committed
🐛 Fix analyzer, parent recurse
1 parent 9adea42 commit 7c433fc

4 files changed

Lines changed: 60 additions & 59 deletions

File tree

app/src/main/java/com/kyhsgeekcode/disassembler/AnalysisResultFragment.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ class AnalysisResultFragment : Fragment() {
9393
val analyzer = Analyzer(fileContent)
9494
withContext(Dispatchers.Default) {
9595
analyzer.analyze { i, total, caption ->
96-
circularType.setMessage(caption)
97-
snackProgressBarManager.setProgress(i)
98-
activity?.runOnUiThread {
96+
withContext(Dispatchers.Main) {
97+
circularType.setMessage(caption)
98+
snackProgressBarManager.setProgress(i)
9999
snackProgressBarManager.show(
100100
circularType,
101101
SnackProgressBarManager.LENGTH_INDEFINITE

app/src/main/java/com/kyhsgeekcode/disassembler/Analyzer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class Analyzer(private val bytes: ByteArray) {
166166
return sb.toString()
167167
}
168168

169-
fun analyze(progress: (Int, Int, String) -> Boolean) { // Count shorts, calculate average, ...
169+
suspend fun analyze(progress: suspend (Int, Int, String) -> Boolean) { // Count shorts, calculate average, ...
170170
Logger.v(TAG, "Counting numbers")
171171
Arrays.fill(nums, 0)
172172
for (i in uBytes.indices) {

app/src/main/java/com/kyhsgeekcode/disassembler/FileDrawerListAdapter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ class FileDrawerListAdapter(val progressHandler: ProgressHandler) :
212212
return items
213213
}
214214

215-
override fun getParent(anObject: FileDrawerListItem): FileDrawerListItem {
216-
TODO()
217-
}
215+
// override fun getParent(anObject: FileDrawerListItem): FileDrawerListItem {
216+
// return anObject
217+
// }
218218

219219
private fun getValueFromTypeKindAndBytes(bytes: ByteArray, kind: Int): Any {
220220
val bb = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN)

multilevellistview/src/main/java/com/kyhsgeekcode/multilevellistview/MultiLevelListAdapter.kt

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ abstract class MultiLevelListAdapter<T> {
5656
* @param object
5757
* @return
5858
*/
59-
protected abstract fun getParent(anObject: T): T
59+
// protected abstract fun getParent(anObject: T): T
6060

6161
/**
6262
* Gets view configured to display the object.
@@ -132,9 +132,9 @@ abstract class MultiLevelListAdapter<T> {
132132
val result: MutableList<Node<T>> = ArrayList()
133133
if (dataItems != null) {
134134
for (dataItem in dataItems) {
135-
if (parent === mRoot) {
136-
mRoot.mObject = getParent(dataItem)
137-
}
135+
// if (parent === mRoot) {
136+
// mRoot.mObject = getParent(dataItem)
137+
// }
138138
val isExpandable = isExpandable(dataItem)
139139
val node = Node(dataItem, parent)
140140
node.isExpandable = isExpandable
@@ -170,9 +170,9 @@ abstract class MultiLevelListAdapter<T> {
170170
val result: MutableList<Node<T>> = ArrayList()
171171
if (dataItems != null) {
172172
for (dataItem in dataItems) {
173-
if (parent === mRoot) {
174-
mRoot.mObject = getParent(dataItem)
175-
}
173+
// if (parent === mRoot) {
174+
// mRoot.mObject = getParent(dataItem)
175+
// }
176176
val isExpandable = isExpandable(dataItem!!)
177177
val node = Node(dataItem, parent)
178178
node.isExpandable = isExpandable
@@ -324,41 +324,41 @@ abstract class MultiLevelListAdapter<T> {
324324
}
325325
}
326326

327-
fun extendToNode(nodeObj: T?, expandItems: Stack<T?>?): Int {
328-
var expandItems = expandItems
329-
if (nodeObj == null) {
330-
return -1
331-
}
332-
if (nodeObj === mRoot.mObject) {
333-
return -2
334-
}
335-
if (expandItems == null) {
336-
expandItems = Stack()
337-
}
338-
val nextNodeObj: T?
339-
val flatPos = getPosFromObject(nodeObj)
340-
if (flatPos < 0) {
341-
// add to stack
342-
expandItems.push(nodeObj)
343-
nextNodeObj = getParent(nodeObj)
344-
} else {
345-
if (expandItems.size == 0) {
346-
// finish
347-
mProxyAdapter.notifyDataSetChanged()
348-
return flatPos
349-
} else {
350-
// expand node
351-
val node: Node<T> = mFlatItems!![flatPos]
352-
node.setSubNodes(createNodeListFromDataItems(getSubObjects(node.mObject), node))
353-
354-
// update flat list (add new node subnodes)
355-
mFlatItems = createItemsForCurrentStat()
356-
// get from stack
357-
nextNodeObj = expandItems.pop()
358-
}
359-
}
360-
return extendToNode(nextNodeObj, expandItems)
361-
}
327+
// fun extendToNode(nodeObj: T?, expandItems: Stack<T?>?): Int {
328+
// var expandItems = expandItems
329+
// if (nodeObj == null) {
330+
// return -1
331+
// }
332+
// if (nodeObj === mRoot.mObject) {
333+
// return -2
334+
// }
335+
// if (expandItems == null) {
336+
// expandItems = Stack()
337+
// }
338+
// val nextNodeObj: T?
339+
// val flatPos = getPosFromObject(nodeObj)
340+
// if (flatPos < 0) {
341+
// // add to stack
342+
// expandItems.push(nodeObj)
343+
// nextNodeObj = getParent(nodeObj)
344+
// } else {
345+
// if (expandItems.size == 0) {
346+
// // finish
347+
// mProxyAdapter.notifyDataSetChanged()
348+
// return flatPos
349+
// } else {
350+
// // expand node
351+
// val node: Node<T> = mFlatItems!![flatPos]
352+
// node.setSubNodes(createNodeListFromDataItems(getSubObjects(node.mObject), node))
353+
//
354+
// // update flat list (add new node subnodes)
355+
// mFlatItems = createItemsForCurrentStat()
356+
// // get from stack
357+
// nextNodeObj = expandItems.pop()
358+
// }
359+
// }
360+
// return extendToNode(nextNodeObj, expandItems)
361+
// }
362362

363363
/**
364364
* Collapse node.
@@ -396,12 +396,13 @@ abstract class MultiLevelListAdapter<T> {
396396
val nodes: List<Node<T>>? = parent?.subNodes
397397
if (nodes != null) {
398398
for (sibling in nodes) {
399-
if (sibling !== node) {
399+
if (sibling != node) {
400400
sibling.clearSubNodes()
401401
}
402402
}
403403
}
404-
clearPathToNode(parent)
404+
if (parent != null)
405+
clearPathToNode(parent)
405406
}
406407

407408
/**
@@ -445,13 +446,13 @@ abstract class MultiLevelListAdapter<T> {
445446
return addItem(parentNode)
446447
}
447448

448-
fun addItem(parentNodeObj: T?): Boolean {
449-
val expandHierarchy = Stack<T?>()
450-
val flatPos = extendToNode(parentNodeObj, expandHierarchy)
451-
return if (flatPos == -2) {
452-
addItem(mRoot)
453-
} else addItem(flatPos, true)
454-
}
449+
// fun addItem(parentNodeObj: T?): Boolean {
450+
// val expandHierarchy = Stack<T?>()
451+
// val flatPos = extendToNode(parentNodeObj, expandHierarchy)
452+
// return if (flatPos == -2) {
453+
// addItem(mRoot)
454+
// } else addItem(flatPos, true)
455+
// }
455456
/**
456457
* Update the subNodes list of {@param parentNode} to add the new node and expand it.
457458
* @param parentNode
@@ -545,7 +546,7 @@ abstract class MultiLevelListAdapter<T> {
545546
return i.toLong()
546547
}
547548

548-
override fun getView(i: Int, convertView: View, viewGroup: ViewGroup): View {
549+
override fun getView(i: Int, convertView: View?, viewGroup: ViewGroup): View {
549550
val node: Node<T> = mFlatItems!![i]
550551
return getViewForObject(node.mObject!!, convertView, node.itemInfo, i)
551552
}

0 commit comments

Comments
 (0)