diff --git a/browse/src/main/kotlin/com/alfresco/content/browse/processes/list/ProcessesFragment.kt b/browse/src/main/kotlin/com/alfresco/content/browse/processes/list/ProcessesFragment.kt index 98d2a5d6d..ad66c853a 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/processes/list/ProcessesFragment.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/processes/list/ProcessesFragment.kt @@ -34,7 +34,7 @@ class ProcessesFragment : ProcessListFragment super.invalidate() - filterTitle.text = viewModel.filterName + filterTitle.text = requireContext().getLocalizedName(viewModel.filterName) rlFilters.contentDescription = getString(R.string.text_filter_option, viewModel.filterName) } diff --git a/browse/src/main/kotlin/com/alfresco/content/browse/processes/list/ProcessesViewModel.kt b/browse/src/main/kotlin/com/alfresco/content/browse/processes/list/ProcessesViewModel.kt index 431156245..3053a1074 100644 --- a/browse/src/main/kotlin/com/alfresco/content/browse/processes/list/ProcessesViewModel.kt +++ b/browse/src/main/kotlin/com/alfresco/content/browse/processes/list/ProcessesViewModel.kt @@ -10,6 +10,7 @@ import com.alfresco.content.browse.R import com.alfresco.content.data.TaskRepository import com.alfresco.content.data.payloads.ProcessFilters import com.alfresco.content.data.payloads.TaskProcessFiltersPayload +import com.alfresco.content.getLocalizedName import com.alfresco.content.listview.processes.ProcessListViewModel import com.alfresco.content.listview.processes.ProcessListViewState import com.alfresco.coroutines.asFlow @@ -25,12 +26,12 @@ class ProcessesViewModel( ) : ProcessListViewModel(state) { val listProcesses = mapOf( - ProcessFilters.All.name to ProcessFilters.All.name, - ProcessFilters.Active.name to ProcessFilters.Running.name, - ProcessFilters.Completed.name to ProcessFilters.Completed.name + ProcessFilters.All.filter to ProcessFilters.All.name, + ProcessFilters.Active.filter to ProcessFilters.Running.name, + ProcessFilters.Completed.filter to ProcessFilters.Completed.name ) - var filterName: String = ProcessFilters.Active.name + var filterName: String = ProcessFilters.Active.filter var filterValue: String = "" init { @@ -71,7 +72,7 @@ class ProcessesViewModel( override fun emptyMessageArgs(state: ProcessListViewState): Triple { return when (state.request) { - is Fail -> Triple(R.drawable.ic_empty_recent, R.string.workflows_empty_title, R.string.account_not_configured) + is Fail -> Triple(R.drawable.ic_empty_recent, R.string.workflows_empty_title, R.string.workflows_account_not_configured) else -> Triple(R.drawable.ic_empty_recent, R.string.workflows_empty_title, R.string.workflows_empty_message) } } @@ -99,8 +100,9 @@ class ProcessesViewModel( /** * Filter applied and execute api */ - fun applyFilters(key: String?) { - key?.let { + fun applyFilters(name: String?) { + val selectedKey = listProcesses.keys.find { name == context.getLocalizedName(it) } + selectedKey?.let { filterName = it filterValue = listProcesses.getValue(filterName) } diff --git a/browse/src/main/res/values/strings.xml b/browse/src/main/res/values/strings.xml index 9f41215ff..80194eef0 100644 --- a/browse/src/main/res/values/strings.xml +++ b/browse/src/main/res/values/strings.xml @@ -98,5 +98,6 @@ Tasks Workflows Filter Option %s + Workflows are not enabled for this account. diff --git a/data/src/main/kotlin/com/alfresco/content/data/payloads/TaskProcessFiltersPayload.kt b/data/src/main/kotlin/com/alfresco/content/data/payloads/TaskProcessFiltersPayload.kt index 96443ceeb..774c18e7f 100644 --- a/data/src/main/kotlin/com/alfresco/content/data/payloads/TaskProcessFiltersPayload.kt +++ b/data/src/main/kotlin/com/alfresco/content/data/payloads/TaskProcessFiltersPayload.kt @@ -52,9 +52,9 @@ data class TaskProcessFiltersPayload( /** * Marked as ProcessFilters */ -enum class ProcessFilters { - All, - Running, - Active, - Completed +enum class ProcessFilters(val filter: String) { + All("filter.option.all"), + Running("running"), + Active("filter.option.active"), + Completed("filter.option.completed") } diff --git a/listview/src/main/kotlin/com/alfresco/content/listview/processes/ProcessListFragment.kt b/listview/src/main/kotlin/com/alfresco/content/listview/processes/ProcessListFragment.kt index 83450abb3..886652862 100644 --- a/listview/src/main/kotlin/com/alfresco/content/listview/processes/ProcessListFragment.kt +++ b/listview/src/main/kotlin/com/alfresco/content/listview/processes/ProcessListFragment.kt @@ -12,10 +12,12 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import com.airbnb.epoxy.AsyncEpoxyController import com.airbnb.epoxy.EpoxyRecyclerView import com.airbnb.mvrx.Async +import com.airbnb.mvrx.Fail import com.airbnb.mvrx.Loading import com.airbnb.mvrx.MavericksState import com.airbnb.mvrx.MavericksView import com.airbnb.mvrx.MavericksViewModel +import com.airbnb.mvrx.Success import com.airbnb.mvrx.withState import com.alfresco.content.data.ProcessEntry import com.alfresco.content.data.ResponseList @@ -23,6 +25,10 @@ import com.alfresco.content.listview.EntryListener import com.alfresco.content.listview.R import com.alfresco.content.listview.listViewMessage import com.alfresco.content.simpleController +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext /** * Mark as ProcessListViewState interface @@ -132,7 +138,11 @@ abstract class ProcessListFragment, S : ProcessList } private fun epoxyController() = simpleController(viewModel) { state -> + if (state.request.complete && state.request is Fail) { + visibleFilters(false) + } if (state.processEntries.isEmpty() && state.request.complete) { + if (state.request is Success) visibleFilters(true) val args = viewModel.emptyMessageArgs(state) listViewMessage { id("empty_message") @@ -141,6 +151,7 @@ abstract class ProcessListFragment, S : ProcessList message(args.third) } } else if (state.processEntries.isNotEmpty()) { + visibleFilters(true) state.processEntries.forEach { listViewProcessRow { id(it.id) @@ -151,4 +162,12 @@ abstract class ProcessListFragment, S : ProcessList } } } + + private fun visibleFilters(isVisible: Boolean) { + GlobalScope.launch { + withContext(Dispatchers.Main) { + rlFilters.visibility = if (isVisible) View.VISIBLE else View.GONE + } + } + } }