Skip to content

Commit

Permalink
fixed deletion issue and removed unused code (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco authored Jul 27, 2023
1 parent 3ade100 commit 913bf7b
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ data class ActionStartProcess(

override fun copy(_entries: List<Entry>): 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?) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ContextualActionsViewModel(
viewModelScope.on<ActionAddOffline>(block = ::updateState)
viewModelScope.on<ActionRemoveOffline>(block = ::updateState)
viewModelScope.on<ActionMoveFilesFolders>(block = ::updateState)
viewModelScope.on<ActionUpdateFileFolder>(block = ::updateState)
viewModelScope.on<ActionStartProcess>(block = ::updateState)
}

private fun buildModelSingleSelection() = withState { state ->
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Entry>): List<Entry> {
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<Entry>) = entries.isNotEmpty() && (entries.any { it.canDelete } && (entries.all { it.isFile || it.isFolder }))
143 changes: 0 additions & 143 deletions actions/src/main/kotlin/com/alfresco/content/actions/MultiAction.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class BrowseFragment : ListFragment<BrowseViewModel, BrowseViewState>() {
}

override fun onProcessStart(entries: List<ParentEntry>) {
if (isAdded && isVisible) {
if (isAdded && isVisible && isResumed) {
ProcessDefinitionsSheet.with(entries.map { it as Entry }).show(parentFragmentManager, null)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ data class ProcessDetailViewState(
if (entry == null) {
return this
}
println("data == 1 :: $entry")
println("data == 2 :: ${listContents.size}")

val list: List<Entry>
if (listContents.isNotEmpty()) {
Expand All @@ -60,7 +58,7 @@ data class ProcessDetailViewState(
list = listOf(entry)
}

return copy(baseEntries = listOf(entry), listContents = list.distinct())
return copy(baseEntries = list, listContents = list)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class ProcessDefinitionsSheet : BottomSheetDialogFragment(), MavericksView {
/**
* returns the instance of ProcessDefinitionsSheet with attached entry as bundle
*/
fun with(entrie: List<Entry> = emptyList()) = ProcessDefinitionsSheet().apply {
arguments = bundleOf(Mavericks.KEY_ARG to entrie)
fun with(entries: List<Entry> = emptyList()) = ProcessDefinitionsSheet().apply {
arguments = bundleOf(Mavericks.KEY_ARG to entries)
}
}
}
1 change: 1 addition & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
<string name="warning_message_uploading_in_progress">The upload is currently in progress. Do you want to continue without uploading?</string>
<string name="none">None</string>
<string name="title_action_mode">%d Selected</string>
<string name="message_no_internet">Please check your internet connection and Try again.</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ interface EntryListener {
/**
* It will get called on tap of start workflow on the option list
*/
fun onProcessStart(entry: List<ParentEntry>) {}
fun onProcessStart(entries: List<ParentEntry>) {}
}

0 comments on commit 913bf7b

Please sign in to comment.