-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnyoneButMeEventPopupController.kt
More file actions
136 lines (123 loc) · 4.56 KB
/
Copy pathAnyoneButMeEventPopupController.kt
File metadata and controls
136 lines (123 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.eatssu.android.presentation.event
import android.content.Context
import android.content.Intent
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.lifecycle.LifecycleCoroutineScope
import com.eatssu.android.R
import com.eatssu.android.data.local.AppFeatureDataStore
import com.eatssu.android.presentation.mypage.terms.WebViewActivity
import com.eatssu.android.presentation.util.openInBrowser
import com.eatssu.common.analytics.AnalyticsTracker
import com.eatssu.common.analytics.PopupEvent
import com.eatssu.common.enums.ScreenId
import com.eatssu.design_system.theme.EatssuTheme
import dagger.hilt.android.qualifiers.ActivityContext
import dagger.hilt.android.scopes.ActivityScoped
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import javax.inject.Inject
@ActivityScoped
class AnyoneButMeEventPopupController @Inject constructor(
@ActivityContext private val context: Context,
private val appFeatureDataStore: AppFeatureDataStore,
private val analyticsTracker: AnalyticsTracker,
) {
private companion object {
const val POPUP_NAME_PLZ_NOT_ME = "plz_not_me"
const val ACTION_CLICK_POPUP_IMAGE = "click_popup_image"
const val ACTION_GO_INSTA = "go_insta"
const val ACTION_NOT_SHOW_AGAIN = "not_show_again"
const val ACTION_CLOSE = "close"
}
private lateinit var composeView: ComposeView
private lateinit var lifecycleScope: LifecycleCoroutineScope
private var canAutoShowOnLaunch = false
private var hasHandledLaunchPopup = false
private val isPopupVisible = mutableStateOf(false)
fun bind(
composeView: ComposeView,
lifecycleScope: LifecycleCoroutineScope,
showOnLaunch: Boolean,
) {
this.composeView = composeView
this.lifecycleScope = lifecycleScope
canAutoShowOnLaunch = showOnLaunch
setupContent()
observePopupState()
}
private fun setupContent() {
composeView.setViewCompositionStrategy(
ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed
)
composeView.setContent {
EatssuTheme {
if (isPopupVisible.value) {
AnyoneButMeEventDialog(
onDismiss = ::closePopup,
onDismissForever = ::dismissForever,
onInstagramClick = ::openInstagramFromPopup,
onAnyoneButMeClick = ::openAnyoneButMePageFromPopup
)
}
}
}
}
private fun observePopupState() {
lifecycleScope.launch {
appFeatureDataStore.isAnyoneButMeEventPopupDismissed.collectLatest { dismissed ->
if (canAutoShowOnLaunch && !hasHandledLaunchPopup && !dismissed) {
hasHandledLaunchPopup = true
isPopupVisible.value = true
}
}
}
}
private fun dismissForever() {
trackPopupAction(ACTION_NOT_SHOW_AGAIN)
hide()
lifecycleScope.launch {
appFeatureDataStore.setAnyoneButMeEventPopupDismissed(true)
}
}
private fun closePopup() {
trackPopupAction(ACTION_CLOSE)
hide()
}
private fun openAnyoneButMePageFromPopup() {
trackPopupAction(ACTION_CLICK_POPUP_IMAGE)
openAnyoneButMePage()
}
fun openAnyoneButMePage() {
hide()
context.startActivity(
Intent(context, WebViewActivity::class.java).apply {
putExtra(WebViewActivity.EXTRA_URL, context.getString(R.string.anyone_but_me_url))
putExtra(WebViewActivity.EXTRA_TITLE, context.getString(R.string.nav_anyone_but_me))
putExtra("SCREEN_ID", ScreenId.ANYONE_BUT_ME_MAIN.name)
putExtra(
WebViewActivity.EXTRA_BACK_ICON_RES_ID,
com.eatssu.design_system.R.drawable.ic_close
)
}
)
}
private fun openInstagramFromPopup() {
trackPopupAction(ACTION_GO_INSTA)
hide()
context.openInBrowser(context.getString(R.string.eatssu_event_instagram_url))
}
private fun trackPopupAction(action: String) {
analyticsTracker.track(
PopupEvent(
popupName = POPUP_NAME_PLZ_NOT_ME,
popupAction = action,
),
)
}
private fun hide() {
canAutoShowOnLaunch = false
isPopupVisible.value = false
}
}