Skip to content

Commit

Permalink
Mobileapps 1295 (#91)
Browse files Browse the repository at this point in the history
* Mobileapps 1272 (#137)

* added task navigation

* Mobileapps 1294 (#135)

* changed analytics name as per client feedback

* updated analytics name

* code merging
  • Loading branch information
aman-alfresco authored Jul 15, 2022
1 parent 666b3e3 commit 1f7f41a
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class BrowseFragment : ListFragment<BrowseViewModel, BrowseViewState>() {
if (entry.isTrashed) return

if (entry.isFolder)
AnalyticsManager().screenViewEvent(PageView.FolderName, folderName = "PageView_${entry.name}")
AnalyticsManager().screenViewEvent(PageView.PersonalFiles)

if (entry.isUpload)
entry.mimeType?.let {
Expand Down
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
}
}
35 changes: 17 additions & 18 deletions data/src/main/kotlin/com/alfresco/content/data/AnalyticsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class AnalyticsManager(val session: Session = SessionManager.requireSession) {
params.putString(Parameters.FileMimeType.value, fileMimeType)
params.putString(Parameters.FileExtension.value, fileExtension)
params.putBoolean(Parameters.Success.value, success)
params.putString(Parameters.EventName.value, EventName.FilePreview.value)
repository.logEvent(EventType.ActionEvent, params)
params.putString(Parameters.EventName.value, EventName.FilePreview.value.lowercase())
repository.logEvent(EventName.FilePreview.value.lowercase(), params)
}

/**
Expand All @@ -29,8 +29,8 @@ class AnalyticsManager(val session: Session = SessionManager.requireSession) {
val params = repository.defaultParams()
params.putString(Parameters.FileMimeType.value, fileMimeType)
params.putString(Parameters.FileExtension.value, fileExtension)
params.putString(Parameters.EventName.value, eventName.value)
repository.logEvent(EventType.ActionEvent, params)
params.putString(Parameters.EventName.value, eventName.value.lowercase())
repository.logEvent(eventName.value.lowercase(), params)
}

/**
Expand All @@ -39,17 +39,17 @@ class AnalyticsManager(val session: Session = SessionManager.requireSession) {
fun theme(name: String) {
val params = repository.defaultParams()
params.putString(Parameters.ThemeName.value, name)
params.putString(Parameters.EventName.value, EventName.ChangeTheme.value)
repository.logEvent(EventType.ActionEvent, params)
params.putString(Parameters.EventName.value, EventName.ChangeTheme.value.lowercase())
repository.logEvent(EventName.ChangeTheme.value.lowercase(), params)
}

/**
* analytics for app launch
*/
fun appLaunch() {
val params = repository.defaultParams()
params.putString(Parameters.EventName.value, EventName.AppLaunched.value)
repository.logEvent(EventType.ActionEvent, params)
params.putString(Parameters.EventName.value, EventName.AppLaunched.value.lowercase())
repository.logEvent(EventName.AppLaunched.value.lowercase(), params)
}

/**
Expand All @@ -58,8 +58,10 @@ class AnalyticsManager(val session: Session = SessionManager.requireSession) {
fun searchFacets(name: String) {
val params = repository.defaultParams()
params.putString(Parameters.FacetName.value, name)
params.putString(Parameters.EventName.value, EventName.SearchFacets.value.lowercase())
repository.logEvent(EventName.SearchFacets.value.lowercase(), params)
params.putString(Parameters.EventName.value, EventName.SearchFacets.value)
repository.logEvent(EventType.ActionEvent, params)
repository.logEvent(EventName.SearchFacets.value, params)
}

/**
Expand All @@ -68,34 +70,31 @@ class AnalyticsManager(val session: Session = SessionManager.requireSession) {
fun discardCapture() {
val params = repository.defaultParams()
params.putString(Parameters.EventName.value, EventName.DISCARD_CAPTURE.value)
repository.logEvent(EventType.ActionEvent, params)
repository.logEvent(EventName.DISCARD_CAPTURE.value, params)
}

/**
* analytics for multiple screen view
*/
fun screenViewEvent(pageViewName: PageView, noOfFiles: Int = -1, folderName: String = "") {
fun screenViewEvent(pageViewName: PageView, noOfFiles: Int = -1) {
val params = repository.defaultParams()

if (noOfFiles > -1)
params.putInt(Parameters.NumberOfFiles.value, noOfFiles)

if (pageViewName == PageView.FolderName)
params.putString(Parameters.EventName.value, folderName)
else
params.putString(Parameters.EventName.value, pageViewName.value)
repository.logEvent(EventType.ScreenView, params)
params.putString(Parameters.EventName.value, pageViewName.value.lowercase())
repository.logEvent(pageViewName.value.lowercase(), params)
}

/**
* analytics for API tracker
*/
fun apiTracker(apiName: APIEvent, status: Boolean = false, size: String = "") {
val params = repository.defaultParams()
params.putString(Parameters.EventName.value, apiName.value)
params.putString(Parameters.EventName.value, apiName.value.lowercase())
params.putBoolean(Parameters.Success.value, status)
if (size.isNotEmpty())
params.putString(Parameters.FileSize.value, size)
repository.logEvent(EventType.ApiTracker, params)
repository.logEvent(apiName.value.lowercase(), params)
}
}
Loading

0 comments on commit 1f7f41a

Please sign in to comment.