From 913bf7bc4bfdee64a8b56b16930e944b8deee1f1 Mon Sep 17 00:00:00 2001 From: Amanpal Singh <87360222+aman-alfresco@users.noreply.github.com> Date: Thu, 27 Jul 2023 06:39:31 -0700 Subject: [PATCH] fixed deletion issue and removed unused code (#280) --- .../content/actions/ActionStartProcess.kt | 3 +- .../actions/ContextualActionsBarFragment.kt | 5 + .../content/actions/ContextualActionsSheet.kt | 29 +++- .../actions/ContextualActionsViewModel.kt | 3 + .../ContextualActionsViewModelExtension.kt | 11 +- .../alfresco/content/actions/MultiAction.kt | 143 ------------------ .../app/activity/MainActivityViewModel.kt | 6 +- .../alfresco/content/browse/BrowseFragment.kt | 2 +- .../content/browse/FavoritesFragment.kt | 7 - .../ProcessAttachedFilesFragment.kt | 1 - .../details/ProcessDetailFragment.kt | 3 - .../details/ProcessDetailViewState.kt | 4 +- .../sheet/ProcessDefinitionsSheet.kt | 4 +- common/src/main/res/values/strings.xml | 1 + .../content/listview/EntryListener.kt | 2 +- 15 files changed, 45 insertions(+), 179 deletions(-) delete mode 100644 actions/src/main/kotlin/com/alfresco/content/actions/MultiAction.kt 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 a0f516f5b..8d8397da3 100644 --- a/actions/src/main/kotlin/com/alfresco/content/actions/ActionStartProcess.kt +++ b/actions/src/main/kotlin/com/alfresco/content/actions/ActionStartProcess.kt @@ -29,6 +29,5 @@ data class ActionStartProcess( 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) + override fun showToast(view: View, anchorView: View?) {} } diff --git a/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsBarFragment.kt b/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsBarFragment.kt index 0407918fa..b8aec7aef 100644 --- a/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsBarFragment.kt +++ b/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsBarFragment.kt @@ -6,6 +6,7 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageButton import android.widget.LinearLayout +import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.lifecycle.lifecycleScope import com.airbnb.mvrx.MavericksView @@ -42,6 +43,10 @@ class ContextualActionsBarFragment : Fragment(), MavericksView { } override fun invalidate() = withState(viewModel) { + it.entries.first().let { entry -> + (requireActivity() as AppCompatActivity).supportActionBar?.title = entry.name + } + view.removeAllViews() addButtons(view, it.topActions) } 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 13875400e..398b95b9c 100644 --- a/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsSheet.kt +++ b/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsSheet.kt @@ -18,6 +18,7 @@ import com.alfresco.content.data.MultiSelectionData import com.alfresco.ui.BottomSheetDialogFragment import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog +import com.google.android.material.snackbar.Snackbar class ContextualActionsSheet : BottomSheetDialogFragment(), MavericksView { val viewModel: ContextualActionsViewModel by fragmentViewModel() @@ -69,18 +70,40 @@ class ContextualActionsSheet : BottomSheetDialogFragment(), MavericksView { withState(viewModel) { newState -> if (!newState.isMultiSelection) { viewModel.execute(it) + dismiss() } else { - viewModel.executeMulti(it) - MultiSelection.multiSelectionChangedFlow.tryEmit(MultiSelectionData(isMultiSelectionEnabled = false)) + executeMultiAction(it) } } - dismiss() } } } } } + private fun executeMultiAction(action: Action) { + when (viewModel.canPerformActionOverNetwork()) { + true -> { + performMultiAction(action) + dismiss() + } + + else -> { + if (action is ActionAddOffline || action is ActionRemoveOffline) { + performMultiAction(action) + dismiss() + } else { + Snackbar.make(binding.root, R.string.message_no_internet, Snackbar.LENGTH_SHORT).show() + } + } + } + } + + private fun performMultiAction(action: Action) { + viewModel.executeMulti(action) + MultiSelection.multiSelectionChangedFlow.tryEmit(MultiSelectionData(isMultiSelectionEnabled = false)) + } + companion object { fun with(contextualActionData: ContextualActionData) = ContextualActionsSheet().apply { arguments = bundleOf(Mavericks.KEY_ARG to contextualActionData) 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 7b3e48169..f5aacd682 100644 --- a/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsViewModel.kt +++ b/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsViewModel.kt @@ -35,6 +35,8 @@ class ContextualActionsViewModel( viewModelScope.on(block = ::updateState) viewModelScope.on(block = ::updateState) viewModelScope.on(block = ::updateState) + viewModelScope.on(block = ::updateState) + viewModelScope.on(block = ::updateState) } private fun buildModelSingleSelection() = withState { state -> @@ -71,6 +73,7 @@ class ContextualActionsViewModel( private fun updateState(action: Action) { setState { val entry = action.entry as Entry + ContextualActionsState( entries = if (isMultiSelection) action.entries else listOf(entry), actions = if (isMultiSelection) makeMultiActions(this) else makeActions(entry), diff --git a/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsViewModelExtension.kt b/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsViewModelExtension.kt index 282e6bc6f..bc39664c8 100644 --- a/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsViewModelExtension.kt +++ b/actions/src/main/kotlin/com/alfresco/content/actions/ContextualActionsViewModelExtension.kt @@ -1,14 +1,7 @@ package com.alfresco.content.actions import com.alfresco.content.data.Entry -import com.alfresco.content.data.OfflineStatus - -fun getFilteredEntries(entries: List): List { - val filteredEntries = entries.filter { - (!it.isUpload || it.offlineStatus == OfflineStatus.UNDEFINED) && - (it.offlineStatus == OfflineStatus.UNDEFINED || it.offlineStatus == OfflineStatus.SYNCED) - } - return filteredEntries -} +import com.alfresco.content.network.ConnectivityTracker +internal fun ContextualActionsViewModel.canPerformActionOverNetwork() = ConnectivityTracker.isActiveNetwork(context) fun isMoveDeleteAllowed(entries: List) = entries.isNotEmpty() && (entries.any { it.canDelete } && (entries.all { it.isFile || it.isFolder })) diff --git a/actions/src/main/kotlin/com/alfresco/content/actions/MultiAction.kt b/actions/src/main/kotlin/com/alfresco/content/actions/MultiAction.kt deleted file mode 100644 index f5d290cbe..000000000 --- a/actions/src/main/kotlin/com/alfresco/content/actions/MultiAction.kt +++ /dev/null @@ -1,143 +0,0 @@ -package com.alfresco.content.actions - -import android.annotation.SuppressLint -import android.content.Context -import android.view.View -import androidx.annotation.StringRes -import com.alfresco.Logger -import com.alfresco.content.data.APIEvent -import com.alfresco.content.data.AnalyticsManager -import com.alfresco.content.data.Entry -import com.alfresco.content.data.EventName -import com.alfresco.content.data.ParentEntry -import com.alfresco.content.data.UploadServerType -import com.alfresco.events.EventBus -import com.alfresco.events.on -import com.google.android.material.snackbar.Snackbar -import kotlinx.coroutines.CancellationException -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.launch -import java.net.SocketTimeoutException - -interface MultiAction { - val entry: ParentEntry - val entries: List - get() = emptyList() - val icon: Int - val title: Int - val eventName: EventName - - suspend fun execute(context: Context): List - fun copy(_entries: List): MultiAction - - fun execute( - context: Context, - scope: CoroutineScope, - ) = scope.launch { - val bus = EventBus.default - try { - val newEntry = execute(context) - val newAction = copy(newEntry) - sendAnalytics(true) - bus.send(newAction) - } catch (ex: CancellationException) { - // no-op - if (entry is Entry && (entry as Entry).uploadServer == UploadServerType.UPLOAD_TO_TASK && - ex.message == ERROR_FILE_SIZE_EXCEED - ) { - bus.send(Error(context.getString(R.string.error_file_size_exceed))) - } - } catch (ex: Exception) { - sendAnalytics(false) - bus.send(Error(ex.message ?: "")) - } catch (ex: SocketTimeoutException) { - sendAnalytics(false) - bus.send(Error(context.getString(R.string.action_timeout_error))) - } catch (ex: kotlin.Exception) { - sendAnalytics(false) - Logger.e(ex) - when (title) { - R.string.action_create_folder -> { - if (ex.message?.contains("409") == true) { - bus.send(Error(context.getString(R.string.error_duplicate_folder))) - } - } - else -> bus.send(Error(context.getString(R.string.action_generic_error))) - } - } - } - - private fun sendAnalytics(status: Boolean) { - if (title == R.string.action_create_folder) { - AnalyticsManager().apiTracker(APIEvent.NewFolder, status) - } - } - - /** - * returns the parent ID on the basis of uploading server - */ - fun getParentId(entry: Entry): String { - return when (entry.uploadServer) { - UploadServerType.DEFAULT -> entry.id - UploadServerType.UPLOAD_TO_TASK, UploadServerType.UPLOAD_TO_PROCESS -> entry.parentId ?: "" - else -> "" - } - } - - fun showToast(view: View, anchorView: View? = null) {} - - fun maxFileNameInToast(view: View) = - view.context.resources.getInteger(R.integer.action_toast_file_name_max_length) - - data class Error(val message: String) - - class Exception(string: String) : kotlin.Exception(string) - - companion object { - const val ERROR_FILE_SIZE_EXCEED = "File size exceed" - fun showActionToasts(scope: CoroutineScope, view: View?, anchorView: View? = null) { - scope.on(block = showToast(view, anchorView)) - scope.on { - if (view != null) { - showToast(view, anchorView, it.message) - } - } - } - - private fun showToast(view: View?, anchorView: View?): suspend (value: T) -> Unit { - return { action: T -> - // Don't call on backstack views - if (view != null) { - action.showToast(view, anchorView) - } - } - } - - internal fun showToast( - view: View, - anchorView: View?, - @StringRes messageResId: Int, - vararg formatArgs: String, - ) = showToast( - view, - anchorView, - view.resources.getString( - messageResId, - *formatArgs, - ), - ) - - @SuppressLint("ShowToast") - internal fun showToast( - view: View, - anchorView: View?, - message: CharSequence, - ) { - Snackbar.make( - view, - message, - Snackbar.LENGTH_LONG, - ).setAnchorView(anchorView).show() - } - } -} diff --git a/app/src/main/java/com/alfresco/content/app/activity/MainActivityViewModel.kt b/app/src/main/java/com/alfresco/content/app/activity/MainActivityViewModel.kt index 7aeb5de4b..426a52497 100644 --- a/app/src/main/java/com/alfresco/content/app/activity/MainActivityViewModel.kt +++ b/app/src/main/java/com/alfresco/content/app/activity/MainActivityViewModel.kt @@ -22,7 +22,6 @@ import com.alfresco.content.actions.ActionMoveFilesFolders import com.alfresco.content.actions.ActionRemoveOffline import com.alfresco.content.actions.ActionSyncNow import com.alfresco.content.actions.ActionUploadMedia -import com.alfresco.content.actions.getFilteredEntries import com.alfresco.content.actions.isMoveDeleteAllowed import com.alfresco.content.browse.transfer.TransferSyncNow import com.alfresco.content.data.AnalyticsManager @@ -211,9 +210,8 @@ class MainActivityViewModel( } fun moveFilesFolder() { - val filteredEntries = getFilteredEntries(entriesMultiSelection) - if (filteredEntries.isNotEmpty() && isMoveDeleteAllowed(filteredEntries)) { - execute(ActionMoveFilesFolders(Entry.withSelectedEntries(filteredEntries), filteredEntries)) + if (entriesMultiSelection.isNotEmpty() && isMoveDeleteAllowed(entriesMultiSelection)) { + execute(ActionMoveFilesFolders(Entry.withSelectedEntries(entriesMultiSelection), entriesMultiSelection)) } } 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 baa76c793..39508fad3 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/BrowseFragment.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/BrowseFragment.kt @@ -265,7 +265,7 @@ class BrowseFragment : ListFragment() { } override fun onProcessStart(entries: List) { - if (isAdded && isVisible) { + if (isAdded && isVisible && isResumed) { ProcessDefinitionsSheet.with(entries.map { it as Entry }).show(parentFragmentManager, null) } } diff --git a/browse/src/main/kotlin/com/alfresco/content/browse/FavoritesFragment.kt b/browse/src/main/kotlin/com/alfresco/content/browse/FavoritesFragment.kt index f1c8956f1..9bd23cfe2 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/FavoritesFragment.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/FavoritesFragment.kt @@ -84,11 +84,4 @@ class FavoritesFragment : Fragment() { else -> context.getString(R.string.favorites_tab_libraries) } } - - fun clearMultiSelection() { - /*val fragment = listFragments[pager.currentItem] - if (fragment is BrowseFragment && fragment.isAdded) { - fragment.clearMultiSelection() - }*/ - } } diff --git a/browse/src/main/kotlin/com/alfresco/content/browse/processes/attachments/ProcessAttachedFilesFragment.kt b/browse/src/main/kotlin/com/alfresco/content/browse/processes/attachments/ProcessAttachedFilesFragment.kt index dbff816d7..591a35204 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/processes/attachments/ProcessAttachedFilesFragment.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/processes/attachments/ProcessAttachedFilesFragment.kt @@ -103,7 +103,6 @@ class ProcessAttachedFilesFragment : BaseDetailFragment(), MavericksView, EntryL listViewAttachmentRow { id(stableId(obj)) data(obj) - clickListener { model, _, _, _ -> onItemClicked(model.data()) } deleteContentClickListener { model, _, _, _ -> onConfirmDelete(model.data().id) } } } diff --git a/browse/src/main/kotlin/com/alfresco/content/browse/processes/details/ProcessDetailFragment.kt b/browse/src/main/kotlin/com/alfresco/content/browse/processes/details/ProcessDetailFragment.kt index 5b8277f74..bbf5af62d 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/processes/details/ProcessDetailFragment.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/processes/details/ProcessDetailFragment.kt @@ -181,9 +181,6 @@ class ProcessDetailFragment : BaseDetailFragment(), MavericksView, EntryListener listViewAttachmentRow { id(stableId(obj)) data(obj) - clickListener { model, _, _, _ -> - onItemClicked(model.data()) - } deleteContentClickListener { model, _, _, _ -> onConfirmDelete(model.data().id) } } } 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 9d9adcd80..591dbaed9 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,8 +49,6 @@ data class ProcessDetailViewState( if (entry == null) { return this } - println("data == 1 :: $entry") - println("data == 2 :: ${listContents.size}") val list: List if (listContents.isNotEmpty()) { @@ -60,7 +58,7 @@ data class ProcessDetailViewState( list = listOf(entry) } - return copy(baseEntries = listOf(entry), listContents = list.distinct()) + return copy(baseEntries = list, listContents = list) } /** 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 411705fbc..f2502b8cc 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 @@ -98,8 +98,8 @@ class ProcessDefinitionsSheet : BottomSheetDialogFragment(), MavericksView { /** * returns the instance of ProcessDefinitionsSheet with attached entry as bundle */ - fun with(entrie: List = emptyList()) = ProcessDefinitionsSheet().apply { - arguments = bundleOf(Mavericks.KEY_ARG to entrie) + fun with(entries: List = emptyList()) = ProcessDefinitionsSheet().apply { + arguments = bundleOf(Mavericks.KEY_ARG to entries) } } } diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index cbc234a45..f84124ea2 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -28,4 +28,5 @@ The upload is currently in progress. Do you want to continue without uploading? None %d Selected + Please check your internet connection and Try again. 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 8fc392ba4..4afd31da1 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: List) {} + fun onProcessStart(entries: List) {} }