compose test

This commit is contained in:
rhunk
2023-07-28 02:03:39 +02:00
parent ec6ba52b58
commit 304bd9fe94
16 changed files with 384 additions and 16 deletions

View File

@ -8,21 +8,25 @@ plugins {
android {
namespace = "me.rhunk.snapenhance"
compileSdk = 33
compileSdk = 34
buildFeatures {
aidl = true
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.8"
}
defaultConfig {
applicationId = "me.rhunk.snapenhance"
applicationId = rootProject.ext["applicationId"].toString()
minSdk = 28
//noinspection OldTargetApi
targetSdk = 33
multiDexEnabled = true
}
buildTypes {
release {
isMinifyEnabled = false
@ -76,7 +80,11 @@ android {
dependencies {
implementation(project(":core"))
implementation(libs.androidx.material.icons.extended)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.activity.ktx)
implementation(libs.androidx.material3)
implementation(libs.androidx.material)
}
afterEvaluate {

View File

@ -38,7 +38,7 @@
</service>
<activity
android:name=".ui.download.DownloadManagerActivity"
android:name=".manager.MainActivity"
android:theme="@style/AppTheme"
android:exported="true">
<intent-filter>

View File

@ -1,10 +1,65 @@
package me.rhunk.snapenhance.manager
import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.navigation
import androidx.navigation.compose.rememberNavController
class MainActivity : ComponentActivity() {
@SuppressLint("UnusedMaterialScaffoldPaddingParameter")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
App()
}
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun App() {
val navController = rememberNavController()
AppMaterialTheme {
Scaffold(
topBar = {
TopAppBar(
title = { Text(text = "SnapEnhance") },
actions = {
IconButton(onClick = { /*TODO*/ }) {
Icon(Icons.Filled.Settings, contentDescription = "Settings")
}
}
)
},
containerColor = MaterialTheme.colorScheme.background,
bottomBar = { NavBar(navController = navController) }
) { innerPadding ->
NavHost(navController, startDestination = "main", Modifier.padding(innerPadding)) {
navigation(MainSections.HOME.route, "main") {
MainSections.values().toList().forEach { section ->
composable(section.route) {
section.content()
}
}
}
}
}
}
}

View File

@ -0,0 +1,113 @@
package me.rhunk.snapenhance.manager
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.requiredWidth
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.BugReport
import androidx.compose.material.icons.filled.Download
import androidx.compose.material.icons.filled.Group
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Stars
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.compose.currentBackStackEntryAsState
import me.rhunk.snapenhance.manager.sections.NotImplemented
enum class MainSections(
val route: String,
val title: String,
val icon: ImageVector,
val content: @Composable () -> Unit
) {
DOWNLOADS(
route = "downloads",
title = "Downloads",
icon = Icons.Filled.Download,
content = { NotImplemented() }
),
FEATURES(
route = "features",
title = "Features",
icon = Icons.Filled.Stars,
content = { NotImplemented() }
),
HOME(
route = "home",
title = "Home",
icon = Icons.Filled.Home,
content = { NotImplemented() }
),
FRIENDS(
route = "friends",
title = "Friends",
icon = Icons.Filled.Group,
content = { NotImplemented() }
),
DEBUG(
route = "debug",
title = "Debug",
icon = Icons.Filled.BugReport,
content = { NotImplemented() }
);
}
@Composable
fun NavBar(
navController: NavController
) {
NavigationBar {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
MainSections.values().toList().forEach { section ->
fun selected() = currentDestination?.hierarchy?.any { it.route == section.route } == true
NavigationBarItem(
modifier = Modifier
.requiredWidth(120.dp)
.fillMaxHeight(),
icon = {
val iconOffset by animateDpAsState(
if (selected()) 0.dp else 10.dp,
label = ""
)
Icon(
imageVector = section.icon,
contentDescription = null,
modifier = Modifier.offset(y = iconOffset)
)
},
label = {
val labelOffset by animateDpAsState(
if (selected()) 0.dp else (-5).dp,
label = ""
)
Text(text = if (selected()) section.title else "", modifier = Modifier.offset(y = labelOffset))
},
selected = selected(),
onClick = {
navController.navigate(section.route) {
popUpTo(navController.graph.findStartDestination().id) {
saveState = true
}
launchSingleTop = true
restoreState = true
}
}
)
}
}
}

View File

@ -0,0 +1,164 @@
package me.rhunk.snapenhance.manager
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
val md_theme_light_primary = Color(0xFF6750A4)
val md_theme_light_onPrimary = Color(0xFFFFFFFF)
val md_theme_light_primaryContainer = Color(0xFFE9DDFF)
val md_theme_light_onPrimaryContainer = Color(0xFF22005D)
val md_theme_light_secondary = Color(0xFF625B71)
val md_theme_light_onSecondary = Color(0xFFFFFFFF)
val md_theme_light_secondaryContainer = Color(0xFFE8DEF8)
val md_theme_light_onSecondaryContainer = Color(0xFF1E192B)
val md_theme_light_tertiary = Color(0xFF3C5BA9)
val md_theme_light_onTertiary = Color(0xFFFFFFFF)
val md_theme_light_tertiaryContainer = Color(0xFFDBE1FF)
val md_theme_light_onTertiaryContainer = Color(0xFF001849)
val md_theme_light_error = Color(0xFFBA1A1A)
val md_theme_light_errorContainer = Color(0xFFFFDAD6)
val md_theme_light_onError = Color(0xFFFFFFFF)
val md_theme_light_onErrorContainer = Color(0xFF410002)
val md_theme_light_background = Color(0xFFFFFBFF)
val md_theme_light_onBackground = Color(0xFF1C1B1E)
val md_theme_light_surface = Color(0xFFFFFBFF)
val md_theme_light_onSurface = Color(0xFF1C1B1E)
val md_theme_light_surfaceVariant = Color(0xFFE7E0EB)
val md_theme_light_onSurfaceVariant = Color(0xFF49454E)
val md_theme_light_outline = Color(0xFF7A757F)
val md_theme_light_inverseOnSurface = Color(0xFFF4EFF4)
val md_theme_light_inverseSurface = Color(0xFF313033)
val md_theme_light_inversePrimary = Color(0xFFCFBCFF)
val md_theme_light_surfaceTint = Color(0xFF6750A4)
val md_theme_light_outlineVariant = Color(0xFFCAC4CF)
val md_theme_light_scrim = Color(0xFF000000)
val md_theme_dark_primary = Color(0xFFCFBCFF)
val md_theme_dark_onPrimary = Color(0xFF381E72)
val md_theme_dark_primaryContainer = Color(0xFF4F378A)
val md_theme_dark_onPrimaryContainer = Color(0xFFE9DDFF)
val md_theme_dark_secondary = Color(0xFFCBC2DB)
val md_theme_dark_onSecondary = Color(0xFF332D41)
val md_theme_dark_secondaryContainer = Color(0xFF4A4458)
val md_theme_dark_onSecondaryContainer = Color(0xFFE8DEF8)
val md_theme_dark_tertiary = Color(0xFFB3C5FF)
val md_theme_dark_onTertiary = Color(0xFF002B75)
val md_theme_dark_tertiaryContainer = Color(0xFF21428F)
val md_theme_dark_onTertiaryContainer = Color(0xFFDBE1FF)
val md_theme_dark_error = Color(0xFFFFB4AB)
val md_theme_dark_errorContainer = Color(0xFF93000A)
val md_theme_dark_onError = Color(0xFF690005)
val md_theme_dark_onErrorContainer = Color(0xFFFFDAD6)
val md_theme_dark_background = Color(0xFF1C1B1E)
val md_theme_dark_onBackground = Color(0xFFE6E1E6)
val md_theme_dark_surface = Color(0xFF1C1B1E)
val md_theme_dark_onSurface = Color(0xFFE6E1E6)
val md_theme_dark_surfaceVariant = Color(0xFF49454E)
val md_theme_dark_onSurfaceVariant = Color(0xFFCAC4CF)
val md_theme_dark_outline = Color(0xFF948F99)
val md_theme_dark_inverseOnSurface = Color(0xFF1C1B1E)
val md_theme_dark_inverseSurface = Color(0xFFE6E1E6)
val md_theme_dark_inversePrimary = Color(0xFF6750A4)
val md_theme_dark_surfaceTint = Color(0xFFCFBCFF)
val md_theme_dark_outlineVariant = Color(0xFF49454E)
val md_theme_dark_scrim = Color(0xFF000000)
val seed = Color(0xFF6750A4)
private val LightThemeColors = lightColorScheme(
primary = md_theme_light_primary,
onPrimary = md_theme_light_onPrimary,
primaryContainer = md_theme_light_primaryContainer,
onPrimaryContainer = md_theme_light_onPrimaryContainer,
secondary = md_theme_light_secondary,
onSecondary = md_theme_light_onSecondary,
secondaryContainer = md_theme_light_secondaryContainer,
onSecondaryContainer = md_theme_light_onSecondaryContainer,
tertiary = md_theme_light_tertiary,
onTertiary = md_theme_light_onTertiary,
tertiaryContainer = md_theme_light_tertiaryContainer,
onTertiaryContainer = md_theme_light_onTertiaryContainer,
error = md_theme_light_error,
onError = md_theme_light_onError,
errorContainer = md_theme_light_errorContainer,
onErrorContainer = md_theme_light_onErrorContainer,
background = md_theme_light_background,
onBackground = md_theme_light_onBackground,
surface = md_theme_light_surface,
onSurface = md_theme_light_onSurface,
surfaceVariant = md_theme_light_surfaceVariant,
onSurfaceVariant = md_theme_light_onSurfaceVariant,
outline = md_theme_light_outline,
inverseOnSurface = md_theme_light_inverseOnSurface,
inverseSurface = md_theme_light_inverseSurface,
inversePrimary = md_theme_light_inversePrimary,
surfaceTint = md_theme_light_surfaceTint,
outlineVariant = md_theme_light_outlineVariant,
scrim = md_theme_light_scrim
)
private val DarkThemeColors = lightColorScheme(
primary = md_theme_dark_primary,
onPrimary = md_theme_dark_onPrimary,
primaryContainer = md_theme_dark_primaryContainer,
onPrimaryContainer = md_theme_dark_onPrimaryContainer,
secondary = md_theme_dark_secondary,
onSecondary = md_theme_dark_onSecondary,
secondaryContainer = md_theme_dark_secondaryContainer,
onSecondaryContainer = md_theme_dark_onSecondaryContainer,
tertiary = md_theme_dark_tertiary,
onTertiary = md_theme_dark_onTertiary,
tertiaryContainer = md_theme_dark_tertiaryContainer,
onTertiaryContainer = md_theme_dark_onTertiaryContainer,
error = md_theme_dark_error,
onError = md_theme_dark_onError,
errorContainer = md_theme_dark_errorContainer,
onErrorContainer = md_theme_dark_onErrorContainer,
background = md_theme_dark_background,
onBackground = md_theme_dark_onBackground,
surface = md_theme_dark_surface,
onSurface = md_theme_dark_onSurface,
surfaceVariant = md_theme_dark_surfaceVariant,
onSurfaceVariant = md_theme_dark_onSurfaceVariant,
outline = md_theme_dark_outline,
inverseOnSurface = md_theme_dark_inverseOnSurface,
inverseSurface = md_theme_dark_inverseSurface,
inversePrimary = md_theme_dark_inversePrimary,
surfaceTint = md_theme_dark_surfaceTint,
outlineVariant = md_theme_dark_outlineVariant,
scrim = md_theme_dark_scrim
)
@Composable
fun AppMaterialTheme(
isDarkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
val dynamicColor = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
val colorScheme = when {
dynamicColor && isDarkTheme -> {
dynamicDarkColorScheme(LocalContext.current)
}
dynamicColor && !isDarkTheme -> {
dynamicLightColorScheme(LocalContext.current)
}
!isDarkTheme -> LightThemeColors
else -> DarkThemeColors
}
MaterialTheme(
colorScheme = colorScheme,
content = content
)
}

View File

@ -0,0 +1,18 @@
package me.rhunk.snapenhance.manager.sections
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@Composable
fun NotImplemented() {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(text = "Not Implemented")
}
}

View File

@ -7,5 +7,6 @@ plugins {
rootProject.ext.set("appVersionName", "1.1.0")
rootProject.ext.set("appVersionCode", 7)
rootProject.ext.set("applicationId", "me.rhunk.snapenhance")
true // Needed to make the Suppress annotation work for the plugins block

View File

@ -5,16 +5,18 @@ plugins {
}
android {
namespace = "me.rhunk.snapenhance.core"
compileSdk = 33
compileSdk = 34
buildFeatures {
aidl = true
buildConfig = true
}
defaultConfig {
minSdk = 28
buildConfigField("String", "VERSION_NAME", "\"${rootProject.ext["appVersionName"]}\"")
buildConfigField("int", "VERSION_CODE", "${rootProject.ext["appVersionCode"]}")
buildConfigField("String", "APPLICATION_ID", "\"${rootProject.ext["applicationId"]}\"")
}
kotlinOptions {

View File

@ -35,7 +35,7 @@ class SnapEnhance {
//for lspatch builds, we need to check if the service is correctly installed
runCatching {
appContext.androidContext.packageManager.getApplicationInfoCompat(BuildConfig.LIBRARY_PACKAGE_NAME, PackageManager.GET_META_DATA)
appContext.androidContext.packageManager.getApplicationInfoCompat(BuildConfig.APPLICATION_ID, PackageManager.GET_META_DATA)
}.onFailure {
appContext.crash("SnapEnhance bridge service is not installed. Please download stable version from https://github.com/rhunk/SnapEnhance/releases")
return@hook

View File

@ -11,7 +11,7 @@ class OpenMap: AbstractAction("action.open_map", dependsOnProperty = ConfigPrope
override fun run() {
context.runOnUiThread {
val mapActivityIntent = Intent()
mapActivityIntent.setClassName(BuildConfig.LIBRARY_PACKAGE_NAME, MapActivity::class.java.name)
mapActivityIntent.setClassName(BuildConfig.APPLICATION_ID, MapActivity::class.java.name)
mapActivityIntent.putExtra("location", Bundle().apply {
putDouble("latitude", context.config.string(ConfigProperty.LATITUDE).toDouble())
putDouble("longitude", context.config.string(ConfigProperty.LONGITUDE).toDouble())

View File

@ -32,12 +32,12 @@ class BridgeClient(
with(context.androidContext) {
//ensure the remote process is running
startActivity(Intent()
.setClassName(BuildConfig.LIBRARY_PACKAGE_NAME, ForceStartActivity::class.java.name)
.setClassName(BuildConfig.APPLICATION_ID, ForceStartActivity::class.java.name)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
)
val intent = Intent()
.setClassName(BuildConfig.LIBRARY_PACKAGE_NAME, BridgeService::class.java.name)
.setClassName(BuildConfig.APPLICATION_ID, BridgeService::class.java.name)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
bindService(
intent,

View File

@ -48,7 +48,7 @@ class SettingsGearInjector : AbstractMenu() {
setOnClickListener {
val intent = Intent().apply {
setClassName(BuildConfig.LIBRARY_PACKAGE_NAME, ConfigActivity::class.java.name)
setClassName(BuildConfig.APPLICATION_ID, ConfigActivity::class.java.name)
}
intent.putExtra("lspatched", File(context.cacheDir, "lspatch/origin").exists())
context.startActivity(intent)

View File

@ -191,7 +191,7 @@ class MessageExporter(
runCatching {
ZipFile(
context.androidContext.packageManager.getApplicationInfoCompat(BuildConfig.LIBRARY_PACKAGE_NAME, PackageManager.GET_META_DATA).publicSourceDir
context.androidContext.packageManager.getApplicationInfoCompat(BuildConfig.APPLICATION_ID, PackageManager.GET_META_DATA).publicSourceDir
).use { apkFile ->
//export rawinflate.js
apkFile.getEntry("assets/web/rawinflate.js").let { entry ->

View File

@ -21,5 +21,4 @@ kotlin.code.style=official
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false

View File

@ -1,10 +1,13 @@
[versions]
agp = "8.1.0"
agp = "8.2.0-alpha13"
androidx-material = "1.6.0-alpha02"
junit = "4.13.2"
kotlin = "1.8.21"
kotlin = "1.8.22"
kotlinx-coroutines-android = "1.7.2"
kotlin-reflect = "1.8.21"
recyclerview = "1.3.0"
material-icons-extended = "1.6.0-alpha03"
navigation-compose = "2.6.0"
recyclerview = "1.3.1"
gson = "2.10.1"
ffmpeg-kit = "5.1.LTS"
osmdroid-android = "6.1.16"
@ -12,9 +15,13 @@ okhttp = "5.0.0-alpha.11"
dexlib2 = "2.5.2"
androidx-documentfile = "1.1.0-alpha01"
activity-ktx = "1.7.2"
material3 = "1.1.1"
[libraries]
androidx-material = { module = "androidx.compose.material:material", version.ref = "androidx-material" }
androidx-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "material-icons-extended" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigation-compose" }
coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "kotlinx-coroutines-android" }
junit = { module = "junit:junit", version.ref = "junit" }
kotlin-reflect = { group = "org.jetbrains.kotlin", name = "kotlin-reflect", version.ref = "kotlin-reflect" }
@ -26,6 +33,7 @@ okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhtt
dexlib2 = { group = "org.smali", name = "dexlib2", version.ref = "dexlib2" }
androidx-documentfile = { group = "androidx.documentfile", name = "documentfile", version.ref = "androidx-documentfile" }
androidx-activity-ktx = { group = "androidx.activity", name = "activity-ktx", version.ref = "activity-ktx" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" }
[plugins]

View File

@ -1,6 +1,6 @@
#Fri May 12 21:23:16 CEST 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME