Moved getCheckedLabelsForAllMessages method from MessageActionSheetViewModel to ManageLabelsActionSheetViewModel and removed selected labels list from parameters list of ManageLabelsActionSheet.
MAILAND-1760
This commit is contained in:
parent
f710c2d47e
commit
2f0ea1f43b
|
@ -14,15 +14,6 @@
|
|||
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="PACKAGES_IMPORT_LAYOUT">
|
||||
<value>
|
||||
<package name="" alias="false" withSubpackages="true" />
|
||||
<package name="java" alias="false" withSubpackages="true" />
|
||||
<package name="javax" alias="false" withSubpackages="true" />
|
||||
<package name="kotlin" alias="false" withSubpackages="true" />
|
||||
<package name="" alias="true" withSubpackages="true" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
|
||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
|
||||
<option name="WRAP_EXPRESSION_BODY_FUNCTIONS" value="1" />
|
||||
|
@ -157,4 +148,4 @@
|
|||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
</component>
|
||||
</component>
|
|
@ -144,21 +144,18 @@ class ManageLabelsActionSheet : BottomSheetDialogFragment() {
|
|||
|
||||
companion object {
|
||||
|
||||
const val EXTRA_ARG_MESSAGE_CHECKED_LABELS = "extra_arg_message_checked_labels"
|
||||
const val EXTRA_ARG_MESSAGES_IDS = "extra_arg_messages_ids"
|
||||
const val EXTRA_ARG_ACTION_SHEET_TYPE = "extra_arg_action_sheet_type"
|
||||
const val EXTRA_ARG_CURRENT_FOLDER_LOCATION_ID = "extra_arg_current_folder_location_id"
|
||||
|
||||
fun newInstance(
|
||||
checkedLabels: List<String>,
|
||||
messageIds: List<String>,
|
||||
labelActionSheetType: Type = Type.LABEL,
|
||||
currentFolderLocationId: Int
|
||||
currentFolderLocationId: Int,
|
||||
labelActionSheetType: Type = Type.LABEL
|
||||
): ManageLabelsActionSheet {
|
||||
|
||||
return ManageLabelsActionSheet().apply {
|
||||
arguments = bundleOf(
|
||||
EXTRA_ARG_MESSAGE_CHECKED_LABELS to checkedLabels,
|
||||
EXTRA_ARG_MESSAGES_IDS to messageIds,
|
||||
EXTRA_ARG_ACTION_SHEET_TYPE to labelActionSheetType,
|
||||
EXTRA_ARG_CURRENT_FOLDER_LOCATION_ID to currentFolderLocationId
|
||||
|
|
|
@ -30,6 +30,7 @@ import ch.protonmail.android.labels.domain.usecase.MoveMessagesToFolder
|
|||
import ch.protonmail.android.labels.domain.usecase.UpdateLabels
|
||||
import ch.protonmail.android.labels.presentation.model.ManageLabelItemUiModel
|
||||
import ch.protonmail.android.labels.presentation.ui.ManageLabelsActionSheet
|
||||
import ch.protonmail.android.repository.MessageRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
@ -39,17 +40,14 @@ import javax.inject.Inject
|
|||
|
||||
@HiltViewModel
|
||||
class ManageLabelsActionSheetViewModel @Inject constructor(
|
||||
private val savedStateHandle: SavedStateHandle,
|
||||
savedStateHandle: SavedStateHandle,
|
||||
private val getAllLabels: GetAllLabels,
|
||||
private val userManager: UserManager,
|
||||
private val updateLabels: UpdateLabels,
|
||||
private val moveMessagesToFolder: MoveMessagesToFolder
|
||||
private val moveMessagesToFolder: MoveMessagesToFolder,
|
||||
private val messageRepository: MessageRepository
|
||||
) : ViewModel() {
|
||||
|
||||
private val initialLabelsSelection = savedStateHandle.get<List<String>>(
|
||||
ManageLabelsActionSheet.EXTRA_ARG_MESSAGE_CHECKED_LABELS
|
||||
) ?: emptyList()
|
||||
|
||||
private val labelsSheetType = savedStateHandle.get<ManageLabelsActionSheet.Type>(
|
||||
ManageLabelsActionSheet.EXTRA_ARG_ACTION_SHEET_TYPE
|
||||
) ?: ManageLabelsActionSheet.Type.LABEL
|
||||
|
@ -73,7 +71,11 @@ class ManageLabelsActionSheetViewModel @Inject constructor(
|
|||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
labelsMutableFlow.value = getAllLabels(initialLabelsSelection, labelsSheetType, currentMessageFolder)
|
||||
labelsMutableFlow.value = getAllLabels(
|
||||
getCheckedLabelsForAllMessages(messageIds),
|
||||
labelsSheetType,
|
||||
currentMessageFolder
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,4 +150,18 @@ class ManageLabelsActionSheetViewModel @Inject constructor(
|
|||
moveMessagesToFolder(messageIds, selectedFolderId, currentMessageFolder.messageLocationTypeValue.toString())
|
||||
actionsResultMutableFlow.value = ManageLabelActionResult.MessageSuccessfullyMoved
|
||||
}
|
||||
|
||||
private suspend fun getCheckedLabelsForAllMessages(
|
||||
messageIds: List<String>
|
||||
): List<String> {
|
||||
val checkedLabels = mutableListOf<String>()
|
||||
messageIds.forEach { messageId ->
|
||||
val message = messageRepository.findMessageById(messageId)
|
||||
Timber.v("Checking message labels: ${message?.labelIDsNotIncludingLocations}")
|
||||
message?.labelIDsNotIncludingLocations?.let {
|
||||
checkedLabels.addAll(it)
|
||||
}
|
||||
}
|
||||
return checkedLabels
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,6 +135,7 @@ import ch.protonmail.android.jobs.PostStarJob
|
|||
import ch.protonmail.android.jobs.PostTrashJobV2
|
||||
import ch.protonmail.android.jobs.PostUnreadJob
|
||||
import ch.protonmail.android.jobs.PostUnstarJob
|
||||
import ch.protonmail.android.labels.presentation.ui.ManageLabelsActionSheet
|
||||
import ch.protonmail.android.mailbox.presentation.MailboxViewModel.MaxLabelsReached
|
||||
import ch.protonmail.android.mailbox.presentation.model.MailboxUiItem
|
||||
import ch.protonmail.android.prefs.SecureSharedPreferences
|
||||
|
@ -1261,6 +1262,12 @@ class MailboxActivity :
|
|||
val messageIds = selectedMessages.map { message -> message.messageId }
|
||||
actionModeRunnable = ActionModeInteractionRunnable(actionMode)
|
||||
ShowLabelsManagerDialogTask(supportFragmentManager, messageDetailsRepository, messageIds).execute()
|
||||
|
||||
ManageLabelsActionSheet.newInstance(
|
||||
messageIds,
|
||||
currentMailboxLocation.messageLocationTypeValue,
|
||||
)
|
||||
.show(supportFragmentManager, ManageLabelsActionSheet::class.qualifiedName)
|
||||
}
|
||||
mailboxActionsView.setOnMoreActionClickListener {
|
||||
val messagesIds = selectedMessages.map { message -> message.messageId }
|
||||
|
|
|
@ -326,7 +326,6 @@ class MessageActionSheet : BottomSheetDialogFragment() {
|
|||
Timber.v("Action received $sheetAction")
|
||||
when (sheetAction) {
|
||||
is MessageActionSheetAction.ShowLabelsManager -> showManageLabelsActionSheet(
|
||||
sheetAction.checkedLabels,
|
||||
sheetAction.messageIds,
|
||||
sheetAction.labelActionSheetType,
|
||||
sheetAction.currentFolderLocationId
|
||||
|
@ -337,16 +336,14 @@ class MessageActionSheet : BottomSheetDialogFragment() {
|
|||
}
|
||||
|
||||
private fun showManageLabelsActionSheet(
|
||||
checkedLabels: List<String>,
|
||||
messageIds: List<String>,
|
||||
labelActionSheetType: ManageLabelsActionSheet.Type,
|
||||
currentFolderLocationId: Int
|
||||
) {
|
||||
ManageLabelsActionSheet.newInstance(
|
||||
checkedLabels,
|
||||
messageIds,
|
||||
labelActionSheetType,
|
||||
currentFolderLocationId
|
||||
currentFolderLocationId,
|
||||
labelActionSheetType
|
||||
)
|
||||
.show(parentFragmentManager, ManageLabelsActionSheet::class.qualifiedName)
|
||||
dismiss()
|
||||
|
|
|
@ -29,7 +29,6 @@ sealed class MessageActionSheetAction {
|
|||
object Default : MessageActionSheetAction()
|
||||
data class ShowLabelsManager(
|
||||
val messageIds: List<String>,
|
||||
val checkedLabels: List<String>,
|
||||
val currentFolderLocationId: Int,
|
||||
val labelActionSheetType: ManageLabelsActionSheet.Type = ManageLabelsActionSheet.Type.LABEL
|
||||
) : MessageActionSheetAction()
|
||||
|
|
|
@ -31,7 +31,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import me.proton.core.util.kotlin.EMPTY_STRING
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
|
@ -53,7 +52,6 @@ class MessageActionSheetViewModel @Inject constructor(
|
|||
viewModelScope.launch {
|
||||
val showLabelsManager = MessageActionSheetAction.ShowLabelsManager(
|
||||
messageIds,
|
||||
getCheckedLabelsForAllMessages(messageIds),
|
||||
currentLocation.messageLocationTypeValue,
|
||||
labelsSheetType
|
||||
)
|
||||
|
@ -61,20 +59,6 @@ class MessageActionSheetViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun getCheckedLabelsForAllMessages(
|
||||
messageIds: List<String>
|
||||
): List<String> {
|
||||
val checkedLabels = mutableListOf<String>()
|
||||
messageIds.forEach { messageId ->
|
||||
val message = messageRepository.findMessageById(messageId)
|
||||
Timber.v("Checking message labels: ${message?.labelIDsNotIncludingLocations}")
|
||||
message?.labelIDsNotIncludingLocations?.let {
|
||||
checkedLabels.addAll(it)
|
||||
}
|
||||
}
|
||||
return checkedLabels
|
||||
}
|
||||
|
||||
fun deleteMessage(messageIds: List<String>) {
|
||||
viewModelScope.launch {
|
||||
deleteMessage(
|
||||
|
@ -115,11 +99,9 @@ class MessageActionSheetViewModel @Inject constructor(
|
|||
currentFolder.messageLocationTypeValue.toString()
|
||||
)
|
||||
|
||||
fun starMessage(messageId: List<String>) =
|
||||
messageRepository.starMessages(messageId)
|
||||
fun starMessage(messageId: List<String>) = messageRepository.starMessages(messageId)
|
||||
|
||||
fun unStarMessage(messageId: List<String>) =
|
||||
messageRepository.unStarMessages(messageId)
|
||||
fun unStarMessage(messageId: List<String>) = messageRepository.unStarMessages(messageId)
|
||||
|
||||
fun markUnread(messageIds: List<String>) = messageRepository.markUnRead(messageIds)
|
||||
|
||||
|
|
|
@ -23,12 +23,14 @@ import android.graphics.Color
|
|||
import androidx.lifecycle.SavedStateHandle
|
||||
import ch.protonmail.android.core.Constants
|
||||
import ch.protonmail.android.core.UserManager
|
||||
import ch.protonmail.android.data.local.model.Message
|
||||
import ch.protonmail.android.labels.domain.model.ManageLabelActionResult
|
||||
import ch.protonmail.android.labels.domain.usecase.GetAllLabels
|
||||
import ch.protonmail.android.labels.domain.usecase.MoveMessagesToFolder
|
||||
import ch.protonmail.android.labels.domain.usecase.UpdateLabels
|
||||
import ch.protonmail.android.labels.presentation.model.ManageLabelItemUiModel
|
||||
import ch.protonmail.android.labels.presentation.ui.ManageLabelsActionSheet
|
||||
import ch.protonmail.android.repository.MessageRepository
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.Runs
|
||||
import io.mockk.coEvery
|
||||
|
@ -36,6 +38,7 @@ import io.mockk.coVerify
|
|||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.just
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.test.runBlockingTest
|
||||
import me.proton.core.test.android.ArchTest
|
||||
import me.proton.core.test.kotlin.CoroutinesTest
|
||||
|
@ -60,18 +63,24 @@ class ManageLabelsActionSheetViewModelTest : ArchTest, CoroutinesTest {
|
|||
@MockK
|
||||
private lateinit var savedStateHandle: SavedStateHandle
|
||||
|
||||
@MockK
|
||||
private lateinit var messageRepository: MessageRepository
|
||||
|
||||
private lateinit var viewModel: ManageLabelsActionSheetViewModel
|
||||
|
||||
private val checkedLabelId1 = "checkedLabelId1"
|
||||
private val messageId1 = "messageId1"
|
||||
private val labelId = "labelId1"
|
||||
private val labelId1 = "labelId1"
|
||||
private val labelId2 = "labelId2"
|
||||
private val iconRes = 123
|
||||
private val title = "title"
|
||||
private val titleRes = 321
|
||||
private val colorInt = Color.YELLOW
|
||||
private val message1 = mockk<Message> {
|
||||
every { messageId } returns messageId1
|
||||
every { labelIDsNotIncludingLocations } returns listOf(labelId1)
|
||||
}
|
||||
private val model1label = ManageLabelItemUiModel(
|
||||
labelId,
|
||||
labelId1,
|
||||
iconRes,
|
||||
title,
|
||||
titleRes,
|
||||
|
@ -95,11 +104,6 @@ class ManageLabelsActionSheetViewModelTest : ArchTest, CoroutinesTest {
|
|||
every { savedStateHandle.get<List<String>>(ManageLabelsActionSheet.EXTRA_ARG_MESSAGES_IDS) } returns listOf(
|
||||
messageId1
|
||||
)
|
||||
every {
|
||||
savedStateHandle.get<List<String>>(
|
||||
ManageLabelsActionSheet.EXTRA_ARG_MESSAGE_CHECKED_LABELS
|
||||
)
|
||||
} returns listOf(checkedLabelId1)
|
||||
every {
|
||||
savedStateHandle.get<ManageLabelsActionSheet.Type>(
|
||||
ManageLabelsActionSheet.EXTRA_ARG_ACTION_SHEET_TYPE
|
||||
|
@ -111,13 +115,15 @@ class ManageLabelsActionSheetViewModelTest : ArchTest, CoroutinesTest {
|
|||
} returns 0
|
||||
|
||||
coEvery { getAllLabels.invoke(any(), any(), any()) } returns listOf(model1label, model2folder)
|
||||
coEvery { messageRepository.findMessageById(messageId1) } returns message1
|
||||
|
||||
viewModel = ManageLabelsActionSheetViewModel(
|
||||
savedStateHandle,
|
||||
getAllLabels,
|
||||
userManager,
|
||||
updateLabels,
|
||||
moveMessagesToFolder
|
||||
moveMessagesToFolder,
|
||||
messageRepository
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,6 @@ class MessageActionSheetViewModelTest : ArchTest, CoroutinesTest {
|
|||
val labelsSheetType = ManageLabelsActionSheet.Type.LABEL
|
||||
val expected = MessageActionSheetAction.ShowLabelsManager(
|
||||
messageIds,
|
||||
labelIds,
|
||||
currentLocation.messageLocationTypeValue,
|
||||
labelsSheetType
|
||||
)
|
||||
|
@ -109,7 +108,6 @@ class MessageActionSheetViewModelTest : ArchTest, CoroutinesTest {
|
|||
val labelsSheetType = ManageLabelsActionSheet.Type.FOLDER
|
||||
val expected = MessageActionSheetAction.ShowLabelsManager(
|
||||
messageIds,
|
||||
labelIds,
|
||||
currentLocation.messageLocationTypeValue,
|
||||
labelsSheetType
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue