Skip to content

Commit

Permalink
added row changes for every actions
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco committed Sep 19, 2024
1 parent 512c631 commit 7a597eb
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,7 +75,7 @@ class MainActivity : AppCompatActivity(), MavericksView, ActionMode.Callback {
private var signedOutDialog = WeakReference<AlertDialog>(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)
Expand All @@ -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()
}
}
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -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) {
Expand Down
105 changes: 105 additions & 0 deletions data/src/main/kotlin/com/alfresco/content/data/CommonRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -17,6 +56,72 @@ class CommonRepository(val session: Session = SessionManager.requireSession) {
saveJsonToSharedPrefs(session.context, KEY_FEATURES_MOBILE, data)
}

fun isAllMultiActionsEnabled(serverList: List<AppMenu>?, entries: List<Entry> = emptyList()): Boolean {
val list = mutableListOf<MenuActions>()

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<AppMenu>?, entry: Entry): Boolean {
val list = mutableListOf<MenuActions>()

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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ data class MobileConfigDataEntry(
) : Parcelable {

companion object {

fun with(configData: MobileConfigData): MobileConfigDataEntry {
return MobileConfigDataEntry(
featuresMobile = MobileFeatures.with(configData.featuresMobile),
Expand Down Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -194,16 +195,10 @@ abstract class ListFragment<VM : ListViewModel<S>, 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<MobileConfigDataEntry>(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)
Expand Down Expand Up @@ -317,6 +312,10 @@ abstract class ListFragment<VM : ListViewModel<S>, S : ListViewState>(layoutID:
title(it.name)
}
} else {
val menus = getJsonFromSharedPrefs<MobileConfigDataEntry>(requireContext(), KEY_FEATURES_MOBILE)?.featuresMobile
?.menus
val menuActionsEnabled = CommonRepository().isAllSingleFileActionsEnabled(menus, it)

listViewRow {
id(stableId(it))
data(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7a597eb

Please sign in to comment.