diff --git a/actions/src/main/kotlin/com/alfresco/content/actions/ActionStartProcess.kt b/actions/src/main/kotlin/com/alfresco/content/actions/ActionStartProcess.kt index d81361fe5..a0f516f5b 100644 --- a/actions/src/main/kotlin/com/alfresco/content/actions/ActionStartProcess.kt +++ b/actions/src/main/kotlin/com/alfresco/content/actions/ActionStartProcess.kt @@ -11,6 +11,7 @@ import com.alfresco.content.data.ParentEntry */ data class ActionStartProcess( override val entry: Entry, + override val entries: List = emptyList(), override val icon: Int = R.drawable.ic_start_workflow, override val title: Int = R.string.action_start_workflow, override val eventName: EventName = EventName.StartWorkflow, @@ -20,9 +21,14 @@ data class ActionStartProcess( return entry } + override suspend fun executeMulti(context: Context): Pair> { + return Pair(entry, entries) + } + override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as Entry) - override fun showToast(view: View, anchorView: View?) = + override fun copy(_entries: List): Action = copy(entries = _entries) + override fun showToast(view: View, anchorView: View?) = Action.showToast(view, anchorView, R.string.action_workflow_started) } diff --git a/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsSheet.kt b/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsSheet.kt index 929822f58..13875400e 100644 --- a/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsSheet.kt +++ b/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsSheet.kt @@ -69,13 +69,8 @@ class ContextualActionsSheet : BottomSheetDialogFragment(), MavericksView { withState(viewModel) { newState -> if (!newState.isMultiSelection) { viewModel.execute(it) - } else if (it is ActionDelete || it is ActionRestore || it is ActionDeleteForever || - it is ActionMoveFilesFolders || it is ActionAddOffline || it is ActionRemoveOffline || - it is ActionAddFavorite || it is ActionRemoveFavorite - ) { - viewModel.executeMulti(it) - MultiSelection.multiSelectionChangedFlow.tryEmit(MultiSelectionData(isMultiSelectionEnabled = false)) } else { + viewModel.executeMulti(it) MultiSelection.multiSelectionChangedFlow.tryEmit(MultiSelectionData(isMultiSelectionEnabled = false)) } } diff --git a/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsViewModel.kt b/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsViewModel.kt index 379fe8d67..7b3e48169 100644 --- a/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsViewModel.kt +++ b/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsViewModel.kt @@ -65,7 +65,7 @@ class ContextualActionsViewModel( private fun buildModelForMultiSelection() = withState { state -> // If entry is partial and not in the offline tab - setState { copy(entries = state.entries, actions = makeMultiActions(getFilteredEntries(state.entries), state), topActions = emptyList()) } + setState { copy(entries = state.entries, actions = makeMultiActions(state), topActions = emptyList()) } } private fun updateState(action: Action) { @@ -73,7 +73,7 @@ class ContextualActionsViewModel( val entry = action.entry as Entry ContextualActionsState( entries = if (isMultiSelection) action.entries else listOf(entry), - actions = if (isMultiSelection) makeMultiActions(action.entries, this) else makeActions(entry), + actions = if (isMultiSelection) makeMultiActions(this) else makeActions(entry), topActions = makeTopActions(entry), ) } @@ -106,7 +106,7 @@ class ContextualActionsViewModel( } } - fun makeMultiActions(filteredEntries: List, state: ContextualActionsState): List { + fun makeMultiActions(state: ContextualActionsState): List { val actions = mutableListOf() val entry = Entry.withSelectedEntries(state.entries) @@ -117,40 +117,44 @@ class ContextualActionsViewModel( } state.entries.all { it.hasOfflineStatus } -> { - actions.add(offlineMultiActionFor(entry, state.entries)) - processMultiActionFor(entry, state.entries)?.let { action -> - actions.add(action) - } + // Added Favorite Action + actions.addAll(sharedActions(entry, state.entries)) } else -> { - // Added Favorite Action - if (filteredEntries.any { !it.isFavorite }) { - actions.add(ActionAddFavorite(entry, state.entries)) - } else { - actions.add(ActionRemoveFavorite(entry, state.entries)) - } + actions.addAll(sharedActions(entry, state.entries)) + } + } - // Added Start Process Action - processMultiActionFor(entry, filteredEntries)?.let { action -> - actions.add(action) - } + return actions + } - // Added Move Action - if (isMoveDeleteAllowed(filteredEntries)) { - actions.add(ActionMoveFilesFolders(entry, state.entries)) - } + private fun sharedActions(entry: Entry, entries: List): List { + val actions = mutableListOf() + // Added Favorite Action + if (entries.any { !it.isFavorite }) { + actions.add(ActionAddFavorite(entry, entries)) + } else { + actions.add(ActionRemoveFavorite(entry, entries)) + } - // Added Offline Action - actions.add(offlineMultiActionFor(entry, state.entries)) + // Added Start Process Action + processMultiActionFor(entry, entries)?.let { action -> + actions.add(action) + } - // Added Delete Action - if (isMoveDeleteAllowed(filteredEntries)) { - actions.add((ActionDelete(entry, state.entries))) - } - } + // Added Move Action + if (isMoveDeleteAllowed(entries)) { + actions.add(ActionMoveFilesFolders(entry, entries)) } + // Added Offline Action + actions.add(offlineMultiActionFor(entry, entries)) + + // Added Delete Action + if (isMoveDeleteAllowed(entries)) { + actions.add((ActionDelete(entry, entries))) + } return actions } @@ -179,7 +183,7 @@ class ContextualActionsViewModel( private fun processMultiActionFor(entry: Entry, entries: List): Action? { if (settings.isProcessEnabled && (entries.isNotEmpty() && entries.all { it.isFile })) { - return ActionStartProcess(entry) + return ActionStartProcess(entry, entries) } return null } diff --git a/browse/src/main/kotlin/com/alfresco/content/browse/BrowseFragment.kt b/browse/src/main/kotlin/com/alfresco/content/browse/BrowseFragment.kt index 5cfd0ea9c..baa76c793 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/BrowseFragment.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/BrowseFragment.kt @@ -264,9 +264,9 @@ class BrowseFragment : ListFragment() { } } - override fun onProcessStart(entry: ParentEntry) { + override fun onProcessStart(entries: List) { if (isAdded && isVisible) { - ProcessDefinitionsSheet.with(entry as Entry).show(parentFragmentManager, null) + ProcessDefinitionsSheet.with(entries.map { it as Entry }).show(parentFragmentManager, null) } } diff --git a/browse/src/main/kotlin/com/alfresco/content/browse/offline/OfflineFragment.kt b/browse/src/main/kotlin/com/alfresco/content/browse/offline/OfflineFragment.kt index 8e6adb92a..1b18b9875 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/offline/OfflineFragment.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/offline/OfflineFragment.kt @@ -138,9 +138,9 @@ class OfflineFragment : ListFragment() { } } - override fun onProcessStart(entry: ParentEntry) { + override fun onProcessStart(entries: List) { if (isAdded && isVisible) { - ProcessDefinitionsSheet.with(entry as Entry).show(parentFragmentManager, null) + ProcessDefinitionsSheet.with(entries.map { it as Entry }).show(parentFragmentManager, null) } } diff --git a/browse/src/main/kotlin/com/alfresco/content/browse/processes/details/ProcessDetailViewModel.kt b/browse/src/main/kotlin/com/alfresco/content/browse/processes/details/ProcessDetailViewModel.kt index 00fdff60e..52056e97c 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/processes/details/ProcessDetailViewModel.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/processes/details/ProcessDetailViewModel.kt @@ -25,7 +25,7 @@ import com.alfresco.events.on import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job import kotlinx.coroutines.launch -import java.util.UUID +import java.util.* /** * Marked as ProcessDetailViewModel @@ -39,6 +39,7 @@ class ProcessDetailViewModel( private var observeUploadsJob: Job? = null var entryListener: EntryListener? = null var observerID: String = "" + private var isExecuted = false init { observerID = UUID.randomUUID().toString() @@ -220,8 +221,9 @@ class ProcessDetailViewModel( is Loading -> copy(requestProfile = Loading()) is Fail -> copy(requestProfile = Fail(it.error)) is Success -> { - repository.saveProcessUserDetails(it()) - copy(requestProfile = Success(it())) + val response = it() + repository.saveProcessUserDetails(response) + copy(requestProfile = Success(response)) } else -> { @@ -239,12 +241,17 @@ class ProcessDetailViewModel( is Loading -> copy(requestAccountInfo = Loading()) is Fail -> copy(requestAccountInfo = Fail(it.error)) is Success -> { - repository.saveSourceName(it().listAccounts.first()) - val sourceName = it().listAccounts.first().sourceName - state.parent?.defaultEntry?.let { entry -> - linkContentToProcess(entry, sourceName) + val response = it() + + repository.saveSourceName(response.listAccounts.first()) + val sourceName = response.listAccounts.first().sourceName + if (!isExecuted) { + isExecuted = true + state.parent?.defaultEntries?.map { entry -> + linkContentToProcess(entry, sourceName) + } } - copy(requestAccountInfo = Success(it())) + copy(requestAccountInfo = Success(response)) } else -> { @@ -265,7 +272,8 @@ class ProcessDetailViewModel( is Loading -> copy(requestTasks = Loading()) is Fail -> copy(requestTasks = Fail(it.error)) is Success -> { - updateTasks(it()).copy(requestTasks = Success(it())) + val response = it() + updateTasks(response).copy(requestTasks = Success(response)) } else -> { diff --git a/browse/src/main/kotlin/com/alfresco/content/browse/processes/details/ProcessDetailViewState.kt b/browse/src/main/kotlin/com/alfresco/content/browse/processes/details/ProcessDetailViewState.kt index 08fc9f999..9d9adcd80 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/processes/details/ProcessDetailViewState.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/processes/details/ProcessDetailViewState.kt @@ -49,7 +49,18 @@ data class ProcessDetailViewState( if (entry == null) { return this } - return copy(baseEntries = listOf(entry), listContents = listOf(entry)) + println("data == 1 :: $entry") + println("data == 2 :: ${listContents.size}") + + val list: List + if (listContents.isNotEmpty()) { + list = listContents.toMutableList() + list.add(entry) + } else { + list = listOf(entry) + } + + return copy(baseEntries = listOf(entry), listContents = list.distinct()) } /** diff --git a/browse/src/main/kotlin/com/alfresco/content/browse/processes/sheet/ProcessDefinitionsSheet.kt b/browse/src/main/kotlin/com/alfresco/content/browse/processes/sheet/ProcessDefinitionsSheet.kt index 8b1cae0dc..411705fbc 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/processes/sheet/ProcessDefinitionsSheet.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/processes/sheet/ProcessDefinitionsSheet.kt @@ -81,7 +81,7 @@ class ProcessDefinitionsSheet : BottomSheetDialogFragment(), MavericksView { id(it.id) processDefinition(it) clickListener { model, _, _, _ -> - val processEntry = ProcessEntry.with(model.processDefinition(), state.entry) + val processEntry = ProcessEntry.with(model.processDefinition(), state.entries) startActivity( Intent(requireActivity(), ProcessDetailActivity::class.java) .putExtra(Mavericks.KEY_ARG, processEntry), @@ -98,8 +98,8 @@ class ProcessDefinitionsSheet : BottomSheetDialogFragment(), MavericksView { /** * returns the instance of ProcessDefinitionsSheet with attached entry as bundle */ - fun with(entry: Entry? = null) = ProcessDefinitionsSheet().apply { - arguments = bundleOf(Mavericks.KEY_ARG to entry) + fun with(entrie: List = emptyList()) = ProcessDefinitionsSheet().apply { + arguments = bundleOf(Mavericks.KEY_ARG to entrie) } } } diff --git a/browse/src/main/kotlin/com/alfresco/content/browse/processes/sheet/ProcessDefinitionsState.kt b/browse/src/main/kotlin/com/alfresco/content/browse/processes/sheet/ProcessDefinitionsState.kt index b5106aa4b..988be18ca 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/processes/sheet/ProcessDefinitionsState.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/processes/sheet/ProcessDefinitionsState.kt @@ -8,8 +8,8 @@ import com.alfresco.content.data.RuntimeProcessDefinitionDataEntry * Marked as ProcessDefinitionsState */ data class ProcessDefinitionsState( - val entry: Entry? = null, + val entries: List = emptyList(), val listProcessDefinitions: List? = null, ) : MavericksState { - constructor(target: Entry) : this(entry = target) + constructor(target: List) : this(entries = target) } diff --git a/browse/src/main/kotlin/com/alfresco/content/browse/processes/sheet/ProcessDefinitionsViewModel.kt b/browse/src/main/kotlin/com/alfresco/content/browse/processes/sheet/ProcessDefinitionsViewModel.kt index 9d678c35f..350d5e77e 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/processes/sheet/ProcessDefinitionsViewModel.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/processes/sheet/ProcessDefinitionsViewModel.kt @@ -25,14 +25,14 @@ internal class ProcessDefinitionsViewModel( when (it) { is Success -> { ProcessDefinitionsState( - entry = state.entry, + entries = state.entries, listProcessDefinitions = it().listRuntimeProcessDefinitions, ) } else -> { ProcessDefinitionsState( - entry = state.entry, + entries = state.entries, listProcessDefinitions = null, ) } diff --git a/data/src/main/kotlin/com/alfresco/content/data/ProcessEntry.kt b/data/src/main/kotlin/com/alfresco/content/data/ProcessEntry.kt index e081c1761..8562d5323 100644 --- a/data/src/main/kotlin/com/alfresco/content/data/ProcessEntry.kt +++ b/data/src/main/kotlin/com/alfresco/content/data/ProcessEntry.kt @@ -31,7 +31,7 @@ data class ProcessEntry( val suspended: Boolean? = null, var priority: Int = 0, val formattedDueDate: String? = null, - val defaultEntry: Entry? = null, + val defaultEntries: List = emptyList(), val reviewerType: ReviewerType = ReviewerType.OTHER, ) : ParentEntry(), Parcelable { @@ -66,12 +66,12 @@ data class ProcessEntry( /** * return the ProcessEntry using RuntimeProcessDefinitionDataEntry */ - fun with(data: RuntimeProcessDefinitionDataEntry, entry: Entry?): ProcessEntry { + fun with(data: RuntimeProcessDefinitionDataEntry, entries: List): ProcessEntry { return ProcessEntry( id = data.id?.toString() ?: "", name = data.name ?: "", description = data.description ?: "", - defaultEntry = entry, + defaultEntries = entries, ) } @@ -86,7 +86,7 @@ data class ProcessEntry( startFormDefined = dataObj.hasStartForm, processDefinitionKey = dataObj.key, tenantId = dataObj.tenantId, - defaultEntry = processEntry?.defaultEntry, + defaultEntries = processEntry?.defaultEntries ?: emptyList(), ) } diff --git a/listview/src/main/kotlin/com/alfresco/content/listview/EntryListener.kt b/listview/src/main/kotlin/com/alfresco/content/listview/EntryListener.kt index eddc3fd61..8fc392ba4 100644 --- a/listview/src/main/kotlin/com/alfresco/content/listview/EntryListener.kt +++ b/listview/src/main/kotlin/com/alfresco/content/listview/EntryListener.kt @@ -15,5 +15,5 @@ interface EntryListener { /** * It will get called on tap of start workflow on the option list */ - fun onProcessStart(entry: ParentEntry) {} + fun onProcessStart(entry: List) {} } diff --git a/listview/src/main/kotlin/com/alfresco/content/listview/ListFragment.kt b/listview/src/main/kotlin/com/alfresco/content/listview/ListFragment.kt index 580df63af..b8a3abf7f 100644 --- a/listview/src/main/kotlin/com/alfresco/content/listview/ListFragment.kt +++ b/listview/src/main/kotlin/com/alfresco/content/listview/ListFragment.kt @@ -86,12 +86,12 @@ abstract class ListViewModel( viewModelScope.on { updateActionEntries(it.entry, it.entries) } viewModelScope.on { updateActionEntries(it.entry, it.entries) } viewModelScope.on { onMove(it) } - viewModelScope.on { onStartProcess(it.entry) } + viewModelScope.on { onStartProcess(it.entries.ifEmpty { listOf(it.entry) }) } } - private fun onStartProcess(entry: Entry) = entry.run { - if (entry.isFile) { - folderListener?.onProcessStart(entry) + private fun onStartProcess(entries: List) = entries.run { + if (entries.all { it.isFile }) { + folderListener?.onProcessStart(entries) } }