Skip to content

Commit

Permalink
feat: improve install screen UI (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine authored May 19, 2024
1 parent 6e16368 commit 7156f08
Show file tree
Hide file tree
Showing 20 changed files with 417 additions and 186 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/Theme.AliucordManager.SplashScreen">
android:screenOrientation="portrait"
android:theme="@style/Theme.AliucordManager.SplashScreen"
tools:ignore="DiscouragedApi,LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class KotlinInstallRunner(options: InstallOptions) : StepRunner() {
DownloadInjectorStep(),
DownloadAliuhookStep(),
DownloadKotlinStep(),
CopyDependenciesStep(),

// Patch
CopyDependenciesStep(),
ReplaceIconStep(options),
PatchManifestStep(options),
AddInjectorStep(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.aliucord.manager.installer.steps.patch
package com.aliucord.manager.installer.steps.download

import com.aliucord.manager.R
import com.aliucord.manager.installer.steps.StepGroup
import com.aliucord.manager.installer.steps.StepRunner
import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.steps.download.DownloadDiscordStep
import com.aliucord.manager.manager.PathManager
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
Expand All @@ -22,7 +21,7 @@ class CopyDependenciesStep : Step(), KoinComponent {
val patchedApk: File = paths.patchingWorkingDir()
.resolve("patched.apk")

override val group = StepGroup.Patch
override val group = StepGroup.Download
override val localizedName = R.string.install_step_copy

override suspend fun execute(container: StepRunner) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.aliucord.manager.installer.steps.StepGroup
import com.aliucord.manager.installer.steps.StepRunner
import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.steps.base.StepState
import com.aliucord.manager.installer.steps.patch.CopyDependenciesStep
import com.aliucord.manager.installer.steps.download.CopyDependenciesStep
import com.github.diamondminer88.zip.*
import org.koin.core.component.KoinComponent

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.aliucord.manager.installer.steps.StepGroup
import com.aliucord.manager.installer.steps.StepRunner
import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.steps.base.StepState
import com.aliucord.manager.installer.steps.patch.CopyDependenciesStep
import com.aliucord.manager.installer.steps.download.CopyDependenciesStep
import com.aliucord.manager.installers.InstallerResult
import com.aliucord.manager.manager.InstallerManager
import com.aliucord.manager.manager.PreferencesManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.aliucord.manager.R
import com.aliucord.manager.installer.steps.StepGroup
import com.aliucord.manager.installer.steps.StepRunner
import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.steps.patch.CopyDependenciesStep
import com.aliucord.manager.installer.steps.download.CopyDependenciesStep
import com.aliucord.manager.installer.util.Signer
import org.koin.core.component.KoinComponent

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.aliucord.manager.R
import com.aliucord.manager.installer.steps.StepGroup
import com.aliucord.manager.installer.steps.StepRunner
import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.steps.download.CopyDependenciesStep
import com.aliucord.manager.installer.steps.download.DownloadAliuhookStep
import com.github.diamondminer88.zip.ZipReader
import com.github.diamondminer88.zip.ZipWriter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import com.aliucord.manager.R
import com.aliucord.manager.installer.steps.StepGroup
import com.aliucord.manager.installer.steps.StepRunner
import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.steps.download.DownloadInjectorStep
import com.aliucord.manager.installer.steps.download.DownloadKotlinStep
import com.aliucord.manager.installer.steps.download.*
import com.github.diamondminer88.zip.ZipReader
import com.github.diamondminer88.zip.ZipWriter
import org.koin.core.component.KoinComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.aliucord.manager.R
import com.aliucord.manager.installer.steps.StepGroup
import com.aliucord.manager.installer.steps.StepRunner
import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.steps.download.CopyDependenciesStep
import com.aliucord.manager.installer.util.ManifestPatcher
import com.aliucord.manager.ui.screens.installopts.InstallOptions
import com.github.diamondminer88.zip.ZipReader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.aliucord.manager.installer.steps.StepGroup
import com.aliucord.manager.installer.steps.StepRunner
import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.steps.base.StepState
import com.aliucord.manager.installer.steps.download.CopyDependenciesStep
import com.aliucord.manager.installer.util.ArscUtil
import com.aliucord.manager.installer.util.ArscUtil.addColorResource
import com.aliucord.manager.installer.util.ArscUtil.addResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ object ManifestPatcher {
override fun attr(ns: String?, name: String, resourceId: Int, type: Int, value: Any?) {
if (name == NETWORK_SECURITY_CONFIG) return
super.attr(ns, name, resourceId, type, value)
if (name == REQUEST_LEGACY_EXTERNAL_STORAGE) addLegacyStorage = false;
if (name == REQUEST_LEGACY_EXTERNAL_STORAGE) addLegacyStorage = false
if (name == DEBUGGABLE) addDebuggable = false
if (name == USES_CLEARTEXT_TRAFFIC) addUseClearTextTraffic = false
}
Expand Down
58 changes: 58 additions & 0 deletions app/src/main/kotlin/com/aliucord/manager/ui/TextBanner.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.aliucord.manager.ui

import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.unit.dp
import com.aliucord.manager.ui.util.thenIf

@Composable
fun TextBanner(
text: String,
icon: Painter,
iconColor: Color,
outlineColor: Color?,
containerColor: Color,
onClick: (() -> Unit)? = null,
modifier: Modifier = Modifier,
) {
Box(
contentAlignment = Alignment.Center,
modifier = modifier
.thenIf(outlineColor) { color ->
border(
width = 2.dp,
color = color,
shape = MaterialTheme.shapes.medium,
)
}
.clip(MaterialTheme.shapes.medium)
.background(containerColor)
.thenIf(onClick) { clickable(onClick = it) }
) {
Row(
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.padding(horizontal = 20.dp, vertical = 14.dp)
) {
Icon(
painter = icon,
tint = iconColor,
contentDescription = null,
modifier = Modifier.size(28.dp),
)

Text(
text = text,
style = MaterialTheme.typography.labelMedium,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ package com.aliucord.manager.ui.screens.install

import android.annotation.SuppressLint
import android.app.Application
import android.content.Intent
import android.os.Build
import android.util.Log
import androidx.annotation.StringRes
import androidx.compose.runtime.*
import cafe.adriel.voyager.core.model.StateScreenModel
import cafe.adriel.voyager.core.model.screenModelScope
Expand All @@ -25,6 +27,7 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import java.text.SimpleDateFormat
import java.util.Date
import kotlin.time.Duration.Companion.seconds

class InstallModel(
private val application: Application,
Expand All @@ -35,16 +38,35 @@ class InstallModel(
private var installJob: Job? = null
private var stepRunner: StepRunner? = null

private var autocloseCancelled: Boolean = false

var installSteps by mutableStateOf<ImmutableMap<StepGroup, ImmutableList<Step>>?>(null)
private set

var showGppWarning by mutableStateOf(false)
private set

@get:StringRes
var funFact by mutableIntStateOf(0)
private set

init {
restart()

// Rotate fun facts every 20s
screenModelScope.launch {
while (true) {
funFact = FUN_FACTS.random()
delay(20.seconds)
}
}
}

fun launchApp() {
if (state.value !is InstallScreenState.Success)
return

Intent(options.packageName)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.also(application::startActivity)
}

fun copyDebugToClipboard() {
Expand All @@ -68,17 +90,10 @@ class InstallModel(
}

fun clearCache() {
paths.clearCache()
screenModelScope.launch { paths.clearCache() }
application.showToast(R.string.action_cleared_cache)
}

/**
* Cancel the screen auto-close once installation was completed
*/
fun cancelAutoclose() {
autocloseCancelled = true
}

/**
* Hide the 'Google Play Protect is enabled on your device' warning dialog
*/
Expand Down Expand Up @@ -130,13 +145,6 @@ class InstallModel(
// At this point, the installation has successfully completed
else {
mutableState.value = InstallScreenState.Success
autocloseCancelled = false

// Wait 5s before returning to Home if screen hasn't been clicked
delay(5000)
if (!autocloseCancelled) {
mutableState.value = InstallScreenState.CloseScreen
}
}
}

Expand Down Expand Up @@ -188,6 +196,25 @@ class InstallModel(
SOC: $soc
""".trimIndent()

return header + "\n\n" + Log.getStackTraceString(stacktrace)
return header + "\n\n" + Log.getStackTraceString(stacktrace).trimEnd()
}

private companion object {
/**
* Random fun facts to show on the installation screen.
*/
val FUN_FACTS = arrayOf(
R.string.fun_fact_1,
R.string.fun_fact_2,
R.string.fun_fact_3,
R.string.fun_fact_4,
R.string.fun_fact_5,
R.string.fun_fact_6,
R.string.fun_fact_7,
R.string.fun_fact_8,
R.string.fun_fact_9,
R.string.fun_fact_10,
R.string.fun_fact_11,
)
}
}
Loading

0 comments on commit 7156f08

Please sign in to comment.