Skip to content

Commit

Permalink
tidy up yesterday's code
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Aug 1, 2024
1 parent fa24a61 commit 113d4c1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 59 deletions.
58 changes: 12 additions & 46 deletions app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private class CreatePartDataHolder(val vm: WizardActivityState): ProgressListene
@Composable
fun lateInit() {
noobMode = LocalContext.current.getSharedPreferences("abm", 0).getBoolean("noob_mode", BuildConfig.DEFAULT_NOOB_MODE)
meta = SDUtils.generateMeta(vm.deviceInfo!!)
meta = SDUtils.generateMeta(vm.deviceInfo)
(meta?.s?.find { vm.activity.intent.getLongExtra("part_sid", -1L) == it.startSector } as SDUtils.Partition.FreeSpace?)?.also { p = it }
}

Expand Down Expand Up @@ -800,41 +800,7 @@ private fun Download(c: CreatePartDataHolder) {
}
})
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
) {
Column {
Text(stringResource(id = R.string.installer_sh))
}
Column {
if (c.vm.flashes.containsKey("InstallShFlashType")) {
Button(onClick = {
c.vm.flashes.remove("InstallShFlashType")
}) {
Text(stringResource(R.string.undo))
}
} else {
if (c.scriptInet != null) {
Button(onClick = {
c.vm.flashes["InstallShFlashType"] = Pair(Uri.parse(c.scriptInet!!), c.scriptShaInet)
}) {
Text(stringResource(R.string.download))
}
}
Button(onClick = {
c.vm.activity.chooseFile("*/*") {
c.vm.flashes["InstallShFlashType"] = Pair(it, null)
}
}) {
Text(stringResource(R.string.choose))
}
}
}
}
for (i in c.idNeeded) {
val inet = c.inetAvailable.containsKey(i)
for (i in (c.idNeeded + listOf("_install.sh_"))) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
Expand All @@ -843,7 +809,8 @@ private fun Download(c: CreatePartDataHolder) {
Column {
Text(i)
Text(
if (c.inetDesc.containsKey(i)) c.inetDesc[i]!! else stringResource(R.string.user_selected),
if (c.inetDesc.containsKey(i)) c.inetDesc[i]!! else stringResource(
if (i == "_install.sh_") R.string.installer_sh else R.string.user_selected),
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
Expand All @@ -856,7 +823,7 @@ private fun Download(c: CreatePartDataHolder) {
Text(stringResource(R.string.undo))
}
} else {
if (inet) {
if (c.inetAvailable.containsKey(i) || i == "_install.sh_") {
Button(onClick = {
downloading = true
progressText = c.vm.activity.getString(R.string.connecting_text)
Expand All @@ -874,7 +841,8 @@ private fun Download(c: CreatePartDataHolder) {
try {
val downloadedFile = File(c.vm.logic.cacheDir, i)
val request =
Request.Builder().url(c.inetAvailable[i]!!).build()
Request.Builder().url(if (i == "_install.sh_")
c.scriptInet!! else c.inetAvailable[i]!!).build()
val call = c.client.newCall(request)
val response = call.execute()

Expand Down Expand Up @@ -919,7 +887,7 @@ private fun Download(c: CreatePartDataHolder) {
}
}
c.vm.btnsOverride = true
if (c.idNeeded.find { !c.chosen.containsKey(it) } == null) {
if (c.idNeeded.find { !c.chosen.containsKey(it) } == null && c.chosen.containsKey("_install.sh_")) {
c.vm.onNext.value = { it.navigate("flash") }
c.vm.nextText.value = stringResource(id = R.string.install)
} else {
Expand All @@ -939,14 +907,13 @@ private fun Flash(c: CreatePartDataHolder) {
val gn = c.t3.value
terminal.add(vm.activity.getString(R.string.term_f_name, fn))
terminal.add(vm.activity.getString(R.string.term_g_name, gn))
val tmpFile = createTempFileSu("abm", ".sh", vm.logic.rootTmpDir)
vm.copyPriv(vm.flashStream("InstallShFlashType"), tmpFile)
val tmpFile = c.chosen["_install.sh_"]!!.toFile(vm)
tmpFile.setExecutable(true)
terminal.add(vm.activity.getString(R.string.term_creating_pt))

// After creating partitions:
fun installMore() {
val meta = SDUtils.generateMeta(vm.deviceInfo!!)
val meta = SDUtils.generateMeta(vm.deviceInfo)
if (meta == null) {
terminal.add(vm.activity.getString(R.string.term_cant_get_meta))
return
Expand Down Expand Up @@ -1007,7 +974,6 @@ private fun Flash(c: CreatePartDataHolder) {
cmd += " " + i.value
}
val result = vm.logic.runShFileWithArgs(cmd).to(terminal).exec()
tmpFile.delete()
if (!result.isSuccess) {
terminal.add(vm.activity.getString(R.string.term_failure))
return
Expand Down Expand Up @@ -1045,7 +1011,7 @@ private fun Flash(c: CreatePartDataHolder) {
terminal.add(vm.activity.getString(R.string.term_reboot_asap))
}
parts[it] = c.meta!!.nid
c.meta = SDUtils.generateMeta(c.vm.deviceInfo!!)
c.meta = SDUtils.generateMeta(c.vm.deviceInfo)
if (it + 1 < c.count.intValue) {
c.p = c.meta!!.s.find { it1 -> it1.type == SDUtils.PartitionType.FREE && (offset + k) < it1.startSector } as SDUtils.Partition.FreeSpace
}
Expand All @@ -1056,7 +1022,7 @@ private fun Flash(c: CreatePartDataHolder) {
makeOne(it + 1)
} else {
terminal.add(vm.activity.getString(R.string.term_created_pt))
vm.logic.mountBootset(vm.deviceInfo!!)
vm.logic.mountBootset(vm.deviceInfo)
installMore()
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/andbootmgr/app/DeviceInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ class JsonDeviceInfoFactory(private val ctx: Context) {
}
val jsonRoot = JSONTokener(jsonText).nextValue() as JSONObject? ?: return null
val json = jsonRoot.getJSONObject("deviceInfo")
if (BuildConfig.VERSION_CODE < json.getInt("minAppVersion"))
if (BuildConfig.VERSION_CODE < jsonRoot.getInt("minAppVersion"))
throw IllegalStateException("please upgrade app")
if (fromNet) {
val newRoot = JSONObject()
newRoot.put("deviceInfo", json)
newRoot.put("minAppVersion", jsonRoot.getInt("minAppVersion"))
File(ctx.filesDir, "abm_dd_cache.json").writeText(newRoot.toString())
}
if (!json.getBoolean("metaOnSd"))
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DroidBootWizardPageFactory(private val vm: WizardActivityState) {
Start(vm)
}, WizardPage("input",
NavButton(vm.activity.getString(R.string.prev)) { it.navigate("start") },
NavButton(vm.activity.getString(R.string.next)) { it.navigate(if (vm.deviceInfo!!.postInstallScript) "shSel" else
NavButton(vm.activity.getString(R.string.next)) { it.navigate(if (vm.deviceInfo.postInstallScript) "shSel" else
(if (!vm.deviceInfo.isBooted(vm.logic)) "select" else "flash")) }
) {
Input(vm)
Expand All @@ -48,7 +48,7 @@ class DroidBootWizardPageFactory(private val vm: WizardActivityState) {
) {
SelectInstallSh(vm)
}, WizardPage("select",
NavButton(vm.activity.getString(R.string.prev)) { it.navigate(if (vm.deviceInfo!!.postInstallScript) "shSel" else "input") },
NavButton(vm.activity.getString(R.string.prev)) { it.navigate(if (vm.deviceInfo.postInstallScript) "shSel" else "input") },
NavButton("") {}
) {
SelectDroidBoot(vm)
Expand All @@ -68,7 +68,7 @@ private fun Start(vm: WizardActivityState) {
) {
Text(stringResource(R.string.welcome_text))
Text(
if (vm.deviceInfo!!.isBooted(vm.logic)) {
if (vm.deviceInfo.isBooted(vm.logic)) {
stringResource(R.string.install_abm)
} else {
stringResource(R.string.install_abm_dboot)
Expand Down Expand Up @@ -171,7 +171,7 @@ fun SelectDroidBoot(vm: WizardActivityState) {

// shared across DroidBootFlow, UpdateDroidBootFlow, FixDroidBootFlow
@Composable
fun SelectInstallSh(vm: WizardActivityState) {
fun SelectInstallSh(vm: WizardActivityState, update: Boolean = false) {
val nextButtonAvailable = remember { mutableStateOf(false) }
val flashType = "InstallShFlashType"

Expand All @@ -181,7 +181,7 @@ fun SelectInstallSh(vm: WizardActivityState) {
if (nextButtonAvailable.value) {
Text(stringResource(id = R.string.successfully_selected))
vm.nextText.value = stringResource(id = R.string.next)
vm.onNext.value = { it.navigate(if (!vm.deviceInfo!!.isBooted(vm.logic)) "select" else "flash") }
vm.onNext.value = { it.navigate(if (!vm.deviceInfo.isBooted(vm.logic) || update) "select" else "flash") }
} else {
Text(stringResource(R.string.choose_install_s_online))
Button(onClick = {
Expand Down Expand Up @@ -242,7 +242,7 @@ private fun Flash(vm: WizardActivityState) {
}
}

if (vm.deviceInfo!!.metaonsd) {
if (vm.deviceInfo.metaonsd) {
var meta = SDUtils.generateMeta(vm.deviceInfo)
if (meta == null) {
terminal.add(vm.activity.getString(R.string.term_cant_get_meta))
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FixDroidBootWizardPageFactory(private val vm: WizardActivityState) {
fun get(): List<IWizardPage> {
return listOf(WizardPage("start",
NavButton(vm.activity.getString(R.string.cancel)) { it.finish() },
NavButton(vm.activity.getString(R.string.next)) { it.navigate(if (vm.deviceInfo!!.postInstallScript) "shSel" else "select") })
NavButton(vm.activity.getString(R.string.next)) { it.navigate(if (vm.deviceInfo.postInstallScript) "shSel" else "select") })
{
Start(vm)
}, WizardPage("shSel",
Expand All @@ -28,7 +28,7 @@ class FixDroidBootWizardPageFactory(private val vm: WizardActivityState) {
) {
SelectInstallSh(vm)
},WizardPage("select",
NavButton(vm.activity.getString(R.string.prev)) { it.navigate(if (vm.deviceInfo!!.postInstallScript) "shSel" else "start") },
NavButton(vm.activity.getString(R.string.prev)) { it.navigate(if (vm.deviceInfo.postInstallScript) "shSel" else "start") },
NavButton("") {}
) {
SelectDroidBoot(vm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class UpdateDroidBootWizardPageFactory(private val vm: WizardActivityState) {
NavButton(vm.activity.getString(R.string.prev)) { it.navigate("start") },
NavButton("") {}
) {
SelectInstallSh(vm)
SelectInstallSh(vm, update = true)
},WizardPage("select",
NavButton(vm.activity.getString(R.string.prev)) { it.navigate(if (vm.deviceInfo!!.postInstallScript) "shSel" else "start") },
NavButton("") {}
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/drawable/ut_logo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
xmlns:tools="http://schemas.android.com/tools"
android:width="48dp"
android:height="48dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="425.197"
android:viewportHeight="425.197">
<path
android:fillColor="@android:color/black"
android:pathData="M354.331,212.595c0,78.279 -63.45,141.735 -141.729,141.735c-78.279,0 -141.735,-63.456 -141.735,-141.735c0,-78.274 63.457,-141.728 141.735,-141.728C290.881,70.867 354.331,134.32 354.331,212.595z"/>
<path
android:pathData="M139.043,212.595c0,10.064 -8.159,18.225 -18.23,18.225c-10.059,0 -18.218,-8.16 -18.218,-18.225c0,-10.06 8.159,-18.219 18.218,-18.219C130.884,194.376 139.043,202.535 139.043,212.595zM242.717,301.201c5.033,8.709 16.173,11.696 24.889,6.67c8.715,-5.033 11.701,-16.179 6.669,-24.895c-5.032,-8.715 -16.173,-11.695 -24.888,-6.663C240.671,281.346 237.685,292.486 242.717,301.201zM274.274,142.219c5.032,-8.717 2.052,-19.86 -6.669,-24.887c-8.71,-5.032 -19.855,-2.046 -24.889,6.667c-5.032,8.715 -2.046,19.857 6.67,24.889C258.102,153.92 269.248,150.934 274.274,142.219zM212.602,160.632c27.153,0 49.434,20.814 51.761,47.364l26.372,-0.416c-1.252,-19.727 -9.809,-37.469 -22.995,-50.551c-6.98,2.693 -15.079,2.327 -22.066,-1.71c-6.992,-4.037 -11.359,-10.871 -12.514,-18.275c-6.554,-1.78 -13.448,-2.733 -20.558,-2.733c-12.471,0 -24.259,2.916 -34.727,8.103l12.832,23.043C197.357,162.367 204.784,160.632 212.602,160.632zM160.633,212.595c0,-17.577 8.734,-33.121 22.097,-42.52l-13.54,-22.634c-15.684,10.474 -27.367,26.451 -32.296,45.183c5.833,4.697 9.57,11.897 9.57,19.972c0,8.08 -3.738,15.28 -9.57,19.978c4.929,18.731 16.612,34.708 32.296,45.188l13.54,-22.634C169.367,245.722 160.633,230.184 160.633,212.595zM212.602,264.568c-7.817,0 -15.244,-1.734 -21.895,-4.83l-12.832,23.043c10.468,5.191 22.255,8.104 34.727,8.104c7.109,0 14.004,-0.946 20.558,-2.729c1.154,-7.409 5.521,-14.243 12.514,-18.273c6.987,-4.037 15.086,-4.404 22.066,-1.711c13.187,-13.088 21.743,-30.83 22.995,-50.557l-26.372,-0.409C262.035,243.749 239.755,264.568 212.602,264.568z"
android:fillColor="@android:color/white"
Expand Down

0 comments on commit 113d4c1

Please sign in to comment.