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-1449 #165

Merged
merged 4 commits into from
Sep 21, 2022
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 @@ -56,7 +56,7 @@ interface Action {
AnalyticsManager().apiTracker(APIEvent.NewFolder, status)
}

fun showToast(view: View, anchorView: View? = null)
fun showToast(view: View, anchorView: View? = null) {}

fun maxFileNameInToast(view: View) =
view.context.resources.getInteger(R.integer.action_toast_file_name_max_length)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.alfresco.content.actions

import android.content.Context
import android.view.View
import com.alfresco.content.data.AnalyticsManager
import com.alfresco.content.data.EventName
import com.alfresco.content.data.ParentEntry
Expand Down Expand Up @@ -40,7 +39,4 @@ data class ActionCreateTask(
}

override fun copy(_entry: ParentEntry): Action = copy(entry = _entry as TaskEntry)

override fun showToast(view: View, anchorView: View?) =
Action.showToast(view, anchorView, R.string.action_create_folder_toast, entry.name)
}
2 changes: 2 additions & 0 deletions actions/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,7 @@
<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_menu_edit">Edit</string>
<string name="action_menu_done">Done</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import android.os.Bundle
import android.text.TextUtils
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
Expand All @@ -27,6 +30,7 @@ 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.TaskViewerActivity
import com.alfresco.content.browse.tasks.attachments.listViewAttachmentRow
import com.alfresco.content.component.ComponentBuilder
import com.alfresco.content.component.ComponentData
Expand Down Expand Up @@ -66,8 +70,10 @@ 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

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -85,18 +91,78 @@ class TaskDetailFragment : Fragment(), MavericksView, EntryListener {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
AnalyticsManager().screenViewEvent(PageView.TaskView)
(requireActivity() as TaskViewerActivity).setSupportActionBar(binding.toolbar)
withState(viewModel) { state ->
if (!viewModel.isTaskCompleted(state)) {
setHasOptionsMenu(true)
}
}

binding.toolbar.apply {
navigationContentDescription = getString(R.string.label_navigation_back)
navigationIcon = requireContext().getDrawableForAttribute(R.attr.homeAsUpIndicator)
setNavigationOnClickListener { requireActivity().onBackPressed() }
setNavigationOnClickListener {
if (viewModel.hasTaskEditMode)
saveProgressPrompt()
else requireActivity().onBackPressed()
}
title = resources.getString(R.string.title_task_view)
}
binding.recyclerViewAttachments.setController(epoxyAttachmentController)

setListeners()
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.menu_task_detail, menu)
menuDetail = menu
withState(viewModel) { state ->
if (state.parent?.isNewTaskCreated == true) {
menu.findItem(R.id.action_edit).isVisible = false
menu.findItem(R.id.action_done).isVisible = true
updateTaskDetailUI(true)
} else {
menu.findItem(R.id.action_done).isVisible = false
menu.findItem(R.id.action_edit).isVisible = true
}
}
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.action_edit -> {
item.isVisible = false
updateTaskDetailUI(true)
menuDetail.findItem(R.id.action_done).isVisible = true
true
}
R.id.action_done -> {
item.isVisible = false
updateTaskDetailUI(false)
menuDetail.findItem(R.id.action_edit).isVisible = true
true
}
else -> super.onOptionsItemSelected(item)
}
}

private fun updateTaskDetailUI(isEdit: Boolean) {
viewModel.hasTaskEditMode = isEdit
if (isEdit) {
binding.iconTitleEdit.visibility = View.VISIBLE
binding.iconDueDateClear.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.iconPriorityEdit.visibility = View.INVISIBLE
binding.iconAssignedEdit.visibility = View.INVISIBLE
binding.completeButton.isEnabled = true
}
}

private fun setListeners() {
viewModel.setListener(this)
binding.tvAddComment.setOnClickListener {
Expand Down Expand Up @@ -182,7 +248,7 @@ class TaskDetailFragment : Fragment(), MavericksView, EntryListener {
binding.tvIdentifierValue.text = dataObj.id
binding.tvTaskDescription.text = if (dataObj.description.isNullOrEmpty()) requireContext().getString(R.string.empty_description) else dataObj.description

binding.tvTaskDescription.addTextViewPrefix(requireContext().getString(R.string.text_view_all)) {
binding.tvTaskDescription.addTextViewPrefix(requireContext().getString(R.string.suffix_view_all)) {
viewLifecycleOwner.lifecycleScope.launch {
showComponentSheetDialog(
requireContext(), ComponentData(
Expand All @@ -198,27 +264,20 @@ class TaskDetailFragment : Fragment(), MavericksView, EntryListener {
if (viewModel.isTaskCompleted(state)) {
binding.tvAddComment.visibility = View.GONE
binding.iconAddCommentUser.visibility = View.GONE
binding.iconCompleted.visibility = View.VISIBLE
binding.tvCompletedTitle.visibility = View.VISIBLE
binding.tvCompletedValue.visibility = View.VISIBLE
binding.clCompleted.visibility = View.VISIBLE
if (state.listComments.isEmpty()) binding.viewComment2.visibility = View.GONE else View.VISIBLE
binding.tvCompletedValue.text = dataObj.endDate?.toLocalDate().toString().getDateZoneFormat(DATE_FORMAT_1, DATE_FORMAT_4)
(binding.iconDueDate.layoutParams as ConstraintLayout.LayoutParams).apply {

(binding.clDueDate.layoutParams as ConstraintLayout.LayoutParams).apply {
topMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24f, resources.displayMetrics).toInt()
}
binding.iconStatus.visibility = View.GONE
binding.tvStatusTitle.visibility = View.GONE
binding.tvStatusValue.visibility = View.GONE
binding.clStatus.visibility = View.GONE
} else {
binding.iconCompleted.visibility = View.GONE
binding.tvCompletedTitle.visibility = View.GONE
binding.tvCompletedValue.visibility = View.GONE
(binding.iconDueDate.layoutParams as ConstraintLayout.LayoutParams).apply {
binding.clCompleted.visibility = View.GONE
(binding.clDueDate.layoutParams as ConstraintLayout.LayoutParams).apply {
topMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0f, resources.displayMetrics).toInt()
}
binding.iconStatus.visibility = View.VISIBLE
binding.tvStatusTitle.visibility = View.VISIBLE
binding.tvStatusValue.visibility = View.VISIBLE
binding.clStatus.visibility = View.VISIBLE
binding.tvStatusValue.text = getString(R.string.status_active)
}
}
Expand Down Expand Up @@ -273,15 +332,29 @@ class TaskDetailFragment : Fragment(), MavericksView, EntryListener {
val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(getString(R.string.dialog_title_complete_task))
.setMessage(getString(R.string.dialog_message_complete_task))
.setNegativeButton(getString(R.string.dialog_negative_button_complete_task), null)
.setPositiveButton(getString(R.string.dialog_positive_button_complete_task)) { _, _ ->
.setNegativeButton(getString(R.string.dialog_negative_button_task), null)
.setPositiveButton(getString(R.string.dialog_positive_button_task)) { _, _ ->
AnalyticsManager().taskEvent(EventName.TaskComplete)
viewModel.completeTask()
}
.show()
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 @@ -25,6 +25,7 @@ class TaskDetailViewModel(
) : MavericksViewModel<TaskDetailViewState>(state) {

var isAddComment = false
var hasTaskEditMode = false
var entryListener: EntryListener? = null

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ data class TaskDetailViewState(
) : MavericksState {

constructor(target: TaskEntry) : this(parent = target)

/**
* update the taskDetailObj params after getting the response from server.
*/
Expand Down
9 changes: 9 additions & 0 deletions browse/src/main/res/drawable/ic_clear.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="40dp"
android:viewportWidth="40"
android:viewportHeight="40">
<path
android:pathData="M27,14.41L25.59,13L20,18.59L14.41,13L13,14.41L18.59,20L13,25.59L14.41,27L20,21.41L25.59,27L27,25.59L21.41,20L27,14.41Z"
android:fillColor="@color/color_gray_30"/>
</vector>
10 changes: 10 additions & 0 deletions browse/src/main/res/drawable/ic_edit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="40dp"
android:viewportWidth="40"
android:viewportHeight="40">
<path
android:pathData="M25.659,11C25.409,11 25.149,11.1 24.959,11.29L23.129,13.12L26.879,16.87L28.709,15.04C29.099,14.65 29.099,14.02 28.709,13.63L26.369,11.29C26.169,11.09 25.919,11 25.659,11ZM22.059,17.02L22.979,17.94L13.919,27H12.999V26.08L22.059,17.02ZM10.999,25.25L22.059,14.19L25.809,17.94L14.749,29H10.999V25.25Z"
android:fillColor="@color/color_gray_30"
android:fillType="evenOdd"/>
</vector>
Loading