1- package com.getcode.view.main.home
1+ package com.getcode
22
33import android.Manifest
44import android.annotation.SuppressLint
@@ -12,8 +12,6 @@ import androidx.core.app.NotificationManagerCompat
1212import androidx.core.net.toUri
1313import androidx.lifecycle.viewModelScope
1414import cafe.adriel.voyager.core.model.ScreenModel
15- import com.getcode.BuildConfig
16- import com.getcode.R
1715import com.getcode.analytics.AnalyticsManager
1816import com.getcode.analytics.AnalyticsService
1917import com.getcode.domain.CashLinkManager
@@ -99,9 +97,8 @@ import com.getcode.utils.nonce
9997import com.getcode.utils.trace
10098import com.getcode.vendor.Base58
10199import com.getcode.view.BaseViewModel
102- import com.kik.kikx.kikcodes.KikCodeScanner
100+ import com.getcode.view.main.scanner.UiElement
103101import com.kik.kikx.kikcodes.implementation.KikCodeAnalyzer
104- import com.kik.kikx.kikcodes.implementation.KikCodeScannerImpl
105102import com.kik.kikx.models.ScannableKikCode
106103import dagger.hilt.android.lifecycle.HiltViewModel
107104import io.reactivex.rxjava3.core.Completable
@@ -147,7 +144,7 @@ sealed interface PresentationStyle {
147144 data object Slide : PresentationStyle , Visible
148145}
149146
150- data class HomeUiModel (
147+ data class SessionState (
151148 val isCameraPermissionGranted : Boolean? = null ,
152149 val vibrateOnScan : Boolean = false ,
153150 val balance : KinAmount ? = null ,
@@ -167,14 +164,18 @@ data class HomeUiModel(
167164 val invertedDragZoom : Feature = InvertedDragZoomFeature (),
168165 val gallery : Feature = GalleryFeature (),
169166 val flippableTipCard : Feature = FlippableTipCardFeature (),
170- val actions : List <HomeAction > = listOf(HomeAction .GIVE_KIN , HomeAction .TIP_CARD , HomeAction .BALANCE ),
167+ val scannerElements : List <UiElement > = listOf(
168+ UiElement .GIVE_KIN ,
169+ UiElement .TIP_CARD ,
170+ UiElement .BALANCE
171+ ),
171172 val tipCardConnected : Boolean = false ,
172173)
173174
174- sealed interface HomeEvent {
175- data object PresentTipEntry : HomeEvent
176- data object RequestNotificationPermissions : HomeEvent
177- data class SendIntent (val intent : Intent ): HomeEvent
175+ sealed interface SessionEvent {
176+ data object PresentTipEntry : SessionEvent
177+ data object RequestNotificationPermissions : SessionEvent
178+ data class SendIntent (val intent : Intent ): SessionEvent
178179}
179180
180181enum class RestrictionType {
@@ -185,7 +186,7 @@ enum class RestrictionType {
185186
186187@SuppressLint(" CheckResult" )
187188@HiltViewModel
188- class HomeViewModel @Inject constructor(
189+ class Session @Inject constructor(
189190 private val client : Client ,
190191 private val receiveTransactionRepository : ReceiveTransactionRepository ,
191192 private val paymentRepository : PaymentRepository ,
@@ -210,10 +211,10 @@ class HomeViewModel @Inject constructor(
210211 betaFlagsRepository : BetaFlagsRepository ,
211212 features : FeatureRepository ,
212213) : BaseViewModel(resources), ScreenModel {
213- val uiFlow = MutableStateFlow (HomeUiModel ())
214+ val uiFlow = MutableStateFlow (SessionState ())
214215
215- private val _eventFlow : MutableSharedFlow <HomeEvent > = MutableSharedFlow ()
216- val eventFlow: SharedFlow <HomeEvent > = _eventFlow .asSharedFlow()
216+ private val _eventFlow : MutableSharedFlow <SessionEvent > = MutableSharedFlow ()
217+ val eventFlow: SharedFlow <SessionEvent > = _eventFlow .asSharedFlow()
217218
218219 private var sheetDismissTimer: TimerTask ? = null
219220
@@ -280,7 +281,7 @@ class HomeViewModel @Inject constructor(
280281 betaFlagsRepository.observe()
281282 .distinctUntilChanged()
282283 .onEach { betaFlags ->
283- uiFlow.update { it.copy(actions = buildActions (betaFlags)) }
284+ uiFlow.update { it.copy(scannerElements = buildScannerElements (betaFlags)) }
284285 }.launchIn(viewModelScope)
285286
286287 tipController.showTwitterSplat
@@ -441,21 +442,21 @@ class HomeViewModel @Inject constructor(
441442 }
442443 }
443444
444- private fun buildActions (
445+ private fun buildScannerElements (
445446 betaOptions : BetaOptions ,
446- ): List <HomeAction > {
447- val actions = mutableListOf (HomeAction .GIVE_KIN )
447+ ): List <UiElement > {
448+ val actions = mutableListOf (UiElement .GIVE_KIN )
448449 actions + = if (betaOptions.tipCardOnHomeScreen) {
449- HomeAction .TIP_CARD
450+ UiElement .TIP_CARD
450451 } else {
451- HomeAction .GET_KIN
452+ UiElement .GET_KIN
452453 }
453454
454455 if (betaOptions.conversationsEnabled) {
455- actions + = HomeAction .CHAT
456+ actions + = UiElement .CHAT
456457 }
457458
458- actions + = HomeAction .BALANCE
459+ actions + = UiElement .BALANCE
459460
460461 return actions
461462 }
@@ -863,7 +864,7 @@ class HomeViewModel @Inject constructor(
863864 when {
864865 isDenied -> {
865866 viewModelScope.launch {
866- _eventFlow .emit(HomeEvent .RequestNotificationPermissions )
867+ _eventFlow .emit(SessionEvent .RequestNotificationPermissions )
867868 }
868869 }
869870 else -> {
@@ -918,7 +919,7 @@ class HomeViewModel @Inject constructor(
918919 )
919920 )
920921 viewModelScope.launch {
921- _eventFlow .emit(HomeEvent .SendIntent (intent))
922+ _eventFlow .emit(SessionEvent .SendIntent (intent))
922923 }
923924 cancelTip()
924925 },
@@ -928,7 +929,7 @@ class HomeViewModel @Inject constructor(
928929 )
929930 }.onSuccess {
930931 delay(300 .milliseconds)
931- _eventFlow .emit(HomeEvent .PresentTipEntry )
932+ _eventFlow .emit(SessionEvent .PresentTipEntry )
932933 analytics.tipCardShown(username)
933934 }
934935 }
@@ -1194,7 +1195,7 @@ class HomeViewModel @Inject constructor(
11941195 ).apply {
11951196 flags = Intent .FLAG_ACTIVITY_NEW_TASK
11961197 }
1197- _eventFlow .emit(HomeEvent .SendIntent (intent))
1198+ _eventFlow .emit(SessionEvent .SendIntent (intent))
11981199 }
11991200 }
12001201 } else {
@@ -1208,7 +1209,7 @@ class HomeViewModel @Inject constructor(
12081209 ).apply {
12091210 flags = Intent .FLAG_ACTIVITY_NEW_TASK
12101211 }
1211- _eventFlow .emit(HomeEvent .SendIntent (intent))
1212+ _eventFlow .emit(SessionEvent .SendIntent (intent))
12121213 }
12131214 }
12141215 }
@@ -1361,7 +1362,7 @@ class HomeViewModel @Inject constructor(
13611362 ).apply {
13621363 flags = Intent .FLAG_ACTIVITY_NEW_TASK
13631364 }
1364- _eventFlow .emit(HomeEvent .SendIntent (intent))
1365+ _eventFlow .emit(SessionEvent .SendIntent (intent))
13651366 }
13661367 } else {
13671368 request?.successUrl?.let { url ->
@@ -1371,7 +1372,7 @@ class HomeViewModel @Inject constructor(
13711372 ).apply {
13721373 flags = Intent .FLAG_ACTIVITY_NEW_TASK
13731374 }
1374- _eventFlow .emit(HomeEvent .SendIntent (intent))
1375+ _eventFlow .emit(SessionEvent .SendIntent (intent))
13751376 }
13761377 }
13771378 }
@@ -1550,7 +1551,7 @@ class HomeViewModel @Inject constructor(
15501551 withContext(Dispatchers .Main ) {
15511552 val shareIntent = IntentUtils .tipCard(connectedAccount.username, connectedAccount.platform)
15521553
1553- _eventFlow .emit(HomeEvent .SendIntent (shareIntent))
1554+ _eventFlow .emit(SessionEvent .SendIntent (shareIntent))
15541555 }
15551556 }
15561557
@@ -1581,7 +1582,7 @@ class HomeViewModel @Inject constructor(
15811582
15821583 CoroutineScope (Dispatchers .IO ).launch {
15831584 withContext(Dispatchers .Main ) {
1584- _eventFlow .emit(HomeEvent .SendIntent (shareIntent))
1585+ _eventFlow .emit(SessionEvent .SendIntent (shareIntent))
15851586 }
15861587 delay(2500 )
15871588
0 commit comments