Skip to content

Commit

Permalink
refactor refactor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nift4 committed Aug 20, 2024
1 parent 815e1bc commit 8ef3cff
Show file tree
Hide file tree
Showing 15 changed files with 1,036 additions and 1,102 deletions.
7 changes: 0 additions & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.compose")
id("org.jetbrains.kotlinx.atomicfu")
id("com.mikepenz.aboutlibraries.plugin")
}

Expand Down Expand Up @@ -111,19 +110,13 @@ android {
}
}

atomicfu {
dependenciesVersion = "0.25.0"
jvmVariant = "FU"
}

tasks.register("setAssetTs", Task::class) {
doLast {
File("$rootDir/app/src/main/assets/cp/_ts").writeText((System.currentTimeMillis() / 1000L).toString())
}
}

dependencies {
compileOnly("org.jetbrains.kotlinx:atomicfu:0.25.0")
implementation("androidx.core:core-splashscreen:1.0.1")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("androidx.legacy:legacy-support-v4:1.0.0")
Expand Down
7 changes: 1 addition & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@
android:value="Update Android device bootloader / install OS to SD card"/>
</service>

<activity
android:name=".WizardActivity"
android:configChanges="density|fontScale|keyboard|keyboardHidden|layoutDirection|locale|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"
android:exported="false"
android:theme="@style/AppTheme" />
<activity
android:name=".MainActivity"
android:exported="true"
android:configChanges="keyboard|keyboardHidden|orientation"
android:theme="@style/AppTheme">
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
10 changes: 4 additions & 6 deletions app/src/main/java/org/andbootmgr/app/BackupRestoreFlow.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.andbootmgr.app

import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -28,7 +27,7 @@ class BackupRestoreWizardPageFactory(private val vm: WizardActivityState) {
fun get(): List<IWizardPage> {
val c = CreateBackupDataHolder(vm)
return listOf(WizardPage("start",
NavButton(vm.activity.getString(R.string.cancel)) { it.startActivity(Intent(it, MainActivity::class.java)); it.finish() },
NavButton(vm.activity.getString(R.string.cancel)) { it.finish() },
NavButton("") {})
{
ChooseAction(c)
Expand All @@ -46,19 +45,18 @@ class BackupRestoreWizardPageFactory(private val vm: WizardActivityState) {
}
}

private class CreateBackupDataHolder(val vm: WizardActivityState){
private class CreateBackupDataHolder(val vm: WizardActivityState) {
var pi: Int = -1
var action: Int = 0
var path: Uri? = null
var meta: SDUtils.SDPartitionMeta? = null

}

@Composable
private fun ChooseAction(c: CreateBackupDataHolder) {
LaunchedEffect(Unit) {
c.meta = SDUtils.generateMeta(c.vm.deviceInfo)
c.pi = c.vm.activity.intent.getIntExtra("partitionid", -1)
c.pi = c.vm.mvm.wizardCompatPid!!
}

Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center,
Expand Down Expand Up @@ -163,6 +161,6 @@ private fun Flash(c: CreateBackupDataHolder) {
terminal.add(c.vm.activity.getString(R.string.term_success))
c.vm.btnsOverride = true
c.vm.nextText.value = c.vm.activity.getString(R.string.finish)
c.vm.onNext.value = { it.startActivity(Intent(it, MainActivity::class.java)); it.finish() }
c.vm.onNext.value = { it.finish() }
}
}
43 changes: 7 additions & 36 deletions app/src/main/java/org/andbootmgr/app/CreatePartFlow.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.andbootmgr.app

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.util.Log
import android.widget.Toast
Expand All @@ -20,7 +19,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.io.SuFile
Expand All @@ -30,30 +28,25 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.*
import okio.*
import org.andbootmgr.app.util.AbmTheme
import org.andbootmgr.app.util.ConfigFile
import org.andbootmgr.app.util.SDUtils
import org.andbootmgr.app.util.SOUtils
import org.andbootmgr.app.util.Terminal
import org.json.JSONObject
import org.json.JSONTokener
import java.io.File
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.io.InputStream
import java.math.BigDecimal
import java.util.concurrent.TimeUnit
import org.json.JSONObject
import org.json.JSONTokener
import java.io.FileNotFoundException
import java.net.URL
import java.nio.charset.Charset
import java.util.concurrent.TimeUnit

class CreatePartWizardPageFactory(private val vm: WizardActivityState) {
fun get(): List<IWizardPage> {
val c = CreatePartDataHolder(vm)
return listOf(WizardPage("start",
NavButton(vm.activity.getString(R.string.cancel)) {
it.startActivity(Intent(it, MainActivity::class.java))
it.finish()
},
NavButton(vm.activity.getString(R.string.cancel)) { it.finish() },
NavButton("") {}
) {
Start(c)
Expand All @@ -68,10 +61,7 @@ class CreatePartWizardPageFactory(private val vm: WizardActivityState) {
) {
Os(c)
}, WizardPage("dload",
NavButton(vm.activity.getString(R.string.cancel)) {
it.startActivity(Intent(it, MainActivity::class.java))
it.finish()
},
NavButton(vm.activity.getString(R.string.cancel)) { it.finish() },
NavButton("") {}
) {
Download(c)
Expand Down Expand Up @@ -996,10 +986,7 @@ private fun Flash(c: CreatePartDataHolder) {
terminal.add(vm.activity.getString(R.string.term_success))
vm.btnsOverride = true
vm.nextText.value = vm.activity.getString(R.string.finish)
vm.onNext.value = {
it.startActivity(Intent(it, MainActivity::class.java))
it.finish()
}
vm.onNext.value = { it.finish() }
}

// Fucking complicated code to fairly and flexibly partition space based on preset percentage & bytes values
Expand Down Expand Up @@ -1063,7 +1050,6 @@ private fun Flash(c: CreatePartDataHolder) {
vm.btnsOverride = true
vm.nextText.value = c.vm.activity.getString(R.string.finish)
vm.onNext.value = {
it.startActivity(Intent(it, MainActivity::class.java))
it.finish()
}
terminal.add(vm.activity.getString(R.string.term_success))
Expand All @@ -1072,19 +1058,4 @@ private fun Flash(c: CreatePartDataHolder) {
}
}
}
}

@Composable
@Preview
private fun Preview() {
val vm = WizardActivityState("null")
val c = CreatePartDataHolder(vm)
AbmTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Start(c)
}
}
}
42 changes: 18 additions & 24 deletions app/src/main/java/org/andbootmgr/app/DroidBootFlow.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
package org.andbootmgr.app

import android.content.Intent
import android.net.Uri
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
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.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.topjohnwu.superuser.Shell
import com.topjohnwu.superuser.io.SuFile
import com.topjohnwu.superuser.io.SuFileInputStream
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.andbootmgr.app.util.AbmTheme
import org.andbootmgr.app.util.ConfigFile
import org.andbootmgr.app.util.SDUtils
import org.andbootmgr.app.util.Terminal
Expand All @@ -38,7 +46,7 @@ import java.net.URL
class DroidBootWizardPageFactory(private val vm: WizardActivityState) {
fun get(): List<IWizardPage> {
return listOf(WizardPage("start",
NavButton(vm.activity.getString(R.string.cancel)) { it.startActivity(Intent(it, MainActivity::class.java)); it.finish() },
NavButton(vm.activity.getString(R.string.cancel)) { it.finish() },
NavButton(vm.activity.getString(R.string.next)) { it.navigate("input") })
{
Start(vm)
Expand Down Expand Up @@ -370,26 +378,12 @@ private fun Flash(vm: WizardActivityState) {
vm.nextText.value = vm.activity.getString(R.string.finish)
vm.onNext.value = {
if (vm.deviceInfo.isBooted(vm.logic)) {
it.startActivity(Intent(it, MainActivity::class.java))
it.finish()
} else {
// TODO prompt user to reboot?
it.finish()
}
it.finish()
}
}
}
}

@Composable
@Preview
private fun Preview() {
val vm = WizardActivityState("null")
AbmTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Input(vm)
}
}
}
20 changes: 1 addition & 19 deletions app/src/main/java/org/andbootmgr/app/FixDroidBootFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ package org.andbootmgr.app
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.*
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import com.topjohnwu.superuser.io.SuFile
import com.topjohnwu.superuser.io.SuFileInputStream
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.andbootmgr.app.util.AbmTheme
import org.andbootmgr.app.util.Terminal
import java.io.File
import java.io.IOException
Expand Down Expand Up @@ -103,18 +99,4 @@ private fun Flash(vm: WizardActivityState) {
}
}
}
}

@Composable
@Preview
private fun Preview() {
val vm = WizardActivityState("null")
AbmTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
SelectDroidBoot(vm)
}
}
}
Loading

0 comments on commit 8ef3cff

Please sign in to comment.