Skip to content

Commit

Permalink
feat : 이벤트 팝업 노출
Browse files Browse the repository at this point in the history
  • Loading branch information
HamBP committed Jan 16, 2025
1 parent 839d0a3 commit 46941ef
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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<Preferences> by context.pre

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

suspend fun hidePopupToday() {

}
}
13 changes: 11 additions & 2 deletions data/src/main/java/com/nexters/boolti/data/di/DataSourceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -135,7 +135,7 @@ fun BTDialog(
fun BTDialogPreview() {
BooltiTheme {
Surface {
BTDialog(
EventDialog(
imageUrl = "",
actionUrl = "",
onDismiss = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -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")
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,33 @@ 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
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<User.My?> = authRepository.cachedUser.stateIn(
Expand All @@ -38,6 +46,7 @@ class ShowViewModel @Inject constructor(

init {
search()
fetchPopup()
}

private fun sendEvent(event: ShowEvent) {
Expand All @@ -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)
}
}

0 comments on commit 46941ef

Please sign in to comment.