Skip to content

Commit

Permalink
feat: move to voyager, clean up, remove NavBar
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Jan 13, 2024
1 parent 0efd525 commit 5339459
Show file tree
Hide file tree
Showing 55 changed files with 1,106 additions and 1,120 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Aliucord Manager [![Crowdin](https://badges.crowdin.net/aliucord-manager/localized.svg)](https://crowdin.com/project/aliucord-manager)
Aliucord Manager - Aliucord Installer rewrite in [Kotlin](https://kotlinlang.org) and [Jetpack Compose](https://developer.android.com/jetpack/compose).

Aliucord Manager - Aliucord Installer rewrite in [Kotlin](https://kotlinlang.org)
and [Jetpack Compose](https://developer.android.com/jetpack/compose).

INFO: This app is not functional yet, if you want to install Aliucord - [read this](https://github.com/Aliucord/Aliucord#-installation)
7 changes: 5 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ android {
jvmTarget = "11"
freeCompilerArgs += listOf(
"-Xcontext-receivers",
"-P", "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=${reportsDir}",
"-opt-in=androidx.compose.foundation.ExperimentalFoundationApi",
"-opt-in=androidx.compose.animation.ExperimentalAnimationApi",
"-opt-in=androidx.compose.material3.ExperimentalMaterial3Api",
// "-P", "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=${reportsDir}",
)
}

Expand All @@ -110,6 +113,7 @@ dependencies {
implementation(libs.bundles.compose)
implementation(libs.bundles.koin)
implementation(libs.bundles.ktor)
implementation(libs.bundles.voyager)

implementation(libs.compose.ui.tooling.preview)
debugImplementation(libs.compose.ui.tooling)
Expand All @@ -122,7 +126,6 @@ dependencies {
implementation(libs.axml)
implementation(libs.bouncycastle)
implementation(libs.coil)
implementation(libs.navigationReimagined)
implementation(variantOf(libs.zip) { artifactType("aar") })
}

Expand Down
58 changes: 15 additions & 43 deletions app/src/main/kotlin/com/aliucord/manager/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import cafe.adriel.voyager.navigator.Navigator
import cafe.adriel.voyager.transitions.FadeTransition
import com.aliucord.manager.domain.manager.PreferencesManager
import com.aliucord.manager.ui.dialog.StoragePermissionsDialog
import com.aliucord.manager.ui.dialog.UpdaterDialog
import com.aliucord.manager.ui.navigation.*
import com.aliucord.manager.ui.screen.*
import com.aliucord.manager.ui.theme.ManagerTheme
import com.aliucord.manager.ui.theme.Theme
import dev.olshevski.navigation.reimagined.*
import kotlinx.collections.immutable.persistentListOf
import com.aliucord.manager.ui.components.*
import com.aliucord.manager.ui.components.dialogs.StoragePermissionsDialog
import com.aliucord.manager.ui.screens.home.HomeScreen
import com.aliucord.manager.ui.widgets.updater.UpdaterDialog
import org.koin.android.ext.android.inject

// TODO: move to a path provider in DI
val aliucordDir = Environment.getExternalStorageDirectory().resolve("Aliucord")

class MainActivity : ComponentActivity() {
Expand All @@ -38,12 +37,6 @@ class MainActivity : ComponentActivity() {
isDarkTheme = preferences.theme == Theme.DARK || preferences.theme == Theme.SYSTEM && isSystemInDarkTheme(),
isDynamicColor = preferences.dynamicColor
) {
val navController = rememberNavController<AppDestination>(AppDestination.Home)

BackHandler {
navController.back()
}

StoragePermissionsDialog()

@Suppress("KotlinConstantConditions")
Expand All @@ -55,36 +48,15 @@ class MainActivity : ComponentActivity() {
UpdaterDialog()
}

NavHost(
controller = navController,
) {
when (val dest = this.currentHostEntry.destination) {
is BaseScreenDestination -> BaseScreen(
currentNavItem = dest,
bottomNavItems = persistentListOf(AppDestination.Home, AppDestination.Plugins, AppDestination.Settings),
onNavChanged = { navController.replaceLast(it) }
) {
when (dest) {
is AppDestination.Home -> HomeScreen(
onClickInstall = { data ->
navController.navigate(AppDestination.Install(data))
}
)

is AppDestination.Plugins -> PluginsScreen()
is AppDestination.Settings -> SettingsScreen()
}
}

is AppDestination.Install -> InstallerScreen(
installData = dest.installData,
onBackClick = { navController.back() }
)

is AppDestination.About -> AboutScreen(
onBackClick = { navController.back() }
)
Navigator(
screen = HomeScreen(),
onBackPressed = null,
) { navigator ->
BackHandler {
navigator.back(this@MainActivity)
}

FadeTransition(navigator)
}
}
}
Expand Down
20 changes: 13 additions & 7 deletions app/src/main/kotlin/com/aliucord/manager/ManagerApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import com.aliucord.manager.di.*
import com.aliucord.manager.domain.repository.AliucordMavenRepository
import com.aliucord.manager.domain.repository.GithubRepository
import com.aliucord.manager.network.service.*
import com.aliucord.manager.ui.viewmodel.*
import com.aliucord.manager.ui.screens.about.AboutModel
import com.aliucord.manager.ui.screens.home.HomeModel
import com.aliucord.manager.ui.screens.install.InstallModel
import com.aliucord.manager.ui.screens.plugins.PluginsModel
import com.aliucord.manager.ui.screens.settings.SettingsModel
import com.aliucord.manager.ui.widgets.updater.UpdaterViewModel
import org.koin.android.ext.koin.androidContext
import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.core.context.startKoin
import org.koin.core.module.dsl.factoryOf
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module

Expand Down Expand Up @@ -39,13 +45,13 @@ class ManagerApplication : Application() {
singleOf(::AliucordMavenRepository)
})

// ViewModels
// UI Models
modules(module {
viewModelOf(::HomeViewModel)
viewModelOf(::PluginsViewModel)
viewModelOf(::AboutViewModel)
viewModelOf(::InstallViewModel)
viewModelOf(::SettingsViewModel)
factoryOf(::HomeModel)
factoryOf(::PluginsModel)
factoryOf(::AboutModel)
factoryOf(::InstallModel)
factoryOf(::SettingsModel)
viewModelOf(::UpdaterViewModel)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import java.io.File
import kotlin.coroutines.*

class DownloadManager(
private val application: Application
private val application: Application,
) {
private val downloadManager = application.getSystemService<DownloadManager>()!!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.aliucord.manager.domain.manager

import android.content.SharedPreferences
import com.aliucord.manager.domain.manager.base.BasePreferenceManager
import com.aliucord.manager.ui.theme.Theme
import com.aliucord.manager.ui.components.Theme

class PreferencesManager(preferences: SharedPreferences) : BasePreferenceManager(preferences) {
var theme by enumPreference("theme", Theme.SYSTEM)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.core.content.edit
import kotlin.reflect.KProperty

abstract class BasePreferenceManager(
private val prefs: SharedPreferences
private val prefs: SharedPreferences,
) {
protected fun getString(key: String, defaultValue: String) = prefs.getString(key, defaultValue) ?: defaultValue
private fun getBoolean(key: String, defaultValue: Boolean) = prefs.getBoolean(key, defaultValue)
Expand All @@ -25,7 +25,7 @@ abstract class BasePreferenceManager(
private val key: String,
defaultValue: T,
getter: (key: String, defaultValue: T) -> T,
private val setter: (key: String, newValue: T) -> Unit
private val setter: (key: String, newValue: T) -> Unit,
) {
@Suppress("RedundantSetter")
var value by mutableStateOf(getter(key, defaultValue))
Expand All @@ -40,7 +40,7 @@ abstract class BasePreferenceManager(

protected fun stringPreference(
key: String,
defaultValue: String
defaultValue: String,
) = Preference(
key = key,
defaultValue = defaultValue,
Expand All @@ -50,7 +50,7 @@ abstract class BasePreferenceManager(

protected fun booleanPreference(
key: String,
defaultValue: Boolean
defaultValue: Boolean,
) = Preference(
key = key,
defaultValue = defaultValue,
Expand All @@ -60,7 +60,7 @@ abstract class BasePreferenceManager(

protected fun intPreference(
key: String,
defaultValue: Int
defaultValue: Int,
) = Preference(
key = key,
defaultValue = defaultValue,
Expand All @@ -70,7 +70,7 @@ abstract class BasePreferenceManager(

protected fun floatPreference(
key: String,
defaultValue: Float
defaultValue: Float,
) = Preference(
key = key,
defaultValue = defaultValue,
Expand All @@ -80,7 +80,7 @@ abstract class BasePreferenceManager(

protected inline fun <reified E : Enum<E>> enumPreference(
key: String,
defaultValue: E
defaultValue: E,
) = Preference(
key = key,
defaultValue = defaultValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ import com.github.diamondminer88.zip.ZipReader
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import org.koin.core.context.GlobalContext
import org.koin.core.component.KoinComponent
import org.koin.core.component.get
import java.io.File

private val json: Json = GlobalContext.get().get()

@Immutable
data class Plugin(val file: File) {
data class Plugin(val file: File) : KoinComponent {
val manifest: Manifest

init {
Expand All @@ -25,7 +24,7 @@ data class Plugin(val file: File) {
?: throw Exception("Plugin ${file.nameWithoutExtension} has no manifest.")

@OptIn(ExperimentalSerializationApi::class)
this.manifest = json.decodeFromStream(manifest.read().inputStream())
this.manifest = get<Json>().decodeFromStream(manifest.read().inputStream())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.aliucord.manager.network.utils.*
import io.ktor.http.HttpStatusCode

class AliucordMavenRepository(
private val maven: MavenService
private val maven: MavenService,
) {
suspend fun getAliuhookVersion(): ApiResponse<String> {
return maven.getArtifactMetadata(BASE_URL, ALIUHOOK).transform {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.aliucord.manager.network.service.AliucordGithubService
import com.aliucord.manager.network.utils.transform

class GithubRepository(
private val service: AliucordGithubService
private val service: AliucordGithubService,
) {
suspend fun getCommits(page: Int = 0) = service.getCommits(page)
suspend fun getContributors() = service.getContributors()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object ManifestPatcher {
manifestBytes: ByteArray,
packageName: String,
appName: String,
debuggable: Boolean
debuggable: Boolean,
): ByteArray {
val reader = AxmlReader(manifestBytes)
val writer = AxmlWriter()
Expand Down Expand Up @@ -142,7 +142,7 @@ object ManifestPatcher {

fun renamePackage(
manifestBytes: ByteArray,
packageName: String
packageName: String,
): ByteArray {
val reader = AxmlReader(manifestBytes)
val writer = AxmlWriter()
Expand All @@ -160,7 +160,7 @@ object ManifestPatcher {

private open class ReplaceAttrsVisitor(
nv: NodeVisitor,
private val attrs: Map<String, Any>
private val attrs: Map<String, Any>,
) : NodeVisitor(nv) {
override fun attr(ns: String?, name: String, resourceId: Int, type: Int, value: Any?) {
val replace = attrs.containsKey(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class Commit(
val htmlUrl: String,
val sha: String,
val commit: Commit,
val author: Author?
val author: Author?,
) {
@Serializable
data class Author(@SerialName("login") val name: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ data class GithubRelease(
val createdAt: String,
val assets: List<GithubReleaseAssets>,
@SerialName("tag_name")
val tagName: String
val tagName: String,
) {
@Serializable
data class GithubReleaseAssets(
val name: String,
@SerialName("browser_download_url")
val browserDownloadUrl: String
val browserDownloadUrl: String,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ import kotlinx.serialization.Serializable
data class GithubUser(
@SerialName("login")
val name: String,
val contributions: Int
val contributions: Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import kotlinx.serialization.Serializable
data class Version(
val versionCode: String,
val versionName: String,
val aliucordHash: String
val aliucordHash: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlinx.coroutines.withContext

class AliucordGithubService(
val github: GithubService,
val http: HttpService
val http: HttpService,
) {
suspend fun getDataJson(): ApiResponse<Version> {
return withContext(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ApiFailure(error: Throwable, body: String?) : Error(body, error)
inline fun <T, R> ApiResponse<T>.fold(
success: (T) -> R,
error: (ApiError) -> R,
failure: (ApiFailure) -> R
failure: (ApiFailure) -> R,
): R {
return when (this) {
is ApiResponse.Success -> success(this.data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class SemVer(
val major: Int,
val minor: Int,
val patch: Int,
private val vPrefix: Boolean = false
private val vPrefix: Boolean = false,
) : Comparable<SemVer> {
override fun compareTo(other: SemVer): Int {
val pairs = arrayOf(
Expand Down
Loading

0 comments on commit 5339459

Please sign in to comment.