Skip to content

Commit

Permalink
Issues boostcampwm-2022#287 feat: SettingList 갱신 깜박임 문제 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
audxo112 committed Mar 1, 2023
1 parent 29b68d5 commit 066164a
Show file tree
Hide file tree
Showing 24 changed files with 237 additions and 124 deletions.
41 changes: 27 additions & 14 deletions app/src/main/java/com/lighthouse/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.lighthouse.beep.R
import com.lighthouse.beep.databinding.ActivityMainBinding
import com.lighthouse.features.common.ext.repeatOnStarted
import com.lighthouse.features.common.model.NavigationItem
import com.lighthouse.features.common.navigator.NavigationViewModel
import com.lighthouse.features.common.navigator.AppNavigationViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand All @@ -21,7 +21,7 @@ class MainActivity : AppCompatActivity() {

private val viewModel: MainViewModel by viewModels()

private val navigationViewModel: NavigationViewModel by viewModels()
private val appNavigationViewModel: AppNavigationViewModel by viewModels()

private lateinit var navController: NavController

Expand All @@ -43,15 +43,28 @@ class MainActivity : AppCompatActivity() {

private fun setUpNavigation() {
repeatOnStarted {
navigationViewModel.navigation.collect { item ->
appNavigationViewModel.navigation.collect { item ->
when (item) {
NavigationItem.Popup -> navController.popBackStack()
NavigationItem.UsedGifticon -> navController.navigate(R.id.used_gifticon_nav_graph)
NavigationItem.Security -> navController.navigate(R.id.security_nav_graph)
NavigationItem.Coffee -> navController.navigate(R.id.coffee_nav_graph)
NavigationItem.TermsOfUse -> navController.navigate(R.id.terms_of_use_nav_graph)
NavigationItem.PersonalInfoPolicy -> navController.navigate(R.id.personal_info_policy_nav_graph)
NavigationItem.OpensourceLicense -> navController.navigate(R.id.open_source_license_nav_graph)
NavigationItem.Popup ->
navController.popBackStack()

NavigationItem.UsedGifticon ->
navController.navigate(R.id.used_gifticon_nav_graph)

NavigationItem.Security ->
navController.navigate(R.id.security_nav_graph)

NavigationItem.Coffee ->
navController.navigate(R.id.coffee_nav_graph)

NavigationItem.TermsOfUse ->
navController.navigate(R.id.terms_of_use_nav_graph)

NavigationItem.PersonalInfoPolicy ->
navController.navigate(R.id.personal_info_policy_nav_graph)

NavigationItem.OpensourceLicense ->
navController.navigate(R.id.open_source_license_nav_graph)
}
}
}
Expand All @@ -60,10 +73,10 @@ class MainActivity : AppCompatActivity() {
private fun setUpIsLogin() {
repeatOnStarted {
viewModel.isLogin().collect { isLogin ->
if (isLogin) {
navController.navigate(R.id.action_global_main_graph)
} else {
navController.navigate(R.id.action_global_intro_graph)
when (isLogin) {
true -> navController.navigate(R.id.action_global_main_graph)
false -> navController.navigate(R.id.action_global_intro_graph)
else -> Unit
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/lighthouse/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.lighthouse.ui

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.lighthouse.domain.usecase.user.IsLoginUserUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject

@HiltViewModel
Expand All @@ -11,4 +14,5 @@ internal class MainViewModel @Inject constructor(
) : ViewModel() {

fun isLogin() = isLoginUserUseCase()
.stateIn(viewModelScope, SharingStarted.Eagerly, null)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ import javax.inject.Inject

internal class AuthRepositoryImpl @Inject constructor() : AuthRepository {

private val isGuestFlow = callbackFlow {
override fun isGuest(): Flow<Boolean> = callbackFlow {
val authStateListener = AuthStateListener {
trySend(it.currentUser == null)
}

Firebase.auth.addAuthStateListener(authStateListener)
awaitClose {
Firebase.auth.removeAuthStateListener(authStateListener)
}
}

override fun isGuest(): Flow<Boolean> {
return isGuestFlow
}

override fun getCurrentUserId(): String {
return Firebase.auth.currentUser?.uid ?: GUEST_ID
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ sealed class UIText(
}

override fun hashCode(): Int {
var result = resId.hashCode()
result = 31 * result + args.contentHashCode()
return result
return 31 * resId.hashCode() + args.contentHashCode()
}
}

Expand Down Expand Up @@ -82,9 +80,7 @@ sealed class UIText(
}

override fun hashCode(): Int {
var result = text.hashCode()
result = 31 * result + spans.contentHashCode()
return result
return 31 * text.hashCode() + spans.contentHashCode()
}
}

Expand Down
5 changes: 5 additions & 0 deletions features/ui-coffee/src/main/res/layout/fragment_coffee.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="개발자에게 커피 사주기"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class NavigationViewModel @Inject constructor() : ViewModel() {
class AppNavigationViewModel @Inject constructor() : ViewModel() {

private val _navigation = MutableEventFlow<NavigationItem>()
val navigation = _navigation.asEventFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import com.lighthouse.core.android.utils.permission.core.permissions
import com.lighthouse.features.common.binding.viewBindings
import com.lighthouse.features.main.R
import com.lighthouse.features.main.databinding.FragmentMainContainerBinding
import com.lighthouse.features.main.navigator.MainNav
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class MainContainerFragment : Fragment(R.layout.fragment_main_container) {
Expand All @@ -24,17 +22,15 @@ class MainContainerFragment : Fragment(R.layout.fragment_main_container) {

private val storagePermission: StoragePermissionManager by permissions()

@Inject
lateinit var nav: MainNav

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

setUpBottomNavigation()
}

private fun setUpBottomNavigation() {
val navHostFragment = childFragmentManager.findFragmentById(R.id.fcv_main) as NavHostFragment
val navHostFragment =
childFragmentManager.findFragmentById(R.id.fcv_main) as NavHostFragment
val navController = navHostFragment.navController
binding.bnv.setupWithNavController(navController)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="오픈소스라이센스"/>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="개인정보방침"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="보안설정"/>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
2 changes: 1 addition & 1 deletion features/ui-setting/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {
implementation(projects.domain)
implementation(projects.common)
implementation(projects.commonAndroid)
implementation(projects.auth)
implementation(projects.authGoogle)
implementation(projects.uiCommon)

implementation(libs.androidX.core.ktx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,27 @@ import com.lighthouse.features.setting.model.SettingItem
internal class SettingItemDiff : DiffUtil.ItemCallback<SettingItem>() {

override fun areItemsTheSame(oldItem: SettingItem, newItem: SettingItem): Boolean {
return oldItem === newItem
if (oldItem == newItem) return true
if (oldItem is SettingItem.Button &&
newItem is SettingItem.Button &&
oldItem.menu == newItem.menu
) {
return true
} else if (
oldItem is SettingItem.StateButton &&
newItem is SettingItem.StateButton &&
oldItem.menu == newItem.menu
) {
return true
} else if (
oldItem is SettingItem.StateSwitch &&
newItem is SettingItem.StateSwitch &&
oldItem.menu == newItem.menu
) {
return true
}

return false
}

override fun areContentsTheSame(oldItem: SettingItem, newItem: SettingItem): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ import com.lighthouse.core.android.utils.resource.UIText

internal class SettingGroup(val title: UIText?, val items: List<SettingItem>) {

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is SettingGroup) return false

return title == other.title && items == other.items
}

override fun hashCode(): Int {
return 31 * title.hashCode() + items.hashCode()
}

class Builder {
private var title: UIText? = null
private val items = ArrayList<SettingItem>()
Expand Down Expand Up @@ -32,4 +43,8 @@ internal class SettingGroup(val title: UIText?, val items: List<SettingItem>) {
return SettingGroup(title, items.toList())
}
}

companion object {
val Empty = SettingGroup(null, listOf())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import com.lighthouse.features.setting.R
internal enum class SettingMenu(val uiText: UIText) {

USED_GIFTICON(UIText.StringResource(R.string.used_gifticon)),
IMMINENT_NOTIFICATION(UIText.StringResource(R.string.setting_imminent_notification)),
SECURITY(UIText.StringResource(R.string.setting_security)),
LOCATION(UIText.StringResource(R.string.setting_location_permission)),
IMMINENT_NOTIFICATION(UIText.StringResource(R.string.config_imminent_notification)),
SECURITY(UIText.StringResource(R.string.config_security)),
LOCATION(UIText.StringResource(R.string.config_location_permission)),
SIGN_IN(UIText.StringResource(R.string.user_sign_in)),
SIGN_OUT(UIText.StringResource(R.string.user_sign_out)),
WITHDRAWAL(UIText.StringResource(R.string.user_withdrawal)),
Expand Down

This file was deleted.

Loading

0 comments on commit 066164a

Please sign in to comment.