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로그인해 주세요.
전화 문의하기