From 339fe9b0b2a8cc0d113449de6f525899324a6538 Mon Sep 17 00:00:00 2001 From: algosketch Date: Thu, 25 Jul 2024 02:45:48 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20[=EC=84=A0=EB=AC=BC=EB=93=B1?= =?UTF-8?q?=EB=A1=9D]=20=EB=B9=84=EB=A1=9C=EA=B7=B8=EC=9D=B8=EC=9D=B8=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=9A=94?= =?UTF-8?q?=EC=B2=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/screen/home/HomeDialog.kt | 5 ++++ .../presentation/screen/home/HomeEvent.kt | 2 ++ .../presentation/screen/home/HomeScreen.kt | 27 +++++++++++++++++-- .../presentation/screen/home/HomeViewModel.kt | 11 ++++++-- presentation/src/main/res/values/strings.xml | 2 ++ 5 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeDialog.kt diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeDialog.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeDialog.kt new file mode 100644 index 00000000..2afa471a --- /dev/null +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeDialog.kt @@ -0,0 +1,5 @@ +package com.nexters.boolti.presentation.screen.home + +enum class HomeDialog { + NEED_LOGIN_FOR_GIFT +} \ No newline at end of file diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeEvent.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeEvent.kt index aacc2f9a..bac1778d 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeEvent.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeEvent.kt @@ -4,4 +4,6 @@ sealed interface HomeEvent { data class DeepLinkEvent( val deepLink: String, ) : HomeEvent + + data object RequireLoginForGift : HomeEvent } \ No newline at end of file diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeScreen.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeScreen.kt index 997408e0..a15664ce 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeScreen.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeScreen.kt @@ -19,6 +19,9 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.Stable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource @@ -33,6 +36,7 @@ import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import androidx.navigation.navDeepLink import com.nexters.boolti.presentation.R +import com.nexters.boolti.presentation.component.BTDialog import com.nexters.boolti.presentation.extension.requireActivity import com.nexters.boolti.presentation.screen.my.MyScreen import com.nexters.boolti.presentation.screen.show.ShowScreen @@ -61,18 +65,24 @@ fun HomeScreen( val loggedIn by viewModel.loggedIn.collectAsStateWithLifecycle() val context = LocalContext.current + var dialog: HomeDialog? by rememberSaveable { mutableStateOf(null) } + LaunchedEffect(Unit) { viewModel.events.collect { event -> when (event) { is HomeEvent.DeepLinkEvent -> navController.navigate(Uri.parse(event.deepLink)) + HomeEvent.RequireLoginForGift -> { + dialog = HomeDialog.NEED_LOGIN_FOR_GIFT + } } } } LaunchedEffect(Unit) { val intent = context.requireActivity().intent - intent.action?.let { deepLink -> - val regex = "^https://app.boolti.in/gift/(\\w)+$".toRegex() + intent.action?.let { _ -> + val deepLink = intent.data.toString() + val regex = "^https://app.boolti.in/gift/([\\w-])+$".toRegex() if (regex.matches(deepLink)) { val giftUuid = deepLink.split("/").last() viewModel.receiveGift(giftUuid) @@ -151,6 +161,19 @@ fun HomeScreen( } } } + + if (dialog != null) { + val dialogText = stringResource(id = R.string.gift_need_login) + val action = requireLogin + + BTDialog( + onDismiss = { dialog = null }, + onClickPositiveButton = action, + positiveButtonLabel = stringResource(id = R.string.gift_login), + ) { + Text(text = dialogText) + } + } } @Stable diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeViewModel.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeViewModel.kt index c3cd78f7..a4a1fdc4 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeViewModel.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/home/HomeViewModel.kt @@ -14,7 +14,6 @@ import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -import kotlinx.coroutines.flow.shareIn import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import kotlinx.coroutines.plus @@ -62,7 +61,15 @@ class HomeViewModel @Inject constructor( } fun receiveGift(giftUuid: String) { - // TODO: 선물 받는 로직 + when (loggedIn.value) { + true -> TODO("선물 받는 로직") + false -> { + giftRepository.saveGift(giftUuid) + sendEvent(HomeEvent.RequireLoginForGift) + } + + null -> TODO() + } } private fun sendEvent(event: HomeEvent) { diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index 26be2cd3..ad0831cf 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -185,6 +185,8 @@ 마이 > 결제 내역 > 결제 내역 상세에서 선물을 취소할 수 있습니다. 받는 분이 선물 거절 시 결제가 자동 취소됩니다. + 로그인하기 + 로그인 후 선물 등록이 가능합니다.\n로그인해 주세요. 전화 문의하기