Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOP-87 featurne core:navigation 모듈 구현 #111

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ android {
}

dependencies {
implementation(project(":core:navigation"))
implementation(project(":core:ui"))
implementation(project(":domain"))
implementation(project(":data"))
Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/com/tht/tht/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.lifecycle.repeatOnLifecycle
import com.tht.tht.databinding.ActivityHomeBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import tht.core.navigation.ToHotNavigation
import tht.core.ui.base.BaseActivity
import tht.core.ui.base.FragmentNavigator
import tht.core.ui.delegate.viewBinding
Expand All @@ -20,6 +21,7 @@ import tht.feature.chat.ChatFragment
import tht.feature.heart.HeartFragment
import tht.feature.setting.MyFragment
import tht.feature.tohot.tohot.fragment.ToHotFragment
import javax.inject.Inject

@SuppressLint("CommitTransaction")
@AndroidEntryPoint
Expand All @@ -28,6 +30,9 @@ class HomeActivity : BaseActivity<HomeViewModel, ActivityHomeBinding>(), Fragmen
override val vm by viewModels<HomeViewModel>()
override val binding by viewBinding(ActivityHomeBinding::inflate)

@Inject
lateinit var toHotNavigation: ToHotNavigation

override fun initViews() {
initNavigationBar()
}
Expand All @@ -42,7 +47,10 @@ class HomeActivity : BaseActivity<HomeViewModel, ActivityHomeBinding>(), Fragmen
binding.bnvHome.setOnItemSelectedListener { item ->
when (item.itemId) {
R.id.menu_tohot -> {
showFragment(ToHotFragment.TAG)
toHotNavigation.navigateToHot(
supportFragmentManager,
R.id.fragment_container
)
true
}
R.id.menu_heart -> {
Expand Down
28 changes: 11 additions & 17 deletions app/src/main/java/com/tht/tht/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ package com.tht.tht
import android.animation.Animator
import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import com.tht.tht.databinding.ActivitySplashBinding
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import tht.core.navigation.SignupNavigation
import tht.core.ui.delegate.viewBinding
import tht.feature.signin.prelogin.PreloginActivity
import javax.inject.Inject

@SuppressLint("CustomSplashScreen")
@AndroidEntryPoint
Expand All @@ -22,6 +21,12 @@ class SplashActivity : AppCompatActivity() {
private val viewModel: SplashViewModel by viewModels()
private val binding: ActivitySplashBinding by viewBinding(ActivitySplashBinding::inflate)

@Inject
lateinit var signupNavigation: SignupNavigation

@Inject
lateinit var homeNavigation: SignupNavigation

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)
Expand All @@ -46,27 +51,16 @@ class SplashActivity : AppCompatActivity() {
}

private fun observeViewModel() {
val signupResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
binding.lottieView.isVisible = false
when (it.resultCode) {
RESULT_OK -> viewModel.signupSuccessEvent()
else -> viewModel.signupCancelEvent()
}
}

lifecycleScope.launch {
viewModel.sideEffect.collect {
when (it) {
is SplashSideEffect.Signup -> {
signupResult.launch(PreloginActivity.getIntent(this@SplashActivity))
}

is SplashSideEffect.Home -> {
startActivity(HomeActivity.newIntent(this@SplashActivity))
signupNavigation.navigatePreLogin(this@SplashActivity)
finish()
}

is SplashSideEffect.Cancel -> {
is SplashSideEffect.Home -> {
homeNavigation.navigatePreLogin(this@SplashActivity)
finish()
}
}
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/com/tht/tht/SplashViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ class SplashViewModel @Inject constructor(
checkAutoLogin()
}

fun signupSuccessEvent() {
checkAutoLogin()
}

private fun checkAutoLogin() {
viewModelScope.launch {
fetchThtTokenUseCase()
Expand All @@ -36,16 +32,9 @@ class SplashViewModel @Inject constructor(
}
}
}

fun signupCancelEvent() {
viewModelScope.launch {
_sideEffect.emit(SplashSideEffect.Cancel)
}
}
}

sealed class SplashSideEffect {
object Signup : SplashSideEffect()
object Home : SplashSideEffect()
object Cancel : SplashSideEffect()
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/tht/tht/navigation/HomeNavigationImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.tht.tht.navigation

import android.content.Context
import com.tht.tht.HomeActivity
import tht.core.navigation.HomeNavigation
import javax.inject.Inject

class HomeNavigationImpl @Inject constructor() : HomeNavigation {

override fun navigateHome(context: Context) {
context.startActivity(HomeActivity.newIntent(context))
}
}
25 changes: 25 additions & 0 deletions app/src/main/java/com/tht/tht/navigation/NavigationModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.tht.tht.navigation

import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import tht.core.navigation.HomeNavigation
import tht.core.navigation.SignupNavigation
import tht.core.navigation.ToHotNavigation
import tht.feature.signin.navigation.SignupNavigationImpl
import tht.feature.tohot.navigation.ToHotNavigationImpl

@Module
@InstallIn(SingletonComponent::class)
abstract class NavigationModule {

@Binds
abstract fun bindHomeNavigation(impl: HomeNavigationImpl): HomeNavigation

@Binds
abstract fun bindSignupNavigation(impl: SignupNavigationImpl): SignupNavigation

@Binds
abstract fun bindToHotNavigation(impl: ToHotNavigationImpl): ToHotNavigation
}
4 changes: 2 additions & 2 deletions core/compose-ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ plugins {

android {
namespace = "com.example.compose_ui"
compileSdk = 33
compileSdk = rootProject.ext.get("compileSdk") as Int

defaultConfig {
minSdk = 24
minSdk = rootProject.ext.get("minSdkVersion") as Int

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
1 change: 1 addition & 0 deletions core/navigation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
39 changes: 39 additions & 0 deletions core/navigation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}

android {
namespace = "tht.core.navigation"
compileSdk = rootProject.ext.get("compileSdk") as Int

defaultConfig {
minSdk = rootProject.ext.get("minSdkVersion") as Int

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_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.8.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}
Empty file.
21 changes: 21 additions & 0 deletions core/navigation/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package tht.core.navigation

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("tht.core.navigation.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions core/navigation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package tht.core.navigation

import android.content.Context

interface HomeNavigation {
fun navigateHome(context: Context)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package tht.core.navigation

import android.content.Context

interface SignupNavigation {
fun navigatePreLogin(context: Context)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package tht.core.navigation

import androidx.fragment.app.FragmentManager

interface ToHotNavigation {
fun navigateToHot(
fragmentManager: FragmentManager,
fragmentContainerResourceId: Int
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tht.core.navigation

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)
}
}
1 change: 1 addition & 0 deletions feature/chat/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ android {
}

dependencies {
implementation(project(":core:navigation"))
implementation(project(":core:ui"))
implementation(project(":core:compose-ui"))
implementation(project(":domain"))
Expand Down
1 change: 1 addition & 0 deletions feature/heart/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ android {
}

dependencies {
implementation(project(":core:navigation"))
implementation(project(":core:ui"))
implementation(project(":domain"))

Expand Down
1 change: 1 addition & 0 deletions feature/setting/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ android {
}

dependencies {
implementation(project(":core:navigation"))
implementation(project(":core:ui"))
implementation(project(":domain"))

Expand Down
1 change: 1 addition & 0 deletions feature/signin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ android {
}

dependencies {
implementation(project(":core:navigation"))
implementation(project(":core:ui"))
implementation(project(":domain"))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package tht.feature.signin.navigation

import android.content.Context
import tht.core.navigation.SignupNavigation
import tht.feature.signin.prelogin.PreloginActivity
import javax.inject.Inject

class SignupNavigationImpl @Inject constructor() : SignupNavigation {
override fun navigatePreLogin(context: Context) {
context.startActivity(PreloginActivity.getIntent(context))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package tht.feature.signin.prelogin

import android.content.Context
import android.content.Intent
import android.util.Log
import androidx.activity.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
Expand Down Expand Up @@ -30,13 +29,6 @@ class PreloginActivity : BaseStateActivity<PreloginViewModel, ActivityPreloginBi

override val binding by viewBinding(ActivityPreloginBinding::inflate)

override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
Log.d("TAG", "onNewIntent PreLoginActivity")
setResult(RESULT_OK)
finish()
}

override fun initViews() = with(binding) {
btnKakaoLogin.setOnClickListener {
vm.requestKakaoLogin()
Expand Down
Loading