Skip to content

Commit

Permalink
Mobileapps 1315 (#166)
Browse files Browse the repository at this point in the history
* added feature to update the task name and description

* added accessibility for update task name and description

* codacy correction

* removed unused code
  • Loading branch information
aman-alfresco authored Sep 21, 2022
1 parent 635f86e commit a750c53
Show file tree
Hide file tree
Showing 21 changed files with 145 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data class ActionCreateTask(

private suspend fun showCreateTaskDialog(context: Context) = withContext(Dispatchers.Main) {
suspendCoroutine {
CreateTaskDialog.Builder(context, entry.name)
CreateTaskDialog.Builder(context, false, entry)
.onSuccess { title, description ->
it.resume(CreateMetadata(title, description))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class ActionUpdateFileFolder(
}

private suspend fun showCreateFolderDialog(context: Context) = withContext(Dispatchers.Main) {
suspendCoroutine<CreateFolderMetadata?> {
suspendCoroutine {
val name = if (entry.isFile) entry.name.nameAndExtension().first else entry.name
CreateFolderDialog.Builder(context, true, name)
.onSuccess { title, description ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.alfresco.content.actions

import android.content.Context
import com.alfresco.content.data.AnalyticsManager
import com.alfresco.content.data.EventName
import com.alfresco.content.data.ParentEntry
import com.alfresco.content.data.TaskEntry
import kotlin.coroutines.cancellation.CancellationException
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
* Mark as ActionUpdateNameDescription class
*/
data class ActionUpdateNameDescription(
override var entry: TaskEntry,
override val icon: Int = R.drawable.ic_action_create_folder,
override val title: Int = R.string.action_update_task_name_description,
override val eventName: EventName = EventName.None
) : Action {
override suspend fun execute(context: Context): TaskEntry {
val result = showCreateTaskDialog(context) ?: throw CancellationException("User Cancellation")
AnalyticsManager().taskEvent(eventName)
return TaskEntry.updateTaskNameDescription(entry, result.name, result.description)
}

private suspend fun showCreateTaskDialog(context: Context) = withContext(Dispatchers.Main) {
suspendCoroutine {
CreateTaskDialog.Builder(context, true, entry)
.onSuccess { title, description ->
it.resume(CreateMetadata(title, description))
}
.onCancel { it.resume(null) }
.show()
}
}

override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as TaskEntry)
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CreateFolderDialog : DialogFragment() {
dialog?.dismiss()
}
.setPositiveButton(
if (isUpdate) getString(R.string.action_file_folder_save)
if (isUpdate) getString(R.string.action_text_save)
else getString(R.string.action_folder_create)
) { _, _ ->
onSuccess?.invoke(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import com.alfresco.content.actions.databinding.DialogCreateLayoutBinding
import com.alfresco.content.data.TaskEntry
import com.google.android.material.dialog.MaterialAlertDialogBuilder

internal typealias CreateTaskSuccessCallback = (String, String) -> Unit
Expand All @@ -34,17 +35,18 @@ class CreateTaskDialog : DialogFragment() {

var onSuccess: CreateTaskSuccessCallback? = null
var onCancel: CreateTaskCancelCallback? = null
var name: String? = null

var isUpdate: Boolean = false
var taskEntry: TaskEntry? = null
override fun onCreateDialog(savedInstanceState: Bundle?): AlertDialog =
MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.action_create_task))
.setTitle(getString(if (isUpdate) R.string.action_update_task_name_description else R.string.action_create_task))
.setNegativeButton(getString(R.string.action_folder_cancel)) { _, _ ->
onCancel?.invoke()
dialog?.dismiss()
}
.setPositiveButton(
getString(R.string.action_task_next)
if (isUpdate) getString(R.string.action_text_save)
else getString(R.string.action_task_next)
) { _, _ ->
onSuccess?.invoke(
binding.nameInput.text.toString(),
Expand Down Expand Up @@ -72,9 +74,14 @@ class CreateTaskDialog : DialogFragment() {
}
})

// Default disabled
positiveButton.isEnabled = false

if (isUpdate && taskEntry?.name != null) {
binding.nameInput.setText(taskEntry?.name)
positiveButton.isEnabled = true
} else {
// Default disabled
positiveButton.isEnabled = binding.nameInput.text.toString().isNotEmpty()
}
binding.descriptionInput.setText(taskEntry?.description)
binding.nameInput.requestFocus()
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
}
Expand All @@ -95,7 +102,8 @@ class CreateTaskDialog : DialogFragment() {
*/
data class Builder(
val context: Context,
val name: String? = null,
val isUpdate: Boolean,
val taskEntry: TaskEntry? = null,
var onSuccess: CreateTaskSuccessCallback? = null,
var onCancel: CreateTaskCancelCallback? = null
) {
Expand Down Expand Up @@ -124,7 +132,8 @@ class CreateTaskDialog : DialogFragment() {
CreateTaskDialog().apply {
onSuccess = this@Builder.onSuccess
onCancel = this@Builder.onCancel
name = this@Builder.name
isUpdate = this@Builder.isUpdate
taskEntry = this@Builder.taskEntry
}.show(fragmentManager, CreateTaskDialog::class.java.simpleName)
}
}
Expand Down
2 changes: 1 addition & 1 deletion actions/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@

<string name="action_rename_file_folder">Umbenennen</string>
<string name="action_rename_file_folder_toast">%s wurde umbenannt</string>
<string name="action_file_folder_save">Speichern</string>
<string name="action_text_save">Speichern</string>

</resources>
2 changes: 1 addition & 1 deletion actions/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@

<string name="action_rename_file_folder">Cambiar nombre</string>
<string name="action_rename_file_folder_toast">Se ha cambiado el nombre de %s</string>
<string name="action_file_folder_save">Guardar</string>
<string name="action_text_save">Guardar</string>

</resources>
2 changes: 1 addition & 1 deletion actions/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@

<string name="action_rename_file_folder">Renommer</string>
<string name="action_rename_file_folder_toast">%s a été renommé</string>
<string name="action_file_folder_save">Enregistrer</string>
<string name="action_text_save">Enregistrer</string>

</resources>
2 changes: 1 addition & 1 deletion actions/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@

<string name="action_rename_file_folder">Rinomina</string>
<string name="action_rename_file_folder_toast">%s è stato rinominato</string>
<string name="action_file_folder_save">Salva</string>
<string name="action_text_save">Salva</string>

</resources>
2 changes: 1 addition & 1 deletion actions/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@

<string name="action_rename_file_folder">Naam wijzigen</string>
<string name="action_rename_file_folder_toast">Naam van %s is gewijzigd</string>
<string name="action_file_folder_save">Opslaan</string>
<string name="action_text_save">Opslaan</string>

</resources>
3 changes: 2 additions & 1 deletion actions/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@

<string name="action_rename_file_folder">Rename</string>
<string name="action_rename_file_folder_toast">%s was renamed</string>
<string name="action_file_folder_save">Save</string>
<string name="action_text_save">Save</string>
<string name="action_menu_edit">Edit</string>
<string name="action_menu_done">Done</string>
<string name="action_update_task_name_description">Name &amp; Description</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.airbnb.mvrx.withState
import com.alfresco.content.DATE_FORMAT_1
import com.alfresco.content.DATE_FORMAT_4
import com.alfresco.content.actions.ActionOpenWith
import com.alfresco.content.actions.ActionUpdateNameDescription
import com.alfresco.content.browse.R
import com.alfresco.content.browse.databinding.FragmentTaskDetailBinding
import com.alfresco.content.browse.databinding.ViewListCommentRowBinding
Expand Down Expand Up @@ -70,7 +71,6 @@ class TaskDetailFragment : Fragment(), MavericksView, EntryListener {
private lateinit var commentViewBinding: ViewListCommentRowBinding
private val epoxyAttachmentController: AsyncEpoxyController by lazy { epoxyAttachmentController() }
private var taskCompleteConfirmationDialog = WeakReference<AlertDialog>(null)
private var saveProgressConfirmationDialog = WeakReference<AlertDialog>(null)
private var viewLayout: View? = null
private val dispatcher: CoroutineDispatcher = Dispatchers.Main
private lateinit var menuDetail: Menu
Expand Down Expand Up @@ -102,9 +102,7 @@ class TaskDetailFragment : Fragment(), MavericksView, EntryListener {
navigationContentDescription = getString(R.string.label_navigation_back)
navigationIcon = requireContext().getDrawableForAttribute(R.attr.homeAsUpIndicator)
setNavigationOnClickListener {
if (viewModel.hasTaskEditMode)
saveProgressPrompt()
else requireActivity().onBackPressed()
requireActivity().onBackPressed()
}
title = resources.getString(R.string.title_task_view)
}
Expand Down Expand Up @@ -137,9 +135,10 @@ class TaskDetailFragment : Fragment(), MavericksView, EntryListener {
true
}
R.id.action_done -> {
AnalyticsManager().taskEvent(EventName.UpdateTaskDetails)
item.isVisible = false
updateTaskDetailUI(false)
menuDetail.findItem(R.id.action_edit).isVisible = true
updateTaskDetailUI(false)
true
}
else -> super.onOptionsItemSelected(item)
Expand All @@ -150,13 +149,13 @@ class TaskDetailFragment : Fragment(), MavericksView, EntryListener {
viewModel.hasTaskEditMode = isEdit
if (isEdit) {
binding.iconTitleEdit.visibility = View.VISIBLE
binding.iconDueDateClear.visibility = View.VISIBLE
binding.iconDueDateEditClear.visibility = View.VISIBLE
binding.iconPriorityEdit.visibility = View.VISIBLE
binding.iconAssignedEdit.visibility = View.VISIBLE
binding.completeButton.isEnabled = false
} else {
binding.iconTitleEdit.visibility = View.GONE
binding.iconDueDateClear.visibility = View.INVISIBLE
binding.iconDueDateEditClear.visibility = View.INVISIBLE
binding.iconPriorityEdit.visibility = View.INVISIBLE
binding.iconAssignedEdit.visibility = View.INVISIBLE
binding.completeButton.isEnabled = true
Expand All @@ -181,6 +180,11 @@ class TaskDetailFragment : Fragment(), MavericksView, EntryListener {
binding.completeButton.setOnClickListener {
taskCompletePrompt()
}
binding.iconTitleEdit.setOnClickListener {
withState(viewModel) { state ->
viewModel.execute(ActionUpdateNameDescription(requireNotNull(state.parent)))
}
}
}

private fun navigateToCommentScreen() {
Expand All @@ -200,9 +204,11 @@ class TaskDetailFragment : Fragment(), MavericksView, EntryListener {

binding.completeButton.visibility = if (viewModel.isCompleteButtonVisible(state)) View.VISIBLE else View.GONE

if (state.requestCompleteTask.invoke()?.code() == 200) {
viewModel.updateTaskList()
requireActivity().onBackPressed()
when {
state.requestCompleteTask.invoke()?.code() == 200 -> {
viewModel.updateTaskList()
requireActivity().onBackPressed()
}
}

if (state.requestContents.complete)
Expand Down Expand Up @@ -241,8 +247,19 @@ class TaskDetailFragment : Fragment(), MavericksView, EntryListener {
val dataObj = state.parent
if (dataObj != null) {
binding.tvTaskTitle.text = dataObj.name
binding.tvDueDateValue.text =
if (dataObj.dueDate != null) dataObj.dueDate?.toLocalDate().toString().getDateZoneFormat(DATE_FORMAT_1, DATE_FORMAT_4) else requireContext().getString(R.string.empty_no_due_date)
if (dataObj.dueDate != null) {
binding.tvDueDateValue.text = dataObj.dueDate?.toLocalDate().toString().getDateZoneFormat(DATE_FORMAT_1, DATE_FORMAT_4)
binding.iconDueDateEditClear.apply {
contentDescription = context.getString(R.string.icon_due_date_clear)
setImageResource(R.drawable.ic_clear)
}
} else {
binding.tvDueDateValue.text = requireContext().getString(R.string.empty_no_due_date)
binding.iconDueDateEditClear.apply {
contentDescription = context.getString(R.string.icon_due_date_edit)
setImageResource(R.drawable.ic_edit)
}
}
binding.tvPriorityValue.updatePriorityView(dataObj.priority)
binding.tvAssignedValue.text = dataObj.assignee?.name
binding.tvIdentifierValue.text = dataObj.id
Expand Down Expand Up @@ -341,20 +358,6 @@ class TaskDetailFragment : Fragment(), MavericksView, EntryListener {
taskCompleteConfirmationDialog = WeakReference(dialog)
}

private fun saveProgressPrompt() {
val oldDialog = saveProgressConfirmationDialog.get()
if (oldDialog != null && oldDialog.isShowing) return
val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.dialog_title_save_progress))
.setMessage(getString(R.string.dialog_message_save_progress))
.setNegativeButton(getString(R.string.dialog_negative_button_task), null)
.setPositiveButton(getString(R.string.dialog_positive_button_task)) { _, _ ->
requireActivity().onBackPressed()
}
.show()
saveProgressConfirmationDialog = WeakReference(dialog)
}

override fun onEntryCreated(entry: ParentEntry) {
if (isAdded)
startActivity(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import com.airbnb.mvrx.MavericksViewModel
import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.ViewModelContext
import com.alfresco.content.actions.Action
import com.alfresco.content.actions.ActionOpenWith
import com.alfresco.content.actions.ActionUpdateNameDescription
import com.alfresco.content.data.TaskRepository
import com.alfresco.content.data.payloads.CommentPayload
import com.alfresco.content.listview.EntryListener
import com.alfresco.coroutines.asFlow
import com.alfresco.events.on
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

/**
Expand All @@ -36,6 +39,9 @@ class TaskDetailViewModel(
if (!it.entry.path.isNullOrEmpty())
entryListener?.onEntryCreated(it.entry)
}
viewModelScope.on<ActionUpdateNameDescription> {
setState { copy(parent = it.entry) }
}
}

private fun getTaskDetails() = withState { state ->
Expand Down Expand Up @@ -138,7 +144,6 @@ class TaskDetailViewModel(
is Loading -> copy(requestCompleteTask = Loading())
is Fail -> copy(requestCompleteTask = Fail(it.error))
is Success -> {

copy(requestCompleteTask = Success(it()))
}
else -> {
Expand All @@ -156,6 +161,11 @@ class TaskDetailViewModel(
this.entryListener = listener
}

/**
* It will execute while showing the dialog to update task name and description.
*/
fun execute(action: Action) = action.execute(context, GlobalScope)

companion object : MavericksViewModelFactory<TaskDetailViewModel, TaskDetailViewState> {

override fun create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class TasksFragment : TaskListFragment<TasksViewModel, TasksViewState>() {
.toInt()
)
}
contentDescription = context.getString(R.string.text_create_task)
setImageResource(R.drawable.ic_add_fab)
setOnClickListener {
val action = ActionCreateTask(TaskEntry())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.alfresco.content.listview.tasks.TaskListViewState
import com.alfresco.coroutines.asFlow
import com.alfresco.events.on
import java.text.SimpleDateFormat
import java.util.Locale
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -179,7 +180,7 @@ class TasksViewModel(

if (dateString.isNullOrEmpty()) return ""

val currentFormat = SimpleDateFormat("dd-MMM-yy")
val currentFormat = SimpleDateFormat("dd-MMM-yy", Locale.ENGLISH)
val zonedFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")

return currentFormat.parse(dateString)?.let { zonedFormat.format(it) } ?: ""
Expand Down
Loading

0 comments on commit a750c53

Please sign in to comment.