From ae17168291df35745a4e90aac0e1a408974913b1 Mon Sep 17 00:00:00 2001 From: Doohyun Nam Date: Sat, 21 Dec 2024 15:59:23 +0900 Subject: [PATCH 1/6] Implement #343 - add dependencies --- app/build.gradle.kts | 3 +++ build.gradle.kts | 1 + gradle/libs.versions.toml | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 74b7a018..e732a9b3 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -19,6 +19,7 @@ plugins { alias(libs.plugins.nlab.android.application.jacoco) alias(libs.plugins.nlab.android.hilt) alias(libs.plugins.androidx.navigation.safearges) + alias(libs.plugins.kotlin.serialization) alias(libs.plugins.ksp) id("kotlin-parcelize") kotlin("kapt") @@ -97,6 +98,7 @@ dependencies { implementation(libs.kotlinx.coroutines.android) implementation(libs.kotlinx.collections.immutable) + implementation(libs.kotlinx.serialization.json) implementation(libs.androidx.core.ktx) implementation(libs.androidx.core.splashscreen) @@ -108,6 +110,7 @@ dependencies { implementation(libs.androidx.navigation.fragment.ktx) implementation(libs.androidx.hilt.navigation.compose) implementation(libs.androidx.navigation.ui.ktx) + implementation(libs.androidx.navigation.compose) implementation(libs.androidx.startup.runtime) implementation(libs.androidx.datastore.preferences) implementation(libs.androidx.activity.compose) diff --git a/build.gradle.kts b/build.gradle.kts index dd312233..fce7cfc8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,5 +22,6 @@ plugins { alias(libs.plugins.google.hilt) apply false alias(libs.plugins.jetbrains.kotlin.android) apply false alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.kotlin.serialization) apply false alias(libs.plugins.ksp) apply false } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 05a1efa0..cf2bba45 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -38,6 +38,7 @@ javafaker = "1.0.2" jsoup = "1.18.1" junit = "4.13.2" kotlin = "2.1.0" +kotlinxSerializationJson = "1.6.3" ksp = "2.1.0-1.0.29" kotlinxCollectionsImmutable = "0.3.7" kotlinxCoroutine = "1.10.1" @@ -67,11 +68,13 @@ androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", version.ref = "androidxCoreSplashScreen" } androidx-datastore-preferences = { module = "androidx.datastore:datastore-preferences", version.ref = "androidxDataStore" } androidx-fragment = { module = "androidx.fragment:fragment", version.ref = "androidxFragment" } +androidx-fragment-compose = { module = "androidx.fragment:fragment-compose", version.ref = "androidxFragment" } androidx-hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "androidxHiltNavigationCompose" } androidx-lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidxLifecycle" } androidx-lifecycle-runtimeCompose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "androidxLifecycle" } androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidxLifecycle" } androidx-navigation-fragment-ktx = { module = "androidx.navigation:navigation-fragment-ktx", version.ref = "androidxNavigation" } +androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "androidxNavigation" } androidx-navigation-ui-ktx = { module = "androidx.navigation:navigation-ui-ktx", version.ref = "androidxNavigation" } androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "androidxRecyclerView" } androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "androidxRoom" } @@ -97,6 +100,7 @@ kotlinx-collections-immutable = { module = "org.jetbrains.kotlinx:kotlinx-collec kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinxCoroutine" } kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinxCoroutine" } kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinxCoroutine" } +kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" } mockito-inline = { module = "org.mockito:mockito-inline", version.ref = "mockitoInline" } mockito-kotlin = { module = "org.mockito.kotlin:mockito-kotlin", version.ref = "mockitoKotlin" } squeare-leakcanary = { module = "com.squareup.leakcanary:leakcanary-android", version.ref = "squareLeakcanary" } @@ -117,6 +121,7 @@ androidx-navigation-safearges = { id = "androidx.navigation.safeargs.kotlin", ve compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } google-hilt = { id = "com.google.dagger.hilt.android", version.ref = "googleHilt" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } # Plugins defined by this project From 6fd1af8e612045016946df397e29e3b3d386a1ec Mon Sep 17 00:00:00 2001 From: Doohyun Nam Date: Sat, 21 Dec 2024 16:00:51 +0900 Subject: [PATCH 2/6] Implement #343 - add exclude jacoco rules --- .../src/main/kotlin/com/nlab/reminder/AndroidJacoco.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/build-logic/convention/src/main/kotlin/com/nlab/reminder/AndroidJacoco.kt b/build-logic/convention/src/main/kotlin/com/nlab/reminder/AndroidJacoco.kt index a81d876b..df51361f 100644 --- a/build-logic/convention/src/main/kotlin/com/nlab/reminder/AndroidJacoco.kt +++ b/build-logic/convention/src/main/kotlin/com/nlab/reminder/AndroidJacoco.kt @@ -80,6 +80,7 @@ private fun Project.androidJacocoClassDirectories(variant: Variant): Configurabl "**/Manifest*.*", "**/android/**", "**/ui/**", + "**/navigation/**", "**/test/**", "**/di/**", "**/fake/**", From c8871bd55d188223d70415a87ff1da511eb9a3f4 Mon Sep 17 00:00:00 2001 From: Doohyun Nam Date: Sat, 21 Dec 2024 17:40:18 +0900 Subject: [PATCH 3/6] Refactor #343 - replace compose base navController --- app/src/main/AndroidManifest.xml | 2 +- .../feature/main => apps}/ui/MainActivity.kt | 21 +++++--- .../com/nlab/reminder/apps/ui/PlaneatApp.kt | 36 ++++++++++++++ .../nlab/reminder/apps/ui/PlaneatAppState.kt | 37 ++++++++++++++ .../nlab/reminder/apps/ui/PlaneatNavHost.kt | 44 +++++++++++++++++ .../feature/home/navigation/HomeNavigation.kt | 48 +++++++++++++++++++ .../domain/feature/home/ui/HomeFragment.kt | 2 +- .../domain/feature/home/ui/HomeScreen.kt | 7 ++- app/src/main/res/layout/activity_main.xml | 2 +- .../compose/component/PlaneatLoading.kt | 3 +- .../src/main/res/values/themes.xml | 3 +- 11 files changed, 191 insertions(+), 14 deletions(-) rename app/src/main/java/com/nlab/reminder/{domain/feature/main => apps}/ui/MainActivity.kt (67%) create mode 100644 app/src/main/java/com/nlab/reminder/apps/ui/PlaneatApp.kt create mode 100644 app/src/main/java/com/nlab/reminder/apps/ui/PlaneatAppState.kt create mode 100644 app/src/main/java/com/nlab/reminder/apps/ui/PlaneatNavHost.kt create mode 100644 app/src/main/java/com/nlab/reminder/domain/feature/home/navigation/HomeNavigation.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1c9b2682..af9212e9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,7 +32,7 @@ tools:targetApi="tiramisu"> diff --git a/app/src/main/java/com/nlab/reminder/domain/feature/main/ui/MainActivity.kt b/app/src/main/java/com/nlab/reminder/apps/ui/MainActivity.kt similarity index 67% rename from app/src/main/java/com/nlab/reminder/domain/feature/main/ui/MainActivity.kt rename to app/src/main/java/com/nlab/reminder/apps/ui/MainActivity.kt index 1f06f5cb..fa827e5c 100644 --- a/app/src/main/java/com/nlab/reminder/domain/feature/main/ui/MainActivity.kt +++ b/app/src/main/java/com/nlab/reminder/apps/ui/MainActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 The N's lab Open Source Project + * Copyright (C) 2024 The N's lab Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,31 @@ * limitations under the License. */ -package com.nlab.reminder.domain.feature.main.ui +package com.nlab.reminder.apps.ui -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen -import com.nlab.reminder.R +import com.nlab.reminder.core.designsystem.compose.theme.PlaneatTheme import dagger.hilt.android.AndroidEntryPoint /** * @author Doohyun */ @AndroidEntryPoint -class MainActivity : AppCompatActivity() { +class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { installSplashScreen() - enableEdgeToEdge() super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) + + enableEdgeToEdge() + setContent { + val appState = rememberPlaneatAppState() + PlaneatTheme { + PlaneatApp(appState = appState) + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/nlab/reminder/apps/ui/PlaneatApp.kt b/app/src/main/java/com/nlab/reminder/apps/ui/PlaneatApp.kt new file mode 100644 index 00000000..1936b19e --- /dev/null +++ b/app/src/main/java/com/nlab/reminder/apps/ui/PlaneatApp.kt @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2024 The N's lab Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.nlab.reminder.apps.ui + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier + +/** + * @author Thalys + */ +@Composable +fun PlaneatApp( + appState: PlaneatAppState +) { + Box(modifier = Modifier.fillMaxSize()) { + PlaneatNavHost( + appState = appState + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/nlab/reminder/apps/ui/PlaneatAppState.kt b/app/src/main/java/com/nlab/reminder/apps/ui/PlaneatAppState.kt new file mode 100644 index 00000000..6e22133b --- /dev/null +++ b/app/src/main/java/com/nlab/reminder/apps/ui/PlaneatAppState.kt @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2024 The N's lab Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.nlab.reminder.apps.ui + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.Stable +import androidx.navigation.NavHostController +import androidx.navigation.compose.rememberNavController + +/** + * @author Thalys + */ +@Stable +class PlaneatAppState( + val navController: NavHostController +) + +@Composable +fun rememberPlaneatAppState( + navController: NavHostController = rememberNavController() +): PlaneatAppState = PlaneatAppState( + navController = navController +) \ No newline at end of file diff --git a/app/src/main/java/com/nlab/reminder/apps/ui/PlaneatNavHost.kt b/app/src/main/java/com/nlab/reminder/apps/ui/PlaneatNavHost.kt new file mode 100644 index 00000000..4c7a8b41 --- /dev/null +++ b/app/src/main/java/com/nlab/reminder/apps/ui/PlaneatNavHost.kt @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2024 The N's lab Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.nlab.reminder.apps.ui + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.navigation.compose.NavHost +import com.nlab.reminder.domain.feature.home.navigation.HomeBaseRoute +import com.nlab.reminder.domain.feature.home.navigation.homeScreen + +/** + * @author Thalys + */ +@Composable +fun PlaneatNavHost( + appState: PlaneatAppState, + modifier: Modifier = Modifier +) { + val navController = appState.navController + NavHost( + navController = navController, + startDestination = HomeBaseRoute, + modifier = modifier + ) { + homeScreen( + onAllScheduleClicked = {}, + allScheduleDestination = {} + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/nlab/reminder/domain/feature/home/navigation/HomeNavigation.kt b/app/src/main/java/com/nlab/reminder/domain/feature/home/navigation/HomeNavigation.kt new file mode 100644 index 00000000..5cc88951 --- /dev/null +++ b/app/src/main/java/com/nlab/reminder/domain/feature/home/navigation/HomeNavigation.kt @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2024 The N's lab Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.nlab.reminder.domain.feature.home.navigation + +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavOptions +import androidx.navigation.compose.composable +import androidx.navigation.navigation +import com.nlab.reminder.domain.feature.home.ui.HomeScreen +import kotlinx.serialization.Serializable + +/** + * @author Thalys + */ +@Serializable +internal data object HomeRoute + +@Serializable +data object HomeBaseRoute + +fun NavController.navigateToHome(navOptions: NavOptions) = navigate(route = HomeRoute, navOptions) + +fun NavGraphBuilder.homeScreen( + onAllScheduleClicked: () -> Unit, + allScheduleDestination: NavGraphBuilder.() -> Unit +) { + navigation(startDestination = HomeRoute) { + composable { + HomeScreen(onAllScheduleClicked) + } + allScheduleDestination() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/nlab/reminder/domain/feature/home/ui/HomeFragment.kt b/app/src/main/java/com/nlab/reminder/domain/feature/home/ui/HomeFragment.kt index 9a890965..3b4bf170 100644 --- a/app/src/main/java/com/nlab/reminder/domain/feature/home/ui/HomeFragment.kt +++ b/app/src/main/java/com/nlab/reminder/domain/feature/home/ui/HomeFragment.kt @@ -35,7 +35,7 @@ internal class HomeFragment : ComponentFragment() { setContent { PlaneatTheme { HomeScreen( - navigateToAllScheduleEnd = navController::navigateToAllScheduleEnd + onAllScheduleClicked = navController::navigateToAllScheduleEnd ) } } diff --git a/app/src/main/java/com/nlab/reminder/domain/feature/home/ui/HomeScreen.kt b/app/src/main/java/com/nlab/reminder/domain/feature/home/ui/HomeScreen.kt index 41ee9c4c..bfd136e6 100644 --- a/app/src/main/java/com/nlab/reminder/domain/feature/home/ui/HomeScreen.kt +++ b/app/src/main/java/com/nlab/reminder/domain/feature/home/ui/HomeScreen.kt @@ -99,7 +99,7 @@ import com.nlab.reminder.domain.feature.home.* */ @Composable internal fun HomeScreen( - navigateToAllScheduleEnd: () -> Unit, + onAllScheduleClicked: () -> Unit, modifier: Modifier = Modifier, viewModel: HomeViewModel = hiltViewModel() ) { @@ -109,7 +109,10 @@ internal fun HomeScreen( modifier = modifier, onTodayCategoryClicked = throttleClick { viewModel.onTodayCategoryClicked() }, onTimetableCategoryClicked = { viewModel.onTimetableCategoryClicked() }, - onAllCategoryClicked = { viewModel.onAllCategoryClicked() }, + onAllCategoryClicked = { + onAllScheduleClicked() + // viewModel.onAllCategoryClicked() TODO just logging, + }, onInteracted = { viewModel.interacted() }, onTagClicked = { // TODO implements diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 766682f1..ea9940a4 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -20,7 +20,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".domain.feature.main.ui.MainActivity"> + tools:context=".apps.ui.MainActivity"> - +