Skip to content

Commit

Permalink
feat : data layer 제외 로직 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
HamBP committed Jan 16, 2025
1 parent bb8cde4 commit 204b027
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.nexters.boolti.data.datasource

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import com.nexters.boolti.data.network.api.PopupService
import com.nexters.boolti.data.network.response.PopupResponse
import javax.inject.Inject
Expand All @@ -12,14 +9,14 @@ internal class PopupDataSource @Inject constructor(
private val service: PopupService,
private val context: Context,
) {
// private val dataStore: DataStore<Preferences> by context.pre

suspend fun getPopup(): PopupResponse = service.getPopup()
suspend fun shouldShowPopup(): Boolean {

suspend fun shouldShowEvent(): Boolean {
// todo
return true
}

suspend fun hidePopupToday() {

suspend fun hideEventToday() {
// todo
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@ package com.nexters.boolti.data.repository

import com.nexters.boolti.data.datasource.PopupDataSource
import com.nexters.boolti.domain.repository.PopupRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

internal class PopupRepositoryImpl @Inject constructor(
private val dataSource: PopupDataSource,
) : PopupRepository {

override fun shouldShowEvent(): Flow<Boolean> = flow {
emit(true) // TODO : preference에서 가져오기
}

override fun hideEventToday(): Flow<Unit> = flow {
// TODO : preference에 저장
}

override fun getPopup() = flow {
emit(dataSource.getPopup().toDomain())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ import com.nexters.boolti.domain.model.Popup
import kotlinx.coroutines.flow.Flow

interface PopupRepository {
fun shouldShowEvent(): Flow<Boolean>
fun hideEventToday(): Flow<Unit>
fun getPopup(): Flow<Popup>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.nexters.boolti.domain.usecase

import com.nexters.boolti.domain.model.Popup
import com.nexters.boolti.domain.repository.PopupRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class GetPopupUseCase @Inject constructor(
private val popupRepository: PopupRepository,
) {
operator fun invoke(): Flow<Popup> = popupRepository
.getPopup()
.filter { popup ->
popup is Popup.Notice || popupRepository.shouldShowEvent().first()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ fun NoticeDialog(
title: String,
content: String,
emphasizedText: String = "",
onDismiss: () -> Unit,
) {
BTDialog {
BTDialog(
onDismiss = onDismiss,
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Expand Down Expand Up @@ -196,6 +199,7 @@ fun NoticeDialogPreview() {
NoticeDialog(
title = "맴뱀페이 결제 불가 안내",
content = "이용에 불편을 드려 죄송합니다. 서비스가 정상화되는 즉시 다시 안내드릴 예정이오니, 다른 결제수단을 이용해 주시면 감사하겠습니다.",
onDismiss = {}
)
}
}
Expand All @@ -210,6 +214,7 @@ fun NoticeEmphasizedDialogPreview() {
title = "맴뱀페이 결제 불가 안내",
content = "이용에 불편을 드려 죄송합니다. 서비스가 정상화되는 즉시 다시 안내드릴 예정이오니, 다른 결제수단을 이용해 주시면 감사하겠습니다.",
emphasizedText = "현재 야근 중인 관계로 코딩이 영구적으로 불가합니다.",
onDismiss = {}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.nexters.boolti.domain.model.Popup
import com.nexters.boolti.presentation.R
import com.nexters.boolti.presentation.component.BusinessInformation
import com.nexters.boolti.presentation.component.NoticeDialog
import com.nexters.boolti.presentation.component.ShowFeed
import com.nexters.boolti.presentation.component.StatusBarCover
import com.nexters.boolti.presentation.extension.extractEmphasizedText
import com.nexters.boolti.presentation.extension.toPx
import com.nexters.boolti.presentation.theme.Grey05
import com.nexters.boolti.presentation.theme.Grey15
Expand Down Expand Up @@ -193,12 +195,22 @@ fun ShowScreen(
EventDialog(
imageUrl = popup.imageUrl,
actionUrl = popup.eventUrl,
onDismiss = { popupToShow = null },
onDismiss = { hideToday ->
popupToShow = null
if (hideToday) viewModel.hideEventToday()
},
)
}

is Popup.Notice -> {
TODO("implement notice dialog")
val (emphasizedText, remainingText) = popup.description.extractEmphasizedText()

NoticeDialog(
title = popup.title,
emphasizedText = emphasizedText,
content = remainingText,
onDismiss = { popupToShow = null },
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ import com.nexters.boolti.domain.model.User
import com.nexters.boolti.domain.repository.AuthRepository
import com.nexters.boolti.domain.repository.PopupRepository
import com.nexters.boolti.domain.repository.ShowRepository
import com.nexters.boolti.domain.usecase.GetPopupUseCase
import com.nexters.boolti.presentation.base.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
Expand All @@ -30,6 +28,7 @@ import javax.inject.Inject
class ShowViewModel @Inject constructor(
private val showRepository: ShowRepository,
private val popupRepository: PopupRepository,
private val getPopupUseCase: GetPopupUseCase,
authRepository: AuthRepository,
) : BaseViewModel() {
val user: StateFlow<User.My?> = authRepository.cachedUser.stateIn(
Expand Down Expand Up @@ -70,13 +69,15 @@ class ShowViewModel @Inject constructor(
_uiState.update { it.copy(keyword = newKeyword) }
}

@OptIn(ExperimentalCoroutinesApi::class)
private fun fetchPopup() {
popupRepository
.shouldShowPopup()
.filter { it }
.flatMapLatest { popupRepository.getPopup() }
getPopupUseCase()
.onEach { popup -> sendEvent(ShowEvent.ShowPopup(popup)) }
.launchIn(viewModelScope + recordExceptionHandler)
}

fun hideEventToday() {
popupRepository
.hideEventToday()
.launchIn(viewModelScope + recordExceptionHandler)
}
}

0 comments on commit 204b027

Please sign in to comment.