Skip to content

Commit

Permalink
Mobileapps 1272 (#137)
Browse files Browse the repository at this point in the history
* added task navigation
  • Loading branch information
aman-alfresco authored Jul 15, 2022
1 parent efebbe4 commit b61a598
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.alfresco.content.browse.tasks
import android.os.Bundle
import android.view.View
import com.airbnb.mvrx.fragmentViewModel
import com.alfresco.content.data.AnalyticsManager
import com.alfresco.content.data.PageView
import com.alfresco.content.listview.tasks.TaskListFragment

/**
Expand All @@ -19,4 +21,9 @@ class TasksFragment : TaskListFragment<TasksViewModel, TasksViewState>() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}

override fun onResume() {
super.onResume()
AnalyticsManager().screenViewEvent(PageView.Tasks)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class TasksViewModel(

init {
fetchInitial()
withState {
if (it.sortOrder == TasksViewState.SortOrder.ByModifiedDate) {
TasksViewState.ModifiedGroup.prepare(context)
}
}
}

override fun refresh() = fetchInitial()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.alfresco.content.browse.tasks

import android.content.Context
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.Uninitialized
import com.alfresco.content.browse.R
import com.alfresco.content.data.Entry
import com.alfresco.content.data.ResponseList
import com.alfresco.content.data.TaskEntry
import com.alfresco.content.data.Tasks
import com.alfresco.content.data.Tasks.Active
import com.alfresco.content.listview.tasks.TaskListViewState
import java.time.ZonedDateTime
import java.time.temporal.ChronoField

/**
* Marked as TasksViewState class
Expand All @@ -17,6 +21,7 @@ data class TasksViewState(
override val taskEntries: List<TaskEntry> = emptyList(),
override val hasMoreItems: Boolean = false,
override val request: Async<ResponseList> = Uninitialized,
val baseTaskEntries: List<TaskEntry> = emptyList(),
val displayTask: Tasks = Active,
val loadItemsCount: Int = 0,
val page: Int = 0
Expand All @@ -40,16 +45,114 @@ data class TasksViewState(

val newTaskEntries = if (response.start != 0) {
totalLoadCount = loadItemsCount.plus(response.size)
taskEntries + taskPageEntries
baseTaskEntries + taskPageEntries
} else {
totalLoadCount = response.size
taskPageEntries
}

return copy(
taskEntries = newTaskEntries,
return copyUpdatingEntries(newTaskEntries).copy(
baseTaskEntries = taskPageEntries,
loadItemsCount = totalLoadCount,
hasMoreItems = totalLoadCount < response.total
)
}

private fun copyUpdatingEntries(newEntries: List<TaskEntry>) =
when (sortOrder) {
SortOrder.ByModifiedDate -> groupByModifiedDateReducer(newEntries)
else -> defaultReducer(newEntries)
}

/**
* set sort order depends on the different views
*/
val sortOrder: SortOrder
get() = SortOrder.ByModifiedDate

private fun defaultReducer(newEntries: List<TaskEntry>): TasksViewState =
copy(
taskEntries = newEntries
)

private fun groupByModifiedDateReducer(newEntries: List<TaskEntry>): TasksViewState {
val now = ZonedDateTime.now()
val startOfDay = now.toLocalDate().atStartOfDay(now.zone)
val startOfYesterday = startOfDay.minusDays(1)
val firstOfWeek = startOfDay.with(ChronoField.DAY_OF_WEEK, 1)
val firstOfLastWeek = firstOfWeek.minusWeeks(1)

var currentGroup = ModifiedGroup.None
val groupedList = mutableListOf<TaskEntry>()
for (entry in newEntries) {
val modified = entry.created ?: startOfDay

val targetGroup = when {
modified >= startOfDay -> ModifiedGroup.Today
modified >= startOfYesterday -> ModifiedGroup.Yesterday
modified >= firstOfWeek -> ModifiedGroup.ThisWeek
modified >= firstOfLastWeek -> ModifiedGroup.LastWeek
else -> ModifiedGroup.Older
}

if (currentGroup != targetGroup) {
currentGroup = targetGroup

groupedList.add(
TaskEntry(
id = currentGroup.title(),
type = TaskEntry.Type.GROUP,
name = currentGroup.title()
)
)
}
groupedList.add(entry)
}

return copy(
taskEntries = groupedList
)
}

/**
* Marked as ModifiedGroup enum class
*/
enum class ModifiedGroup {
Today,
Yesterday,
ThisWeek,
LastWeek,
Older,
None;

/**
* set default value for title
*/
fun title(): String {
return valueMap[this] ?: ""
}

companion object {
private val valueMap = HashMap<ModifiedGroup, String>()

/**
* fetching the sort title values from string.xml
*/
fun prepare(context: Context) {
valueMap[Today] = context.getString(R.string.modified_group_today)
valueMap[Yesterday] = context.getString(R.string.modified_group_yesterday)
valueMap[ThisWeek] = context.getString(R.string.modified_group_this_week)
valueMap[LastWeek] = context.getString(R.string.modified_group_last_week)
valueMap[Older] = context.getString(R.string.modified_group_older)
}
}
}

/**
* Marked as SortOrder enum class
*/
enum class SortOrder {
ByModifiedDate,
Default
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ enum class EventName(val value: String) {
enum class PageView(val value: String) {
Recent("PageView_Recent"),
Favorites("PageView_Favorites"),
Tasks("page_view_tasks"),
Offline("PageView_Offline"),
Browse("PageView_Browse"),
PersonalFiles("PageView_Personal files"),
Expand Down
15 changes: 13 additions & 2 deletions data/src/main/kotlin/com/alfresco/content/data/TaskEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.alfresco.content.data
import android.os.Parcelable
import com.alfresco.process.models.AssigneeInfo
import com.alfresco.process.models.TaskDataEntry
import java.time.ZonedDateTime
import kotlinx.parcelize.Parcelize

/**
Expand All @@ -12,8 +13,10 @@ import kotlinx.parcelize.Parcelize
data class TaskEntry(
val id: String = "",
val name: String = "",
val assignee: Assignee,
val priority: String = ""
val assignee: Assignee? = null,
val priority: String = "",
val created: ZonedDateTime? = null,
val type: Type = Type.UNKNOWN
) : Parcelable {
companion object {

Expand All @@ -29,6 +32,14 @@ data class TaskEntry(
)
}
}

/**
* Marked as Type enum class
*/
enum class Type {
GROUP,
UNKNOWN
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ListViewTaskRow @JvmOverloads constructor(
@ModelProp
fun setData(entry: TaskEntry) {
binding.title.text = entry.name
binding.subtitle.text = entry.assignee.name
binding.subtitle.text = entry.assignee?.name

updatePriority(entry.priority)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.airbnb.mvrx.withState
import com.alfresco.content.data.ResponseList
import com.alfresco.content.data.TaskEntry
import com.alfresco.content.listview.R
import com.alfresco.content.listview.listViewGroupHeader
import com.alfresco.content.listview.listViewMessage
import com.alfresco.content.listview.listViewPageBoundary
import com.alfresco.content.listview.listViewPageLoading
Expand Down Expand Up @@ -123,10 +124,17 @@ abstract class TaskListFragment<VM : TaskListViewModel<S>, S : TaskListViewState
}
} else if (state.taskEntries.isNotEmpty()) {
state.taskEntries.forEach {
listViewTaskRow {
id(it.id)
data(it)
compact(state.isCompact)
if (it.type == TaskEntry.Type.GROUP) {
listViewGroupHeader {
id(it.name)
title(it.name)
}
} else {
listViewTaskRow {
id(it.id)
data(it)
compact(state.isCompact)
}
}
}
}
Expand Down

0 comments on commit b61a598

Please sign in to comment.