Use MailboxState in MailboxActivity.kt and MailboxViewModel.kt
Replaced old flows with MailboxState.isUpdatedFromRemote and MailboxState.unreadChip MAILAND-1498, MAILAND-2820
This commit is contained in:
parent
0fbfa9cb7e
commit
afaf743d9b
|
@ -171,9 +171,9 @@
|
|||
<!-- Begin - Root Activities -->
|
||||
<activity-alias
|
||||
android:name=".activities.SplashActivity"
|
||||
android:targetActivity=".mailbox.presentation.MailboxActivity"/>
|
||||
android:targetActivity=".mailbox.presentation.ui.MailboxActivity"/>
|
||||
<activity
|
||||
android:name=".mailbox.presentation.MailboxActivity"
|
||||
android:name=".mailbox.presentation.ui.MailboxActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:exported="true"
|
||||
android:launchMode="standard"
|
||||
|
@ -198,10 +198,10 @@
|
|||
android:name=".details.presentation.ui.MessageDetailsActivity"
|
||||
android:exported="false"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:parentActivityName=".mailbox.presentation.MailboxActivity">
|
||||
android:parentActivityName=".mailbox.presentation.ui.MailboxActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".mailbox.presentation.MailboxActivity" />
|
||||
android:value=".mailbox.presentation.ui.MailboxActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activities.messageDetails.MessageViewHeadersActivity"
|
||||
|
@ -215,12 +215,12 @@
|
|||
<activity
|
||||
android:name=".activities.composeMessage.ComposeMessageActivity"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:parentActivityName=".mailbox.presentation.MailboxActivity"
|
||||
android:parentActivityName=".mailbox.presentation.ui.MailboxActivity"
|
||||
android:windowSoftInputMode="adjustResize|stateAlwaysVisible"
|
||||
android:exported="true">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".mailbox.presentation.MailboxActivity" />
|
||||
android:value=".mailbox.presentation.ui.MailboxActivity" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
|
|
|
@ -94,12 +94,11 @@ import ch.protonmail.android.labels.domain.model.Label
|
|||
import ch.protonmail.android.labels.domain.model.LabelId
|
||||
import ch.protonmail.android.labels.domain.model.LabelType
|
||||
import ch.protonmail.android.labels.presentation.ui.LabelsActionSheet
|
||||
import ch.protonmail.android.mailbox.domain.model.UnreadCounter
|
||||
import ch.protonmail.android.mailbox.presentation.model.EmptyMailboxUiModel
|
||||
import ch.protonmail.android.mailbox.presentation.model.MailboxItemUiModel
|
||||
import ch.protonmail.android.mailbox.presentation.model.MailboxListState
|
||||
import ch.protonmail.android.mailbox.presentation.model.MailboxState
|
||||
import ch.protonmail.android.mailbox.presentation.model.UnreadChipUiModel
|
||||
import ch.protonmail.android.mailbox.presentation.model.UnreadChipState
|
||||
import ch.protonmail.android.mailbox.presentation.util.ConversationModeEnabled
|
||||
import ch.protonmail.android.mailbox.presentation.viewmodel.FLOW_START_ACTIVITY
|
||||
import ch.protonmail.android.mailbox.presentation.viewmodel.FLOW_TRY_COMPOSE
|
||||
|
@ -152,7 +151,6 @@ import me.proton.core.util.android.sharedpreferences.observe
|
|||
import me.proton.core.util.android.sharedpreferences.set
|
||||
import me.proton.core.util.kotlin.EMPTY_STRING
|
||||
import me.proton.core.util.kotlin.exhaustive
|
||||
import me.proton.core.util.kotlin.takeIfNotBlank
|
||||
import timber.log.Timber
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.UUID
|
||||
|
@ -219,7 +217,6 @@ internal class MailboxActivity :
|
|||
private val mailboxViewModel: MailboxViewModel by viewModels()
|
||||
private var storageLimitApproachingAlertDialog: AlertDialog? = null
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private var unreadCountersCache: List<UnreadCounter> = emptyList()
|
||||
|
||||
private val startMessageDetailsLauncher = registerForActivityResult(MessageDetailsActivity.Launcher()) {}
|
||||
private val startComposeLauncher = registerForActivityResult(StartCompose()) {}
|
||||
|
@ -353,11 +350,7 @@ internal class MailboxActivity :
|
|||
.launchIn(lifecycleScope)
|
||||
|
||||
mailboxLocation
|
||||
.onEach {
|
||||
mailboxAdapter.setNewLocation(it)
|
||||
updateUnreadCounters()
|
||||
updatedStatusTextView.isVisible = false
|
||||
}
|
||||
.onEach(mailboxAdapter::setNewLocation)
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
drawerLabels
|
||||
|
@ -365,7 +358,7 @@ internal class MailboxActivity :
|
|||
.launchIn(lifecycleScope)
|
||||
|
||||
unreadCounters
|
||||
.onEach(::updateUnreadCounters)
|
||||
.onEach(sideDrawer::setUnreadCounters)
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
exitSelectionModeSharedFlow
|
||||
|
@ -541,11 +534,25 @@ internal class MailboxActivity :
|
|||
|
||||
private fun renderState(state: MailboxState) {
|
||||
Timber.v("New mailbox state: ${state.javaClass.canonicalName}")
|
||||
updatedStatusTextView.isVisible = state.isUpdatedFromRemote
|
||||
renderUnreadChipState(state.unreadChip)
|
||||
renderListState(state.list)
|
||||
}
|
||||
|
||||
private fun renderUnreadChipState(state: UnreadChipState) {
|
||||
when (state) {
|
||||
UnreadChipState.Loading -> {}
|
||||
is UnreadChipState.Data -> {
|
||||
unreadMessagesStatusChip.bind(
|
||||
model = state.model,
|
||||
onEnableFilter = {},
|
||||
onDisableFilter = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun renderListState(state: MailboxListState) {
|
||||
Timber.v("New mailbox state: ${state.javaClass.canonicalName}")
|
||||
setLoadingMore(false)
|
||||
|
||||
when (state) {
|
||||
|
@ -555,7 +562,6 @@ internal class MailboxActivity :
|
|||
setRefreshing(false)
|
||||
include_mailbox_no_messages.isVisible =
|
||||
state.lastFetchedItemsIds.isEmpty() && mailboxAdapter.itemCount == 0
|
||||
updatedStatusTextView.isVisible = true
|
||||
}
|
||||
is MailboxListState.Data -> {
|
||||
Timber.v("Data state items count: ${state.items.size}")
|
||||
|
@ -1262,26 +1268,6 @@ internal class MailboxActivity :
|
|||
mailboxViewModel.setNewMailboxLabel(labelId)
|
||||
}
|
||||
|
||||
private fun updateUnreadCounters(counters: List<UnreadCounter>? = null) {
|
||||
if (counters != null) {
|
||||
unreadCountersCache = counters
|
||||
}
|
||||
sideDrawer.setUnreadCounters(unreadCountersCache)
|
||||
|
||||
val currentLabelId = currentLabelId?.takeIfNotBlank() ?: currentMailboxLocation.asLabelIdString()
|
||||
val currentLocationUnreadCount = unreadCountersCache.find { it.labelId == currentLabelId }
|
||||
?.unreadCount
|
||||
?: 0
|
||||
unreadMessagesStatusChip.bind(
|
||||
UnreadChipUiModel(
|
||||
unreadCount = currentLocationUnreadCount,
|
||||
isFilterEnabled = false
|
||||
),
|
||||
onEnableFilter = {},
|
||||
onDisableFilter = {}
|
||||
)
|
||||
}
|
||||
|
||||
private val fcmBroadcastReceiver: BroadcastReceiver = FcmBroadcastReceiver()
|
||||
|
||||
private class OnMessageClickTask internal constructor(
|
||||
|
|
|
@ -62,6 +62,8 @@ import ch.protonmail.android.mailbox.presentation.mapper.MailboxItemUiModelMappe
|
|||
import ch.protonmail.android.mailbox.presentation.model.MailboxItemUiModel
|
||||
import ch.protonmail.android.mailbox.presentation.model.MailboxListState
|
||||
import ch.protonmail.android.mailbox.presentation.model.MailboxState
|
||||
import ch.protonmail.android.mailbox.presentation.model.UnreadChipState
|
||||
import ch.protonmail.android.mailbox.presentation.model.UnreadChipUiModel
|
||||
import ch.protonmail.android.mailbox.presentation.util.ConversationModeEnabled
|
||||
import ch.protonmail.android.notifications.presentation.usecase.ClearNotificationsForUser
|
||||
import ch.protonmail.android.settings.domain.GetMailSettings
|
||||
|
@ -197,8 +199,10 @@ internal class MailboxViewModel @Inject constructor(
|
|||
|
||||
val unreadCounters: Flow<List<UnreadCounter>> = combine(
|
||||
mutableUserId,
|
||||
mailboxLocation,
|
||||
mutableMailboxLabelId,
|
||||
mutableRefreshFlow.onStart { emit(false) }
|
||||
) { userId, _ -> userId }
|
||||
) { userId, _, _, _ -> userId }
|
||||
.flatMapLatest { userId ->
|
||||
if (userId == null) return@flatMapLatest flowOf(emptyList())
|
||||
combineTransform(
|
||||
|
@ -219,6 +223,19 @@ internal class MailboxViewModel @Inject constructor(
|
|||
emit(value)
|
||||
}
|
||||
}
|
||||
}.onEach { list ->
|
||||
val currentLabelId = getLabelId(mailboxLocation.value, mutableMailboxLabelId.value).id
|
||||
val currentLocationUnreadCounter = list.find { it.labelId == currentLabelId }
|
||||
?.unreadCount
|
||||
?: 0
|
||||
val newUnreadChipState = UnreadChipState.Data(
|
||||
UnreadChipUiModel(
|
||||
isFilterEnabled = false,
|
||||
unreadCount = currentLocationUnreadCounter
|
||||
)
|
||||
)
|
||||
val newMailboxState = mailboxState.value.copy(unreadChip = newUnreadChipState, isUpdatedFromRemote = false)
|
||||
mutableMailboxState.emit(newMailboxState)
|
||||
}
|
||||
|
||||
private lateinit var mailboxStateFlow: LoadMoreFlow<MailboxListState>
|
||||
|
@ -255,8 +272,12 @@ internal class MailboxViewModel @Inject constructor(
|
|||
)
|
||||
)
|
||||
}
|
||||
.onEach {
|
||||
val newState = mailboxState.value.copy(list = it)
|
||||
.onEach { mailboxListState ->
|
||||
val newState = if (mailboxListState is MailboxListState.DataRefresh) {
|
||||
mailboxState.value.copy(list = mailboxListState, isUpdatedFromRemote = true)
|
||||
} else {
|
||||
mailboxState.value.copy(list = mailboxListState)
|
||||
}
|
||||
mutableMailboxState.value = newState
|
||||
}
|
||||
.launchIn(viewModelScope)
|
||||
|
@ -453,7 +474,7 @@ internal class MailboxViewModel @Inject constructor(
|
|||
private suspend fun messagesToMailboxItems(
|
||||
userId: UserId,
|
||||
messages: List<Message>,
|
||||
currentLabelId: LabelId,
|
||||
currentLabelId: LabelId,
|
||||
labelsList: List<Label>?
|
||||
): List<MailboxItemUiModel> {
|
||||
Timber.v("messagesToMailboxItems size: ${messages.size}")
|
||||
|
@ -682,6 +703,7 @@ internal class MailboxViewModel @Inject constructor(
|
|||
)
|
||||
vibrator.vibrate(vibrationEffect)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
vibrator.vibrate(SWIPE_VIBRATION_DURATION)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue