From 066164a2f3ca91012d692d2491324020a7dc54d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AA=85=EC=84=9D?= Date: Wed, 1 Mar 2023 10:35:14 +0900 Subject: [PATCH] =?UTF-8?q?Issues=20#287=20feat:=20SettingList=20=EA=B0=B1?= =?UTF-8?q?=EC=8B=A0=20=EA=B9=9C=EB=B0=95=EC=9E=84=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/lighthouse/ui/MainActivity.kt | 41 ++++--- .../java/com/lighthouse/ui/MainViewModel.kt | 4 + .../auth/repository/AuthRepositoryImpl.kt | 8 +- .../core/android/utils/resource/UIText.kt | 8 +- .../src/main/res/layout/fragment_coffee.xml | 5 + ...ViewModel.kt => AppNavigationViewModel.kt} | 2 +- .../features/main/ui/MainContainerFragment.kt | 8 +- .../layout/fragment_open_source_license.xml | 6 + .../layout/fragment_personal_info_policy.xml | 5 + .../src/main/res/layout/fragment_security.xml | 6 + features/ui-setting/build.gradle.kts | 2 +- .../setting/adapter/SettingItemDiff.kt | 22 +++- .../features/setting/model/SettingGroup.kt | 15 +++ .../features/setting/model/SettingMenu.kt | 6 +- .../features/setting/navigator/SettingNav.kt | 5 - .../features/setting/ui/SettingFragment.kt | 64 ++++++++-- .../features/setting/ui/SettingViewModel.kt | 115 ++++++++++-------- .../src/main/res/layout/fragment_setting.xml | 11 +- .../src/main/res/layout/item_state_button.xml | 2 +- .../src/main/res/layout/item_state_switch.xml | 2 +- .../src/main/res/values/strings.xml | 8 +- .../main/res/layout/fragment_terms_of_use.xml | 5 + .../res/layout/fragment_used_gifticon.xml | 5 + .../worker/workers/NotificationWorker.kt | 6 +- 24 files changed, 237 insertions(+), 124 deletions(-) rename features/ui-common/src/main/java/com/lighthouse/features/common/navigator/{NavigationViewModel.kt => AppNavigationViewModel.kt} (90%) delete mode 100644 features/ui-setting/src/main/java/com/lighthouse/features/setting/navigator/SettingNav.kt diff --git a/app/src/main/java/com/lighthouse/ui/MainActivity.kt b/app/src/main/java/com/lighthouse/ui/MainActivity.kt index b1d7ae125..7d16b6e17 100644 --- a/app/src/main/java/com/lighthouse/ui/MainActivity.kt +++ b/app/src/main/java/com/lighthouse/ui/MainActivity.kt @@ -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 @@ -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 @@ -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) } } } @@ -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 } } } diff --git a/app/src/main/java/com/lighthouse/ui/MainViewModel.kt b/app/src/main/java/com/lighthouse/ui/MainViewModel.kt index 3014cc36b..e6bd57c59 100644 --- a/app/src/main/java/com/lighthouse/ui/MainViewModel.kt +++ b/app/src/main/java/com/lighthouse/ui/MainViewModel.kt @@ -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 @@ -11,4 +14,5 @@ internal class MainViewModel @Inject constructor( ) : ViewModel() { fun isLogin() = isLoginUserUseCase() + .stateIn(viewModelScope, SharingStarted.Eagerly, null) } diff --git a/auth/src/main/java/com/lighthouse/auth/repository/AuthRepositoryImpl.kt b/auth/src/main/java/com/lighthouse/auth/repository/AuthRepositoryImpl.kt index c3dafdf6b..0ac0cae97 100644 --- a/auth/src/main/java/com/lighthouse/auth/repository/AuthRepositoryImpl.kt +++ b/auth/src/main/java/com/lighthouse/auth/repository/AuthRepositoryImpl.kt @@ -11,20 +11,16 @@ import javax.inject.Inject internal class AuthRepositoryImpl @Inject constructor() : AuthRepository { - private val isGuestFlow = callbackFlow { + override fun isGuest(): Flow = callbackFlow { val authStateListener = AuthStateListener { trySend(it.currentUser == null) } - + Firebase.auth.addAuthStateListener(authStateListener) awaitClose { Firebase.auth.removeAuthStateListener(authStateListener) } } - override fun isGuest(): Flow { - return isGuestFlow - } - override fun getCurrentUserId(): String { return Firebase.auth.currentUser?.uid ?: GUEST_ID } diff --git a/core-android/src/main/java/com/lighthouse/core/android/utils/resource/UIText.kt b/core-android/src/main/java/com/lighthouse/core/android/utils/resource/UIText.kt index 2327f5bde..0ce59da3c 100644 --- a/core-android/src/main/java/com/lighthouse/core/android/utils/resource/UIText.kt +++ b/core-android/src/main/java/com/lighthouse/core/android/utils/resource/UIText.kt @@ -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() } } @@ -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() } } diff --git a/features/ui-coffee/src/main/res/layout/fragment_coffee.xml b/features/ui-coffee/src/main/res/layout/fragment_coffee.xml index 78e83e1c4..1bec8c879 100644 --- a/features/ui-coffee/src/main/res/layout/fragment_coffee.xml +++ b/features/ui-coffee/src/main/res/layout/fragment_coffee.xml @@ -5,5 +5,10 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + \ No newline at end of file diff --git a/features/ui-common/src/main/java/com/lighthouse/features/common/navigator/NavigationViewModel.kt b/features/ui-common/src/main/java/com/lighthouse/features/common/navigator/AppNavigationViewModel.kt similarity index 90% rename from features/ui-common/src/main/java/com/lighthouse/features/common/navigator/NavigationViewModel.kt rename to features/ui-common/src/main/java/com/lighthouse/features/common/navigator/AppNavigationViewModel.kt index 54bf5d35e..5eb8197de 100644 --- a/features/ui-common/src/main/java/com/lighthouse/features/common/navigator/NavigationViewModel.kt +++ b/features/ui-common/src/main/java/com/lighthouse/features/common/navigator/AppNavigationViewModel.kt @@ -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() val navigation = _navigation.asEventFlow() diff --git a/features/ui-main/src/main/java/com/lighthouse/features/main/ui/MainContainerFragment.kt b/features/ui-main/src/main/java/com/lighthouse/features/main/ui/MainContainerFragment.kt index 49013c0d0..93d6314e8 100644 --- a/features/ui-main/src/main/java/com/lighthouse/features/main/ui/MainContainerFragment.kt +++ b/features/ui-main/src/main/java/com/lighthouse/features/main/ui/MainContainerFragment.kt @@ -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) { @@ -24,9 +22,6 @@ 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) @@ -34,7 +29,8 @@ class MainContainerFragment : Fragment(R.layout.fragment_main_container) { } 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) } diff --git a/features/ui-opensourcelicense/src/main/res/layout/fragment_open_source_license.xml b/features/ui-opensourcelicense/src/main/res/layout/fragment_open_source_license.xml index 78e83e1c4..5091f64be 100644 --- a/features/ui-opensourcelicense/src/main/res/layout/fragment_open_source_license.xml +++ b/features/ui-opensourcelicense/src/main/res/layout/fragment_open_source_license.xml @@ -5,5 +5,11 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + \ No newline at end of file diff --git a/features/ui-personalinfopolicy/src/main/res/layout/fragment_personal_info_policy.xml b/features/ui-personalinfopolicy/src/main/res/layout/fragment_personal_info_policy.xml index c652ecc18..38f5b532c 100644 --- a/features/ui-personalinfopolicy/src/main/res/layout/fragment_personal_info_policy.xml +++ b/features/ui-personalinfopolicy/src/main/res/layout/fragment_personal_info_policy.xml @@ -6,5 +6,10 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + \ No newline at end of file diff --git a/features/ui-security/src/main/res/layout/fragment_security.xml b/features/ui-security/src/main/res/layout/fragment_security.xml index 78e83e1c4..10bbbd80b 100644 --- a/features/ui-security/src/main/res/layout/fragment_security.xml +++ b/features/ui-security/src/main/res/layout/fragment_security.xml @@ -5,5 +5,11 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + \ No newline at end of file diff --git a/features/ui-setting/build.gradle.kts b/features/ui-setting/build.gradle.kts index 109972e01..e961a3912 100644 --- a/features/ui-setting/build.gradle.kts +++ b/features/ui-setting/build.gradle.kts @@ -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) diff --git a/features/ui-setting/src/main/java/com/lighthouse/features/setting/adapter/SettingItemDiff.kt b/features/ui-setting/src/main/java/com/lighthouse/features/setting/adapter/SettingItemDiff.kt index 3c0d2e226..47892e2f9 100644 --- a/features/ui-setting/src/main/java/com/lighthouse/features/setting/adapter/SettingItemDiff.kt +++ b/features/ui-setting/src/main/java/com/lighthouse/features/setting/adapter/SettingItemDiff.kt @@ -6,7 +6,27 @@ import com.lighthouse.features.setting.model.SettingItem internal class SettingItemDiff : DiffUtil.ItemCallback() { 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 { diff --git a/features/ui-setting/src/main/java/com/lighthouse/features/setting/model/SettingGroup.kt b/features/ui-setting/src/main/java/com/lighthouse/features/setting/model/SettingGroup.kt index cd125a0fd..bb52a8d75 100644 --- a/features/ui-setting/src/main/java/com/lighthouse/features/setting/model/SettingGroup.kt +++ b/features/ui-setting/src/main/java/com/lighthouse/features/setting/model/SettingGroup.kt @@ -4,6 +4,17 @@ import com.lighthouse.core.android.utils.resource.UIText internal class SettingGroup(val title: UIText?, val items: List) { + 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() @@ -32,4 +43,8 @@ internal class SettingGroup(val title: UIText?, val items: List) { return SettingGroup(title, items.toList()) } } + + companion object { + val Empty = SettingGroup(null, listOf()) + } } diff --git a/features/ui-setting/src/main/java/com/lighthouse/features/setting/model/SettingMenu.kt b/features/ui-setting/src/main/java/com/lighthouse/features/setting/model/SettingMenu.kt index 9cf9e2724..87e43e92b 100644 --- a/features/ui-setting/src/main/java/com/lighthouse/features/setting/model/SettingMenu.kt +++ b/features/ui-setting/src/main/java/com/lighthouse/features/setting/model/SettingMenu.kt @@ -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)), diff --git a/features/ui-setting/src/main/java/com/lighthouse/features/setting/navigator/SettingNav.kt b/features/ui-setting/src/main/java/com/lighthouse/features/setting/navigator/SettingNav.kt deleted file mode 100644 index ee9d2dddf..000000000 --- a/features/ui-setting/src/main/java/com/lighthouse/features/setting/navigator/SettingNav.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.lighthouse.features.setting.navigator - -import javax.inject.Inject - -class SettingNav @Inject constructor() diff --git a/features/ui-setting/src/main/java/com/lighthouse/features/setting/ui/SettingFragment.kt b/features/ui-setting/src/main/java/com/lighthouse/features/setting/ui/SettingFragment.kt index 19e9f5b4f..3b3a3de92 100644 --- a/features/ui-setting/src/main/java/com/lighthouse/features/setting/ui/SettingFragment.kt +++ b/features/ui-setting/src/main/java/com/lighthouse/features/setting/ui/SettingFragment.kt @@ -3,13 +3,17 @@ package com.lighthouse.features.setting.ui import android.os.Bundle import android.view.View import androidx.fragment.app.Fragment +import androidx.fragment.app.activityViewModels import androidx.fragment.app.viewModels +import com.lighthouse.auth.google.repository.GoogleClient import com.lighthouse.features.common.binding.viewBindings +import com.lighthouse.features.common.ext.repeatOnStarted +import com.lighthouse.features.common.model.NavigationItem +import com.lighthouse.features.common.navigator.AppNavigationViewModel import com.lighthouse.features.setting.R import com.lighthouse.features.setting.adapter.SettingAdapter import com.lighthouse.features.setting.databinding.FragmentSettingBinding import com.lighthouse.features.setting.model.SettingMenu -import com.lighthouse.features.setting.navigator.SettingNav import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @@ -20,7 +24,9 @@ class SettingFragment : Fragment(R.layout.fragment_setting) { private val viewModel: SettingViewModel by viewModels() - private val adapter = SettingAdapter( + private val appNavigationViewModel: AppNavigationViewModel by activityViewModels() + + private val settingAdapter = SettingAdapter( onClick = { menu -> setUpMenuOnClick(menu) }, @@ -30,31 +36,63 @@ class SettingFragment : Fragment(R.layout.fragment_setting) { ) @Inject - lateinit var nav: SettingNav + lateinit var googleClient: GoogleClient override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + + setUpSettingMenu() } private fun setUpSettingMenu() { + binding.rvList.adapter = settingAdapter + repeatOnStarted { + viewModel.settingMenus.collect { menus -> + settingAdapter.submitList(menus) + } + } } private fun setUpMenuOnClick(menu: SettingMenu) { when (menu) { - SettingMenu.USED_GIFTICON -> {} - SettingMenu.SECURITY -> {} - SettingMenu.LOCATION -> {} - SettingMenu.SIGN_IN -> {} - SettingMenu.SIGN_OUT -> {} - SettingMenu.WITHDRAWAL -> {} - SettingMenu.COFFEE -> {} - SettingMenu.TERMS_OF_USE -> {} - SettingMenu.PERSONAL_INFO_POLICY -> {} - SettingMenu.OPEN_SOURCE_LICENSE -> {} + SettingMenu.USED_GIFTICON -> + appNavigationViewModel.navigate(NavigationItem.UsedGifticon) + + SettingMenu.SECURITY -> + appNavigationViewModel.navigate(NavigationItem.Security) + + SettingMenu.LOCATION -> location() + SettingMenu.SIGN_IN -> signIn() + SettingMenu.SIGN_OUT -> signOut() + SettingMenu.WITHDRAWAL -> withdrawal() + SettingMenu.COFFEE -> + appNavigationViewModel.navigate(NavigationItem.Coffee) + + SettingMenu.TERMS_OF_USE -> + appNavigationViewModel.navigate(NavigationItem.TermsOfUse) + + SettingMenu.PERSONAL_INFO_POLICY -> + appNavigationViewModel.navigate(NavigationItem.PersonalInfoPolicy) + + SettingMenu.OPEN_SOURCE_LICENSE -> + appNavigationViewModel.navigate(NavigationItem.OpensourceLicense) + else -> Unit } } + private fun location() { + } + + private fun signIn() { + } + + private fun signOut() { + } + + private fun withdrawal() { + } + private fun setUpMenuOnCheckedChange(menu: SettingMenu, isChecked: Boolean) { when (menu) { SettingMenu.IMMINENT_NOTIFICATION -> viewModel.setNotificationEnable(isChecked) diff --git a/features/ui-setting/src/main/java/com/lighthouse/features/setting/ui/SettingViewModel.kt b/features/ui-setting/src/main/java/com/lighthouse/features/setting/ui/SettingViewModel.kt index 0c906ac72..6df2611f6 100644 --- a/features/ui-setting/src/main/java/com/lighthouse/features/setting/ui/SettingViewModel.kt +++ b/features/ui-setting/src/main/java/com/lighthouse/features/setting/ui/SettingViewModel.kt @@ -7,70 +7,32 @@ import com.lighthouse.core.android.utils.resource.UIText import com.lighthouse.domain.usecase.setting.GetNotificationOptionUseCase import com.lighthouse.domain.usecase.setting.GetSecurityOptionUseCase import com.lighthouse.domain.usecase.setting.SetNotificationOptionUseCase -import com.lighthouse.domain.usecase.setting.SetSecurityOptionUseCase import com.lighthouse.domain.usecase.user.IsGuestUseCase import com.lighthouse.features.setting.R import com.lighthouse.features.setting.ext.settingGroup import com.lighthouse.features.setting.ext.settingItems +import com.lighthouse.features.setting.model.SettingGroup import com.lighthouse.features.setting.model.SettingMenu import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel -class SettingViewModel @Inject constructor( - isGuestUseCase: IsGuestUseCase, +internal class SettingViewModel @Inject constructor( + private val isGuestUseCase: IsGuestUseCase, getNotificationOptionUseCase: GetNotificationOptionUseCase, getSecurityOptionUseCase: GetSecurityOptionUseCase, - private val setNotificationOptionUseCase: SetNotificationOptionUseCase, - private val setSecurityOptionUseCase: SetSecurityOptionUseCase + private val setNotificationOptionUseCase: SetNotificationOptionUseCase ) : ViewModel() { - private val settingGroup = settingGroup { - setTitle(UIText.StringResource(R.string.subtitle_setting)) - addStateSwitch(SettingMenu.IMMINENT_NOTIFICATION) - addStateButton(SettingMenu.SECURITY) - addStateButton(SettingMenu.LOCATION) - } - - private val userGroup = settingGroup { - setTitle(UIText.StringResource(R.string.subtitle_user)) - addStateButton(SettingMenu.SIGN_IN) - addStateButton(SettingMenu.SIGN_OUT) - addStateButton(SettingMenu.WITHDRAWAL) - } - - private val etcGroup = settingGroup { - setTitle(UIText.StringResource(R.string.subtitle_etc)) - addButton(SettingMenu.COFFEE) - addButton(SettingMenu.TERMS_OF_USE) - addButton(SettingMenu.PERSONAL_INFO_POLICY) - addButton(SettingMenu.OPEN_SOURCE_LICENSE) - } - - private val menus = settingItems { - addButton(SettingMenu.USED_GIFTICON) - addGroup(settingGroup) - addGroup(userGroup) - addGroup(etcGroup) - } - - private val isGuest = isGuestUseCase() - - val isVisibleSignIn = isGuest.map { - it - }.stateIn(viewModelScope, SharingStarted.Eagerly, false) - - val isVisibleSignOut = isGuest.map { - !it - }.stateIn(viewModelScope, SharingStarted.Eagerly, false) - - val notificationEnable = getNotificationOptionUseCase().map { + private val notificationEnable = getNotificationOptionUseCase().map { it.getOrDefault(false) - }.stateIn(viewModelScope, SharingStarted.Eagerly, false) + } fun setNotificationEnable(enable: Boolean) { viewModelScope.launch { @@ -78,17 +40,68 @@ class SettingViewModel @Inject constructor( } } - val securityOption = getSecurityOptionUseCase().map { + private val securityOption = getSecurityOptionUseCase().map { when (it.getOrDefault(SecurityOption.NONE)) { SecurityOption.NONE -> UIText.StringResource(R.string.security_none) SecurityOption.PIN -> UIText.StringResource(R.string.security_pin) SecurityOption.FINGERPRINT -> UIText.StringResource(R.string.security_fingerprint) + else -> UIText.Empty } - }.stateIn(viewModelScope, SharingStarted.Eagerly, UIText.Empty) + } - fun setSecurityOption(option: SecurityOption) { - viewModelScope.launch { - setSecurityOptionUseCase(option) + private val locationEnableText = MutableStateFlow(UIText.Empty) + + fun setLocationEnable(enable: Boolean) { + val stringRes = if (enable) { + R.string.location_permission_allowed + } else { + R.string.location_permission_not_allowed } + locationEnableText.value = UIText.StringResource(stringRes) } + + private val configGroup = combine( + notificationEnable, + securityOption, + locationEnableText + ) { notificationEnable, securityOption, locationEnableText -> + settingGroup { + setTitle(UIText.StringResource(R.string.subtitle_config)) + addStateSwitch(SettingMenu.IMMINENT_NOTIFICATION, notificationEnable) + addStateButton(SettingMenu.SECURITY, securityOption) + addStateButton(SettingMenu.LOCATION, locationEnableText) + } + }.stateIn(viewModelScope, SharingStarted.Eagerly, SettingGroup.Empty) + + private val userGroup = isGuestUseCase().map { isGuest -> + settingGroup { + setTitle(UIText.StringResource(R.string.subtitle_user)) + if (isGuest) { + addStateButton(SettingMenu.SIGN_IN) + } else { + addStateButton(SettingMenu.SIGN_OUT) + } + addStateButton(SettingMenu.WITHDRAWAL) + } + }.stateIn(viewModelScope, SharingStarted.Eagerly, SettingGroup.Empty) + + val settingMenus = combine( + configGroup, + userGroup + ) { configGroup, userGroup -> + settingItems { + addButton(SettingMenu.USED_GIFTICON) + addGroup(configGroup) + addGroup(userGroup) + addGroup( + settingGroup { + setTitle(UIText.StringResource(R.string.subtitle_etc)) + addButton(SettingMenu.COFFEE) + addButton(SettingMenu.TERMS_OF_USE) + addButton(SettingMenu.PERSONAL_INFO_POLICY) + addButton(SettingMenu.OPEN_SOURCE_LICENSE) + } + ) + } + }.stateIn(viewModelScope, SharingStarted.Eagerly, listOf()) } diff --git a/features/ui-setting/src/main/res/layout/fragment_setting.xml b/features/ui-setting/src/main/res/layout/fragment_setting.xml index 7d39f5588..68e8868d4 100644 --- a/features/ui-setting/src/main/res/layout/fragment_setting.xml +++ b/features/ui-setting/src/main/res/layout/fragment_setting.xml @@ -3,13 +3,6 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> - - - - - + app:layout_behavior="@string/appbar_scrolling_view_behavior" + app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/> \ No newline at end of file diff --git a/features/ui-setting/src/main/res/layout/item_state_button.xml b/features/ui-setting/src/main/res/layout/item_state_button.xml index 09d99aad2..bb6f895e5 100644 --- a/features/ui-setting/src/main/res/layout/item_state_button.xml +++ b/features/ui-setting/src/main/res/layout/item_state_button.xml @@ -12,7 +12,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingVertical="16dp" - android:text="@string/setting_security" + android:text="@string/config_security" app:layout_constraintTop_toTopOf="parent" /> 설정 사용한 기프티콘 확인 - 설정 - 사용 임박 알림 - 보안 인증 + 설정 + 사용 임박 알림 + 보안 인증 사용 안 함 PIN 지문 - 위치 정보 권한 + 위치 정보 권한 허용됨 허용 안 함 diff --git a/features/ui-termsofuse/src/main/res/layout/fragment_terms_of_use.xml b/features/ui-termsofuse/src/main/res/layout/fragment_terms_of_use.xml index 1d13f9b0e..278b51a37 100644 --- a/features/ui-termsofuse/src/main/res/layout/fragment_terms_of_use.xml +++ b/features/ui-termsofuse/src/main/res/layout/fragment_terms_of_use.xml @@ -5,5 +5,10 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + diff --git a/features/ui-usedgifticon/src/main/res/layout/fragment_used_gifticon.xml b/features/ui-usedgifticon/src/main/res/layout/fragment_used_gifticon.xml index f0f6a5700..b02d676e0 100644 --- a/features/ui-usedgifticon/src/main/res/layout/fragment_used_gifticon.xml +++ b/features/ui-usedgifticon/src/main/res/layout/fragment_used_gifticon.xml @@ -5,5 +5,10 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + \ No newline at end of file diff --git a/worker/src/main/java/com/lighthouse/worker/workers/NotificationWorker.kt b/worker/src/main/java/com/lighthouse/worker/workers/NotificationWorker.kt index 0735ecef6..2539ccba3 100644 --- a/worker/src/main/java/com/lighthouse/worker/workers/NotificationWorker.kt +++ b/worker/src/main/java/com/lighthouse/worker/workers/NotificationWorker.kt @@ -23,8 +23,8 @@ import java.util.concurrent.TimeUnit class NotificationWorker @AssistedInject constructor( @Assisted context: Context, @Assisted workerParams: WorkerParameters, - private val getGifticonsUseCase: GetGifticonsWithDDayUseCase, - private val navigator: DetailPendingNavigator + private val getGifticonsUseCase: GetGifticonsWithDDayUseCase +// private val navigator: DetailPendingNavigator ) : CoroutineWorker(context, workerParams) { private val notificationManager by lazy { @@ -68,7 +68,7 @@ class NotificationWorker @AssistedInject constructor( ) ) .setPriority(NotificationCompat.PRIORITY_DEFAULT) - .setContentIntent(navigator.getPendingIntent(applicationContext, gifticon.id)) +// .setContentIntent(navigator.getPendingIntent(applicationContext, gifticon.id)) .build().apply { flags = Notification.FLAG_AUTO_CANCEL }