Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/birthday push #535

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions app/src/main/java/com/mashup/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import com.mashup.ui.main.model.MainTab
import com.mashup.ui.main.popup.MainBottomPopup
import com.mashup.ui.qrscan.CongratsAttendanceScreen
import com.mashup.ui.qrscan.QRScanActivity
import com.mashup.ui.webview.birthday.BirthdayActivity
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -142,16 +141,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
)
}

MainPopupType.BIRTHDAY_CELEBRATION -> {
viewModel.disablePopup(popupType)
startActivity(
BirthdayActivity.newIntent(
context = this@MainActivity,
urlKey = "birthday/event"
)
)
}

else -> {
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/mashup/ui/main/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class MainViewModel @Inject constructor(
if (result.isSuccess()) {
val popupType =
MainPopupType.getMainPopupType(result.data?.firstOrNull() ?: return@mashUpScope)
if (popupType == MainPopupType.UNKNOWN) return@mashUpScope
if (popupType == MainPopupType.UNKNOWN || popupType == MainPopupType.BIRTHDAY_CELEBRATION) return@mashUpScope
_showPopupType.emit(popupType)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ import com.mashup.core.ui.widget.bottomsheet.BottomSheetHandler
import com.mashup.ui.main.MainViewModel
import com.mashup.ui.main.model.MainPopupEntity
import com.mashup.ui.main.model.MainPopupType
import com.mashup.ui.webview.WebViewViewModel
import com.mashup.util.AnalyticsManager
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainBottomPopup : BottomSheetDialogFragment() {

private val mainViewModel: MainViewModel by activityViewModels()
private val webViewViewModel: WebViewViewModel by activityViewModels()

companion object {
fun newInstance(popupType: MainPopupType) = MainBottomPopup().apply {
Expand Down Expand Up @@ -104,6 +106,7 @@ class MainBottomPopup : BottomSheetDialogFragment() {
},
onClickRightButton = {
mainViewModel.onClickPopup(viewModel.popupKey.orEmpty())
webViewViewModel.onClickPopup(viewModel.popupKey.orEmpty())
AnalyticsManager.addEvent(
LOG_COMMON_POPUP_CONFIRM,
bundleOf("key" to viewModel.popupKey)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/mashup/ui/mypage/AttendanceType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ enum class AttendanceType(@DrawableRes val resourceId: Int) {
MASHUP_SUBLEADER(R.drawable.img_mashupsubleader),
TECH_BLOG_WRITE(R.drawable.img_techblogwrite),
MASHUP_CONTENTS_WRITE(R.drawable.img_mashupcontentswrite),
ADD_SCORE_DURING_SEMINAR_ACTIVITY_0_5(R.drawable.img_presentation),
ADD_SCORE_DURING_SEMINAR_ACTIVITY_1(R.drawable.img_presentation),
DEFAULT(R.drawable.img_default_score);

companion object {
Expand Down
47 changes: 45 additions & 2 deletions app/src/main/java/com/mashup/ui/webview/WebViewViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,37 @@ import androidx.lifecycle.viewModelScope
import com.mashup.constant.EXTRA_TITLE_KEY
import com.mashup.constant.EXTRA_URL_KEY
import com.mashup.core.common.base.BaseViewModel
import com.mashup.core.data.repository.PopUpRepository
import com.mashup.data.network.WEB_HOST
import com.mashup.datastore.data.repository.UserPreferenceRepository
import com.mashup.ui.main.model.MainPopupType
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject

@HiltViewModel
class WebViewViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
userPreferenceRepository: UserPreferenceRepository
private val savedStateHandle: SavedStateHandle,
userPreferenceRepository: UserPreferenceRepository,
private val popUpRepository: PopUpRepository
) : BaseViewModel() {

private val showDividerFlow = MutableStateFlow(false)
private val _showPopupType = MutableSharedFlow<MainPopupType>()
val showPopupType: SharedFlow<MainPopupType> = _showPopupType.asSharedFlow()

private val _onClickPopupConfirm = MutableSharedFlow<MainPopupType>()
val onClickPopupConfirm: SharedFlow<MainPopupType> = _onClickPopupConfirm.asSharedFlow()

init {
getBirthDayPopup()
}

val webViewUiState = combine(
savedStateHandle.getStateFlow(EXTRA_TITLE_KEY, ""),
Expand Down Expand Up @@ -50,6 +65,34 @@ class WebViewViewModel @Inject constructor(

override fun handleErrorCode(code: String) {
}

private fun getBirthDayPopup() = mashUpScope {
val result = popUpRepository.getPopupKeyList()
val url = savedStateHandle.getStateFlow(EXTRA_URL_KEY, "").value

if (url == "birthday/event") {
return@mashUpScope
}

if (result.isSuccess()) {
val popupType =
MainPopupType.getMainPopupType(result.data?.firstOrNull() ?: MainPopupType.BIRTHDAY_CELEBRATION.name)
if (popupType != MainPopupType.BIRTHDAY_CELEBRATION) return@mashUpScope
_showPopupType.emit(popupType)
}
}

fun disablePopup(popupKey: MainPopupType) = mashUpScope {
if (popupKey == MainPopupType.UNKNOWN) return@mashUpScope
popUpRepository.patchPopupDisabled(popupKey.name)
}

fun onClickPopup(popupKey: String) = mashUpScope {
val popupType =
MainPopupType.getMainPopupType(popupKey)
if (popupType == MainPopupType.UNKNOWN) return@mashUpScope
_onClickPopupConfirm.emit(popupType)
}
}

sealed interface WebViewUiState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,79 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.KeyEvent
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.imePadding
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import com.mashup.R
import com.mashup.base.BaseActivity
import com.mashup.constant.EXTRA_TITLE_KEY
import com.mashup.constant.EXTRA_URL_KEY
import com.mashup.core.common.bridge.MashupBridge
import com.mashup.core.common.utils.safeShow
import com.mashup.core.ui.theme.MashUpTheme
import com.mashup.databinding.ActivityBirthdayBinding
import com.mashup.ui.main.model.MainPopupType
import com.mashup.ui.main.popup.MainBottomPopup
import com.mashup.ui.webview.WebViewScreen
import com.mashup.ui.webview.WebViewUiState
import com.mashup.ui.webview.WebViewViewModel
import com.mashup.util.setFullScreen
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch

@AndroidEntryPoint
class BirthdayActivity : ComponentActivity() {
class BirthdayActivity : BaseActivity<ActivityBirthdayBinding>() {

override val layoutId = R.layout.activity_birthday

private val webViewViewModel by viewModels<WebViewViewModel>()

override fun initObserves() {
super.initObserves()
flowLifecycleScope {
launch {
webViewViewModel.showPopupType.collectLatest {
MainBottomPopup.newInstance(it).safeShow(supportFragmentManager)
}
}

launch {
webViewViewModel.onClickPopupConfirm.collectLatest { popupType ->
when (popupType) {
MainPopupType.BIRTHDAY_CELEBRATION -> {
webViewViewModel.disablePopup(popupType)
startActivity(
newIntent(
context = this@BirthdayActivity,
urlKey = "birthday/event"
)
)
}
else -> {}
}
}
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()

setContent {
MashUpTheme {
val webViewUiState by webViewViewModel.webViewUiState.collectAsState(WebViewUiState.Loading)
WebViewScreen(
modifier = Modifier.fillMaxSize(),
modifier = Modifier.fillMaxSize().imePadding(),
webViewUiState = webViewUiState,
mashupBridge = MashupBridge(
this,
this@BirthdayActivity,
onBackPressed = ::finish
),
isShowMashUpToolbar = false
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/layout/activity_birthday.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data />


<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.webview.birthday.BirthdayActivity"/>

</layout>
Loading