Skip to content

Commit

Permalink
Issues boostcampwm-2022#287 feat: SAA 구조로 변경 app 모듈에 MainActivity 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
audxo112 committed Feb 27, 2023
1 parent eca278a commit be61838
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ dependencies {
implementation(projects.uiHome)
implementation(projects.uiSetting)

implementation(libs.androidX.core.splashscreen)

implementation(libs.androidX.hilt.work)
implementation(libs.androidX.work.runtime.ktx)

implementation(libs.androidX.navigation.ui.ktx)
implementation(libs.androidX.navigation.fragment.ktx)

implementation(libs.timber)
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,17 @@
android:supportsRtl="true"
android:theme="@style/Theme.BEEP"
tools:targetApi="31">

<activity
android:name="com.lighthouse.ui.MainActivity"
android:exported="true"
android:noHistory="true"
android:theme="@style/Theme.BEEP.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
40 changes: 40 additions & 0 deletions app/src/main/java/com/lighthouse/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.lighthouse.ui

import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.databinding.DataBindingUtil
import androidx.navigation.findNavController
import com.lighthouse.beep.R
import com.lighthouse.beep.databinding.ActivityMainBinding
import com.lighthouse.features.common.ext.repeatOnStarted
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding

private val viewModel: MainViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
setUpIsLogin()
}

private fun setUpIsLogin() {
val navController = findNavController(R.id.fcv)
repeatOnStarted {
viewModel.isLogin().collect { isLogin ->
if (isLogin) {
// navController.navigate()
} else {
// navController.navigate()
}
}
}
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/com/lighthouse/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.lighthouse.ui

import androidx.lifecycle.ViewModel
import com.lighthouse.domain.usecase.user.IsLoginUserUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class MainViewModel @Inject constructor(
private val isLoginUserUseCase: IsLoginUserUseCase
) : ViewModel() {

fun isLogin() = isLoginUserUseCase()
}
22 changes: 22 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="vm"
type="com.lighthouse.features.main.ui.MainViewModel" />
</data>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fcv"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/bnv"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</layout>
6 changes: 6 additions & 0 deletions app/src/main/res/navigation/main_graph.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_graph">

</navigation>
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import com.lighthouse.beep.model.auth.EncryptData
import com.lighthouse.beep.model.user.SecurityOption
import com.lighthouse.domain.repository.user.UserRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import javax.inject.Inject

internal class UserRepositoryImpl @Inject constructor(
private val userPreferenceRepository: UserPreferenceRepository
) : UserRepository {

override suspend fun isLogin(): Boolean {
val loginUserUid = userPreferenceRepository.getLoginUserUid().first()
.getOrDefault("")
return loginUserUid != ""
override fun isLogin(): Flow<Boolean> {
return userPreferenceRepository.getLoginUserUid().map {
it.getOrDefault("") != ""
}
}

override suspend fun login(userId: String): Result<Unit> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlinx.coroutines.flow.Flow

interface UserRepository {

suspend fun isLogin(): Boolean
fun isLogin(): Flow<Boolean>
suspend fun login(userId: String): Result<Unit>

suspend fun setPinPassword(userId: String, encryptData: EncryptData): Result<Unit>
Expand Down

0 comments on commit be61838

Please sign in to comment.