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-1902 #255

Merged
merged 6 commits into from
Jun 14, 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 @@ -24,7 +24,6 @@ import com.alfresco.content.getFormattedDate
import com.alfresco.content.getLocalizedName
import com.alfresco.content.parseDate
import com.alfresco.content.setSafeOnClickListener
import com.google.android.material.snackbar.Snackbar
import kotlin.coroutines.Continuation
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
Expand Down Expand Up @@ -107,11 +106,9 @@ internal fun ProcessDetailFragment.setListeners() {
withState(viewModel) { state ->
val entry = state.listContents.find { it.isUpload }
if (state.parent?.startedBy == null) {
Snackbar.make(
showSnackar(
binding.root,
getString(R.string.error_select_assignee),
Snackbar.LENGTH_SHORT
).show()
getString(R.string.error_select_assignee))
} else if (entry != null) {
confirmContentQueuePrompt()
} else {
Expand Down Expand Up @@ -176,7 +173,7 @@ internal fun ProcessDetailFragment.setData(state: ProcessDetailViewState) {
binding.tvDueDateTitle.text = getString(R.string.title_start_date)
binding.tvAssignedTitle.text = getString(R.string.title_started_by)
binding.tvDueDateValue.text = dataEntry?.started?.toLocalDate()?.toString()?.getFormattedDate(DATE_FORMAT_1, DATE_FORMAT_4)
binding.tvStatusValue.text = if (dataEntry?.ended != null) getString(R.string.status_completed) else getString(R.string.status_running)
binding.tvStatusValue.text = if (dataEntry?.ended != null) getString(R.string.status_completed) else getString(R.string.status_active)
binding.tvTasksValue.text = if (state.listTask.isNotEmpty()) state.listTask.size.toString() else "0"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.MavericksView
import com.airbnb.mvrx.activityViewModel
import com.airbnb.mvrx.withState
Expand Down Expand Up @@ -60,7 +62,7 @@ class TaskStatusFragment : Fragment(), MavericksView {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
AnalyticsManager().screenViewEvent(PageView.TaskStatusView)
AnalyticsManager().screenViewEvent(PageView.WorkflowTaskStatusView)

var instanceActivity: AppCompatActivity? = null
when (requireActivity()) {
Expand Down Expand Up @@ -105,10 +107,7 @@ class TaskStatusFragment : Fragment(), MavericksView {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.action_save -> {
withState(viewModel) { state ->
viewModel.updateTaskStatusAndName(state.parent?.taskFormStatus, binding.commentInput.text.toString().trim())
}
requireActivity().onBackPressed()
viewModel.saveForm()
true
}

Expand Down Expand Up @@ -156,6 +155,14 @@ class TaskStatusFragment : Fragment(), MavericksView {
}

override fun invalidate() = withState(viewModel) { state ->

binding.loading.isVisible = (state.requestSaveForm is Loading)

if (state.requestSaveForm.invoke()?.code() == 200) {
viewModel.updateTaskStatusAndName(state.parent?.taskFormStatus, binding.commentInput.text.toString().trim())
requireActivity().onBackPressed()
}

binding.tvStatus.text = state.parent?.taskFormStatus
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.alfresco.content.browse.tasks

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import com.alfresco.content.REMOTE
Expand All @@ -15,6 +16,7 @@ import com.alfresco.content.data.Entry
import com.alfresco.content.data.EventName
import com.alfresco.content.viewer.ViewerActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import java.lang.ref.WeakReference

/**
Expand Down Expand Up @@ -83,6 +85,15 @@ abstract class BaseDetailFragment : Fragment(), DeleteContentListener {
Intent(requireActivity(), LocalPreviewActivity::class.java)
.putExtra(LocalPreviewActivity.KEY_ENTRY_OBJ, contentEntry)
)

/**
* showing Snackbar
*/
fun showSnackar(snackView: View, message: String) = Snackbar.make(
snackView,
message,
Snackbar.LENGTH_SHORT
).show()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ListViewAttachmentRow @JvmOverloads constructor(
private fun actionButtonVisibility(entry: Entry) =
!entry.isLink && !entry.isUpload &&
// Child folder in offline tab
!(entry.isFolder && entry.hasOfflineStatus && !entry.isOffline)
!(entry.isFolder && entry.hasOfflineStatus && !entry.isOffline) && !entry.isReadOnly

/**
* list row click listener
Expand All @@ -97,14 +97,6 @@ class ListViewAttachmentRow @JvmOverloads constructor(
setOnClickListener(listener)
}

/**
* It will hide the delete button if it's workflow task.
*/
@ModelProp
fun setDeleteButtonVisibility(hasDeleteOption: Boolean) {
binding.deleteContentButton.isVisible = hasDeleteOption
}

/**
* delete icon click listener
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ import com.alfresco.content.common.updatePriorityView
import com.alfresco.content.component.ComponentData
import com.alfresco.content.component.ComponentType
import com.alfresco.content.component.DatePickerBuilder
import com.alfresco.content.data.AnalyticsManager
import com.alfresco.content.data.TaskEntry
import com.alfresco.content.formatDate
import com.alfresco.content.getFormattedDate
import com.alfresco.content.getLocalizedName
import com.alfresco.content.parseDate
import com.alfresco.content.setSafeOnClickListener
import com.google.android.material.button.MaterialButton
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -92,6 +95,7 @@ internal fun TaskDetailFragment.setTaskDetailAfterResponse(dataObj: TaskEntry) =
View.VISIBLE
} else View.GONE
} else {
makeOutcomes()
binding.clCompleted.visibility = View.GONE
(binding.clDueDate.layoutParams as ConstraintLayout.LayoutParams).apply {
topMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0f, resources.displayMetrics).toInt()
Expand Down Expand Up @@ -230,3 +234,26 @@ internal fun TaskDetailFragment.showTitleDescriptionComponent() = withState(view
)
}
}

internal fun TaskDetailFragment.makeOutcomes() = withState(viewModel) { state ->
if (binding.parentOutcomes.childCount == 0)
state.parent?.outcomes?.forEach { dataObj ->
val button = this.layoutInflater.inflate(R.layout.view_layout_outcomes, binding.parentOutcomes, false) as MaterialButton
button.text = requireContext().getLocalizedName(dataObj.name)
button.setOnClickListener {
withState(viewModel) { newState ->
if (viewModel.hasTaskStatusEnabled(newState) && !viewModel.hasTaskStatusValue(newState)
)
showSnackar(
binding.root,
getString(R.string.error_select_status)
)
else {
AnalyticsManager().taskFiltersEvent(dataObj.outcome)
viewModel.actionOutcome(dataObj.outcome)
}
}
}
binding.parentOutcomes.addView(button)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.alfresco.content.browse.tasks.detail

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
Expand All @@ -26,8 +25,6 @@ import com.alfresco.content.actions.ActionOpenWith
import com.alfresco.content.browse.R
import com.alfresco.content.browse.databinding.FragmentTaskDetailBinding
import com.alfresco.content.browse.databinding.ViewListCommentRowBinding
import com.alfresco.content.browse.preview.LocalPreviewActivity
import com.alfresco.content.browse.preview.LocalPreviewActivity.Companion.KEY_ENTRY_OBJ
import com.alfresco.content.browse.tasks.BaseDetailFragment
import com.alfresco.content.browse.tasks.TaskViewerActivity
import com.alfresco.content.browse.tasks.attachments.listViewAttachmentRow
Expand Down Expand Up @@ -89,7 +86,7 @@ class TaskDetailFragment : BaseDetailFragment(), MavericksView, EntryListener {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
AnalyticsManager().screenViewEvent(PageView.TaskView)
AnalyticsManager().screenViewEvent(if (viewModel.isWorkflowTask) PageView.WorkflowTaskView else PageView.TaskView)
(requireActivity() as TaskViewerActivity).setSupportActionBar(binding.toolbar)
withState(viewModel) { state ->
if (!viewModel.isWorkflowTask && !viewModel.isTaskCompleted(state)) {
Expand Down Expand Up @@ -177,7 +174,8 @@ class TaskDetailFragment : BaseDetailFragment(), MavericksView, EntryListener {
(state.requestComments is Loading && state.listComments.isEmpty()) ||
(state.requestContents is Loading && state.listContents.isEmpty()) ||
(state.requestCompleteTask is Loading) || (state.requestUpdateTask is Loading) ||
(state.requestDeleteContent is Loading) || (state.requestTaskForm is Loading)
(state.requestDeleteContent is Loading) || (state.requestTaskForm is Loading) ||
(state.requestOutcomes is Loading)

setData(state)

Expand All @@ -186,7 +184,7 @@ class TaskDetailFragment : BaseDetailFragment(), MavericksView, EntryListener {
binding.completeButton.visibility = if (viewModel.isCompleteButtonVisible(state)) View.VISIBLE else View.GONE

when {
state.requestCompleteTask.invoke()?.code() == 200 -> {
(state.requestCompleteTask.invoke()?.code() == 200) || (state.requestOutcomes.invoke()?.code() == 200) -> {
viewModel.updateTaskList()
requireActivity().onBackPressed()
}
Expand Down Expand Up @@ -284,7 +282,6 @@ class TaskDetailFragment : BaseDetailFragment(), MavericksView, EntryListener {
listViewAttachmentRow {
id(stableId(obj))
data(obj)
deleteButtonVisibility(!viewModel.isWorkflowTask)
clickListener { model, _, _, _ -> onItemClicked(model.data()) }
deleteContentClickListener { model, _, _, _ -> deleteContentPrompt(model.data()) }
}
Expand Down Expand Up @@ -318,10 +315,7 @@ class TaskDetailFragment : BaseDetailFragment(), MavericksView, EntryListener {
remoteViewerIntent(entry)
else
viewModel.executePreview(ActionOpenWith(entry))
} else startActivity(
Intent(requireActivity(), LocalPreviewActivity::class.java)
.putExtra(KEY_ENTRY_OBJ, contentEntry)
)
} else localViewerIntent(contentEntry)
}

internal fun taskCompletePrompt(filesInQueue: Boolean) {
Expand Down Expand Up @@ -361,10 +355,7 @@ class TaskDetailFragment : BaseDetailFragment(), MavericksView, EntryListener {

override fun onEntryCreated(entry: ParentEntry) {
if (isAdded)
startActivity(
Intent(requireActivity(), LocalPreviewActivity::class.java)
.putExtra(KEY_ENTRY_OBJ, entry as Entry)
)
localViewerIntent(entry as Entry)
}

internal suspend fun showComponentSheetDialog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,56 @@ class TaskDetailViewModel(
}
}

/**
* execute the outcome api
*/
fun actionOutcome(outcome: String) = withState { state ->
requireNotNull(state.parent)
viewModelScope.launch {
repository::actionOutcomes.asFlow(outcome, state.parent).execute {
when (it) {
is Loading -> copy(requestOutcomes = Loading())
is Fail -> {
copy(requestOutcomes = Fail(it.error))
}

is Success -> {
copy(requestOutcomes = Success(it()))
}

else -> {
this
}
}
}
}
}

/**
* execute the save-form api
*/
fun saveForm() = withState { state ->
requireNotNull(state.parent)
viewModelScope.launch {
repository::saveForm.asFlow(state.parent).execute {
when (it) {
is Loading -> copy(requestSaveForm = Loading())
is Fail -> {
copy(requestSaveForm = Fail(it.error))
}

is Success -> {
copy(requestSaveForm = Success(it()))
}

else -> {
this
}
}
}
}
}

companion object : MavericksViewModelFactory<TaskDetailViewModel, TaskDetailViewState> {

override fun create(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.alfresco.content.browse.tasks.detail

import com.alfresco.content.actions.Action
import com.alfresco.content.browse.processes.list.UpdateProcessData
import com.alfresco.content.browse.tasks.list.UpdateTasksData
import com.alfresco.content.data.Entry
import com.alfresco.content.data.OfflineRepository
Expand All @@ -15,6 +16,7 @@ import kotlinx.coroutines.launch
internal fun TaskDetailViewModel.updateTaskList() {
viewModelScope.launch {
EventBus.default.send(UpdateTasksData(isRefresh = true))
EventBus.default.send(UpdateProcessData(isRefresh = true))
}
}

Expand Down Expand Up @@ -49,6 +51,11 @@ fun TaskDetailViewModel.isCompleteButtonVisible(state: TaskDetailViewState): Boo
return state.parent?.assignee?.id == repository.getAPSUser().id
}

/**
* returns true if taskFormStatus has value otherwise false
*/
fun TaskDetailViewModel.hasTaskStatusValue(state: TaskDetailViewState) = state.parent?.taskFormStatus != state.parent?.statusOption?.find { option -> option.id == "empty" }?.name

/**
* return true if uploading files are in queue otherwise false
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ data class TaskDetailViewState(
val requestAddComment: Async<CommentEntry> = Uninitialized,
val requestCompleteTask: Async<Response<Unit>> = Uninitialized,
val requestDeleteContent: Async<Response<Unit>> = Uninitialized,
val requestTaskForm: Async<ResponseListForm> = Uninitialized
val requestTaskForm: Async<ResponseListForm> = Uninitialized,
val requestOutcomes: Async<Response<Unit>> = Uninitialized,
val requestSaveForm: Async<Response<Unit>> = Uninitialized
) : MavericksState {

constructor(target: TaskEntry) : this(parent = target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class TasksFragment : TaskListFragment<TasksViewModel, TasksViewState>() {
) = continuation.resume(ComponentMetaData(name = name, query = query, queryMap = queryMap))

override fun onItemClicked(entry: TaskEntry) {
if (viewModel.isWorkflowTask) return
startActivity(
Intent(requireActivity(), TaskViewerActivity::class.java)
.putExtra(Mavericks.KEY_ARG, entry)
Expand Down
10 changes: 10 additions & 0 deletions browse/src/main/res/layout/fragment_task_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -820,4 +820,14 @@
android:text="@string/text_mark_as_complete"
android:visibility="gone" />

<LinearLayout
android:id="@+id/parent_outcomes"
android:layout_width="match_parent"
android:layout_marginStart="@dimen/list_layout_margin_button"
android:layout_marginEnd="@dimen/list_layout_margin_button"
android:layout_marginBottom="@dimen/list_layout_margin_button"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:layout_height="wrap_content"/>

</RelativeLayout>
Loading