Skip to content

Commit

Permalink
🐛 Make it compilable
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed Oct 2, 2023
1 parent 33234d1 commit 178f4d3
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Refresh
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
Expand Down
90 changes: 52 additions & 38 deletions app/src/main/java/com/kyhsgeekcode/disassembler/ui/MainPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import androidx.compose.foundation.clickable
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.DrawerValue
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.ModalNavigationDrawer
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.rememberDrawerState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.rememberCoroutineScope
Expand All @@ -15,58 +23,64 @@ import com.kyhsgeekcode.disassembler.viewmodel.ShowSearchForStringsDialog
import kotlinx.coroutines.launch


@OptIn(ExperimentalMaterial3Api::class)
@ExperimentalFoundationApi
@Composable
fun MainScreen(viewModel: MainViewModel) {
// val navController = rememberNavController()
val state = rememberScaffoldState()
val scope = rememberCoroutineScope()
Scaffold(
scaffoldState = state,
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
ModalNavigationDrawer(
drawerContent = {
FileDrawer(viewModel)
},
topBar = {
TopAppBar(
title = { Text(text = "Disassembler") },
navigationIcon = {
Icon(
Icons.Default.Menu,
"",
modifier = Modifier.clickable(onClick = {
with(state.drawerState) {
scope.launch {
if (isOpen) {
close()
} else {
open()
) {
Scaffold(
topBar = {
TopAppBar(
title = { Text(text = "Disassembler") },
navigationIcon = {
Icon(
Icons.Default.Menu,
"",
modifier = Modifier.clickable(onClick = {
with(drawerState) {
scope.launch {
if (isOpen) {
close()
} else {
open()
}
}
}
}
})
)
},
actions = {
ActivatedMenus(viewModel)
})
)
},
actions = {
ActivatedMenus(viewModel)
}
)
},
content = { paddingValues ->

val drawerState = rememberDrawerState(DrawerValue.Closed)
val scope = rememberCoroutineScope()
val openDrawer = {
scope.launch {
drawerState.open()
}
}
)
},
content = {
val drawerState = rememberDrawerState(DrawerValue.Closed)
val scope = rememberCoroutineScope()
val openDrawer = {
scope.launch {
drawerState.open()
OpenedTabs(viewModel)

val showSearchForStringsDialog =
viewModel.showSearchForStringsDialog.collectAsState()
if (showSearchForStringsDialog.value == ShowSearchForStringsDialog.Shown) {
SearchForStringsDialog(viewModel)
}
}
OpenedTabs(viewModel)
)
}

val showSearchForStringsDialog = viewModel.showSearchForStringsDialog.collectAsState()
if (showSearchForStringsDialog.value == ShowSearchForStringsDialog.Shown) {
SearchForStringsDialog(viewModel)
}
}
)
}


Expand Down
15 changes: 10 additions & 5 deletions app/src/main/java/com/kyhsgeekcode/disassembler/ui/MainTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import android.app.Activity
import android.content.Intent
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.*
import androidx.compose.material.AlertDialog
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -62,7 +67,7 @@ fun ProjectOverview(viewModel: MainViewModel) {
text = {
Text("Copy?")
},
buttons = {
confirmButton = {
Row(
modifier = Modifier.padding(all = 8.dp),
horizontalArrangement = Arrangement.Center
Expand Down
108 changes: 69 additions & 39 deletions app/src/main/java/com/kyhsgeekcode/disassembler/ui/Menus.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
package com.kyhsgeekcode.disassembler.ui

import android.content.Intent
import android.widget.Toast
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.runtime.*
import androidx.compose.material.icons.filled.AddCircle
import androidx.compose.material.icons.filled.Build
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.Info
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import com.kyhsgeekcode.disassembler.Calc.Calculator
import com.kyhsgeekcode.disassembler.preference.SettingsActivity
import com.kyhsgeekcode.disassembler.ui.tabs.BinaryTabData
import com.kyhsgeekcode.disassembler.viewmodel.MainViewModel
Expand All @@ -29,31 +42,35 @@ fun ActivatedMenus(viewModel: MainViewModel) {
DropdownMenuItem(onClick = {
viewModel.openAsHex()
showMenu = false
}) {
}, leadingIcon = {
Icon(imageVector = Icons.Filled.Edit, contentDescription = "Open with hex viewer")
}, text = {
Text("Open with hex viewer")
}
})
DropdownMenuItem(onClick = {
viewModel.searchForStrings()
showMenu = false
}) {
}, leadingIcon = {
Icon(imageVector = Icons.Filled.Build, contentDescription = "Search for strings")
Text("Search for strings")
}
DropdownMenuItem(onClick = {
viewModel.analyze()
showMenu = false
}) {
Icon(imageVector = Icons.Filled.Info, contentDescription = "Analyze")
Text("Analyze")
}
}, text = { Text("Search for strings") }
)
DropdownMenuItem(
onClick = {
viewModel.analyze()
showMenu = false
},
leadingIcon = { Icon(imageVector = Icons.Filled.Info, contentDescription = "Analyze") },
text = { Text("Analyze") }
)
DropdownMenuItem(onClick = {
viewModel.closeCurrentFile()
showMenu = false
}) {
Icon(imageVector = Icons.Filled.Close, contentDescription = "Close File")
Text("Close File")
}
},
leadingIcon = {
Icon(imageVector = Icons.Filled.Close, contentDescription = "Close File")
},
text = { Text("Close File") }
)
if (viewModel.isBinaryTab()) {
BinaryMenuItems(viewModel.getCurrentTabData() as BinaryTabData) {
showMenu = false
Expand All @@ -66,10 +83,12 @@ fun ActivatedMenus(viewModel: MainViewModel) {
DropdownMenuItem(onClick = {
showMenu = false
context.startActivity(Intent(context, SettingsActivity::class.java))
}) {
Icon(imageVector = Icons.Filled.Settings, contentDescription = "Settings / Help")
Text("Settings / Help")
}
},
leadingIcon = {
Icon(imageVector = Icons.Filled.Settings, contentDescription = "Settings / Help")
},
text = { Text("Settings / Help") }
)
}
}

Expand All @@ -81,21 +100,32 @@ fun BinaryMenuItems(binaryTabData: BinaryTabData, dismiss: () -> Unit) {
// Icon(imageVector = Icons.Filled.Delete, contentDescription = "Close Tab")
// Text("Close Tab")
// }
DropdownMenuItem(onClick = {
dismiss()
binaryTabData.jumpto()
}) {
Icon(imageVector = Icons.Filled.Navigation, contentDescription = "Jump to")
Text("Jump to")
}
if (binaryTabData.isDisasmTab()) {
DropdownMenuItem(onClick = {
DropdownMenuItem(
onClick = {
dismiss()
binaryTabData.chooseColumns()
}) {
Icon(imageVector = Icons.Filled.CheckBox, contentDescription = "Choose columns")
Text("Choose columns")
}
binaryTabData.jumpto()
},
leadingIcon = {
Icon(
imageVector = Icons.Filled.AddCircle,
contentDescription = "Jump to"
)
}, text = { Text("Jump to") })
if (binaryTabData.isDisasmTab()) {
DropdownMenuItem(
onClick = {
dismiss()
binaryTabData.chooseColumns()
},
leadingIcon = {
Icon(
imageVector = Icons.Filled.CheckCircle,
contentDescription = "Choose columns"
)
},
text = {
Text("Choose columns")
})
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ package com.kyhsgeekcode.disassembler.ui
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.ScrollableTabRow
import androidx.compose.material.Tab
import androidx.compose.material.Text
import androidx.compose.material3.ScrollableTabRow
import androidx.compose.material3.Tab
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import com.kyhsgeekcode.disassembler.ui.tabs.*
import com.kyhsgeekcode.disassembler.ui.tabs.AnalysisTab
import com.kyhsgeekcode.disassembler.ui.tabs.BinaryTab
import com.kyhsgeekcode.disassembler.ui.tabs.HexTab
import com.kyhsgeekcode.disassembler.ui.tabs.ImageTab
import com.kyhsgeekcode.disassembler.ui.tabs.StringTab
import com.kyhsgeekcode.disassembler.ui.tabs.TextTab
import com.kyhsgeekcode.disassembler.viewmodel.MainViewModel


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.AlertDialog
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -51,7 +51,7 @@ fun AutoCompleteTextFieldDialog(

}
},
buttons = {
confirmButton = {
Row(
modifier = Modifier.padding(all = 8.dp),
horizontalArrangement = Arrangement.Center
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.kyhsgeekcode.disassembler.ui.components
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Text
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -52,10 +52,11 @@ fun DropDownList(
onClick = {
request(false)
selectedString(it)
},
text = {
Text(it, modifier = Modifier.wrapContentWidth())
}
) {
Text(it, modifier = Modifier.wrapContentWidth())
}
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.kyhsgeekcode.disassembler.ui.components

import androidx.compose.material.TextField
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HexTextField(
value: String,
Expand Down
Loading

0 comments on commit 178f4d3

Please sign in to comment.