Skip to content

Commit

Permalink
added message if no actions are available
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco committed Sep 18, 2024
1 parent 6ee3ebf commit cf892ef
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.alfresco.content.actions.sheet.ProcessDefinitionsSheet
import com.alfresco.content.common.EntryListener
import com.alfresco.content.data.CommonRepository.Companion.KEY_FEATURES_MOBILE
import com.alfresco.content.data.ContextualActionData
import com.alfresco.content.data.Entry
import com.alfresco.content.data.MobileConfigDataEntry
import com.alfresco.content.data.ParentEntry
import com.alfresco.content.data.getJsonFromSharedPrefs
import com.alfresco.events.on
import com.alfresco.ui.getDrawableForAttribute
import kotlinx.coroutines.delay

class ContextualActionsBarFragment : Fragment(), MavericksView, EntryListener {
private val viewModel: ContextualActionsViewModel by fragmentViewModel()
private lateinit var view: LinearLayout
var mobileConfigData: MobileConfigDataEntry? = null
var menuActionEnabled = false

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -39,6 +44,10 @@ class ContextualActionsBarFragment : Fragment(), MavericksView, EntryListener {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

mobileConfigData = getJsonFromSharedPrefs<MobileConfigDataEntry>(requireContext(), KEY_FEATURES_MOBILE)
val menus = mobileConfigData?.featuresMobile?.menus ?: emptyList()
menuActionEnabled = menus.isEmpty() || menus.any { it.enabled }

lifecycleScope.on<ActionDelete> {
// delayed back to present the toast
delay(1000)
Expand All @@ -52,8 +61,10 @@ class ContextualActionsBarFragment : Fragment(), MavericksView, EntryListener {

(requireActivity() as AppCompatActivity).supportActionBar?.title = entry.name

view.removeAllViews()
addButtons(view, it.topActions, entry)
if (menuActionEnabled) {
view.removeAllViews()
addButtons(view, it.topActions, entry)
}
}

private fun addButtons(container: LinearLayout, actions: List<Action>, entry: Entry) {
Expand Down Expand Up @@ -122,7 +133,12 @@ class ContextualActionsBarFragment : Fragment(), MavericksView, EntryListener {
setImageResource(R.drawable.ic_more_vert)
setOnClickListener {
withState(viewModel) { state ->
ContextualActionsSheet.with(ContextualActionData.withEntries(state.entries)).show(childFragmentManager, null)
ContextualActionsSheet.with(
ContextualActionData.withEntries(
state.entries,
mobileConfigData = mobileConfigData,
),
).show(childFragmentManager, null)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ class ContextualActionsSheet : BottomSheetDialogFragment(), MavericksView {
setHeader(state)

binding.recyclerView.withModels {
if (state.actions.isEmpty()) {
if (state.actions == null) {
actionListLoading { id("loading") }
}
state.actions.forEach {
if (state.actions?.isEmpty() == true) {
val error = Pair(R.string.no_actions_available_title, R.string.no_actions_available_message)
viewEmptyMessage {
id("empty_message")
title(error.first)
message(error.second)
}
}
state.actions?.forEach {
val entry = it.entry as Entry
actionListRow {
id(it.title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.alfresco.content.data.Entry
data class ContextualActionsState(
val entries: List<Entry> = emptyList(),
val isMultiSelection: Boolean = false,
val actions: List<Action> = emptyList(),
val actions: List<Action>? = null,
val topActions: List<Action> = emptyList(),
val fetch: Async<Entry> = Uninitialized,
val appMenu: List<AppMenu>? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.alfresco.content.actions

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.annotation.StringRes
import com.airbnb.epoxy.ModelProp
import com.airbnb.epoxy.ModelView
import com.alfresco.content.actions.databinding.ViewEmptyMessageBinding

@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_MATCH_HEIGHT)
class ViewEmptyMessage @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) : FrameLayout(context, attrs, defStyleAttr) {

private val binding = ViewEmptyMessageBinding.inflate(LayoutInflater.from(context), this)

@ModelProp
fun setTitle(@StringRes stringRes: Int) {
binding.title.text = resources.getText(stringRes)
}

@ModelProp
fun setMessage(@StringRes stringRes: Int) {
binding.message.text = resources.getText(stringRes)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.airbnb.epoxy.ModelView
import com.alfresco.content.actions.databinding.ViewListProcessMessageBinding

@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_MATCH_HEIGHT)
class ListViewProcessErrorMessage @JvmOverloads constructor(
class ListViewErrorMessage @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ProcessDefinitionsSheet : BottomSheetDialogFragment(), MavericksView {
}
if (state.listProcessDefinitions?.isEmpty() == true) {
val args = viewModel.emptyMessageArgs()
listViewProcessErrorMessage {
listViewErrorMessage {
id("empty_message")
iconRes(args.first)
title(args.second)
Expand Down
30 changes: 30 additions & 0 deletions actions/src/main/res/layout/view_empty_message.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="8dp">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textAlignment="center"
android:textAppearance="?attr/textAppearanceHeadline6" />

<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAlignment="center"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="@color/color_on_surface_60" />

</LinearLayout>
</merge>
3 changes: 3 additions & 0 deletions actions/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,7 @@
<string name="workflows_unavailable_title">Workflows unavailable!</string>
<string name="workflow_unavailable_message">Workflows will appear here when created.</string>

<string name="no_actions_available_title">No Actions Available</string>>
<string name="no_actions_available_message">Contact your administrator for help.</string>>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ abstract class ListFragment<VM : ListViewModel<S>, S : ListViewState>(layoutID:
val menus = getJsonFromSharedPrefs<MobileConfigDataEntry>(requireContext(), KEY_FEATURES_MOBILE)?.featuresMobile
?.menus

println("ListFragment.onViewCreated === ${menus?.size}")

menuActionsEnabled = menus?.isEmpty() == true || menus?.any { it.enabled } == true

loadingAnimation = view.findViewById(R.id.loading_animation)
Expand Down Expand Up @@ -383,6 +381,11 @@ abstract class ListFragment<VM : ListViewModel<S>, S : ListViewState>(layoutID:
open fun onItemLongClicked(entry: Entry) {}

open fun onItemMoreClicked(entry: Entry) {
ContextualActionsSheet.with(ContextualActionData.withEntries(listOf(entry), mobileConfigData = getJsonFromSharedPrefs(requireContext(), KEY_FEATURES_MOBILE))).show(childFragmentManager, null)
ContextualActionsSheet.with(
ContextualActionData.withEntries(
listOf(entry),
mobileConfigData = getJsonFromSharedPrefs(requireContext(), KEY_FEATURES_MOBILE),
),
).show(childFragmentManager, null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import com.airbnb.mvrx.Mavericks
import com.airbnb.mvrx.MavericksView
import com.airbnb.mvrx.withState
import com.alfresco.content.actions.ContextualActionsBarFragment
import com.alfresco.content.data.CommonRepository.Companion.KEY_FEATURES_MOBILE
import com.alfresco.content.data.ContextualActionData
import com.alfresco.content.data.Entry
import com.alfresco.content.data.MobileConfigDataEntry
import com.alfresco.content.data.getJsonFromSharedPrefs
import com.alfresco.content.fragmentViewModelWithArgs
import com.alfresco.content.mimetype.MimeType
import com.alfresco.content.viewer.common.ChildViewerArgs
Expand Down Expand Up @@ -136,8 +139,14 @@ class ViewerFragment : Fragment(), MavericksView {
}

private fun configureActionBar(entry: Entry) {
val mobileConfigDataEntry = getJsonFromSharedPrefs<MobileConfigDataEntry>(requireContext(), KEY_FEATURES_MOBILE)
val fragment = ContextualActionsBarFragment().apply {
arguments = bundleOf(Mavericks.KEY_ARG to ContextualActionData.withEntries(listOf(entry)))
arguments = bundleOf(
Mavericks.KEY_ARG to ContextualActionData.withEntries(
listOf(entry),
mobileConfigData = mobileConfigDataEntry,
),
)
}
parentFragmentManager.beginTransaction().replace(R.id.action_list_bar, fragment).commit()
}
Expand Down

0 comments on commit cf892ef

Please sign in to comment.