11package org.andbootmgr.app
22
33import android.annotation.SuppressLint
4- import android.util.Log
54import android.widget.Toast
65import androidx.compose.foundation.clickable
76import androidx.compose.foundation.layout.Arrangement
@@ -204,14 +203,7 @@ private fun PartTool(vm: MainActivityState) {
204203 LaunchedEffect (Unit ) {
205204 withContext(Dispatchers .IO ) {
206205 val outList = mutableStateMapOf<ConfigFile , File >()
207- val list = SuFile .open(vm.logic!! .abmEntries.absolutePath).listFiles()
208- for (i in list!! ) {
209- try {
210- outList[ConfigFile .importFromFile(i)] = i
211- } catch (e: ActionAbortedCleanlyError ) {
212- Log .e(" ABM" , Log .getStackTraceString(e))
213- }
214- }
206+ outList.putAll(ConfigFile .importFromFolder(vm.logic!! .abmEntries))
215207 entries = outList
216208 }
217209 }
@@ -320,12 +312,11 @@ private fun PartTool(vm: MainActivityState) {
320312 )
321313 }
322314 }
323- val e = ConfigFile ()
324315 Row (horizontalArrangement = Arrangement .SpaceEvenly ,
325316 verticalAlignment = Alignment .CenterVertically ,
326317 modifier = Modifier
327318 .fillMaxWidth()
328- .clickable { editEntryID = e }) {
319+ .clickable { editEntryID = ConfigFile () }) {
329320 Text (stringResource(R .string.new_entry))
330321 }
331322 }
@@ -352,7 +343,7 @@ private fun PartTool(vm: MainActivityState) {
352343 }
353344 )
354345 } else if (editEntryID != null ) {
355- OsEditor (vm, editEntryID!! , entries!! [editEntryID!! ]!! , onClose = {
346+ OsEditor (vm, parts, editEntryID!! , entries!! [editEntryID!! ]!! , onClose = {
356347 if (it) {
357348 entries!! .remove(editEntryID!! .also { editEntryID = null })
358349 // TODO don't call generateMeta on main thread
@@ -368,7 +359,7 @@ private fun PartTool(vm: MainActivityState) {
368359}
369360
370361@Composable
371- private fun OsEditor (vm : MainActivityState , e : ConfigFile , f : File ,
362+ private fun OsEditor (vm : MainActivityState , parts : SDUtils . SDPartitionMeta ? , e : ConfigFile , f : File ,
372363 onClose : (newPt: Boolean ) -> Unit , onOpenUpdater : () -> Unit ) {
373364 var processing by remember { mutableStateOf(false ) }
374365 var delete by remember { mutableStateOf(false ) }
@@ -389,6 +380,8 @@ private fun OsEditor(vm: MainActivityState, e: ConfigFile, f: File,
389380 enabled = e.has(" xupdate" ) && ! e[" xupdate" ].isNullOrBlank()) {
390381 Text (stringResource(R .string.update))
391382 }
383+ // TODO add button to open backup & restore tool (by asking which partition should
384+ // be backed up / restored)
392385 Button (
393386 onClick = {
394387 delete = true
@@ -429,8 +422,8 @@ private fun OsEditor(vm: MainActivityState, e: ConfigFile, f: File,
429422 delete = false
430423 CoroutineScope (Dispatchers .Default ).launch {
431424 var tresult = " "
432- if (e.has(" xpart" ) && ! e[" xpart" ].isNullOrBlank()) {
433- var parts = SDUtils .generateMeta(vm.deviceInfo !! )
425+ if (e.has(" xpart" ) && ! e[" xpart" ].isNullOrBlank() && vm.deviceInfo !! .metaonsd ) {
426+ var parts = parts
434427 val allp = e[" xpart" ]!! .split(" :" )
435428 .map { parts!! .dumpKernelPartition(Integer .valueOf(it)) }
436429 vm.unmountBootset()
@@ -441,6 +434,10 @@ private fun OsEditor(vm: MainActivityState, e: ConfigFile, f: File,
441434 tresult + = r.out .joinToString(" \n " ) + r.err.joinToString(" \n " ) + " \n "
442435 }
443436 vm.mountBootset()
437+ } else if (! vm.deviceInfo!! .metaonsd) {
438+ val f3 = SuFile (vm.logic!! .abmSdLessBootset, f.nameWithoutExtension)
439+ if (! f3.deleteRecursive())
440+ tresult + = vm.activity!! .getString(R .string.cannot_delete, f3.absolutePath)
444441 }
445442 val f2 = SuFile (vm.logic!! .abmBootset, f.nameWithoutExtension)
446443 if (! f2.deleteRecursive())
@@ -577,7 +574,7 @@ private fun PartitionEditor(vm: MainActivityState, p: SDUtils.Partition, simplif
577574 }
578575 }
579576 Button (onClick = {
580- vm.currentWizardFlow = BackupRestoreFlow (p.id, null ) // TODO !metaonsd
577+ vm.currentWizardFlow = BackupRestoreFlow (p.id, null )
581578 }) {
582579 Text (stringResource(R .string.backupnrestore))
583580 }
@@ -852,5 +849,104 @@ private fun EntryEditor(vm: MainActivityState, e: ConfigFile, f: File?, onClose:
852849
853850@Composable
854851private fun BootsetTool (vm : MainActivityState ) {
855- Text (" insert code here" ) // TODO !metaonsd
852+ var filterEntryView by remember { mutableStateOf(false ) }
853+ if (! vm.noobMode)
854+ MyFilterChipBar (
855+ if (filterEntryView) 1 else 0 ,
856+ listOf (
857+ stringResource(R .string.unified),
858+ stringResource(R .string.entries)
859+ )
860+ ) { filterEntryView = it == 1 }
861+
862+ @SuppressLint(" MutableCollectionMutableState" ) // lol
863+ var entries by remember { mutableStateOf<SnapshotStateMap <ConfigFile , File >? > (null ) }
864+ LaunchedEffect (Unit ) {
865+ withContext(Dispatchers .IO ) {
866+ val outList = mutableStateMapOf<ConfigFile , File >()
867+ outList.putAll(ConfigFile .importFromFolder(vm.logic!! .abmEntries))
868+ entries = outList
869+ }
870+ }
871+ var editEntryID by remember { mutableStateOf<ConfigFile ?>(null ) }
872+ Column (
873+ Modifier
874+ .verticalScroll(rememberScrollState())
875+ .fillMaxWidth(), horizontalAlignment = Alignment .CenterHorizontally
876+ ) {
877+ if (vm.noobMode)
878+ MyInfoCard (stringResource(R .string.click2inspect), padding = 5 .dp)
879+ if (entries != null ) {
880+ for (e in entries!! .keys) {
881+ val spaceUsage = null // TODO compute space usage of installed OS
882+ Row (horizontalArrangement = Arrangement .SpaceEvenly ,
883+ verticalAlignment = Alignment .CenterVertically ,
884+ modifier = Modifier
885+ .fillMaxWidth()
886+ .clickable { editEntryID = e }) {
887+ /* format:
888+ entry["title"] = str
889+ entry["linux"] = path(str)
890+ entry["initrd"] = path(str)
891+ entry["dtb"] = path(str)
892+ entry["options"] = str
893+ entry["xtype"] = str
894+ entry["xpart"] = array (str.split(":"))
895+ entry["xupdate"] = uri(str)
896+ */
897+ Text (
898+ (if (e.has(" title" )) {
899+ stringResource(R .string.entry_title, e[" title" ]!! )
900+ } else {
901+ stringResource(R .string.invalid_entry)
902+ }).let {
903+ if (spaceUsage != null )
904+ stringResource(R .string.entry_space_usage, spaceUsage, it)
905+ else it
906+ }
907+ )
908+ }
909+ }
910+ if (filterEntryView) {
911+ Row (horizontalArrangement = Arrangement .SpaceEvenly ,
912+ verticalAlignment = Alignment .CenterVertically ,
913+ modifier = Modifier
914+ .fillMaxWidth()
915+ .clickable { editEntryID = ConfigFile () }) {
916+ Text (stringResource(R .string.new_entry))
917+ }
918+ } else {
919+ Row (horizontalArrangement = Arrangement .SpaceEvenly ,
920+ verticalAlignment = Alignment .CenterVertically ,
921+ modifier = Modifier
922+ .fillMaxWidth()
923+ .clickable { vm.currentWizardFlow = CreatePartFlow (null ) }) {
924+ Text (stringResource(R .string.install_os))
925+ }
926+ }
927+ }
928+ // TODO we eventually want portable partitions for !metaonsd, but not supported yet
929+ if (editEntryID != null && filterEntryView) {
930+ EntryEditor (
931+ vm, editEntryID!! , entries!! [editEntryID!! ],
932+ onClose = { editEntryID = null },
933+ onDeleted = {
934+ entries!! .remove(editEntryID!! .also { editEntryID = null })
935+ },
936+ onEdited = {
937+ entries!! [editEntryID!! .also { editEntryID = null }] = it
938+ }
939+ )
940+ } else if (editEntryID != null ) {
941+ OsEditor (vm, null , editEntryID!! , entries!! [editEntryID!! ]!! , onClose = {
942+ if (it) {
943+ entries!! .remove(editEntryID!! .also { editEntryID = null })
944+ } else
945+ editEntryID = null
946+ }, onOpenUpdater = {
947+ vm.currentWizardFlow = UpdateFlow (entries!! [editEntryID!! ]!! .name)
948+ editEntryID = null
949+ })
950+ }
951+ }
856952}
0 commit comments