From 7a9aee46a604dbe82b46fc3a9ff5f809dab61997 Mon Sep 17 00:00:00 2001 From: Roman Pytkov Date: Fri, 8 Nov 2024 23:55:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B2=D0=B8=D0=B3=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 18 ++-- app/src/main/AndroidManifest.xml | 1 - .../nullptroma/wallenc/app/MainActivity.kt | 82 +++---------------- gradle/libs.versions.toml | 11 +-- presentation/build.gradle.kts | 3 + .../wallenc/presentation/WallencUi.kt | 44 ++++++++++ .../presentation/extensions/Modifier.kt | 25 ++++++ .../presentation/screens/main/MainRoute.kt | 5 ++ .../presentation/screens/main/MainScreen.kt | 31 ++++--- .../screens/settings/SettingsRoute.kt | 5 ++ .../screens/settings/SettingsScreen.kt | 19 +++++ presentation/src/main/res/values/strings.xml | 4 + 12 files changed, 149 insertions(+), 99 deletions(-) create mode 100644 presentation/src/main/java/com/github/nullptroma/wallenc/presentation/WallencUi.kt create mode 100644 presentation/src/main/java/com/github/nullptroma/wallenc/presentation/extensions/Modifier.kt create mode 100644 presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/main/MainRoute.kt create mode 100644 presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/settings/SettingsRoute.kt create mode 100644 presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/settings/SettingsScreen.kt create mode 100644 presentation/src/main/res/values/strings.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4f25f80..8e34666 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -53,9 +53,6 @@ android { } dependencies { - implementation(libs.navigation) - implementation(libs.navigation.hilt.compose) - // Yandex implementation(libs.yandex.oauth) @@ -66,20 +63,17 @@ dependencies { implementation(libs.androidx.core.ktx) implementation(libs.androidx.lifecycle.runtime.ktx) implementation(libs.androidx.activity.compose) - implementation(platform(libs.androidx.compose.bom)) + //implementation(platform(libs.androidx.compose.bom)) - debugImplementation(libs.androidx.ui.tooling) - debugImplementation(libs.androidx.ui.test.manifest) - implementation(libs.androidx.ui) - implementation(libs.androidx.ui.graphics) - implementation(libs.androidx.ui.tooling.preview) - implementation(libs.androidx.material3) + //debugImplementation(libs.androidx.ui.tooling) + //debugImplementation(libs.androidx.ui.test.manifest) + //implementation(libs.androidx.ui) testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) - androidTestImplementation(platform(libs.androidx.compose.bom)) - androidTestImplementation(libs.androidx.ui.test.junit4) + //androidTestImplementation(platform(libs.androidx.compose.bom)) + //androidTestImplementation(libs.androidx.ui.test.junit4) implementation(project(":domain")) implementation(project(":presentation")) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 44f7f9d..423c093 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,7 +20,6 @@ android:theme="@style/Theme.Wallenc"> - diff --git a/app/src/main/java/com/github/nullptroma/wallenc/app/MainActivity.kt b/app/src/main/java/com/github/nullptroma/wallenc/app/MainActivity.kt index 1c29115..064df46 100644 --- a/app/src/main/java/com/github/nullptroma/wallenc/app/MainActivity.kt +++ b/app/src/main/java/com/github/nullptroma/wallenc/app/MainActivity.kt @@ -1,30 +1,10 @@ package com.github.nullptroma.wallenc.app import android.os.Bundle -import android.widget.Toast import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Button -import androidx.compose.material3.Scaffold -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.tooling.preview.Preview -import com.github.nullptroma.wallenc.presentation.screens.main.MainScreen -import com.github.nullptroma.wallenc.presentation.theme.WallencTheme -import com.yandex.authsdk.YandexAuthLoginOptions -import com.yandex.authsdk.YandexAuthOptions -import com.yandex.authsdk.YandexAuthResult -import com.yandex.authsdk.YandexAuthSdk -import com.yandex.authsdk.internal.strategy.LoginType +import com.github.nullptroma.wallenc.presentation.WallencUi import dagger.hilt.android.AndroidEntryPoint @@ -34,57 +14,21 @@ class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() - val sdk = YandexAuthSdk.create(YandexAuthOptions(applicationContext, true)) - val launcher = - registerForActivityResult(sdk.contract) { result -> handleResult(result) } - val loginOptions = YandexAuthLoginOptions(LoginType.CHROME_TAB) +// val sdk = YandexAuthSdk.create(YandexAuthOptions(applicationContext, true)) +// val launcher = +// registerForActivityResult(sdk.contract) { result -> handleResult(result) } +// val loginOptions = YandexAuthLoginOptions(LoginType.CHROME_TAB) setContent { - WallencTheme { - Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> -// Greeting(Modifier.padding(innerPadding)) { -// launcher.launch(loginOptions) -// } - MainScreen( - Modifier.padding( - innerPadding - ) - ) - } - } + WallencUi() } } - private fun handleResult(result: YandexAuthResult) { - when (result) { - is YandexAuthResult.Success -> Toast.makeText(applicationContext, "Success: ${result.token}", Toast.LENGTH_SHORT).show() - is YandexAuthResult.Failure -> Toast.makeText(applicationContext, "Success: ${result.exception}", Toast.LENGTH_SHORT).show() - YandexAuthResult.Cancelled -> Toast.makeText(applicationContext, "Cancel", Toast.LENGTH_SHORT).show() - } - } +// private fun handleResult(result: YandexAuthResult) { +// when (result) { +// is YandexAuthResult.Success -> Toast.makeText(applicationContext, "Success: ${result.token}", Toast.LENGTH_SHORT).show() +// is YandexAuthResult.Failure -> Toast.makeText(applicationContext, "Success: ${result.exception}", Toast.LENGTH_SHORT).show() +// YandexAuthResult.Cancelled -> Toast.makeText(applicationContext, "Cancel", Toast.LENGTH_SHORT).show() +// } +// } } - -@Composable -fun Greeting(modifier: Modifier = Modifier, onClick: () -> Unit) { - Column( - modifier = modifier - .fillMaxWidth() - .fillMaxHeight(), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Button(onClick = onClick) { - Text(text = "Login") - } - } -} - -@Preview(showBackground = true) -@Composable -fun GreetingPreview() { - com.github.nullptroma.wallenc.presentation.theme.WallencTheme { - Greeting(Modifier) { - - } - } -} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 72ca82d..d2d9d49 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,11 +1,12 @@ [versions] agp = "8.7.1" -kotlin = "2.0.20" +kotlin = "2.0.21" coreKtx = "1.15.0" junit = "4.13.2" junitVersion = "1.2.1" espressoCore = "3.6.1" kotlinxCoroutinesCore = "1.9.0" +kotlinxSerializationJson = "1.7.3" lifecycleRuntimeKtx = "2.8.7" activityCompose = "1.9.3" composeBom = "2024.10.01" @@ -19,11 +20,11 @@ retrofit = "2.11.0" gson = "2.11.0" appcompat = "1.7.0" material = "1.12.0" -jetbrainsKotlinJvm = "2.0.20" runtimeAndroid = "1.7.5" [libraries] kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutinesCore" } +kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" } navigation = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigation" } navigation-hilt-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "hiltNavigation" } @@ -69,8 +70,8 @@ androidx-runtime-android = { group = "androidx.compose.runtime", name = "runtime android-application = { id = "com.android.application", version.ref = "agp" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } +jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +jetbrains-kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } dagger-hilt = { id = "com.google.dagger.hilt.android", version.ref = "daggerHilt" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } -android-library = { id = "com.android.library", version.ref = "agp" } -jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "jetbrainsKotlinJvm" } - +android-library = { id = "com.android.library", version.ref = "agp" } \ No newline at end of file diff --git a/presentation/build.gradle.kts b/presentation/build.gradle.kts index 10ec7ac..6f0535b 100644 --- a/presentation/build.gradle.kts +++ b/presentation/build.gradle.kts @@ -3,6 +3,7 @@ plugins { alias(libs.plugins.kotlin.android) alias(libs.plugins.compose.compiler) alias(libs.plugins.dagger.hilt) + alias(libs.plugins.jetbrains.kotlin.serialization) alias(libs.plugins.ksp) } @@ -52,6 +53,8 @@ dependencies { implementation(libs.dagger.hilt) ksp(libs.dagger.hilt.compiler) + implementation(libs.kotlinx.serialization.json) + implementation(libs.androidx.core.ktx) implementation(libs.androidx.lifecycle.runtime.ktx) implementation(libs.androidx.activity.compose) diff --git a/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/WallencUi.kt b/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/WallencUi.kt new file mode 100644 index 0000000..33038b9 --- /dev/null +++ b/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/WallencUi.kt @@ -0,0 +1,44 @@ +package com.github.nullptroma.wallenc.presentation + +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable +import androidx.navigation.compose.rememberNavController +import androidx.navigation.toRoute +import com.github.nullptroma.wallenc.presentation.screens.main.MainRoute +import com.github.nullptroma.wallenc.presentation.screens.main.MainScreen +import com.github.nullptroma.wallenc.presentation.screens.settings.SettingsRoute +import com.github.nullptroma.wallenc.presentation.screens.settings.SettingsScreen +import com.github.nullptroma.wallenc.presentation.theme.WallencTheme + + +@Composable +fun WallencUi() { + WallencTheme { + Surface { + WallencNavRoot() + } + } +} + +@Composable +fun WallencNavRoot() { + val navController = rememberNavController() + Scaffold { innerPaddings -> + NavHost(navController, startDestination = MainRoute()) { + composable { + MainScreen(Modifier.padding(innerPaddings), onSettingsRoute = { settingsRoute -> + navController.navigate(settingsRoute) + }) + } + composable { + val route: SettingsRoute = it.toRoute() + SettingsScreen(Modifier.padding(innerPaddings), route.text) + } + } + } +} \ No newline at end of file diff --git a/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/extensions/Modifier.kt b/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/extensions/Modifier.kt new file mode 100644 index 0000000..b6b1c1e --- /dev/null +++ b/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/extensions/Modifier.kt @@ -0,0 +1,25 @@ +package com.github.nullptroma.wallenc.presentation.extensions + +import androidx.compose.ui.Modifier +import androidx.compose.ui.layout.layout +import androidx.compose.ui.unit.Dp + +fun Modifier.ignoreHorizontalParentPadding(horizontal: Dp): Modifier { + return this.layout { measurable, constraints -> + val overrideWidth = constraints.maxWidth + 2 * horizontal.roundToPx() + val placeable = measurable.measure(constraints.copy(maxWidth = overrideWidth)) + layout(placeable.width, placeable.height) { + placeable.place(0, 0) + } + } +} + +fun Modifier.ignoreVerticalParentPadding(vertical: Dp): Modifier { + return this.layout { measurable, constraints -> + val overrideHeight = constraints.maxHeight + 2 * vertical.roundToPx() + val placeable = measurable.measure(constraints.copy(maxHeight = overrideHeight)) + layout(placeable.width, placeable.height) { + placeable.place(0, 0) + } + } +} \ No newline at end of file diff --git a/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/main/MainRoute.kt b/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/main/MainRoute.kt new file mode 100644 index 0000000..7a83314 --- /dev/null +++ b/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/main/MainRoute.kt @@ -0,0 +1,5 @@ +package com.github.nullptroma.wallenc.presentation.screens.main + +import kotlinx.serialization.Serializable + +@Serializable class MainRoute \ No newline at end of file diff --git a/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/main/MainScreen.kt b/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/main/MainScreen.kt index d05db3e..c5660f5 100644 --- a/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/main/MainScreen.kt +++ b/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/main/MainScreen.kt @@ -1,29 +1,36 @@ package com.github.nullptroma.wallenc.presentation.screens.main -import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.imePadding +import androidx.compose.material3.Button import androidx.compose.material3.Text import androidx.compose.material3.TextField +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.hilt.navigation.compose.hiltViewModel +import com.github.nullptroma.wallenc.presentation.screens.settings.SettingsRoute @androidx.compose.runtime.Composable -fun MainScreen(modifier: Modifier = Modifier.Companion, viewModel: MainViewModel = hiltViewModel()) { +fun MainScreen(modifier: Modifier = Modifier, + viewModel: MainViewModel = hiltViewModel(), + onSettingsRoute: (SettingsRoute) -> Unit) { val state = viewModel.stateFlow - Column(modifier = modifier.imePadding()) { - - Text(text = state.value) - Box( - modifier = Modifier.Companion.fillMaxSize(), - contentAlignment = Alignment.Companion.BottomCenter - ) { - TextField("", onValueChange = { - - }) + var text by remember { mutableStateOf("") } + Column(modifier = modifier.imePadding().fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) { + TextField(text, onValueChange = { s -> + text = s + }) + Button( onClick = { + onSettingsRoute(SettingsRoute(text)) + }) { + Text("Press Me!") } } } \ No newline at end of file diff --git a/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/settings/SettingsRoute.kt b/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/settings/SettingsRoute.kt new file mode 100644 index 0000000..73995c4 --- /dev/null +++ b/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/settings/SettingsRoute.kt @@ -0,0 +1,5 @@ +package com.github.nullptroma.wallenc.presentation.screens.settings + +import kotlinx.serialization.Serializable + +@Serializable class SettingsRoute(val text: String) \ No newline at end of file diff --git a/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/settings/SettingsScreen.kt b/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/settings/SettingsScreen.kt new file mode 100644 index 0000000..fd6855e --- /dev/null +++ b/presentation/src/main/java/com/github/nullptroma/wallenc/presentation/screens/settings/SettingsScreen.kt @@ -0,0 +1,19 @@ +package com.github.nullptroma.wallenc.presentation.screens.settings + +import androidx.compose.foundation.layout.Arrangement +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 +import androidx.compose.ui.res.stringResource +import com.github.nullptroma.wallenc.presentation.R + +@Composable +fun SettingsScreen(modifier: Modifier, text: String) { + Column (modifier = modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) { + Text(text = stringResource(id = R.string.settings_title)) + Text(text = text) + } +} \ No newline at end of file diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml new file mode 100644 index 0000000..c0e963e --- /dev/null +++ b/presentation/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + + Settings Screen Title! + \ No newline at end of file