From 00c5a1dfc7a43f2215dcf563e710b1da0cb2d493 Mon Sep 17 00:00:00 2001 From: sksowk156 Date: Tue, 10 Dec 2024 00:35:50 +0900 Subject: [PATCH 1/7] =?UTF-8?q?#3=20-=20auth,=20etc,=20matching,=20mypage?= =?UTF-8?q?=20=EB=AA=A8=EB=93=88=20=EC=83=9D=EC=84=B1(gradle=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC=20X)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- feature/auth/.gitignore | 1 + feature/auth/build.gradle.kts | 43 +++++++++++++++++++ feature/auth/consumer-rules.pro | 0 feature/auth/proguard-rules.pro | 21 +++++++++ .../example/auth/ExampleInstrumentedTest.kt | 24 +++++++++++ feature/auth/src/main/AndroidManifest.xml | 4 ++ .../java/com/example/auth/ExampleUnitTest.kt | 17 ++++++++ feature/etc/.gitignore | 1 + feature/etc/build.gradle.kts | 43 +++++++++++++++++++ feature/etc/consumer-rules.pro | 0 feature/etc/proguard-rules.pro | 21 +++++++++ .../example/etc/ExampleInstrumentedTest.kt | 24 +++++++++++ feature/etc/src/main/AndroidManifest.xml | 4 ++ .../java/com/example/etc/ExampleUnitTest.kt | 17 ++++++++ feature/matching/.gitignore | 1 + feature/matching/build.gradle.kts | 43 +++++++++++++++++++ feature/matching/consumer-rules.pro | 0 feature/matching/proguard-rules.pro | 21 +++++++++ .../matching/ExampleInstrumentedTest.kt | 24 +++++++++++ feature/matching/src/main/AndroidManifest.xml | 4 ++ .../com/example/matching/ExampleUnitTest.kt | 17 ++++++++ feature/mypage/.gitignore | 1 + feature/mypage/build.gradle.kts | 43 +++++++++++++++++++ feature/mypage/consumer-rules.pro | 0 feature/mypage/proguard-rules.pro | 21 +++++++++ .../example/mypage/ExampleInstrumentedTest.kt | 24 +++++++++++ feature/mypage/src/main/AndroidManifest.xml | 4 ++ .../com/example/mypage/ExampleUnitTest.kt | 17 ++++++++ local.properties | 8 ++-- settings.gradle.kts | 4 ++ 30 files changed, 447 insertions(+), 5 deletions(-) create mode 100644 feature/auth/.gitignore create mode 100644 feature/auth/build.gradle.kts create mode 100644 feature/auth/consumer-rules.pro create mode 100644 feature/auth/proguard-rules.pro create mode 100644 feature/auth/src/androidTest/java/com/example/auth/ExampleInstrumentedTest.kt create mode 100644 feature/auth/src/main/AndroidManifest.xml create mode 100644 feature/auth/src/test/java/com/example/auth/ExampleUnitTest.kt create mode 100644 feature/etc/.gitignore create mode 100644 feature/etc/build.gradle.kts create mode 100644 feature/etc/consumer-rules.pro create mode 100644 feature/etc/proguard-rules.pro create mode 100644 feature/etc/src/androidTest/java/com/example/etc/ExampleInstrumentedTest.kt create mode 100644 feature/etc/src/main/AndroidManifest.xml create mode 100644 feature/etc/src/test/java/com/example/etc/ExampleUnitTest.kt create mode 100644 feature/matching/.gitignore create mode 100644 feature/matching/build.gradle.kts create mode 100644 feature/matching/consumer-rules.pro create mode 100644 feature/matching/proguard-rules.pro create mode 100644 feature/matching/src/androidTest/java/com/example/matching/ExampleInstrumentedTest.kt create mode 100644 feature/matching/src/main/AndroidManifest.xml create mode 100644 feature/matching/src/test/java/com/example/matching/ExampleUnitTest.kt create mode 100644 feature/mypage/.gitignore create mode 100644 feature/mypage/build.gradle.kts create mode 100644 feature/mypage/consumer-rules.pro create mode 100644 feature/mypage/proguard-rules.pro create mode 100644 feature/mypage/src/androidTest/java/com/example/mypage/ExampleInstrumentedTest.kt create mode 100644 feature/mypage/src/main/AndroidManifest.xml create mode 100644 feature/mypage/src/test/java/com/example/mypage/ExampleUnitTest.kt diff --git a/feature/auth/.gitignore b/feature/auth/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/feature/auth/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/feature/auth/build.gradle.kts b/feature/auth/build.gradle.kts new file mode 100644 index 00000000..e130319d --- /dev/null +++ b/feature/auth/build.gradle.kts @@ -0,0 +1,43 @@ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "com.example.auth" + compileSdk = 34 + + defaultConfig { + minSdk = 24 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } +} + +dependencies { + + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.material) + testImplementation(libs.junit4) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.test.espresso.core) +} \ No newline at end of file diff --git a/feature/auth/consumer-rules.pro b/feature/auth/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/feature/auth/proguard-rules.pro b/feature/auth/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/feature/auth/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/feature/auth/src/androidTest/java/com/example/auth/ExampleInstrumentedTest.kt b/feature/auth/src/androidTest/java/com/example/auth/ExampleInstrumentedTest.kt new file mode 100644 index 00000000..734aa6d1 --- /dev/null +++ b/feature/auth/src/androidTest/java/com/example/auth/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.auth + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.auth.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/feature/auth/src/main/AndroidManifest.xml b/feature/auth/src/main/AndroidManifest.xml new file mode 100644 index 00000000..a5918e68 --- /dev/null +++ b/feature/auth/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/feature/auth/src/test/java/com/example/auth/ExampleUnitTest.kt b/feature/auth/src/test/java/com/example/auth/ExampleUnitTest.kt new file mode 100644 index 00000000..14569317 --- /dev/null +++ b/feature/auth/src/test/java/com/example/auth/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.example.auth + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/feature/etc/.gitignore b/feature/etc/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/feature/etc/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/feature/etc/build.gradle.kts b/feature/etc/build.gradle.kts new file mode 100644 index 00000000..3541ef83 --- /dev/null +++ b/feature/etc/build.gradle.kts @@ -0,0 +1,43 @@ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "com.example.etc" + compileSdk = 34 + + defaultConfig { + minSdk = 24 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } +} + +dependencies { + + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.material) + testImplementation(libs.junit4) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.test.espresso.core) +} \ No newline at end of file diff --git a/feature/etc/consumer-rules.pro b/feature/etc/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/feature/etc/proguard-rules.pro b/feature/etc/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/feature/etc/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/feature/etc/src/androidTest/java/com/example/etc/ExampleInstrumentedTest.kt b/feature/etc/src/androidTest/java/com/example/etc/ExampleInstrumentedTest.kt new file mode 100644 index 00000000..985b4826 --- /dev/null +++ b/feature/etc/src/androidTest/java/com/example/etc/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.etc + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.etc.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/feature/etc/src/main/AndroidManifest.xml b/feature/etc/src/main/AndroidManifest.xml new file mode 100644 index 00000000..a5918e68 --- /dev/null +++ b/feature/etc/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/feature/etc/src/test/java/com/example/etc/ExampleUnitTest.kt b/feature/etc/src/test/java/com/example/etc/ExampleUnitTest.kt new file mode 100644 index 00000000..cc7f4c86 --- /dev/null +++ b/feature/etc/src/test/java/com/example/etc/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.example.etc + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/feature/matching/.gitignore b/feature/matching/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/feature/matching/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/feature/matching/build.gradle.kts b/feature/matching/build.gradle.kts new file mode 100644 index 00000000..248a1c0b --- /dev/null +++ b/feature/matching/build.gradle.kts @@ -0,0 +1,43 @@ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "com.example.matching" + compileSdk = 34 + + defaultConfig { + minSdk = 24 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } +} + +dependencies { + + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.material) + testImplementation(libs.junit4) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.test.espresso.core) +} \ No newline at end of file diff --git a/feature/matching/consumer-rules.pro b/feature/matching/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/feature/matching/proguard-rules.pro b/feature/matching/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/feature/matching/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/feature/matching/src/androidTest/java/com/example/matching/ExampleInstrumentedTest.kt b/feature/matching/src/androidTest/java/com/example/matching/ExampleInstrumentedTest.kt new file mode 100644 index 00000000..d17a3acf --- /dev/null +++ b/feature/matching/src/androidTest/java/com/example/matching/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.matching + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.matching.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/feature/matching/src/main/AndroidManifest.xml b/feature/matching/src/main/AndroidManifest.xml new file mode 100644 index 00000000..a5918e68 --- /dev/null +++ b/feature/matching/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/feature/matching/src/test/java/com/example/matching/ExampleUnitTest.kt b/feature/matching/src/test/java/com/example/matching/ExampleUnitTest.kt new file mode 100644 index 00000000..12aee33e --- /dev/null +++ b/feature/matching/src/test/java/com/example/matching/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.example.matching + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/feature/mypage/.gitignore b/feature/mypage/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/feature/mypage/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/feature/mypage/build.gradle.kts b/feature/mypage/build.gradle.kts new file mode 100644 index 00000000..e071353e --- /dev/null +++ b/feature/mypage/build.gradle.kts @@ -0,0 +1,43 @@ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "com.example.mypage" + compileSdk = 34 + + defaultConfig { + minSdk = 24 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } +} + +dependencies { + + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.material) + testImplementation(libs.junit4) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.test.espresso.core) +} \ No newline at end of file diff --git a/feature/mypage/consumer-rules.pro b/feature/mypage/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/feature/mypage/proguard-rules.pro b/feature/mypage/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/feature/mypage/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/feature/mypage/src/androidTest/java/com/example/mypage/ExampleInstrumentedTest.kt b/feature/mypage/src/androidTest/java/com/example/mypage/ExampleInstrumentedTest.kt new file mode 100644 index 00000000..94dc09f5 --- /dev/null +++ b/feature/mypage/src/androidTest/java/com/example/mypage/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.mypage + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.mypage.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/feature/mypage/src/main/AndroidManifest.xml b/feature/mypage/src/main/AndroidManifest.xml new file mode 100644 index 00000000..a5918e68 --- /dev/null +++ b/feature/mypage/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/feature/mypage/src/test/java/com/example/mypage/ExampleUnitTest.kt b/feature/mypage/src/test/java/com/example/mypage/ExampleUnitTest.kt new file mode 100644 index 00000000..2e35aa61 --- /dev/null +++ b/feature/mypage/src/test/java/com/example/mypage/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.example.mypage + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/local.properties b/local.properties index 6d528639..23ab913d 100644 --- a/local.properties +++ b/local.properties @@ -1,10 +1,8 @@ -## This file is automatically generated by Android Studio. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file should *NOT* be checked into Version Control Systems, +## This file must *NOT* be checked into Version Control Systems, # as it contains information specific to your local configuration. # # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -sdk.dir=/Users/antaegyu/Library/Android/sdk \ No newline at end of file +#Mon Dec 09 00:43:52 KST 2024 +sdk.dir=C\:\\Users\\sksow\\AppData\\Local\\Android\\Sdk diff --git a/settings.gradle.kts b/settings.gradle.kts index ff0d480e..12f6b79a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,3 +23,7 @@ dependencyResolutionManagement { rootProject.name = "Chaeum" include(":app") +include(":feature:auth") +include(":feature:mypage") +include(":feature:matching") +include(":feature:etc") From aa8d335ed132f2e7a0c0f900b4000f51d162b5ea Mon Sep 17 00:00:00 2001 From: sksowk156 Date: Tue, 10 Dec 2024 03:37:27 +0900 Subject: [PATCH 2/7] =?UTF-8?q?#3=20-=20appstate,=20navhost,=20bottom=20na?= =?UTF-8?q?vi=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 8 +++ .../main/java/com/yapp/chaeum/MainActivity.kt | 33 ++------- .../com/yapp/chaeum/navigation/AppNavHost.kt | 29 ++++++++ .../chaeum/navigation/TopLevelDestinvation.kt | 40 +++++++++++ app/src/main/java/com/yapp/chaeum/ui/App.kt | 66 +++++++++++++++++ .../main/java/com/yapp/chaeum/ui/AppState.kt | 70 +++++++++++++++++++ feature/auth/build.gradle.kts | 38 ++-------- .../main/java/com/example/auth/AuthScreen.kt | 23 ++++++ .../example/auth/navigation/AuthNavigation.kt | 24 +++++++ feature/etc/build.gradle.kts | 38 ++-------- .../main/java/com/example/etc/EtcScreen.kt | 20 ++++++ .../example/etc/navigation/EtcNavigation.kt | 20 ++++++ feature/matching/build.gradle.kts | 38 ++-------- .../com/example/matching/MatchingScreen.kt | 20 ++++++ .../matching/navigation/MatchingNavigation.kt | 20 ++++++ feature/mypage/build.gradle.kts | 38 ++-------- .../java/com/example/mypage/MyPageScreen.kt | 20 ++++++ .../mypage/navigation/MyPageNavigation.kt | 20 ++++++ gradle/libs.versions.toml | 2 +- 19 files changed, 401 insertions(+), 166 deletions(-) create mode 100644 app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt create mode 100644 app/src/main/java/com/yapp/chaeum/navigation/TopLevelDestinvation.kt create mode 100644 app/src/main/java/com/yapp/chaeum/ui/App.kt create mode 100644 app/src/main/java/com/yapp/chaeum/ui/AppState.kt create mode 100644 feature/auth/src/main/java/com/example/auth/AuthScreen.kt create mode 100644 feature/auth/src/main/java/com/example/auth/navigation/AuthNavigation.kt create mode 100644 feature/etc/src/main/java/com/example/etc/EtcScreen.kt create mode 100644 feature/etc/src/main/java/com/example/etc/navigation/EtcNavigation.kt create mode 100644 feature/matching/src/main/java/com/example/matching/MatchingScreen.kt create mode 100644 feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt create mode 100644 feature/mypage/src/main/java/com/example/mypage/MyPageScreen.kt create mode 100644 feature/mypage/src/main/java/com/example/mypage/navigation/MyPageNavigation.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4572f31b..70859d18 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -2,6 +2,7 @@ plugins { id("chaeum.android.application") id("chaeum.android.compose") alias(libs.plugins.androidx.navigation.safeargs) + alias(libs.plugins.kotlin.serialization) } android { @@ -32,4 +33,11 @@ dependencies { implementation(libs.androidx.core.splashscreen) implementation(libs.androidx.activity.compose) implementation(libs.androidx.navigation.ui) + implementation(libs.androidx.compose.navigation) + implementation(libs.kotlinx.serialization.json) + + implementation(projects.feature.auth) + implementation(projects.feature.etc) + implementation(projects.feature.matching) + implementation(projects.feature.mypage) } \ No newline at end of file diff --git a/app/src/main/java/com/yapp/chaeum/MainActivity.kt b/app/src/main/java/com/yapp/chaeum/MainActivity.kt index 8bc6911d..391c3563 100644 --- a/app/src/main/java/com/yapp/chaeum/MainActivity.kt +++ b/app/src/main/java/com/yapp/chaeum/MainActivity.kt @@ -4,13 +4,8 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Scaffold -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.tooling.preview.Preview +import com.yapp.chaeum.ui.App +import com.yapp.chaeum.ui.rememberAppState import com.yapp.chaeum.ui.theme.ChaeumTheme class MainActivity : ComponentActivity() { @@ -18,30 +13,10 @@ class MainActivity : ComponentActivity() { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { + val appState = rememberAppState() ChaeumTheme { - Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> - Greeting( - name = "Android", - modifier = Modifier.padding(innerPadding) - ) - } + App(appState) } } } -} - -@Composable -fun Greeting(name: String, modifier: Modifier = Modifier) { - Text( - text = "Hello $name!", - modifier = modifier - ) -} - -@Preview(showBackground = true) -@Composable -fun GreetingPreview() { - ChaeumTheme { - Greeting("Android") - } } \ No newline at end of file diff --git a/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt b/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt new file mode 100644 index 00000000..c01b22e4 --- /dev/null +++ b/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt @@ -0,0 +1,29 @@ +package com.yapp.chaeum.navigation + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.navigation.compose.NavHost +import com.example.auth.navigation.AuthRoute +import com.example.auth.navigation.authScreen +import com.example.matching.navigation.matchingScreen +import com.example.mypage.navigation.myPageScreen +import com.yapp.chaeum.ui.AppState + +@Composable +fun AppNavHost( + appState: AppState, + modifier: Modifier = Modifier, +) { + val navController = appState.navController + NavHost( + navController = navController, + startDestination = AuthRoute, + modifier = modifier, + ) { + authScreen( + onLoginSuccess = { appState.loginSuccess() }, + ) + matchingScreen() + myPageScreen() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/yapp/chaeum/navigation/TopLevelDestinvation.kt b/app/src/main/java/com/yapp/chaeum/navigation/TopLevelDestinvation.kt new file mode 100644 index 00000000..9291b1eb --- /dev/null +++ b/app/src/main/java/com/yapp/chaeum/navigation/TopLevelDestinvation.kt @@ -0,0 +1,40 @@ +package com.yapp.chaeum.navigation + +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Call +import androidx.compose.material.icons.outlined.Call +import androidx.compose.ui.graphics.vector.ImageVector +import com.example.etc.navigation.EtcRoute +import com.example.matching.navigation.MatchingRoute +import com.example.mypage.navigation.MyPageRoute +import kotlin.reflect.KClass + +enum class TopLevelDestination( + val selectedIcon: ImageVector, + val unselectedIcon: ImageVector, + val iconText: String, + val titleText: String, + val route: KClass<*>, +) { + MATCHING( + selectedIcon = Icons.Filled.Call, + unselectedIcon = Icons.Outlined.Call, + iconText = "매칭", + titleText = "매칭", + route = MatchingRoute::class, + ), + MYPAGE( + selectedIcon = Icons.Filled.Call, + unselectedIcon = Icons.Outlined.Call, + iconText = "마이페이지", + titleText = "마이페이지", + route = MyPageRoute::class, + ), + ETC( + selectedIcon = Icons.Filled.Call, + unselectedIcon = Icons.Outlined.Call, + iconText = "ETC", + titleText = "ETC", + route = EtcRoute::class, + ), +} diff --git a/app/src/main/java/com/yapp/chaeum/ui/App.kt b/app/src/main/java/com/yapp/chaeum/ui/App.kt new file mode 100644 index 00000000..468825d6 --- /dev/null +++ b/app/src/main/java/com/yapp/chaeum/ui/App.kt @@ -0,0 +1,66 @@ +package com.yapp.chaeum.ui + +import androidx.compose.foundation.layout.navigationBarsPadding +import androidx.compose.foundation.layout.padding +import androidx.compose.material.BottomNavigation +import androidx.compose.material.BottomNavigationItem +import androidx.compose.material.Icon +import androidx.compose.material.Text +import androidx.compose.material3.Scaffold +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.navigation.NavDestination +import androidx.navigation.NavDestination.Companion.hierarchy +import androidx.navigation.compose.currentBackStackEntryAsState +import com.yapp.chaeum.navigation.AppNavHost +import com.yapp.chaeum.navigation.TopLevelDestination +import kotlin.reflect.KClass + +@Composable +fun App(appState: AppState = rememberAppState()) { + val navBackStackEntry by appState.navController.currentBackStackEntryAsState() + val currentDestination = navBackStackEntry?.destination + + // 현재 화면이 TopLevelDestination 중 하나인지 확인 + val isTopLevel = TopLevelDestination.entries.any { + currentDestination?.route == it.route.qualifiedName + } + + Scaffold( + bottomBar = { + if (isTopLevel) { + BottomNavigation( + modifier = Modifier.navigationBarsPadding() + ) { + TopLevelDestination.entries.forEach { topLevelRoute -> + BottomNavigationItem( + icon = { + Icon( + topLevelRoute.selectedIcon, + contentDescription = topLevelRoute.name + ) + }, + label = { Text(topLevelRoute.name) }, + selected = currentDestination?.hierarchy?.any { destination -> + destination.route == topLevelRoute.route.qualifiedName + } == true, + onClick = { + appState.navigateToTopLevelDestination(topLevelRoute) + } + ) + } + } + } + } + ) { innerPadding -> + AppNavHost( + appState = appState, + modifier = Modifier.padding(innerPadding) + ) + } +} + +private fun NavDestination.hasRoute(routeClass: KClass<*>): Boolean { + return this.route == routeClass.qualifiedName +} \ No newline at end of file diff --git a/app/src/main/java/com/yapp/chaeum/ui/AppState.kt b/app/src/main/java/com/yapp/chaeum/ui/AppState.kt new file mode 100644 index 00000000..72833005 --- /dev/null +++ b/app/src/main/java/com/yapp/chaeum/ui/AppState.kt @@ -0,0 +1,70 @@ +package com.yapp.chaeum.ui + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.navigation.NavGraph.Companion.findStartDestination +import androidx.navigation.NavHostController +import androidx.navigation.compose.rememberNavController +import androidx.navigation.navOptions +import com.example.auth.navigation.AuthRoute +import com.example.auth.navigation.navigateToAuth +import com.example.etc.navigation.navigateToEtc +import com.example.matching.navigation.MatchingRoute +import com.example.matching.navigation.navigateToMatching +import com.example.mypage.navigation.navigateToMyPage +import com.yapp.chaeum.navigation.TopLevelDestination + +@Composable +fun rememberAppState( + navController: NavHostController = rememberNavController(), +): AppState { + return remember( + navController, + ) { + AppState( + navController = navController, + ) + } +} + +class AppState( + val navController: NavHostController, +) { + fun navigateToTopLevelDestination(topLevelDestination: TopLevelDestination) { + val topLevelNavOptions = navOptions { + popUpTo(navController.graph.findStartDestination().id) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + + when (topLevelDestination) { + TopLevelDestination.MATCHING -> navController.navigateToMatching(topLevelNavOptions) + TopLevelDestination.MYPAGE -> navController.navigateToMyPage(topLevelNavOptions) + TopLevelDestination.ETC -> navController.navigateToEtc(topLevelNavOptions) + } + } + + fun navigateBack() { + navController.popBackStack() + } + + fun logout() { + navController.navigateToAuth( + navOptions { + popUpTo(navController.graph.findStartDestination().id) { + inclusive = true + } + launchSingleTop = true + } + ) + } + + fun loginSuccess() { + navController.navigate(MatchingRoute) { + popUpTo(AuthRoute) { inclusive = true } + launchSingleTop = true + } + } +} \ No newline at end of file diff --git a/feature/auth/build.gradle.kts b/feature/auth/build.gradle.kts index e130319d..4be47caa 100644 --- a/feature/auth/build.gradle.kts +++ b/feature/auth/build.gradle.kts @@ -1,43 +1,13 @@ plugins { - alias(libs.plugins.android.library) - alias(libs.plugins.kotlin.android) + id("chaeum.android.feature") + alias(libs.plugins.androidx.navigation.safeargs) + alias(libs.plugins.kotlin.serialization) } android { namespace = "com.example.auth" - compileSdk = 34 - - defaultConfig { - minSdk = 24 - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") - } - - buildTypes { - release { - isMinifyEnabled = false - proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" - ) - } - } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - kotlinOptions { - jvmTarget = "11" - } } dependencies { - - implementation(libs.androidx.core.ktx) - implementation(libs.androidx.appcompat) - implementation(libs.material) - testImplementation(libs.junit4) - androidTestImplementation(libs.androidx.junit) - androidTestImplementation(libs.androidx.test.espresso.core) + implementation(libs.kotlinx.serialization.json) } \ No newline at end of file diff --git a/feature/auth/src/main/java/com/example/auth/AuthScreen.kt b/feature/auth/src/main/java/com/example/auth/AuthScreen.kt new file mode 100644 index 00000000..2390183c --- /dev/null +++ b/feature/auth/src/main/java/com/example/auth/AuthScreen.kt @@ -0,0 +1,23 @@ +package com.example.auth + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.sp + +@Composable +fun AuthRoute( + onLoginSuccess: () -> Unit, +) { + Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + Text(text = "AuthRoute", fontSize = 30.sp, modifier = Modifier.clickable { onLoginSuccess() }) + } +} + +@Composable +fun AuthScreen() { +} \ No newline at end of file diff --git a/feature/auth/src/main/java/com/example/auth/navigation/AuthNavigation.kt b/feature/auth/src/main/java/com/example/auth/navigation/AuthNavigation.kt new file mode 100644 index 00000000..60d47f20 --- /dev/null +++ b/feature/auth/src/main/java/com/example/auth/navigation/AuthNavigation.kt @@ -0,0 +1,24 @@ +package com.example.auth.navigation + +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavOptions +import androidx.navigation.compose.composable +import com.example.auth.AuthRoute +import kotlinx.serialization.Serializable + +@Serializable +object AuthRoute + +fun NavController.navigateToAuth(navOptions: NavOptions) = + navigate(route = AuthRoute, navOptions) + +fun NavGraphBuilder.authScreen( + onLoginSuccess: () -> Unit +) { + composable { + AuthRoute( + onLoginSuccess = onLoginSuccess + ) + } +} diff --git a/feature/etc/build.gradle.kts b/feature/etc/build.gradle.kts index 3541ef83..ac13d89b 100644 --- a/feature/etc/build.gradle.kts +++ b/feature/etc/build.gradle.kts @@ -1,43 +1,13 @@ plugins { - alias(libs.plugins.android.library) - alias(libs.plugins.kotlin.android) + id("chaeum.android.feature") + alias(libs.plugins.androidx.navigation.safeargs) + alias(libs.plugins.kotlin.serialization) } android { namespace = "com.example.etc" - compileSdk = 34 - - defaultConfig { - minSdk = 24 - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") - } - - buildTypes { - release { - isMinifyEnabled = false - proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" - ) - } - } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - kotlinOptions { - jvmTarget = "11" - } } dependencies { - - implementation(libs.androidx.core.ktx) - implementation(libs.androidx.appcompat) - implementation(libs.material) - testImplementation(libs.junit4) - androidTestImplementation(libs.androidx.junit) - androidTestImplementation(libs.androidx.test.espresso.core) + implementation(libs.kotlinx.serialization.json) } \ No newline at end of file diff --git a/feature/etc/src/main/java/com/example/etc/EtcScreen.kt b/feature/etc/src/main/java/com/example/etc/EtcScreen.kt new file mode 100644 index 00000000..9adbb5b9 --- /dev/null +++ b/feature/etc/src/main/java/com/example/etc/EtcScreen.kt @@ -0,0 +1,20 @@ +package com.example.etc + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.sp + +@Composable +internal fun EtcRoute() { + Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + Text(text = "EtcRoute", fontSize = 30.sp) + } +} + +@Composable +internal fun EtcScreen() { +} \ No newline at end of file diff --git a/feature/etc/src/main/java/com/example/etc/navigation/EtcNavigation.kt b/feature/etc/src/main/java/com/example/etc/navigation/EtcNavigation.kt new file mode 100644 index 00000000..869b8b5c --- /dev/null +++ b/feature/etc/src/main/java/com/example/etc/navigation/EtcNavigation.kt @@ -0,0 +1,20 @@ +package com.example.etc.navigation + +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavOptions +import androidx.navigation.compose.composable +import com.example.etc.EtcRoute +import kotlinx.serialization.Serializable + +@Serializable +object EtcRoute + +fun NavController.navigateToEtc(navOptions: NavOptions) = + navigate(route = EtcRoute, navOptions) + +fun NavGraphBuilder.etcScreen() { + composable { + EtcRoute() + } +} diff --git a/feature/matching/build.gradle.kts b/feature/matching/build.gradle.kts index 248a1c0b..6455b83b 100644 --- a/feature/matching/build.gradle.kts +++ b/feature/matching/build.gradle.kts @@ -1,43 +1,13 @@ plugins { - alias(libs.plugins.android.library) - alias(libs.plugins.kotlin.android) + id("chaeum.android.feature") + alias(libs.plugins.androidx.navigation.safeargs) + alias(libs.plugins.kotlin.serialization) } android { namespace = "com.example.matching" - compileSdk = 34 - - defaultConfig { - minSdk = 24 - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") - } - - buildTypes { - release { - isMinifyEnabled = false - proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" - ) - } - } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - kotlinOptions { - jvmTarget = "11" - } } dependencies { - - implementation(libs.androidx.core.ktx) - implementation(libs.androidx.appcompat) - implementation(libs.material) - testImplementation(libs.junit4) - androidTestImplementation(libs.androidx.junit) - androidTestImplementation(libs.androidx.test.espresso.core) + implementation(libs.kotlinx.serialization.json) } \ No newline at end of file diff --git a/feature/matching/src/main/java/com/example/matching/MatchingScreen.kt b/feature/matching/src/main/java/com/example/matching/MatchingScreen.kt new file mode 100644 index 00000000..67da3e7a --- /dev/null +++ b/feature/matching/src/main/java/com/example/matching/MatchingScreen.kt @@ -0,0 +1,20 @@ +package com.example.matching + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.sp + +@Composable +internal fun MatchingRoute() { + Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + Text(text = "MatchingRoute", fontSize = 30.sp) + } +} + +@Composable +internal fun MatchingScreen() { +} \ No newline at end of file diff --git a/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt b/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt new file mode 100644 index 00000000..c9fe35b6 --- /dev/null +++ b/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt @@ -0,0 +1,20 @@ +package com.example.matching.navigation + +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavOptions +import androidx.navigation.compose.composable +import com.example.matching.MatchingRoute +import kotlinx.serialization.Serializable + +@Serializable +object MatchingRoute + +fun NavController.navigateToMatching(navOptions: NavOptions) = + navigate(route = MatchingRoute, navOptions) + +fun NavGraphBuilder.matchingScreen() { + composable { + MatchingRoute() + } +} diff --git a/feature/mypage/build.gradle.kts b/feature/mypage/build.gradle.kts index e071353e..0faa29fe 100644 --- a/feature/mypage/build.gradle.kts +++ b/feature/mypage/build.gradle.kts @@ -1,43 +1,13 @@ plugins { - alias(libs.plugins.android.library) - alias(libs.plugins.kotlin.android) + id("chaeum.android.feature") + alias(libs.plugins.androidx.navigation.safeargs) + alias(libs.plugins.kotlin.serialization) } android { namespace = "com.example.mypage" - compileSdk = 34 - - defaultConfig { - minSdk = 24 - - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") - } - - buildTypes { - release { - isMinifyEnabled = false - proguardFiles( - getDefaultProguardFile("proguard-android-optimize.txt"), - "proguard-rules.pro" - ) - } - } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - kotlinOptions { - jvmTarget = "11" - } } dependencies { - - implementation(libs.androidx.core.ktx) - implementation(libs.androidx.appcompat) - implementation(libs.material) - testImplementation(libs.junit4) - androidTestImplementation(libs.androidx.junit) - androidTestImplementation(libs.androidx.test.espresso.core) + implementation(libs.kotlinx.serialization.json) } \ No newline at end of file diff --git a/feature/mypage/src/main/java/com/example/mypage/MyPageScreen.kt b/feature/mypage/src/main/java/com/example/mypage/MyPageScreen.kt new file mode 100644 index 00000000..4ae84a5b --- /dev/null +++ b/feature/mypage/src/main/java/com/example/mypage/MyPageScreen.kt @@ -0,0 +1,20 @@ +package com.example.mypage + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.sp + +@Composable +internal fun MyPageRoute() { + Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + Text(text = "MyPageRoute", fontSize = 30.sp) + } +} + +@Composable +internal fun MyPageScreen() { +} \ No newline at end of file diff --git a/feature/mypage/src/main/java/com/example/mypage/navigation/MyPageNavigation.kt b/feature/mypage/src/main/java/com/example/mypage/navigation/MyPageNavigation.kt new file mode 100644 index 00000000..bafa27f5 --- /dev/null +++ b/feature/mypage/src/main/java/com/example/mypage/navigation/MyPageNavigation.kt @@ -0,0 +1,20 @@ +package com.example.mypage.navigation + +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavOptions +import androidx.navigation.compose.composable +import com.example.mypage.MyPageRoute +import kotlinx.serialization.Serializable + +@Serializable +object MyPageRoute + +fun NavController.navigateToMyPage(navOptions: NavOptions) = + navigate(route = MyPageRoute, navOptions) + +fun NavGraphBuilder.myPageScreen() { + composable { + MyPageRoute() + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6ee8dfcd..c5afaac1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -26,7 +26,7 @@ androidxSplashscreen = "1.0.1" # https://developer.android.com/develop/ui/compose/bom/bom-mapping androidxComposeBom = "2024.11.00" # https://developer.android.com/jetpack/androidx/releases/navigation -androidxComposeNavigation = "2.8.3" +androidxComposeNavigation = "2.8.4" # https://developer.android.com/jetpack/androidx/releases/compose-material androidxComposeMaterial = "1.7.4" # https://developer.android.com/jetpack/androidx/releases/compose-material3 From a6f584e5c978c083424af7c9b82dc65cb8c07258 Mon Sep 17 00:00:00 2001 From: sksowk156 Date: Tue, 10 Dec 2024 03:40:16 +0900 Subject: [PATCH 3/7] =?UTF-8?q?#3=20-=20=EC=97=90=EB=9F=AC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yapp/chaeum/ExampleInstrumentedTest.kt | 6 ++---- app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt | 2 ++ app/src/main/java/com/yapp/chaeum/ui/theme/Theme.kt | 1 - app/src/test/java/com/yapp/chaeum/ExampleUnitTest.kt | 3 +-- .../java/com/example/auth/ExampleInstrumentedTest.kt | 6 ++---- feature/auth/src/main/AndroidManifest.xml | 2 +- feature/auth/src/main/java/com/example/auth/AuthScreen.kt | 5 ++++- .../auth/src/test/java/com/example/auth/ExampleUnitTest.kt | 3 +-- .../java/com/example/etc/ExampleInstrumentedTest.kt | 6 ++---- feature/etc/src/main/AndroidManifest.xml | 2 +- .../etc/src/test/java/com/example/etc/ExampleUnitTest.kt | 3 +-- .../java/com/example/matching/ExampleInstrumentedTest.kt | 6 ++---- feature/matching/src/main/AndroidManifest.xml | 2 +- .../src/test/java/com/example/matching/ExampleUnitTest.kt | 3 +-- .../java/com/example/mypage/ExampleInstrumentedTest.kt | 6 ++---- feature/mypage/src/main/AndroidManifest.xml | 2 +- .../src/test/java/com/example/mypage/ExampleUnitTest.kt | 3 +-- 17 files changed, 25 insertions(+), 36 deletions(-) diff --git a/app/src/androidTest/java/com/yapp/chaeum/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/yapp/chaeum/ExampleInstrumentedTest.kt index 86ed1135..c938cdb2 100644 --- a/app/src/androidTest/java/com/yapp/chaeum/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/com/yapp/chaeum/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package com.yapp.chaeum -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * diff --git a/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt b/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt index c01b22e4..08e922a5 100644 --- a/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt +++ b/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt @@ -5,6 +5,7 @@ import androidx.compose.ui.Modifier import androidx.navigation.compose.NavHost import com.example.auth.navigation.AuthRoute import com.example.auth.navigation.authScreen +import com.example.etc.navigation.etcScreen import com.example.matching.navigation.matchingScreen import com.example.mypage.navigation.myPageScreen import com.yapp.chaeum.ui.AppState @@ -25,5 +26,6 @@ fun AppNavHost( ) matchingScreen() myPageScreen() + etcScreen() } } \ No newline at end of file diff --git a/app/src/main/java/com/yapp/chaeum/ui/theme/Theme.kt b/app/src/main/java/com/yapp/chaeum/ui/theme/Theme.kt index 0eba5f58..dec6301f 100644 --- a/app/src/main/java/com/yapp/chaeum/ui/theme/Theme.kt +++ b/app/src/main/java/com/yapp/chaeum/ui/theme/Theme.kt @@ -1,6 +1,5 @@ package com.yapp.chaeum.ui.theme -import android.app.Activity import android.os.Build import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme diff --git a/app/src/test/java/com/yapp/chaeum/ExampleUnitTest.kt b/app/src/test/java/com/yapp/chaeum/ExampleUnitTest.kt index c35f9ac8..e11269b8 100644 --- a/app/src/test/java/com/yapp/chaeum/ExampleUnitTest.kt +++ b/app/src/test/java/com/yapp/chaeum/ExampleUnitTest.kt @@ -1,9 +1,8 @@ package com.yapp.chaeum +import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.Assert.* - /** * Example local unit test, which will execute on the development machine (host). * diff --git a/feature/auth/src/androidTest/java/com/example/auth/ExampleInstrumentedTest.kt b/feature/auth/src/androidTest/java/com/example/auth/ExampleInstrumentedTest.kt index 734aa6d1..47f4217e 100644 --- a/feature/auth/src/androidTest/java/com/example/auth/ExampleInstrumentedTest.kt +++ b/feature/auth/src/androidTest/java/com/example/auth/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package com.example.auth -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * diff --git a/feature/auth/src/main/AndroidManifest.xml b/feature/auth/src/main/AndroidManifest.xml index a5918e68..44008a43 100644 --- a/feature/auth/src/main/AndroidManifest.xml +++ b/feature/auth/src/main/AndroidManifest.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/feature/auth/src/main/java/com/example/auth/AuthScreen.kt b/feature/auth/src/main/java/com/example/auth/AuthScreen.kt index 2390183c..4eab93e5 100644 --- a/feature/auth/src/main/java/com/example/auth/AuthScreen.kt +++ b/feature/auth/src/main/java/com/example/auth/AuthScreen.kt @@ -14,7 +14,10 @@ fun AuthRoute( onLoginSuccess: () -> Unit, ) { Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { - Text(text = "AuthRoute", fontSize = 30.sp, modifier = Modifier.clickable { onLoginSuccess() }) + Text( + text = "AuthRoute", + fontSize = 30.sp, + modifier = Modifier.clickable { onLoginSuccess() }) } } diff --git a/feature/auth/src/test/java/com/example/auth/ExampleUnitTest.kt b/feature/auth/src/test/java/com/example/auth/ExampleUnitTest.kt index 14569317..a127c830 100644 --- a/feature/auth/src/test/java/com/example/auth/ExampleUnitTest.kt +++ b/feature/auth/src/test/java/com/example/auth/ExampleUnitTest.kt @@ -1,9 +1,8 @@ package com.example.auth +import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.Assert.* - /** * Example local unit test, which will execute on the development machine (host). * diff --git a/feature/etc/src/androidTest/java/com/example/etc/ExampleInstrumentedTest.kt b/feature/etc/src/androidTest/java/com/example/etc/ExampleInstrumentedTest.kt index 985b4826..aef3f6fc 100644 --- a/feature/etc/src/androidTest/java/com/example/etc/ExampleInstrumentedTest.kt +++ b/feature/etc/src/androidTest/java/com/example/etc/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package com.example.etc -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * diff --git a/feature/etc/src/main/AndroidManifest.xml b/feature/etc/src/main/AndroidManifest.xml index a5918e68..44008a43 100644 --- a/feature/etc/src/main/AndroidManifest.xml +++ b/feature/etc/src/main/AndroidManifest.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/feature/etc/src/test/java/com/example/etc/ExampleUnitTest.kt b/feature/etc/src/test/java/com/example/etc/ExampleUnitTest.kt index cc7f4c86..a09e411c 100644 --- a/feature/etc/src/test/java/com/example/etc/ExampleUnitTest.kt +++ b/feature/etc/src/test/java/com/example/etc/ExampleUnitTest.kt @@ -1,9 +1,8 @@ package com.example.etc +import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.Assert.* - /** * Example local unit test, which will execute on the development machine (host). * diff --git a/feature/matching/src/androidTest/java/com/example/matching/ExampleInstrumentedTest.kt b/feature/matching/src/androidTest/java/com/example/matching/ExampleInstrumentedTest.kt index d17a3acf..f0dc667d 100644 --- a/feature/matching/src/androidTest/java/com/example/matching/ExampleInstrumentedTest.kt +++ b/feature/matching/src/androidTest/java/com/example/matching/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package com.example.matching -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * diff --git a/feature/matching/src/main/AndroidManifest.xml b/feature/matching/src/main/AndroidManifest.xml index a5918e68..44008a43 100644 --- a/feature/matching/src/main/AndroidManifest.xml +++ b/feature/matching/src/main/AndroidManifest.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/feature/matching/src/test/java/com/example/matching/ExampleUnitTest.kt b/feature/matching/src/test/java/com/example/matching/ExampleUnitTest.kt index 12aee33e..71d22f0e 100644 --- a/feature/matching/src/test/java/com/example/matching/ExampleUnitTest.kt +++ b/feature/matching/src/test/java/com/example/matching/ExampleUnitTest.kt @@ -1,9 +1,8 @@ package com.example.matching +import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.Assert.* - /** * Example local unit test, which will execute on the development machine (host). * diff --git a/feature/mypage/src/androidTest/java/com/example/mypage/ExampleInstrumentedTest.kt b/feature/mypage/src/androidTest/java/com/example/mypage/ExampleInstrumentedTest.kt index 94dc09f5..959a8f88 100644 --- a/feature/mypage/src/androidTest/java/com/example/mypage/ExampleInstrumentedTest.kt +++ b/feature/mypage/src/androidTest/java/com/example/mypage/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package com.example.mypage -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * diff --git a/feature/mypage/src/main/AndroidManifest.xml b/feature/mypage/src/main/AndroidManifest.xml index a5918e68..44008a43 100644 --- a/feature/mypage/src/main/AndroidManifest.xml +++ b/feature/mypage/src/main/AndroidManifest.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/feature/mypage/src/test/java/com/example/mypage/ExampleUnitTest.kt b/feature/mypage/src/test/java/com/example/mypage/ExampleUnitTest.kt index 2e35aa61..c5faf91b 100644 --- a/feature/mypage/src/test/java/com/example/mypage/ExampleUnitTest.kt +++ b/feature/mypage/src/test/java/com/example/mypage/ExampleUnitTest.kt @@ -1,9 +1,8 @@ package com.example.mypage +import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.Assert.* - /** * Example local unit test, which will execute on the development machine (host). * From 463d91934ab9b1d1adac55146b2dfebb7a0efbb7 Mon Sep 17 00:00:00 2001 From: sksowk156 Date: Wed, 11 Dec 2024 21:16:13 +0900 Subject: [PATCH 4/7] =?UTF-8?q?#3=20-=20=ED=99=94=EB=A9=B4=20=EC=A0=84?= =?UTF-8?q?=ED=99=98=20graph=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yapp/chaeum/navigation/AppNavHost.kt | 22 +++---- .../com/yapp/chaeum/navigation/HomeNavHost.kt | 26 ++++++++ .../chaeum/navigation/TopLevelDestinvation.kt | 4 +- app/src/main/java/com/yapp/chaeum/ui/App.kt | 61 +---------------- .../main/java/com/yapp/chaeum/ui/AppState.kt | 51 ++------------- .../main/java/com/yapp/chaeum/ui/HomeRoute.kt | 65 +++++++++++++++++++ .../main/java/com/yapp/chaeum/ui/HomeState.kt | 41 ++++++++++++ .../example/auth/navigation/AuthNavigation.kt | 26 +++++--- .../matching/navigation/MatchingNavigation.kt | 21 ++++-- 9 files changed, 185 insertions(+), 132 deletions(-) create mode 100644 app/src/main/java/com/yapp/chaeum/navigation/HomeNavHost.kt create mode 100644 app/src/main/java/com/yapp/chaeum/ui/HomeRoute.kt create mode 100644 app/src/main/java/com/yapp/chaeum/ui/HomeState.kt diff --git a/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt b/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt index 08e922a5..6269374b 100644 --- a/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt +++ b/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt @@ -3,12 +3,12 @@ package com.yapp.chaeum.navigation import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.navigation.compose.NavHost -import com.example.auth.navigation.AuthRoute -import com.example.auth.navigation.authScreen -import com.example.etc.navigation.etcScreen -import com.example.matching.navigation.matchingScreen -import com.example.mypage.navigation.myPageScreen +import androidx.navigation.compose.composable +import com.example.auth.navigation.AuthGraph +import com.example.auth.navigation.authNavGraph import com.yapp.chaeum.ui.AppState +import com.yapp.chaeum.ui.HomeGraph +import com.yapp.chaeum.ui.HomeRoute @Composable fun AppNavHost( @@ -18,14 +18,14 @@ fun AppNavHost( val navController = appState.navController NavHost( navController = navController, - startDestination = AuthRoute, + startDestination = AuthGraph, modifier = modifier, ) { - authScreen( + authNavGraph( onLoginSuccess = { appState.loginSuccess() }, ) - matchingScreen() - myPageScreen() - etcScreen() + composable { + HomeRoute() + } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/yapp/chaeum/navigation/HomeNavHost.kt b/app/src/main/java/com/yapp/chaeum/navigation/HomeNavHost.kt new file mode 100644 index 00000000..97729fa0 --- /dev/null +++ b/app/src/main/java/com/yapp/chaeum/navigation/HomeNavHost.kt @@ -0,0 +1,26 @@ +package com.yapp.chaeum.navigation + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.navigation.NavHostController +import androidx.navigation.compose.NavHost +import com.example.etc.navigation.etcScreen +import com.example.matching.navigation.MatchingGraph +import com.example.matching.navigation.matchingNavGraph +import com.example.mypage.navigation.myPageScreen + +@Composable +fun HomeNavHost( + navController: NavHostController, + modifier: Modifier = Modifier, +) { + NavHost( + navController = navController, + startDestination = MatchingGraph, + modifier = modifier, + ) { + matchingNavGraph() + myPageScreen() + etcScreen() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/yapp/chaeum/navigation/TopLevelDestinvation.kt b/app/src/main/java/com/yapp/chaeum/navigation/TopLevelDestinvation.kt index 9291b1eb..18d5fa81 100644 --- a/app/src/main/java/com/yapp/chaeum/navigation/TopLevelDestinvation.kt +++ b/app/src/main/java/com/yapp/chaeum/navigation/TopLevelDestinvation.kt @@ -5,7 +5,7 @@ import androidx.compose.material.icons.filled.Call import androidx.compose.material.icons.outlined.Call import androidx.compose.ui.graphics.vector.ImageVector import com.example.etc.navigation.EtcRoute -import com.example.matching.navigation.MatchingRoute +import com.example.matching.navigation.MatchingGraphDest import com.example.mypage.navigation.MyPageRoute import kotlin.reflect.KClass @@ -21,7 +21,7 @@ enum class TopLevelDestination( unselectedIcon = Icons.Outlined.Call, iconText = "매칭", titleText = "매칭", - route = MatchingRoute::class, + route = MatchingGraphDest.MatchingRoute::class, ), MYPAGE( selectedIcon = Icons.Filled.Call, diff --git a/app/src/main/java/com/yapp/chaeum/ui/App.kt b/app/src/main/java/com/yapp/chaeum/ui/App.kt index 468825d6..13bc2ee6 100644 --- a/app/src/main/java/com/yapp/chaeum/ui/App.kt +++ b/app/src/main/java/com/yapp/chaeum/ui/App.kt @@ -1,66 +1,11 @@ package com.yapp.chaeum.ui -import androidx.compose.foundation.layout.navigationBarsPadding -import androidx.compose.foundation.layout.padding -import androidx.compose.material.BottomNavigation -import androidx.compose.material.BottomNavigationItem -import androidx.compose.material.Icon -import androidx.compose.material.Text -import androidx.compose.material3.Scaffold import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.ui.Modifier -import androidx.navigation.NavDestination -import androidx.navigation.NavDestination.Companion.hierarchy -import androidx.navigation.compose.currentBackStackEntryAsState import com.yapp.chaeum.navigation.AppNavHost -import com.yapp.chaeum.navigation.TopLevelDestination -import kotlin.reflect.KClass @Composable fun App(appState: AppState = rememberAppState()) { - val navBackStackEntry by appState.navController.currentBackStackEntryAsState() - val currentDestination = navBackStackEntry?.destination - - // 현재 화면이 TopLevelDestination 중 하나인지 확인 - val isTopLevel = TopLevelDestination.entries.any { - currentDestination?.route == it.route.qualifiedName - } - - Scaffold( - bottomBar = { - if (isTopLevel) { - BottomNavigation( - modifier = Modifier.navigationBarsPadding() - ) { - TopLevelDestination.entries.forEach { topLevelRoute -> - BottomNavigationItem( - icon = { - Icon( - topLevelRoute.selectedIcon, - contentDescription = topLevelRoute.name - ) - }, - label = { Text(topLevelRoute.name) }, - selected = currentDestination?.hierarchy?.any { destination -> - destination.route == topLevelRoute.route.qualifiedName - } == true, - onClick = { - appState.navigateToTopLevelDestination(topLevelRoute) - } - ) - } - } - } - } - ) { innerPadding -> - AppNavHost( - appState = appState, - modifier = Modifier.padding(innerPadding) - ) - } + AppNavHost( + appState = appState, + ) } - -private fun NavDestination.hasRoute(routeClass: KClass<*>): Boolean { - return this.route == routeClass.qualifiedName -} \ No newline at end of file diff --git a/app/src/main/java/com/yapp/chaeum/ui/AppState.kt b/app/src/main/java/com/yapp/chaeum/ui/AppState.kt index 72833005..3e78c151 100644 --- a/app/src/main/java/com/yapp/chaeum/ui/AppState.kt +++ b/app/src/main/java/com/yapp/chaeum/ui/AppState.kt @@ -5,66 +5,25 @@ import androidx.compose.runtime.remember import androidx.navigation.NavGraph.Companion.findStartDestination import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController -import androidx.navigation.navOptions -import com.example.auth.navigation.AuthRoute -import com.example.auth.navigation.navigateToAuth -import com.example.etc.navigation.navigateToEtc -import com.example.matching.navigation.MatchingRoute -import com.example.matching.navigation.navigateToMatching -import com.example.mypage.navigation.navigateToMyPage -import com.yapp.chaeum.navigation.TopLevelDestination @Composable fun rememberAppState( navController: NavHostController = rememberNavController(), ): AppState { - return remember( - navController, - ) { - AppState( - navController = navController, - ) + return remember(navController) { + AppState(navController = navController) } } class AppState( val navController: NavHostController, ) { - fun navigateToTopLevelDestination(topLevelDestination: TopLevelDestination) { - val topLevelNavOptions = navOptions { + fun loginSuccess() { + navController.navigate(HomeGraph) { popUpTo(navController.graph.findStartDestination().id) { - saveState = true + inclusive = true } launchSingleTop = true - restoreState = true - } - - when (topLevelDestination) { - TopLevelDestination.MATCHING -> navController.navigateToMatching(topLevelNavOptions) - TopLevelDestination.MYPAGE -> navController.navigateToMyPage(topLevelNavOptions) - TopLevelDestination.ETC -> navController.navigateToEtc(topLevelNavOptions) - } - } - - fun navigateBack() { - navController.popBackStack() - } - - fun logout() { - navController.navigateToAuth( - navOptions { - popUpTo(navController.graph.findStartDestination().id) { - inclusive = true - } - launchSingleTop = true - } - ) - } - - fun loginSuccess() { - navController.navigate(MatchingRoute) { - popUpTo(AuthRoute) { inclusive = true } - launchSingleTop = true } } } \ No newline at end of file diff --git a/app/src/main/java/com/yapp/chaeum/ui/HomeRoute.kt b/app/src/main/java/com/yapp/chaeum/ui/HomeRoute.kt new file mode 100644 index 00000000..21023d3a --- /dev/null +++ b/app/src/main/java/com/yapp/chaeum/ui/HomeRoute.kt @@ -0,0 +1,65 @@ +package com.yapp.chaeum.ui + +import androidx.compose.foundation.layout.navigationBarsPadding +import androidx.compose.foundation.layout.padding +import androidx.compose.material.BottomNavigation +import androidx.compose.material.BottomNavigationItem +import androidx.compose.material.Icon +import androidx.compose.material.Text +import androidx.compose.material3.Scaffold +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.navigation.NavDestination.Companion.hierarchy +import androidx.navigation.compose.currentBackStackEntryAsState +import com.yapp.chaeum.navigation.HomeNavHost +import com.yapp.chaeum.navigation.TopLevelDestination +import kotlinx.serialization.Serializable + +@Serializable +data object HomeGraph + +@Composable +fun HomeRoute( + homeState: HomeState = rememberHomeState() +) { + Scaffold( + bottomBar = { + HomeBottomBar(homeState) + } + ) { innerPadding -> + HomeNavHost( + navController = homeState.navController, + modifier = Modifier.padding(innerPadding) + ) + } +} + +@Composable +private fun HomeBottomBar( + homeState: HomeState, +) { + val navBackStackEntry by homeState.navController.currentBackStackEntryAsState() + val currentDestination = navBackStackEntry?.destination + BottomNavigation( + modifier = Modifier.navigationBarsPadding() + ) { + TopLevelDestination.entries.forEach { topLevelRoute -> + BottomNavigationItem( + icon = { + Icon( + imageVector = topLevelRoute.selectedIcon, + contentDescription = topLevelRoute.name + ) + }, + label = { Text(topLevelRoute.name) }, + selected = currentDestination?.hierarchy?.any { destination -> + destination.route == topLevelRoute.route.qualifiedName + } == true, + onClick = { + homeState.navigateToTopLevelDestination(topLevelRoute) + } + ) + } + } +} diff --git a/app/src/main/java/com/yapp/chaeum/ui/HomeState.kt b/app/src/main/java/com/yapp/chaeum/ui/HomeState.kt new file mode 100644 index 00000000..62c41fca --- /dev/null +++ b/app/src/main/java/com/yapp/chaeum/ui/HomeState.kt @@ -0,0 +1,41 @@ +package com.yapp.chaeum.ui + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.navigation.NavGraph.Companion.findStartDestination +import androidx.navigation.NavHostController +import androidx.navigation.compose.rememberNavController +import androidx.navigation.navOptions +import com.example.etc.navigation.navigateToEtc +import com.example.matching.navigation.navigateToMatching +import com.example.mypage.navigation.navigateToMyPage +import com.yapp.chaeum.navigation.TopLevelDestination + +@Composable +fun rememberHomeState( + navController: NavHostController = rememberNavController(), +): HomeState { + return remember(navController) { + HomeState(navController = navController) + } +} + +class HomeState( + val navController: NavHostController, +) { + fun navigateToTopLevelDestination(topLevelDestination: TopLevelDestination) { + val topLevelNavOptions = navOptions { + popUpTo(navController.graph.findStartDestination().id) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + + when (topLevelDestination) { + TopLevelDestination.MATCHING -> navController.navigateToMatching(topLevelNavOptions) + TopLevelDestination.MYPAGE -> navController.navigateToMyPage(topLevelNavOptions) + TopLevelDestination.ETC -> navController.navigateToEtc(topLevelNavOptions) + } + } +} \ No newline at end of file diff --git a/feature/auth/src/main/java/com/example/auth/navigation/AuthNavigation.kt b/feature/auth/src/main/java/com/example/auth/navigation/AuthNavigation.kt index 60d47f20..7d54471b 100644 --- a/feature/auth/src/main/java/com/example/auth/navigation/AuthNavigation.kt +++ b/feature/auth/src/main/java/com/example/auth/navigation/AuthNavigation.kt @@ -4,21 +4,29 @@ import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.NavOptions import androidx.navigation.compose.composable +import androidx.navigation.navigation import com.example.auth.AuthRoute import kotlinx.serialization.Serializable @Serializable -object AuthRoute +data object AuthGraph + +sealed class AuthGraphDest { + @Serializable + data object AuthRoute : AuthGraphDest() +} fun NavController.navigateToAuth(navOptions: NavOptions) = - navigate(route = AuthRoute, navOptions) + navigate(route = AuthGraphDest.AuthRoute, navOptions) -fun NavGraphBuilder.authScreen( - onLoginSuccess: () -> Unit +fun NavGraphBuilder.authNavGraph( + onLoginSuccess: () -> Unit, ) { - composable { - AuthRoute( - onLoginSuccess = onLoginSuccess - ) + navigation(startDestination = AuthGraphDest.AuthRoute) { + composable { + AuthRoute( + onLoginSuccess = onLoginSuccess + ) + } } -} +} \ No newline at end of file diff --git a/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt b/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt index c9fe35b6..0c3f111c 100644 --- a/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt +++ b/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt @@ -4,17 +4,26 @@ import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.NavOptions import androidx.navigation.compose.composable +import androidx.navigation.navigation import com.example.matching.MatchingRoute import kotlinx.serialization.Serializable + @Serializable -object MatchingRoute +data object MatchingGraph + +sealed class MatchingGraphDest { + @Serializable + data object MatchingRoute : MatchingGraphDest() +} fun NavController.navigateToMatching(navOptions: NavOptions) = - navigate(route = MatchingRoute, navOptions) + navigate(route = MatchingGraphDest.MatchingRoute, navOptions) -fun NavGraphBuilder.matchingScreen() { - composable { - MatchingRoute() +fun NavGraphBuilder.matchingNavGraph() { + navigation(startDestination = MatchingGraphDest.MatchingRoute) { + composable { + MatchingRoute() + } } -} +} \ No newline at end of file From a3b32e4904b5cb12f192d36a72406c3f681b8872 Mon Sep 17 00:00:00 2001 From: sksowk156 Date: Sat, 14 Dec 2024 14:02:07 +0900 Subject: [PATCH 5/7] =?UTF-8?q?#3=20-=20NavHost=20=ED=95=98=EB=82=98?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yapp/chaeum/navigation/AppNavHost.kt | 52 ++++++++++-- .../com/yapp/chaeum/navigation/HomeNavHost.kt | 26 ------ .../chaeum/navigation/TopLevelDestinvation.kt | 6 +- app/src/main/java/com/yapp/chaeum/ui/App.kt | 79 ++++++++++++++++++- .../main/java/com/yapp/chaeum/ui/AppState.kt | 43 +++++++++- .../main/java/com/yapp/chaeum/ui/HomeRoute.kt | 65 --------------- .../main/java/com/yapp/chaeum/ui/HomeState.kt | 41 ---------- .../main/java/com/example/etc/EtcScreen.kt | 4 +- .../example/etc/navigation/EtcNavigation.kt | 5 +- .../com/example/matching/MatchingScreen.kt | 28 ++++++- .../matching/navigation/MatchingNavigation.kt | 26 +++++- .../java/com/example/mypage/MyPageScreen.kt | 4 +- .../mypage/navigation/MyPageNavigation.kt | 5 +- 13 files changed, 223 insertions(+), 161 deletions(-) delete mode 100644 app/src/main/java/com/yapp/chaeum/navigation/HomeNavHost.kt delete mode 100644 app/src/main/java/com/yapp/chaeum/ui/HomeRoute.kt delete mode 100644 app/src/main/java/com/yapp/chaeum/ui/HomeState.kt diff --git a/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt b/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt index 6269374b..586d8c6b 100644 --- a/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt +++ b/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt @@ -2,13 +2,21 @@ package com.yapp.chaeum.navigation import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.navigation.NavController +import androidx.navigation.NavGraphBuilder +import androidx.navigation.NavOptions import androidx.navigation.compose.NavHost -import androidx.navigation.compose.composable +import androidx.navigation.navigation import com.example.auth.navigation.AuthGraph +import com.example.auth.navigation.AuthGraphDest import com.example.auth.navigation.authNavGraph +import com.example.etc.navigation.etcScreen +import com.example.matching.navigation.MatchingGraph +import com.example.matching.navigation.MatchingGraphDest +import com.example.matching.navigation.matchingNavGraph +import com.example.mypage.navigation.myPageScreen import com.yapp.chaeum.ui.AppState -import com.yapp.chaeum.ui.HomeGraph -import com.yapp.chaeum.ui.HomeRoute +import kotlinx.serialization.Serializable @Composable fun AppNavHost( @@ -16,16 +24,44 @@ fun AppNavHost( modifier: Modifier = Modifier, ) { val navController = appState.navController + NavHost( navController = navController, startDestination = AuthGraph, - modifier = modifier, ) { authNavGraph( - onLoginSuccess = { appState.loginSuccess() }, + onLoginSuccess = { + navController.navigate(HomeGraph) { + popUpTo(AuthGraphDest.AuthRoute) { inclusive = true } + launchSingleTop = true + restoreState = true + } + }, + ) + homeNavGraph( + onNavigateToDetail = { navController.navigate(MatchingGraphDest.MatchingDetailRoute) }, + onBack = { navController.popBackStack() } + ) + } +} + +@Serializable +data object HomeGraph + +// +//fun NavController.navigateToHome(navOptions: NavOptions) = +// navigate(route = HomeGraphDest.MatchingGraph, navOptions) + +fun NavGraphBuilder.homeNavGraph( + onNavigateToDetail: () -> Unit, + onBack: () -> Unit, +) { + navigation(startDestination = MatchingGraph) { + matchingNavGraph( + onNavigateToDetail = onNavigateToDetail, + onBack = onBack, ) - composable { - HomeRoute() - } + myPageScreen() + etcScreen() } } diff --git a/app/src/main/java/com/yapp/chaeum/navigation/HomeNavHost.kt b/app/src/main/java/com/yapp/chaeum/navigation/HomeNavHost.kt deleted file mode 100644 index 97729fa0..00000000 --- a/app/src/main/java/com/yapp/chaeum/navigation/HomeNavHost.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.yapp.chaeum.navigation - -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.navigation.NavHostController -import androidx.navigation.compose.NavHost -import com.example.etc.navigation.etcScreen -import com.example.matching.navigation.MatchingGraph -import com.example.matching.navigation.matchingNavGraph -import com.example.mypage.navigation.myPageScreen - -@Composable -fun HomeNavHost( - navController: NavHostController, - modifier: Modifier = Modifier, -) { - NavHost( - navController = navController, - startDestination = MatchingGraph, - modifier = modifier, - ) { - matchingNavGraph() - myPageScreen() - etcScreen() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/yapp/chaeum/navigation/TopLevelDestinvation.kt b/app/src/main/java/com/yapp/chaeum/navigation/TopLevelDestinvation.kt index 18d5fa81..f3458097 100644 --- a/app/src/main/java/com/yapp/chaeum/navigation/TopLevelDestinvation.kt +++ b/app/src/main/java/com/yapp/chaeum/navigation/TopLevelDestinvation.kt @@ -36,5 +36,9 @@ enum class TopLevelDestination( iconText = "ETC", titleText = "ETC", route = EtcRoute::class, - ), + ); + + companion object { + val topLevelDestinations = entries + } } diff --git a/app/src/main/java/com/yapp/chaeum/ui/App.kt b/app/src/main/java/com/yapp/chaeum/ui/App.kt index 13bc2ee6..5062f7d3 100644 --- a/app/src/main/java/com/yapp/chaeum/ui/App.kt +++ b/app/src/main/java/com/yapp/chaeum/ui/App.kt @@ -1,11 +1,82 @@ package com.yapp.chaeum.ui +import androidx.compose.foundation.layout.navigationBarsPadding +import androidx.compose.foundation.layout.padding +import androidx.compose.material.BottomNavigation +import androidx.compose.material.BottomNavigationItem +import androidx.compose.material.Icon +import androidx.compose.material.Text +import androidx.compose.material3.Scaffold import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.navigation.NavDestination +import androidx.navigation.NavDestination.Companion.hasRoute +import androidx.navigation.NavDestination.Companion.hierarchy +import com.example.auth.navigation.AuthGraph import com.yapp.chaeum.navigation.AppNavHost +import com.yapp.chaeum.navigation.TopLevelDestination +import kotlin.reflect.KClass @Composable -fun App(appState: AppState = rememberAppState()) { - AppNavHost( - appState = appState, - ) +fun App( + appState: AppState = rememberAppState(), + modifier: Modifier = Modifier, +) { + val currentDestination = appState.currentDestination + + Scaffold( + bottomBar = { + if (currentDestination?.isInAuthGraph() == false) { + AppBottomBar(appState, currentDestination) + } + } + ) { innerPadding -> + val contentModifier = modifier.padding(innerPadding) + AppNavHost( + appState = appState, + modifier = contentModifier, + ) + } +} + +@Composable +private fun AppBottomBar( + appState: AppState, + currentDestination: NavDestination? +) { + BottomNavigation( + modifier = Modifier.navigationBarsPadding() + ) { + TopLevelDestination.topLevelDestinations.forEach { topLevelRoute -> + BottomNavigationItem( + icon = { + Icon( + imageVector = topLevelRoute.selectedIcon, + contentDescription = topLevelRoute.name + ) + }, + label = { Text(topLevelRoute.name) }, + selected = currentDestination.isRouteInHierarchy(topLevelRoute.route), + onClick = { + appState.navigateToTopLevelDestination(topLevelRoute) + } + ) + } + } } + +/** + * 현재 목적지가 AuthGraph 인지 확인하는 메서드 + */ +private fun NavDestination?.isInAuthGraph(): Boolean = + this?.hierarchy?.any { destination -> + destination.route == AuthGraph::class.qualifiedName + } ?: false + +/** + * 현재 목적지가 TopLeveLDestination 라우트에 속하는지 확인하는 메서드 + */ +private fun NavDestination?.isRouteInHierarchy(route: KClass<*>): Boolean = + this?.hierarchy?.any { + it.hasRoute(route) + } ?: false \ No newline at end of file diff --git a/app/src/main/java/com/yapp/chaeum/ui/AppState.kt b/app/src/main/java/com/yapp/chaeum/ui/AppState.kt index 3e78c151..5c3e789c 100644 --- a/app/src/main/java/com/yapp/chaeum/ui/AppState.kt +++ b/app/src/main/java/com/yapp/chaeum/ui/AppState.kt @@ -1,10 +1,22 @@ package com.yapp.chaeum.ui +import android.annotation.SuppressLint +import android.util.Log import androidx.compose.runtime.Composable import androidx.compose.runtime.remember +import androidx.navigation.NavDestination +import androidx.navigation.NavDestination.Companion.hierarchy import androidx.navigation.NavGraph.Companion.findStartDestination import androidx.navigation.NavHostController +import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController +import androidx.navigation.navOptions +import com.example.etc.navigation.navigateToEtc +import com.example.matching.navigation.MatchingGraph +import com.example.matching.navigation.navigateToMatching +import com.example.mypage.navigation.navigateToMyPage +import com.yapp.chaeum.navigation.HomeGraph +import com.yapp.chaeum.navigation.TopLevelDestination @Composable fun rememberAppState( @@ -18,12 +30,35 @@ fun rememberAppState( class AppState( val navController: NavHostController, ) { - fun loginSuccess() { - navController.navigate(HomeGraph) { - popUpTo(navController.graph.findStartDestination().id) { - inclusive = true + val currentDestination: NavDestination? + @Composable get() = navController + .currentBackStackEntryAsState().value?.destination + + fun navigateToTopLevelDestination( + topLevelDestination: TopLevelDestination, + ) { + Log.d( + "whatisthis", + "topLevelNavOptions ${navController.graph.findStartDestination().id}, $topLevelDestination" + ) + val topLevelNavOptions = navOptions { + // Pop up to the start destination of the graph to + // avoid building up a large stack of destinations + // on the back stack as users select items + popUpTo(HomeGraph) { + saveState = true } + // Avoid multiple copies of the same destination when + // reselecting the same item launchSingleTop = true + // Restore state when reselecting a previously selected item + restoreState = true + } + + when (topLevelDestination) { + TopLevelDestination.MATCHING -> navController.navigateToMatching(topLevelNavOptions) + TopLevelDestination.MYPAGE -> navController.navigateToMyPage(topLevelNavOptions) + TopLevelDestination.ETC -> navController.navigateToEtc(topLevelNavOptions) } } } \ No newline at end of file diff --git a/app/src/main/java/com/yapp/chaeum/ui/HomeRoute.kt b/app/src/main/java/com/yapp/chaeum/ui/HomeRoute.kt deleted file mode 100644 index 21023d3a..00000000 --- a/app/src/main/java/com/yapp/chaeum/ui/HomeRoute.kt +++ /dev/null @@ -1,65 +0,0 @@ -package com.yapp.chaeum.ui - -import androidx.compose.foundation.layout.navigationBarsPadding -import androidx.compose.foundation.layout.padding -import androidx.compose.material.BottomNavigation -import androidx.compose.material.BottomNavigationItem -import androidx.compose.material.Icon -import androidx.compose.material.Text -import androidx.compose.material3.Scaffold -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.ui.Modifier -import androidx.navigation.NavDestination.Companion.hierarchy -import androidx.navigation.compose.currentBackStackEntryAsState -import com.yapp.chaeum.navigation.HomeNavHost -import com.yapp.chaeum.navigation.TopLevelDestination -import kotlinx.serialization.Serializable - -@Serializable -data object HomeGraph - -@Composable -fun HomeRoute( - homeState: HomeState = rememberHomeState() -) { - Scaffold( - bottomBar = { - HomeBottomBar(homeState) - } - ) { innerPadding -> - HomeNavHost( - navController = homeState.navController, - modifier = Modifier.padding(innerPadding) - ) - } -} - -@Composable -private fun HomeBottomBar( - homeState: HomeState, -) { - val navBackStackEntry by homeState.navController.currentBackStackEntryAsState() - val currentDestination = navBackStackEntry?.destination - BottomNavigation( - modifier = Modifier.navigationBarsPadding() - ) { - TopLevelDestination.entries.forEach { topLevelRoute -> - BottomNavigationItem( - icon = { - Icon( - imageVector = topLevelRoute.selectedIcon, - contentDescription = topLevelRoute.name - ) - }, - label = { Text(topLevelRoute.name) }, - selected = currentDestination?.hierarchy?.any { destination -> - destination.route == topLevelRoute.route.qualifiedName - } == true, - onClick = { - homeState.navigateToTopLevelDestination(topLevelRoute) - } - ) - } - } -} diff --git a/app/src/main/java/com/yapp/chaeum/ui/HomeState.kt b/app/src/main/java/com/yapp/chaeum/ui/HomeState.kt deleted file mode 100644 index 62c41fca..00000000 --- a/app/src/main/java/com/yapp/chaeum/ui/HomeState.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.yapp.chaeum.ui - -import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember -import androidx.navigation.NavGraph.Companion.findStartDestination -import androidx.navigation.NavHostController -import androidx.navigation.compose.rememberNavController -import androidx.navigation.navOptions -import com.example.etc.navigation.navigateToEtc -import com.example.matching.navigation.navigateToMatching -import com.example.mypage.navigation.navigateToMyPage -import com.yapp.chaeum.navigation.TopLevelDestination - -@Composable -fun rememberHomeState( - navController: NavHostController = rememberNavController(), -): HomeState { - return remember(navController) { - HomeState(navController = navController) - } -} - -class HomeState( - val navController: NavHostController, -) { - fun navigateToTopLevelDestination(topLevelDestination: TopLevelDestination) { - val topLevelNavOptions = navOptions { - popUpTo(navController.graph.findStartDestination().id) { - saveState = true - } - launchSingleTop = true - restoreState = true - } - - when (topLevelDestination) { - TopLevelDestination.MATCHING -> navController.navigateToMatching(topLevelNavOptions) - TopLevelDestination.MYPAGE -> navController.navigateToMyPage(topLevelNavOptions) - TopLevelDestination.ETC -> navController.navigateToEtc(topLevelNavOptions) - } - } -} \ No newline at end of file diff --git a/feature/etc/src/main/java/com/example/etc/EtcScreen.kt b/feature/etc/src/main/java/com/example/etc/EtcScreen.kt index 9adbb5b9..4d8ffa60 100644 --- a/feature/etc/src/main/java/com/example/etc/EtcScreen.kt +++ b/feature/etc/src/main/java/com/example/etc/EtcScreen.kt @@ -9,7 +9,9 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.sp @Composable -internal fun EtcRoute() { +fun EtcRoute( + modifier: Modifier = Modifier, +) { Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Text(text = "EtcRoute", fontSize = 30.sp) } diff --git a/feature/etc/src/main/java/com/example/etc/navigation/EtcNavigation.kt b/feature/etc/src/main/java/com/example/etc/navigation/EtcNavigation.kt index 869b8b5c..6158954f 100644 --- a/feature/etc/src/main/java/com/example/etc/navigation/EtcNavigation.kt +++ b/feature/etc/src/main/java/com/example/etc/navigation/EtcNavigation.kt @@ -1,5 +1,6 @@ package com.example.etc.navigation +import androidx.compose.ui.Modifier import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.NavOptions @@ -13,8 +14,8 @@ object EtcRoute fun NavController.navigateToEtc(navOptions: NavOptions) = navigate(route = EtcRoute, navOptions) -fun NavGraphBuilder.etcScreen() { +fun NavGraphBuilder.etcScreen(modifier: Modifier = Modifier) { composable { - EtcRoute() + EtcRoute(modifier) } } diff --git a/feature/matching/src/main/java/com/example/matching/MatchingScreen.kt b/feature/matching/src/main/java/com/example/matching/MatchingScreen.kt index 67da3e7a..9da0d1bd 100644 --- a/feature/matching/src/main/java/com/example/matching/MatchingScreen.kt +++ b/feature/matching/src/main/java/com/example/matching/MatchingScreen.kt @@ -1,5 +1,6 @@ package com.example.matching +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material.Text @@ -9,8 +10,31 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.sp @Composable -internal fun MatchingRoute() { - Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { +fun MatchingDetailRoute( + onBack: () -> Unit, + modifier: Modifier = Modifier, +) { + Box( + modifier = Modifier + .fillMaxSize() + .clickable { onBack() }, + contentAlignment = Alignment.Center + ) { + Text(text = "MatchingDetailRoute", fontSize = 30.sp) + } +} + +@Composable +fun MatchingRoute( + onNavigateToDetail: () -> Unit, + modifier: Modifier = Modifier, +) { + Box( + modifier = Modifier + .fillMaxSize() + .clickable { onNavigateToDetail() }, + contentAlignment = Alignment.Center + ) { Text(text = "MatchingRoute", fontSize = 30.sp) } } diff --git a/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt b/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt index 0c3f111c..d4c62dfe 100644 --- a/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt +++ b/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt @@ -5,6 +5,7 @@ import androidx.navigation.NavGraphBuilder import androidx.navigation.NavOptions import androidx.navigation.compose.composable import androidx.navigation.navigation +import com.example.matching.MatchingDetailRoute import com.example.matching.MatchingRoute import kotlinx.serialization.Serializable @@ -15,15 +16,32 @@ data object MatchingGraph sealed class MatchingGraphDest { @Serializable data object MatchingRoute : MatchingGraphDest() + + @Serializable + data object MatchingDetailRoute : MatchingGraphDest() } fun NavController.navigateToMatching(navOptions: NavOptions) = - navigate(route = MatchingGraphDest.MatchingRoute, navOptions) + navigate(route = MatchingGraph, navOptions) -fun NavGraphBuilder.matchingNavGraph() { - navigation(startDestination = MatchingGraphDest.MatchingRoute) { +fun NavGraphBuilder.matchingNavGraph( + onNavigateToDetail: () -> Unit, + onBack: () -> Unit, +) { + navigation( + startDestination = MatchingGraphDest.MatchingRoute, + ) { + /** 예시 코드, 삭제 예정 */ composable { - MatchingRoute() + MatchingRoute( + onNavigateToDetail = onNavigateToDetail, + ) + } + + composable { + MatchingDetailRoute( + onBack = onBack, + ) } } } \ No newline at end of file diff --git a/feature/mypage/src/main/java/com/example/mypage/MyPageScreen.kt b/feature/mypage/src/main/java/com/example/mypage/MyPageScreen.kt index 4ae84a5b..992ea3c6 100644 --- a/feature/mypage/src/main/java/com/example/mypage/MyPageScreen.kt +++ b/feature/mypage/src/main/java/com/example/mypage/MyPageScreen.kt @@ -9,7 +9,9 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.sp @Composable -internal fun MyPageRoute() { +fun MyPageRoute( + modifier: Modifier = Modifier, +) { Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Text(text = "MyPageRoute", fontSize = 30.sp) } diff --git a/feature/mypage/src/main/java/com/example/mypage/navigation/MyPageNavigation.kt b/feature/mypage/src/main/java/com/example/mypage/navigation/MyPageNavigation.kt index bafa27f5..42c6779c 100644 --- a/feature/mypage/src/main/java/com/example/mypage/navigation/MyPageNavigation.kt +++ b/feature/mypage/src/main/java/com/example/mypage/navigation/MyPageNavigation.kt @@ -1,5 +1,6 @@ package com.example.mypage.navigation +import androidx.compose.ui.Modifier import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.NavOptions @@ -13,8 +14,8 @@ object MyPageRoute fun NavController.navigateToMyPage(navOptions: NavOptions) = navigate(route = MyPageRoute, navOptions) -fun NavGraphBuilder.myPageScreen() { +fun NavGraphBuilder.myPageScreen(modifier: Modifier = Modifier) { composable { - MyPageRoute() + MyPageRoute(modifier) } } From 2edb6a7bc93f56f18d4be26053da300e6066dd2b Mon Sep 17 00:00:00 2001 From: sksowk156 Date: Sat, 14 Dec 2024 14:21:50 +0900 Subject: [PATCH 6/7] =?UTF-8?q?#3=20-=20=EC=A4=84=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yapp/chaeum/navigation/AppNavHost.kt | 47 +++---------------- .../chaeum/navigation/home/HomeNavigation.kt | 29 ++++++++++++ .../main/java/com/yapp/chaeum/ui/AppState.kt | 32 ++++++------- .../com/yapp/build/logic/KotlinAndroid.kt | 1 - .../main/java/com/example/etc/EtcScreen.kt | 2 +- .../com/example/matching/MatchingScreen.kt | 17 +------ .../matching/detail/MatchingDetailRoute.kt | 25 ++++++++++ .../matching/navigation/MatchingNavigation.kt | 11 ++++- .../java/com/example/mypage/MyPageScreen.kt | 2 +- 9 files changed, 86 insertions(+), 80 deletions(-) create mode 100644 app/src/main/java/com/yapp/chaeum/navigation/home/HomeNavigation.kt create mode 100644 feature/matching/src/main/java/com/example/matching/detail/MatchingDetailRoute.kt diff --git a/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt b/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt index 586d8c6b..55372587 100644 --- a/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt +++ b/app/src/main/java/com/yapp/chaeum/navigation/AppNavHost.kt @@ -2,21 +2,12 @@ package com.yapp.chaeum.navigation import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.navigation.NavController -import androidx.navigation.NavGraphBuilder -import androidx.navigation.NavOptions import androidx.navigation.compose.NavHost -import androidx.navigation.navigation import com.example.auth.navigation.AuthGraph -import com.example.auth.navigation.AuthGraphDest import com.example.auth.navigation.authNavGraph -import com.example.etc.navigation.etcScreen -import com.example.matching.navigation.MatchingGraph -import com.example.matching.navigation.MatchingGraphDest -import com.example.matching.navigation.matchingNavGraph -import com.example.mypage.navigation.myPageScreen +import com.example.matching.navigation.navigateToMatchingDetailRoute +import com.yapp.chaeum.navigation.home.homeNavGraph import com.yapp.chaeum.ui.AppState -import kotlinx.serialization.Serializable @Composable fun AppNavHost( @@ -30,38 +21,12 @@ fun AppNavHost( startDestination = AuthGraph, ) { authNavGraph( - onLoginSuccess = { - navController.navigate(HomeGraph) { - popUpTo(AuthGraphDest.AuthRoute) { inclusive = true } - launchSingleTop = true - restoreState = true - } - }, + onLoginSuccess = appState::navigateToHome, ) homeNavGraph( - onNavigateToDetail = { navController.navigate(MatchingGraphDest.MatchingDetailRoute) }, - onBack = { navController.popBackStack() } + onNavigateToDetail = navController::navigateToMatchingDetailRoute, + onBack = navController::popBackStack, + modifier = modifier, ) } } - -@Serializable -data object HomeGraph - -// -//fun NavController.navigateToHome(navOptions: NavOptions) = -// navigate(route = HomeGraphDest.MatchingGraph, navOptions) - -fun NavGraphBuilder.homeNavGraph( - onNavigateToDetail: () -> Unit, - onBack: () -> Unit, -) { - navigation(startDestination = MatchingGraph) { - matchingNavGraph( - onNavigateToDetail = onNavigateToDetail, - onBack = onBack, - ) - myPageScreen() - etcScreen() - } -} diff --git a/app/src/main/java/com/yapp/chaeum/navigation/home/HomeNavigation.kt b/app/src/main/java/com/yapp/chaeum/navigation/home/HomeNavigation.kt new file mode 100644 index 00000000..2d03f608 --- /dev/null +++ b/app/src/main/java/com/yapp/chaeum/navigation/home/HomeNavigation.kt @@ -0,0 +1,29 @@ +package com.yapp.chaeum.navigation.home + +import androidx.compose.ui.Modifier +import androidx.navigation.NavGraphBuilder +import androidx.navigation.navigation +import com.example.etc.navigation.etcScreen +import com.example.matching.navigation.MatchingGraph +import com.example.matching.navigation.matchingNavGraph +import com.example.mypage.navigation.myPageScreen +import kotlinx.serialization.Serializable + +@Serializable +data object HomeGraph + +fun NavGraphBuilder.homeNavGraph( + onNavigateToDetail: () -> Unit, + onBack: () -> Unit, + modifier: Modifier = Modifier, +) { + navigation(startDestination = MatchingGraph) { + matchingNavGraph( + onNavigateToDetail = onNavigateToDetail, + onBack = onBack, + modifier = modifier, + ) + myPageScreen(modifier) + etcScreen(modifier) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/yapp/chaeum/ui/AppState.kt b/app/src/main/java/com/yapp/chaeum/ui/AppState.kt index 5c3e789c..c60d484a 100644 --- a/app/src/main/java/com/yapp/chaeum/ui/AppState.kt +++ b/app/src/main/java/com/yapp/chaeum/ui/AppState.kt @@ -1,22 +1,18 @@ package com.yapp.chaeum.ui -import android.annotation.SuppressLint -import android.util.Log import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.navigation.NavDestination -import androidx.navigation.NavDestination.Companion.hierarchy -import androidx.navigation.NavGraph.Companion.findStartDestination import androidx.navigation.NavHostController import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import androidx.navigation.navOptions +import com.example.auth.navigation.AuthGraphDest import com.example.etc.navigation.navigateToEtc -import com.example.matching.navigation.MatchingGraph -import com.example.matching.navigation.navigateToMatching +import com.example.matching.navigation.navigateToMatchingGraph import com.example.mypage.navigation.navigateToMyPage -import com.yapp.chaeum.navigation.HomeGraph import com.yapp.chaeum.navigation.TopLevelDestination +import com.yapp.chaeum.navigation.home.HomeGraph @Composable fun rememberAppState( @@ -34,29 +30,29 @@ class AppState( @Composable get() = navController .currentBackStackEntryAsState().value?.destination + fun navigateToHome() { + navController.navigate(HomeGraph) { + popUpTo(AuthGraphDest.AuthRoute) { + inclusive = true + } + launchSingleTop = true + restoreState = true + } + } + fun navigateToTopLevelDestination( topLevelDestination: TopLevelDestination, ) { - Log.d( - "whatisthis", - "topLevelNavOptions ${navController.graph.findStartDestination().id}, $topLevelDestination" - ) val topLevelNavOptions = navOptions { - // Pop up to the start destination of the graph to - // avoid building up a large stack of destinations - // on the back stack as users select items popUpTo(HomeGraph) { saveState = true } - // Avoid multiple copies of the same destination when - // reselecting the same item launchSingleTop = true - // Restore state when reselecting a previously selected item restoreState = true } when (topLevelDestination) { - TopLevelDestination.MATCHING -> navController.navigateToMatching(topLevelNavOptions) + TopLevelDestination.MATCHING -> navController.navigateToMatchingGraph(topLevelNavOptions) TopLevelDestination.MYPAGE -> navController.navigateToMyPage(topLevelNavOptions) TopLevelDestination.ETC -> navController.navigateToEtc(topLevelNavOptions) } diff --git a/build-logic/src/main/java/com/yapp/build/logic/KotlinAndroid.kt b/build-logic/src/main/java/com/yapp/build/logic/KotlinAndroid.kt index afdf4a9e..8330dca4 100644 --- a/build-logic/src/main/java/com/yapp/build/logic/KotlinAndroid.kt +++ b/build-logic/src/main/java/com/yapp/build/logic/KotlinAndroid.kt @@ -2,7 +2,6 @@ package com.yapp.build.logic import org.gradle.api.JavaVersion import org.gradle.api.Project -import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.provideDelegate import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.JvmTarget diff --git a/feature/etc/src/main/java/com/example/etc/EtcScreen.kt b/feature/etc/src/main/java/com/example/etc/EtcScreen.kt index 4d8ffa60..118a1f38 100644 --- a/feature/etc/src/main/java/com/example/etc/EtcScreen.kt +++ b/feature/etc/src/main/java/com/example/etc/EtcScreen.kt @@ -12,7 +12,7 @@ import androidx.compose.ui.unit.sp fun EtcRoute( modifier: Modifier = Modifier, ) { - Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + Box(modifier = modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Text(text = "EtcRoute", fontSize = 30.sp) } } diff --git a/feature/matching/src/main/java/com/example/matching/MatchingScreen.kt b/feature/matching/src/main/java/com/example/matching/MatchingScreen.kt index 9da0d1bd..cf401d77 100644 --- a/feature/matching/src/main/java/com/example/matching/MatchingScreen.kt +++ b/feature/matching/src/main/java/com/example/matching/MatchingScreen.kt @@ -9,28 +9,13 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.sp -@Composable -fun MatchingDetailRoute( - onBack: () -> Unit, - modifier: Modifier = Modifier, -) { - Box( - modifier = Modifier - .fillMaxSize() - .clickable { onBack() }, - contentAlignment = Alignment.Center - ) { - Text(text = "MatchingDetailRoute", fontSize = 30.sp) - } -} - @Composable fun MatchingRoute( onNavigateToDetail: () -> Unit, modifier: Modifier = Modifier, ) { Box( - modifier = Modifier + modifier = modifier .fillMaxSize() .clickable { onNavigateToDetail() }, contentAlignment = Alignment.Center diff --git a/feature/matching/src/main/java/com/example/matching/detail/MatchingDetailRoute.kt b/feature/matching/src/main/java/com/example/matching/detail/MatchingDetailRoute.kt new file mode 100644 index 00000000..300e1cd0 --- /dev/null +++ b/feature/matching/src/main/java/com/example/matching/detail/MatchingDetailRoute.kt @@ -0,0 +1,25 @@ +package com.example.matching.detail + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.sp + +@Composable +fun MatchingDetailRoute( + onBack: () -> Unit, + modifier: Modifier = Modifier, +) { + Box( + modifier = modifier + .fillMaxSize() + .clickable { onBack() }, + contentAlignment = Alignment.Center + ) { + Text(text = "MatchingDetailRoute", fontSize = 30.sp) + } +} \ No newline at end of file diff --git a/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt b/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt index d4c62dfe..ab873755 100644 --- a/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt +++ b/feature/matching/src/main/java/com/example/matching/navigation/MatchingNavigation.kt @@ -1,12 +1,13 @@ package com.example.matching.navigation +import androidx.compose.ui.Modifier import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.NavOptions import androidx.navigation.compose.composable import androidx.navigation.navigation -import com.example.matching.MatchingDetailRoute import com.example.matching.MatchingRoute +import com.example.matching.detail.MatchingDetailRoute import kotlinx.serialization.Serializable @@ -21,12 +22,16 @@ sealed class MatchingGraphDest { data object MatchingDetailRoute : MatchingGraphDest() } -fun NavController.navigateToMatching(navOptions: NavOptions) = +fun NavController.navigateToMatchingGraph(navOptions: NavOptions) = navigate(route = MatchingGraph, navOptions) +fun NavController.navigateToMatchingDetailRoute() = + navigate(MatchingGraphDest.MatchingDetailRoute) + fun NavGraphBuilder.matchingNavGraph( onNavigateToDetail: () -> Unit, onBack: () -> Unit, + modifier: Modifier = Modifier, ) { navigation( startDestination = MatchingGraphDest.MatchingRoute, @@ -35,12 +40,14 @@ fun NavGraphBuilder.matchingNavGraph( composable { MatchingRoute( onNavigateToDetail = onNavigateToDetail, + modifier = modifier, ) } composable { MatchingDetailRoute( onBack = onBack, + modifier = modifier, ) } } diff --git a/feature/mypage/src/main/java/com/example/mypage/MyPageScreen.kt b/feature/mypage/src/main/java/com/example/mypage/MyPageScreen.kt index 992ea3c6..aedb5a9f 100644 --- a/feature/mypage/src/main/java/com/example/mypage/MyPageScreen.kt +++ b/feature/mypage/src/main/java/com/example/mypage/MyPageScreen.kt @@ -12,7 +12,7 @@ import androidx.compose.ui.unit.sp fun MyPageRoute( modifier: Modifier = Modifier, ) { - Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + Box(modifier = modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Text(text = "MyPageRoute", fontSize = 30.sp) } } From ed77c4b1c9036bfc00c72532ce1ed3a4ba79ff6b Mon Sep 17 00:00:00 2001 From: sksowk156 Date: Sat, 14 Dec 2024 14:48:58 +0900 Subject: [PATCH 7/7] =?UTF-8?q?#3=20-=20feature=20gradle=EC=97=90=20implem?= =?UTF-8?q?etation=20(plugins=EB=8A=94=20=EB=AA=BB=ED=95=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 1 - .../com/yapp/build/logic/chaeum.android.feature.gradle.kts | 2 ++ feature/auth/build.gradle.kts | 7 +------ feature/etc/build.gradle.kts | 7 +------ feature/matching/build.gradle.kts | 7 +------ feature/mypage/build.gradle.kts | 7 +------ 6 files changed, 6 insertions(+), 25 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 70859d18..83904e98 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,7 +1,6 @@ plugins { id("chaeum.android.application") id("chaeum.android.compose") - alias(libs.plugins.androidx.navigation.safeargs) alias(libs.plugins.kotlin.serialization) } diff --git a/build-logic/src/main/java/com/yapp/build/logic/chaeum.android.feature.gradle.kts b/build-logic/src/main/java/com/yapp/build/logic/chaeum.android.feature.gradle.kts index ac8cdd5a..ac679704 100644 --- a/build-logic/src/main/java/com/yapp/build/logic/chaeum.android.feature.gradle.kts +++ b/build-logic/src/main/java/com/yapp/build/logic/chaeum.android.feature.gradle.kts @@ -4,6 +4,7 @@ import com.yapp.build.logic.libs plugins { id("chaeum.android.library") id("chaeum.android.compose") +// id("org.jetbrains.kotlin.plugin.serialization") } android { @@ -22,6 +23,7 @@ dependencies { // implementation(project(":core:common-ui")) val libs = project.extensions.libs + implementation(libs.findLibrary("kotlinx.serialization.json").get()) implementation(libs.findLibrary("androidx.compose.navigation").get()) implementation(libs.findLibrary("androidx.lifecycle.viewModelCompose").get()) implementation(libs.findLibrary("androidx.lifecycle.runtimeCompose").get()) diff --git a/feature/auth/build.gradle.kts b/feature/auth/build.gradle.kts index 4be47caa..7f0b1ff3 100644 --- a/feature/auth/build.gradle.kts +++ b/feature/auth/build.gradle.kts @@ -1,13 +1,8 @@ plugins { id("chaeum.android.feature") - alias(libs.plugins.androidx.navigation.safeargs) alias(libs.plugins.kotlin.serialization) } android { - namespace = "com.example.auth" -} - -dependencies { - implementation(libs.kotlinx.serialization.json) + namespace = "com.chaeum.auth" } \ No newline at end of file diff --git a/feature/etc/build.gradle.kts b/feature/etc/build.gradle.kts index ac13d89b..a025060a 100644 --- a/feature/etc/build.gradle.kts +++ b/feature/etc/build.gradle.kts @@ -1,13 +1,8 @@ plugins { id("chaeum.android.feature") - alias(libs.plugins.androidx.navigation.safeargs) alias(libs.plugins.kotlin.serialization) } android { - namespace = "com.example.etc" -} - -dependencies { - implementation(libs.kotlinx.serialization.json) + namespace = "com.chaeum.etc" } \ No newline at end of file diff --git a/feature/matching/build.gradle.kts b/feature/matching/build.gradle.kts index 6455b83b..f149b982 100644 --- a/feature/matching/build.gradle.kts +++ b/feature/matching/build.gradle.kts @@ -1,13 +1,8 @@ plugins { id("chaeum.android.feature") - alias(libs.plugins.androidx.navigation.safeargs) alias(libs.plugins.kotlin.serialization) } android { - namespace = "com.example.matching" -} - -dependencies { - implementation(libs.kotlinx.serialization.json) + namespace = "com.chaeum.matching" } \ No newline at end of file diff --git a/feature/mypage/build.gradle.kts b/feature/mypage/build.gradle.kts index 0faa29fe..60e7176f 100644 --- a/feature/mypage/build.gradle.kts +++ b/feature/mypage/build.gradle.kts @@ -1,13 +1,8 @@ plugins { id("chaeum.android.feature") - alias(libs.plugins.androidx.navigation.safeargs) alias(libs.plugins.kotlin.serialization) } android { - namespace = "com.example.mypage" -} - -dependencies { - implementation(libs.kotlinx.serialization.json) + namespace = "com.chaeum.mypage" } \ No newline at end of file