diff --git a/app/src/main/java/com/alfresco/content/app/activity/MainActivity.kt b/app/src/main/java/com/alfresco/content/app/activity/MainActivity.kt index bb958ddb..ccf666aa 100644 --- a/app/src/main/java/com/alfresco/content/app/activity/MainActivity.kt +++ b/app/src/main/java/com/alfresco/content/app/activity/MainActivity.kt @@ -35,6 +35,7 @@ import com.alfresco.content.actions.ContextualActionsSheet import com.alfresco.content.activityViewModel import com.alfresco.content.app.R import com.alfresco.content.app.widget.ActionBarController +import com.alfresco.content.data.CommonRepository import com.alfresco.content.data.CommonRepository.Companion.KEY_FEATURES_MOBILE import com.alfresco.content.data.ContextualActionData import com.alfresco.content.data.Entry @@ -74,7 +75,7 @@ class MainActivity : AppCompatActivity(), MavericksView, ActionMode.Callback { private var signedOutDialog = WeakReference(null) private var isNewIntent = false private var actionMode: ActionMode? = null - var mobileConfigDataEntry: MobileConfigDataEntry? = null + private var mobileConfigDataEntry: MobileConfigDataEntry? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -87,9 +88,11 @@ class MainActivity : AppCompatActivity(), MavericksView, ActionMode.Callback { Handler(Looper.getMainLooper()).post { viewModel.entriesMultiSelection = it.selectedEntries if (it.isMultiSelectionEnabled) { + println("MainActivity.onCreate test 1") viewModel.path = it.path enableMultiSelection(it.selectedEntries) } else { + println("MainActivity.onCreate test 2") disableMultiSelection() } } @@ -199,7 +202,6 @@ class MainActivity : AppCompatActivity(), MavericksView, ActionMode.Callback { bottomNav.setupWithNavController(navController) setupActionToasts() -// MoveResultContract.addMoveIntent(Intent(this, MoveActivity::class.java)) setupDownloadNotifications() bottomNav.setOnItemSelectedListener { item -> @@ -271,6 +273,14 @@ class MainActivity : AppCompatActivity(), MavericksView, ActionMode.Callback { actionMode?.title = title + val isMultiActionsEnabled = CommonRepository().isAllMultiActionsEnabled( + mobileConfigDataEntry?.featuresMobile?.menus, + viewModel.entriesMultiSelection, + ) + + actionMode?.menu?.findItem(R.id.move)?.isEnabled = isMultiActionsEnabled + actionMode?.menu?.findItem(R.id.more_vert)?.isEnabled = isMultiActionsEnabled + actionBarController?.showHideActionBarLayout(false) bottomNav.slideBottom() if (bottomNav.isVisible) { diff --git a/data/src/main/kotlin/com/alfresco/content/data/CommonRepository.kt b/data/src/main/kotlin/com/alfresco/content/data/CommonRepository.kt index 1bcaaaac..1c03f120 100644 --- a/data/src/main/kotlin/com/alfresco/content/data/CommonRepository.kt +++ b/data/src/main/kotlin/com/alfresco/content/data/CommonRepository.kt @@ -7,6 +7,45 @@ import java.net.URL class CommonRepository(val session: Session = SessionManager.requireSession) { + private val fileMenuSingleActions = listOf( + MenuActions.OpenWith, MenuActions.Download, MenuActions.AddFavourite, MenuActions.RemoveFavourite, MenuActions.StartProcess, + MenuActions.Rename, MenuActions.Move, MenuActions.AddOffline, MenuActions.RemoveOffline, MenuActions.Trash, + ) + + private val fileMenuMultiActions = listOf( + MenuActions.AddFavourite, + MenuActions.RemoveFavourite, + MenuActions.StartProcess, + MenuActions.Move, + MenuActions.AddOffline, + MenuActions.RemoveOffline, + MenuActions.Trash, + ) + + private val folderMenuSingleActions = listOf( + MenuActions.AddFavourite, + MenuActions.RemoveFavourite, + MenuActions.Rename, + MenuActions.Move, + MenuActions.AddOffline, + MenuActions.RemoveOffline, + MenuActions.Trash, + ) + + private val folderMenuMultiActions = listOf( + MenuActions.AddFavourite, + MenuActions.RemoveFavourite, + MenuActions.Move, + MenuActions.AddOffline, + MenuActions.RemoveOffline, + MenuActions.Trash, + ) + + private val trashMenuActions = listOf( + MenuActions.PermanentlyDelete, + MenuActions.Restore, + ) + private val service: MobileConfigApi by lazy { session.createService(MobileConfigApi::class.java) } @@ -17,6 +56,72 @@ class CommonRepository(val session: Session = SessionManager.requireSession) { saveJsonToSharedPrefs(session.context, KEY_FEATURES_MOBILE, data) } + fun isAllMultiActionsEnabled(serverList: List?, entries: List = emptyList()): Boolean { + val list = mutableListOf() + + if (entries.isEmpty() || serverList?.isEmpty() == true) { + return true + } + + val hasFilesOnly = entries.all { it.isFile } + val hasTrashedFilesFolders = entries.any { it.isTrashed } + val hasFoldersOnly = entries.all { it.isFile } + + if (hasTrashedFilesFolders) { + val enabledActions = trashMenuActions.filter { menuAction -> + serverList?.any { it.id.equals(menuAction.value(), ignoreCase = true) && it.enabled } == true + } + list.addAll(enabledActions) + return list.isNotEmpty() + } else if (hasFilesOnly) { + val enabledActions = fileMenuMultiActions.filter { menuAction -> + serverList?.any { it.id.equals(menuAction.value(), ignoreCase = true) && it.enabled } == true + } + list.addAll(enabledActions) + return list.isNotEmpty() + } else if (hasFoldersOnly) { + val enabledActions = folderMenuMultiActions.filter { menuAction -> + serverList?.any { it.id.equals(menuAction.value(), ignoreCase = true) && it.enabled } == true + } + list.addAll(enabledActions) + return list.isNotEmpty() + } else { + val enabledActions = folderMenuMultiActions.filter { menuAction -> + serverList?.any { it.id.equals(menuAction.value(), ignoreCase = true) && it.enabled } == true + } + list.addAll(enabledActions) + return list.isNotEmpty() + } + } + + fun isAllSingleFileActionsEnabled(serverList: List?, entry: Entry): Boolean { + val list = mutableListOf() + + if (serverList?.isEmpty() == true) { + return true + } + + if (entry.isTrashed) { + val enabledActions = trashMenuActions.filter { menuAction -> + serverList?.any { it.id.equals(menuAction.value(), ignoreCase = true) && it.enabled } == true + } + list.addAll(enabledActions) + return list.isNotEmpty() + } else if (entry.isFile) { + val enabledActions = fileMenuSingleActions.filter { menuAction -> + serverList?.any { it.id.equals(menuAction.value(), ignoreCase = true) && it.enabled } == true + } + list.addAll(enabledActions) + return list.isNotEmpty() + } else { + val enabledActions = folderMenuSingleActions.filter { menuAction -> + serverList?.any { it.id.equals(menuAction.value(), ignoreCase = true) && it.enabled } == true + } + list.addAll(enabledActions) + return list.isNotEmpty() + } + } + companion object { const val KEY_FEATURES_MOBILE = "features_mobile" } diff --git a/data/src/main/kotlin/com/alfresco/content/data/MobileConfigDataEntry.kt b/data/src/main/kotlin/com/alfresco/content/data/MobileConfigDataEntry.kt index a9bb7c9a..78427485 100644 --- a/data/src/main/kotlin/com/alfresco/content/data/MobileConfigDataEntry.kt +++ b/data/src/main/kotlin/com/alfresco/content/data/MobileConfigDataEntry.kt @@ -12,6 +12,7 @@ data class MobileConfigDataEntry( ) : Parcelable { companion object { + fun with(configData: MobileConfigData): MobileConfigDataEntry { return MobileConfigDataEntry( featuresMobile = MobileFeatures.with(configData.featuresMobile), @@ -66,4 +67,7 @@ enum class MenuActions(val value: String) { Restore("app.menu.restore"), PermanentlyDelete("app.menu.permanentlyDelete"), StartProcess("app.menu.startProcess"), + ; + + fun value() = value.lowercase() } 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 abe97567..63742be9 100644 --- a/listview/src/main/kotlin/com/alfresco/content/listview/ListFragment.kt +++ b/listview/src/main/kotlin/com/alfresco/content/listview/ListFragment.kt @@ -33,6 +33,7 @@ import com.alfresco.content.actions.ActionStartProcess import com.alfresco.content.actions.ActionUpdateFileFolder import com.alfresco.content.actions.ContextualActionsSheet import com.alfresco.content.common.EntryListener +import com.alfresco.content.data.CommonRepository import com.alfresco.content.data.CommonRepository.Companion.KEY_FEATURES_MOBILE import com.alfresco.content.data.ContextualActionData import com.alfresco.content.data.Entry @@ -194,16 +195,10 @@ abstract class ListFragment, S : ListViewState>(layoutID: private var delayedBoundary: Boolean = false private var isViewRequiredMultiSelection = false var bottomMoveButtonLayout: ConstraintLayout? = null - var menuActionsEnabled: Boolean = false override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val menus = getJsonFromSharedPrefs(requireContext(), KEY_FEATURES_MOBILE)?.featuresMobile - ?.menus - - menuActionsEnabled = menus?.isEmpty() == true || menus?.any { it.enabled } == true - loadingAnimation = view.findViewById(R.id.loading_animation) recyclerView = view.findViewById(R.id.recycler_view) refreshLayout = view.findViewById(R.id.refresh_layout) @@ -317,6 +312,10 @@ abstract class ListFragment, S : ListViewState>(layoutID: title(it.name) } } else { + val menus = getJsonFromSharedPrefs(requireContext(), KEY_FEATURES_MOBILE)?.featuresMobile + ?.menus + val menuActionsEnabled = CommonRepository().isAllSingleFileActionsEnabled(menus, it) + listViewRow { id(stableId(it)) data(it) diff --git a/listview/src/main/kotlin/com/alfresco/content/listview/ListViewRow.kt b/listview/src/main/kotlin/com/alfresco/content/listview/ListViewRow.kt index e28f0419..f497d6a9 100644 --- a/listview/src/main/kotlin/com/alfresco/content/listview/ListViewRow.kt +++ b/listview/src/main/kotlin/com/alfresco/content/listview/ListViewRow.kt @@ -4,7 +4,6 @@ import android.content.Context import android.graphics.drawable.AnimatedVectorDrawable import android.util.AttributeSet import android.view.LayoutInflater -import android.view.View import android.view.ViewGroup import android.widget.FrameLayout import androidx.core.content.ContextCompat @@ -189,10 +188,9 @@ class ListViewRow @JvmOverloads constructor( binding.checkBox.isChecked = false if (!menuActionsEnabled) { - binding.moreButton.visibility = View.GONE - binding.moreButton.isVisible = false + binding.moreButton.isEnabled = false } else { - binding.moreButton.visibility = View.VISIBLE + binding.moreButton.isEnabled = true binding.moreButton.isVisible = actionButtonVisibility(entry) } configureOfflineStatus(entry)