Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MobileApps-1781 #224

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ProcessesFragment : ProcessListFragment<ProcessesViewModel, ProcessesViewS

override fun invalidate() = withState(viewModel) { state ->
super.invalidate()
filterTitle.text = viewModel.filterName
filterTitle.text = requireContext().getLocalizedName(viewModel.filterName)
rlFilters.contentDescription = getString(R.string.text_filter_option, viewModel.filterName)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,12 +26,12 @@ class ProcessesViewModel(
) : ProcessListViewModel<ProcessesViewState>(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 {
Expand Down Expand Up @@ -71,7 +72,7 @@ class ProcessesViewModel(

override fun emptyMessageArgs(state: ProcessListViewState): Triple<Int, Int, Int> {
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)
}
}
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions browse/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,6 @@
<string name="title_tasks">Tasks</string>
<string name="title_workflows">Workflows</string>
<string name="text_filter_option">Filter Option %s</string>
<string name="workflows_account_not_configured">Workflows are not enabled for this account.</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@ 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
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
Expand Down Expand Up @@ -132,7 +138,11 @@ abstract class ProcessListFragment<VM : ProcessListViewModel<S>, 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")
Expand All @@ -141,6 +151,7 @@ abstract class ProcessListFragment<VM : ProcessListViewModel<S>, S : ProcessList
message(args.third)
}
} else if (state.processEntries.isNotEmpty()) {
visibleFilters(true)
state.processEntries.forEach {
listViewProcessRow {
id(it.id)
Expand All @@ -151,4 +162,12 @@ abstract class ProcessListFragment<VM : ProcessListViewModel<S>, S : ProcessList
}
}
}

private fun visibleFilters(isVisible: Boolean) {
GlobalScope.launch {
withContext(Dispatchers.Main) {
rlFilters.visibility = if (isVisible) View.VISIBLE else View.GONE
}
}
}
}