Skip to content

Commit

Permalink
feat : [선물등록] 비로그인인 경우 로그인 요철
Browse files Browse the repository at this point in the history
  • Loading branch information
HamBP committed Jul 24, 2024
1 parent 71b76f3 commit 339fe9b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.nexters.boolti.presentation.screen.home

enum class HomeDialog {
NEED_LOGIN_FOR_GIFT
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ sealed interface HomeEvent {
data class DeepLinkEvent(
val deepLink: String,
) : HomeEvent

data object RequireLoginForGift : HomeEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@
<item>마이 > 결제 내역 > 결제 내역 상세에서 선물을 취소할 수 있습니다.</item>
<item>받는 분이 선물 거절 시 결제가 자동 취소됩니다.</item>
</string-array>
<string name="gift_login">로그인하기</string>
<string name="gift_need_login">로그인 후 선물 등록이 가능합니다.\n로그인해 주세요.</string>

<!-- 공연 -->
<string name="show_call_to_ask">전화 문의하기</string>
Expand Down

0 comments on commit 339fe9b

Please sign in to comment.