diff --git a/data/src/main/java/com/nexters/boolti/data/datasource/PopupDataSource.kt b/data/src/main/java/com/nexters/boolti/data/datasource/PopupDataSource.kt index b4b370b3..54592530 100644 --- a/data/src/main/java/com/nexters/boolti/data/datasource/PopupDataSource.kt +++ b/data/src/main/java/com/nexters/boolti/data/datasource/PopupDataSource.kt @@ -1,11 +1,25 @@ 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 internal class PopupDataSource @Inject constructor( - private val service: PopupService + private val service: PopupService, + private val context: Context, ) { +// private val dataStore: DataStore by context.pre + suspend fun getPopup(): PopupResponse = service.getPopup() + suspend fun shouldShowPopup(): Boolean { + return true + } + + suspend fun hidePopupToday() { + + } } \ No newline at end of file diff --git a/data/src/main/java/com/nexters/boolti/data/di/DataSourceModule.kt b/data/src/main/java/com/nexters/boolti/data/di/DataSourceModule.kt index ff04d2e7..096417a3 100644 --- a/data/src/main/java/com/nexters/boolti/data/di/DataSourceModule.kt +++ b/data/src/main/java/com/nexters/boolti/data/di/DataSourceModule.kt @@ -5,9 +5,11 @@ import com.google.firebase.remoteconfig.FirebaseRemoteConfig import com.nexters.boolti.data.datasource.AuthDataSource import com.nexters.boolti.data.datasource.AuthTokenDataSource import com.nexters.boolti.data.datasource.PolicyDataSource +import com.nexters.boolti.data.datasource.PopupDataSource import com.nexters.boolti.data.datasource.RemoteConfigDataSource import com.nexters.boolti.data.datasource.TokenDataSource import com.nexters.boolti.data.network.api.LoginService +import com.nexters.boolti.data.network.api.PopupService import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -32,7 +34,8 @@ internal object DataSourceModule { @Singleton @Provides - fun provideTokenDataSource(@ApplicationContext context: Context): TokenDataSource = TokenDataSource(context) + fun provideTokenDataSource(@ApplicationContext context: Context): TokenDataSource = + TokenDataSource(context) @Singleton @Provides @@ -46,5 +49,11 @@ internal object DataSourceModule { @Singleton @Provides - fun providePolicyDataSource(@ApplicationContext context: Context): PolicyDataSource = PolicyDataSource(context) + fun providePolicyDataSource(@ApplicationContext context: Context): PolicyDataSource = + PolicyDataSource(context) + + @Singleton + @Provides + fun providePopupDataSource(service: PopupService, @ApplicationContext context: Context) = + PopupDataSource(service, context) } diff --git a/data/src/main/java/com/nexters/boolti/data/network/api/PopupService.kt b/data/src/main/java/com/nexters/boolti/data/network/api/PopupService.kt index 5db4d204..9a3b37fe 100644 --- a/data/src/main/java/com/nexters/boolti/data/network/api/PopupService.kt +++ b/data/src/main/java/com/nexters/boolti/data/network/api/PopupService.kt @@ -4,6 +4,6 @@ import com.nexters.boolti.data.network.response.PopupResponse import retrofit2.http.GET internal interface PopupService { - @GET("/app/api/v1/popup") + @GET("/app/papi/v1/popup") suspend fun getPopup(): PopupResponse } \ No newline at end of file diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/EventDialog.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/EventDialog.kt index 6cde974e..de42cc22 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/EventDialog.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/EventDialog.kt @@ -42,7 +42,7 @@ import com.nexters.boolti.presentation.theme.Grey50 import com.nexters.boolti.presentation.theme.Grey95 @Composable -fun BTDialog( +fun EventDialog( imageUrl: String, actionUrl: String?, onDismiss: (hideToday: Boolean) -> Unit, @@ -135,7 +135,7 @@ fun BTDialog( fun BTDialogPreview() { BooltiTheme { Surface { - BTDialog( + EventDialog( imageUrl = "", actionUrl = "", onDismiss = {} diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/ShowEvent.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/ShowEvent.kt index e7f6e0a7..77017245 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/ShowEvent.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/ShowEvent.kt @@ -1,5 +1,10 @@ package com.nexters.boolti.presentation.screen.show +import com.nexters.boolti.domain.model.Popup + sealed interface ShowEvent { data object Search : ShowEvent + data class ShowPopup( + val popup: Popup + ) : ShowEvent } \ No newline at end of file diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/ShowScreen.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/ShowScreen.kt index 5495ae5b..1c4c235f 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/ShowScreen.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/ShowScreen.kt @@ -34,6 +34,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableFloatStateOf +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue @@ -56,6 +57,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel 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.ShowFeed @@ -106,11 +108,13 @@ fun ShowScreen( } } } + var popupToShow: Popup? by remember { mutableStateOf(null) } LaunchedEffect(Unit) { viewModel.events.collect { event -> when (event) { ShowEvent.Search -> appbarOffsetHeightPx = 0f + is ShowEvent.ShowPopup -> popupToShow = event.popup } } } @@ -181,6 +185,23 @@ fun ShowScreen( onKeywordChanged = viewModel::updateKeyword, search = viewModel::search, ) + + val popup = popupToShow + if (popup != null) { + when (popup) { + is Popup.Event -> { + EventDialog( + imageUrl = popup.imageUrl, + actionUrl = popup.eventUrl, + onDismiss = { popupToShow = null }, + ) + } + + is Popup.Notice -> { + TODO("implement notice dialog") + } + } + } } } diff --git a/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/ShowViewModel.kt b/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/ShowViewModel.kt index 675512be..68acbc99 100644 --- a/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/ShowViewModel.kt +++ b/presentation/src/main/java/com/nexters/boolti/presentation/screen/show/ShowViewModel.kt @@ -3,9 +3,11 @@ package com.nexters.boolti.presentation.screen.show import androidx.lifecycle.viewModelScope 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.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 @@ -13,15 +15,21 @@ 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 import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch +import kotlinx.coroutines.plus import timber.log.Timber import javax.inject.Inject @HiltViewModel class ShowViewModel @Inject constructor( private val showRepository: ShowRepository, + private val popupRepository: PopupRepository, authRepository: AuthRepository, ) : BaseViewModel() { val user: StateFlow = authRepository.cachedUser.stateIn( @@ -38,6 +46,7 @@ class ShowViewModel @Inject constructor( init { search() + fetchPopup() } private fun sendEvent(event: ShowEvent) { @@ -60,4 +69,14 @@ class ShowViewModel @Inject constructor( fun updateKeyword(newKeyword: String) { _uiState.update { it.copy(keyword = newKeyword) } } + + @OptIn(ExperimentalCoroutinesApi::class) + private fun fetchPopup() { + popupRepository + .shouldShowPopup() + .filter { it } + .flatMapLatest { popupRepository.getPopup() } + .onEach { popup -> sendEvent(ShowEvent.ShowPopup(popup)) } + .launchIn(viewModelScope + recordExceptionHandler) + } }