11package org.andbootmgr.app
22
3- import android.net.Uri
43import android.os.Handler
54import android.os.Looper
65import android.util.Log
76import android.widget.Toast
87import androidx.compose.foundation.layout.Arrangement
98import androidx.compose.foundation.layout.Column
10- import androidx.compose.foundation.layout.defaultMinSize
119import androidx.compose.foundation.layout.fillMaxSize
1210import androidx.compose.foundation.layout.padding
13- import androidx.compose.material3.Button
14- import androidx.compose.material3.Icon
1511import androidx.compose.material3.MaterialTheme
1612import androidx.compose.material3.Text
1713import androidx.compose.material3.TextField
@@ -23,8 +19,6 @@ import androidx.compose.runtime.remember
2319import androidx.compose.runtime.setValue
2420import androidx.compose.ui.Alignment
2521import androidx.compose.ui.Modifier
26- import androidx.compose.ui.platform.LocalContext
27- import androidx.compose.ui.res.painterResource
2822import androidx.compose.ui.res.stringResource
2923import androidx.compose.ui.text.style.TextAlign
3024import androidx.compose.ui.unit.dp
@@ -46,7 +40,7 @@ import java.net.URL
4640
4741class DroidBootFlow : WizardFlow () {
4842 override fun get (vm : WizardActivityState ): List <IWizardPage > {
49- val booted = vm.deviceInfo.isBooted (vm.logic )
43+ val d = DroidBootFlowDataHolder (vm)
5044 return listOf (WizardPage (" start" ,
5145 NavButton (vm.activity.getString(R .string.cancel)) { it.finish() },
5246 NavButton (vm.activity.getString(R .string.next)) { it.navigate(" input" ) })
@@ -56,21 +50,25 @@ class DroidBootFlow : WizardFlow() {
5650 NavButton (vm.activity.getString(R .string.prev)) { it.navigate(" start" ) },
5751 NavButton (" " ) {}
5852 ) {
59- Input (vm )
53+ Input (d )
6054 }, WizardPage (" dload" ,
6155 NavButton (vm.activity.getString(R .string.cancel)) { it.finish() },
6256 NavButton (" " ) {}
6357 ) {
64- WizardDownloader (vm)
58+ WizardDownloader (vm, " flash " )
6559 }, WizardPage (" flash" ,
6660 NavButton (" " ) {},
6761 NavButton (" " ) {}
6862 ) {
69- Flash (vm )
63+ Flash (d )
7064 })
7165 }
7266}
7367
68+ class DroidBootFlowDataHolder (val vm : WizardActivityState ) {
69+ var osName by mutableStateOf(vm.activity.getString(R .string.android))
70+ }
71+
7472@Composable
7573private fun Start (vm : WizardActivityState ) {
7674 Column (horizontalAlignment = Alignment .CenterHorizontally , verticalArrangement = Arrangement .Center ,
@@ -118,10 +116,10 @@ fun LoadDroidBootJson(vm: WizardActivityState, content: @Composable () -> Unit)
118116 val i = json.getJSONObject(" installScript" )
119117 val url = i.getString(" url" )
120118 val sha = i.optString(" sha256" )
121- vm.inetAvailable[" install " ] = WizardActivityState .Downloadable (
119+ vm.inetAvailable[" _install.sh_ " ] = WizardActivityState .Downloadable (
122120 url, sha, vm.activity.getString(R .string.installer_sh)
123121 )
124- vm.idNeeded.add(" install " )
122+ vm.idNeeded.add(" _install.sh_ " )
125123 }
126124 loading = false
127125 } catch (e: Exception ) {
@@ -143,28 +141,24 @@ fun LoadDroidBootJson(vm: WizardActivityState, content: @Composable () -> Unit)
143141}
144142
145143@Composable
146- private fun Input (vm : WizardActivityState ) {
147- LoadDroidBootJson (vm) {
144+ private fun Input (d : DroidBootFlowDataHolder ) {
145+ LoadDroidBootJson (d. vm) {
148146 Column (
149147 horizontalAlignment = Alignment .CenterHorizontally ,
150148 verticalArrangement = Arrangement .Center ,
151149 modifier = Modifier .fillMaxSize()
152150 ) {
153- LaunchedEffect (Unit ) { // TODO can't I do this better?
154- if (vm.texts.isBlank())
155- vm.texts = vm.activity.getString(R .string.android)
156- }
157- val e = vm.texts.isBlank() || ! vm.texts.matches(Regex (" [\\ dA-Za-z]+" ))
151+ val e = d.osName.isBlank() || ! d.osName.matches(Regex (" [\\ dA-Za-z]+" ))
158152
159153 Text (
160154 stringResource(R .string.enter_name_for_current),
161155 textAlign = TextAlign .Center ,
162156 modifier = Modifier .padding(vertical = 5 .dp)
163157 )
164158 TextField (
165- value = vm.texts ,
159+ value = d.osName ,
166160 onValueChange = {
167- vm.texts = it
161+ d.osName = it
168162 },
169163 label = { Text (stringResource(R .string.os_name)) },
170164 isError = e
@@ -176,20 +170,20 @@ private fun Input(vm: WizardActivityState) {
176170 }
177171 LaunchedEffect (e) {
178172 if (e) {
179- vm.nextText = " "
180- vm.onNext = {}
173+ d. vm.nextText = " "
174+ d. vm.onNext = {}
181175 } else {
182- vm.nextText = vm.activity.getString(R .string.next)
183- vm.onNext = { it.navigate(if (vm.idNeeded.isNotEmpty()) " dload" else " flash" ) }
176+ d. vm.nextText = d. vm.activity.getString(R .string.next)
177+ d. vm.onNext = { it.navigate(if (d. vm.idNeeded.isNotEmpty()) " dload" else " flash" ) }
184178 }
185179 }
186180 }
187181 }
188182}
189183
190184@Composable
191- private fun Flash (vm : WizardActivityState ) {
192- val flashType = " DroidBootFlashType "
185+ private fun Flash (d : DroidBootFlowDataHolder ) {
186+ val vm = d.vm
193187 Terminal (logFile = " blflash_${System .currentTimeMillis()} .txt" ) { terminal ->
194188 vm.logic.extractToolkit(terminal)
195189 terminal.add(vm.activity.getString(R .string.term_preparing_fs))
@@ -276,7 +270,7 @@ private fun Flash(vm: WizardActivityState) {
276270 }
277271 val tmpFile = if (vm.deviceInfo.postInstallScript) {
278272 val tmpFile = createTempFileSu(" abm" , " .sh" , vm.logic.rootTmpDir)
279- vm.copyPriv(vm.chosen[" install " ]!! .openInputStream(vm), tmpFile)
273+ vm.copyPriv(vm.chosen[" _install.sh_ " ]!! .openInputStream(vm), tmpFile)
280274 tmpFile.setExecutable(true )
281275 tmpFile
282276 } else null
@@ -287,7 +281,7 @@ private fun Flash(vm: WizardActivityState) {
287281 db[" timeout" ] = " 5"
288282 db.exportToFile(File (vm.logic.abmDb, " db.conf" ))
289283 val entry = ConfigFile ()
290- entry[" title" ] = vm.texts .trim()
284+ entry[" title" ] = d.osName .trim()
291285 entry[" linux" ] = " null"
292286 entry[" initrd" ] = " null"
293287 entry[" dtb" ] = " null"
0 commit comments