From 7541a87b2143f5e1579fb4cd10fdbfbdd8cebd09 Mon Sep 17 00:00:00 2001 From: tarsin Date: Tue, 10 Jan 2023 17:54:55 +0800 Subject: [PATCH] Convert login to compose, step 1, skeleton --- app/build.gradle | 4 +- app/src/main/AndroidManifest.xml | 58 +++++++------------ .../com/hippo/ehviewer/ui/LoginActivity.kt | 14 +++++ .../hippo/ehviewer/ui/compose/theme/Theme.kt | 50 ++++++++++++++++ app/src/main/res/navigation/nav_graph.xml | 4 ++ 5 files changed, 91 insertions(+), 39 deletions(-) create mode 100644 app/src/main/java/com/hippo/ehviewer/ui/LoginActivity.kt create mode 100644 app/src/main/java/com/hippo/ehviewer/ui/compose/theme/Theme.kt diff --git a/app/build.gradle b/app/build.gradle index 23c59e936..f327f310a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -104,6 +104,7 @@ android { dependencies { def activity_version = "1.6.1" implementation "androidx.activity:activity-ktx:$activity_version" + implementation "androidx.activity:activity-compose:$activity_version" implementation "androidx.annotation:annotation:1.5.0" implementation "androidx.annotation:annotation-experimental:1.3.0" @@ -128,6 +129,8 @@ dependencies { implementation "androidx.compose.runtime:runtime" implementation "androidx.compose.runtime:runtime-saveable" implementation "androidx.compose.ui:ui" + implementation 'androidx.compose.ui:ui-graphics' + implementation 'androidx.compose.ui:ui-tooling-preview' implementation "androidx.constraintlayout:constraintlayout:2.2.0-alpha05" implementation "androidx.coordinatorlayout:coordinatorlayout:1.2.0" @@ -197,7 +200,6 @@ dependencies { configurations.all { exclude group: 'dev.rikka.rikkax.appcompat', module: 'appcompat' exclude group: 'dev.rikka.rikkax.material', module: 'material' - exclude group: 'androidx.compose.material' exclude group: 'org.jetbrains.kotlin', module: 'kotlin-android-extensions-runtime' exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk7' exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 87816ed1a..15b0568fc 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,19 +1,4 @@ - - + @@ -28,13 +13,12 @@ - - + - + - + @@ -85,26 +72,26 @@ - + + - + + - - @@ -138,21 +125,18 @@ - - - - @@ -177,11 +160,10 @@ android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true"> - - - + + \ No newline at end of file diff --git a/app/src/main/java/com/hippo/ehviewer/ui/LoginActivity.kt b/app/src/main/java/com/hippo/ehviewer/ui/LoginActivity.kt new file mode 100644 index 000000000..5f371db78 --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/ui/LoginActivity.kt @@ -0,0 +1,14 @@ +package com.hippo.ehviewer.ui + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent + +class LoginActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { + + } + } +} diff --git a/app/src/main/java/com/hippo/ehviewer/ui/compose/theme/Theme.kt b/app/src/main/java/com/hippo/ehviewer/ui/compose/theme/Theme.kt new file mode 100644 index 000000000..e503bd465 --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/ui/compose/theme/Theme.kt @@ -0,0 +1,50 @@ +package com.hippo.ehviewer.ui.ui.theme + +import android.app.Activity +import android.graphics.Color +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowCompat + +private val DarkColorScheme = darkColorScheme() +private val LightColorScheme = lightColorScheme() + +@Composable +fun EhViewerTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + val view = LocalView.current + if (!view.isInEditMode) { + SideEffect { + val window = (view.context as Activity).window + window.statusBarColor = Color.TRANSPARENT + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme + } + } + + MaterialTheme( + colorScheme = colorScheme, + content = content + ) +} \ No newline at end of file diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 753d380bf..b05a5d3c7 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -92,4 +92,8 @@ android:id="@+id/cookieSignInScene" android:name="com.hippo.ehviewer.ui.scene.CookieSignInScene" android:label="CookieSignInScene" /> + \ No newline at end of file