mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 13:57:10 +09:00
DROID-1684 Analytics | Views (#413)
This commit is contained in:
parent
b7ac5babe5
commit
96ab51a07a
4 changed files with 126 additions and 37 deletions
|
@ -297,9 +297,11 @@ private fun ViewersWidgetContent(
|
|||
modifier = Modifier
|
||||
.noRippleThrottledClickable {
|
||||
if (!isEditing.value) {
|
||||
|
||||
action.invoke(
|
||||
ViewersWidgetUi.Action.SetActive(
|
||||
view.id
|
||||
id = view.id,
|
||||
type = view.type
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -2023,6 +2023,8 @@ class ObjectSetViewModel(
|
|||
|
||||
// region VIEWS
|
||||
fun onViewersWidgetAction(action: ViewersWidgetUi.Action) {
|
||||
Timber.d("onViewersWidgetAction, action:[$action]")
|
||||
val state = stateReducer.state.value.dataViewState() ?: return
|
||||
when (action) {
|
||||
ViewersWidgetUi.Action.Dismiss -> {
|
||||
viewersWidgetState.value = viewersWidgetState.value.copy(
|
||||
|
@ -2037,13 +2039,21 @@ class ObjectSetViewModel(
|
|||
viewersWidgetState.value = viewersWidgetState.value.copy(isEditing = true)
|
||||
}
|
||||
is ViewersWidgetUi.Action.Delete -> {
|
||||
val state = stateReducer.state.value.dataViewState() ?: return
|
||||
viewModelScope.launch {
|
||||
val startTime = System.currentTimeMillis()
|
||||
onEvent(
|
||||
ViewerEvent.Delete(
|
||||
ctx = context,
|
||||
dv = state.dataViewBlock.id,
|
||||
viewer = action.viewer,
|
||||
onResult = {
|
||||
logEvent(
|
||||
state = state,
|
||||
analytics = analytics,
|
||||
event = ObjectStateAnalyticsEvent.REMOVE_VIEW,
|
||||
startTime = startTime
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -2053,31 +2063,51 @@ class ObjectSetViewModel(
|
|||
showViewerEditWidget()
|
||||
}
|
||||
is ViewersWidgetUi.Action.OnMove -> {
|
||||
Timber.d("onMove Viewer, from:[$action.from], to:[$action.to]")
|
||||
if (action.from == action.to) return
|
||||
val state = stateReducer.state.value.dataViewState() ?: return
|
||||
if (action.to == 0 && session.currentViewerId.value.isNullOrEmpty()) {
|
||||
session.currentViewerId.value = action.currentViews.firstOrNull()?.id
|
||||
}
|
||||
viewModelScope.launch {
|
||||
val startTime = System.currentTimeMillis()
|
||||
val type = action.currentViews[action.to].type
|
||||
viewerDelegate.onEvent(
|
||||
ViewerEvent.UpdatePosition(
|
||||
ctx = context,
|
||||
dv = state.dataViewBlock.id,
|
||||
viewer = action.currentViews[action.to].id,
|
||||
position = action.to
|
||||
position = action.to,
|
||||
onResult = {
|
||||
logEvent(
|
||||
state = state,
|
||||
analytics = analytics,
|
||||
event = ObjectStateAnalyticsEvent.REPOSITION_VIEW,
|
||||
startTime = startTime,
|
||||
type = type.formattedName
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
is ViewersWidgetUi.Action.SetActive -> {
|
||||
val startTime = System.currentTimeMillis()
|
||||
viewModelScope.launch {
|
||||
onEvent(ViewerEvent.SetActive(viewer = action.id))
|
||||
onEvent(ViewerEvent.SetActive(
|
||||
viewer = action.id,
|
||||
onResult = {
|
||||
logEvent(
|
||||
state = state,
|
||||
analytics = analytics,
|
||||
event = ObjectStateAnalyticsEvent.SWITCH_VIEW,
|
||||
startTime = startTime,
|
||||
type = action.type.formattedName
|
||||
)
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
ViewersWidgetUi.Action.Plus -> {
|
||||
val state = stateReducer.state.value.dataViewState() ?: return
|
||||
val activeView = state.viewerByIdOrFirst(session.currentViewerId.value) ?: return
|
||||
val newView = activeView.copy(
|
||||
id = "",
|
||||
|
@ -2085,19 +2115,26 @@ class ObjectSetViewModel(
|
|||
type = DVViewerType.GRID
|
||||
)
|
||||
viewModelScope.launch {
|
||||
val startTime = System.currentTimeMillis()
|
||||
viewerDelegate.onEvent(
|
||||
ViewerEvent.AddNew(
|
||||
ctx = context,
|
||||
dv = state.dataViewBlock.id,
|
||||
viewer = newView,
|
||||
action = { newViewId ->
|
||||
onResult = { newViewId ->
|
||||
logEvent(
|
||||
state = state,
|
||||
analytics = analytics,
|
||||
event = ObjectStateAnalyticsEvent.ADD_VIEW,
|
||||
startTime = startTime,
|
||||
type = newView.type.formattedName
|
||||
)
|
||||
widgetViewerId.value = newViewId
|
||||
showViewerEditWidgetForNewView()
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2187,7 +2224,8 @@ class ObjectSetViewModel(
|
|||
ViewerEvent.UpdateView(
|
||||
ctx = context,
|
||||
dv = state.dataViewBlock.id,
|
||||
viewer = viewer.copy(name = action.name)
|
||||
viewer = viewer.copy(name = action.name),
|
||||
onResult = {}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -2200,11 +2238,20 @@ class ObjectSetViewModel(
|
|||
val state = stateReducer.state.value.dataViewState() ?: return
|
||||
hideViewerEditWidget()
|
||||
viewModelScope.launch {
|
||||
val startTime = System.currentTimeMillis()
|
||||
viewerDelegate.onEvent(
|
||||
ViewerEvent.Delete(
|
||||
ctx = context,
|
||||
dv = state.dataViewBlock.id,
|
||||
viewer = action.id
|
||||
viewer = action.id,
|
||||
onResult = {
|
||||
logEvent(
|
||||
state = state,
|
||||
analytics = analytics,
|
||||
event = ObjectStateAnalyticsEvent.REMOVE_VIEW,
|
||||
startTime = startTime
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -2213,11 +2260,21 @@ class ObjectSetViewModel(
|
|||
val state = stateReducer.state.value.dataViewState() ?: return
|
||||
val viewer = state.viewerById(action.id) ?: return
|
||||
viewModelScope.launch {
|
||||
val startTime = System.currentTimeMillis()
|
||||
viewerDelegate.onEvent(
|
||||
ViewerEvent.Duplicate(
|
||||
ctx = context,
|
||||
dv = state.dataViewBlock.id,
|
||||
viewer = viewer
|
||||
viewer = viewer,
|
||||
onResult = {
|
||||
logEvent(
|
||||
state = state,
|
||||
analytics = analytics,
|
||||
event = ObjectStateAnalyticsEvent.DUPLICATE_VIEW,
|
||||
startTime = startTime,
|
||||
type = viewer.type.formattedName
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -2363,6 +2420,18 @@ class ObjectSetViewModel(
|
|||
}
|
||||
is ViewerLayoutWidgetUi.Action.Type -> {
|
||||
proceedWithUpdateViewer(
|
||||
action = {
|
||||
val startTime = System.currentTimeMillis()
|
||||
viewModelScope.launch {
|
||||
logEvent(
|
||||
state = stateReducer.state.value,
|
||||
analytics = analytics,
|
||||
event = ObjectStateAnalyticsEvent.CHANGE_VIEW_TYPE,
|
||||
startTime = startTime,
|
||||
type = action.type.formattedName
|
||||
)
|
||||
}
|
||||
},
|
||||
viewerId = viewerLayoutWidgetState.value.viewer
|
||||
) { it.copy(type = action.type) }
|
||||
}
|
||||
|
@ -2374,7 +2443,7 @@ class ObjectSetViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
private fun proceedWithUpdateViewer(viewerId: Id?, update: (DVViewer) -> DVViewer) {
|
||||
private fun proceedWithUpdateViewer(action: () -> Unit = {}, viewerId: Id?, update: (DVViewer) -> DVViewer) {
|
||||
val state = stateReducer.state.value.dataViewState() ?: return
|
||||
val viewer = state.viewerById(viewerId)
|
||||
if (viewer == null) {
|
||||
|
@ -2386,7 +2455,8 @@ class ObjectSetViewModel(
|
|||
ViewerEvent.UpdateView(
|
||||
ctx = context,
|
||||
dv = state.dataViewBlock.id,
|
||||
viewer = update.invoke(viewer)
|
||||
viewer = update.invoke(viewer),
|
||||
onResult = action
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.anytypeio.anytype.presentation.sets
|
||||
|
||||
import com.anytypeio.anytype.core_models.DVViewerType
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.presentation.sets.viewer.ViewerView
|
||||
import com.anytypeio.anytype.presentation.widgets.FromIndex
|
||||
|
@ -36,7 +37,7 @@ data class ViewersWidgetUi(
|
|||
val to: ToIndex
|
||||
) : Action()
|
||||
|
||||
data class SetActive(val id: Id) : Action()
|
||||
data class SetActive(val id: Id, val type: DVViewerType) : Action()
|
||||
|
||||
object Plus : Action()
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.anytypeio.anytype.presentation.sets.viewer
|
|||
|
||||
import com.anytypeio.anytype.analytics.base.Analytics
|
||||
import com.anytypeio.anytype.core_models.DVViewer
|
||||
import com.anytypeio.anytype.core_models.DVViewerType
|
||||
import com.anytypeio.anytype.core_models.Id
|
||||
import com.anytypeio.anytype.core_models.Payload
|
||||
import com.anytypeio.anytype.domain.base.fold
|
||||
|
@ -21,17 +20,17 @@ interface ViewerDelegate {
|
|||
}
|
||||
|
||||
sealed class ViewerEvent {
|
||||
data class Delete(val ctx: Id, val dv: Id, val viewer: Id) : ViewerEvent()
|
||||
data class Duplicate(val ctx: Id, val dv: Id, val viewer: DVViewer) : ViewerEvent()
|
||||
data class AddNew(val ctx: Id, val dv: Id, val viewer: DVViewer, val action: (String) -> Unit) :
|
||||
data class Delete(val ctx: Id, val dv: Id, val viewer: Id, val onResult: () -> Unit) : ViewerEvent()
|
||||
data class Duplicate(val ctx: Id, val dv: Id, val viewer: DVViewer, val onResult: () -> Unit) : ViewerEvent()
|
||||
data class AddNew(val ctx: Id, val dv: Id, val viewer: DVViewer, val onResult: (String) -> Unit) :
|
||||
ViewerEvent()
|
||||
|
||||
data class UpdatePosition(val ctx: Id, val dv: Id, val viewer: Id, val position: Int) :
|
||||
data class UpdatePosition(val ctx: Id, val dv: Id, val viewer: Id, val position: Int, val onResult: () -> Unit) :
|
||||
ViewerEvent()
|
||||
|
||||
data class SetActive(val viewer: Id) : ViewerEvent()
|
||||
data class SetActive(val viewer: Id, val onResult: () -> Unit) : ViewerEvent()
|
||||
|
||||
data class UpdateView(val ctx: Id, val dv: Id, val viewer: DVViewer) : ViewerEvent()
|
||||
data class UpdateView(val ctx: Id, val dv: Id, val viewer: DVViewer, val onResult: () -> Unit) : ViewerEvent()
|
||||
}
|
||||
|
||||
class DefaultViewerDelegate @Inject constructor(
|
||||
|
@ -50,44 +49,49 @@ class DefaultViewerDelegate @Inject constructor(
|
|||
is ViewerEvent.Delete -> onDelete(
|
||||
ctx = event.ctx,
|
||||
dv = event.dv,
|
||||
viewer = event.viewer
|
||||
viewer = event.viewer,
|
||||
onResult = event.onResult
|
||||
)
|
||||
|
||||
is ViewerEvent.AddNew -> onAddNew(
|
||||
ctx = event.ctx,
|
||||
dv = event.dv,
|
||||
viewer = event.viewer,
|
||||
action = event.action
|
||||
onResult = event.onResult
|
||||
)
|
||||
|
||||
is ViewerEvent.Duplicate -> onDuplicate(
|
||||
ctx = event.ctx,
|
||||
dv = event.dv,
|
||||
viewer = event.viewer
|
||||
viewer = event.viewer,
|
||||
onResult = event.onResult
|
||||
)
|
||||
|
||||
is ViewerEvent.UpdatePosition -> onUpdatePosition(
|
||||
ctx = event.ctx,
|
||||
dv = event.dv,
|
||||
viewer = event.viewer,
|
||||
position = event.position
|
||||
position = event.position,
|
||||
onResult = event.onResult
|
||||
)
|
||||
|
||||
is ViewerEvent.SetActive -> {
|
||||
session.currentViewerId.value = event.viewer
|
||||
event.onResult()
|
||||
}
|
||||
|
||||
is ViewerEvent.UpdateView -> {
|
||||
onUpdateViewer(
|
||||
ctx = event.ctx,
|
||||
dv = event.dv,
|
||||
viewer = event.viewer
|
||||
viewer = event.viewer,
|
||||
onResult = event.onResult
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun onAddNew(ctx: Id, dv: Id, viewer: DVViewer, action: (String) -> Unit) {
|
||||
private suspend fun onAddNew(ctx: Id, dv: Id, viewer: DVViewer, onResult: (String) -> Unit) {
|
||||
val params = DuplicateDataViewViewer.Params(
|
||||
context = ctx,
|
||||
target = dv,
|
||||
|
@ -97,12 +101,12 @@ class DefaultViewerDelegate @Inject constructor(
|
|||
onFailure = { Timber.e(it, "Error while adding new viewer") },
|
||||
onSuccess = { (id, payload) ->
|
||||
dispatcher.send(payload)
|
||||
action(id)
|
||||
onResult(id)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun onUpdatePosition(ctx: Id, dv: Id, viewer: Id, position: Int) {
|
||||
private suspend fun onUpdatePosition(ctx: Id, dv: Id, viewer: Id, position: Int, onResult: () -> Unit) {
|
||||
val params = SetDataViewViewerPosition.Params(
|
||||
ctx = ctx,
|
||||
dv = dv,
|
||||
|
@ -111,11 +115,14 @@ class DefaultViewerDelegate @Inject constructor(
|
|||
)
|
||||
setDataViewViewerPosition.async(params).fold(
|
||||
onFailure = { Timber.e(it, "Error while updating position") },
|
||||
onSuccess = { dispatcher.send(it) }
|
||||
onSuccess = {
|
||||
dispatcher.send(it)
|
||||
onResult()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun onDuplicate(ctx: Id, dv: Id, viewer: DVViewer) {
|
||||
private suspend fun onDuplicate(ctx: Id, dv: Id, viewer: DVViewer, onResult: () -> Unit) {
|
||||
val params = DuplicateDataViewViewer.Params(
|
||||
context = ctx,
|
||||
target = dv,
|
||||
|
@ -123,11 +130,14 @@ class DefaultViewerDelegate @Inject constructor(
|
|||
)
|
||||
duplicateDataViewViewer.async(params).fold(
|
||||
onFailure = { Timber.e(it, "Error while duplicating view") },
|
||||
onSuccess = { (_, payload) -> dispatcher.send(payload) }
|
||||
onSuccess = { (_, payload) ->
|
||||
dispatcher.send(payload)
|
||||
onResult()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun onDelete(ctx: Id, dv: Id, viewer: Id) {
|
||||
private suspend fun onDelete(ctx: Id, dv: Id, viewer: Id, onResult: () -> Unit) {
|
||||
val params = DeleteDataViewViewer.Params(
|
||||
ctx = ctx,
|
||||
dataview = dv,
|
||||
|
@ -135,11 +145,14 @@ class DefaultViewerDelegate @Inject constructor(
|
|||
)
|
||||
deleteDataViewViewer.async(params).fold(
|
||||
onFailure = { Timber.e(it, "Error while deleting view") },
|
||||
onSuccess = { dispatcher.send(it) }
|
||||
onSuccess = {
|
||||
dispatcher.send(it)
|
||||
onResult()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun onUpdateViewer(ctx: Id, dv: Id, viewer: DVViewer) {
|
||||
private suspend fun onUpdateViewer(ctx: Id, dv: Id, viewer: DVViewer, onResult: () -> Unit) {
|
||||
val params = UpdateDataViewViewer.Params.UpdateView(
|
||||
context = ctx,
|
||||
target = dv,
|
||||
|
@ -147,7 +160,10 @@ class DefaultViewerDelegate @Inject constructor(
|
|||
)
|
||||
updateDataViewViewer.async(params).fold(
|
||||
onFailure = { Timber.e(it, "Error while updating view") },
|
||||
onSuccess = { dispatcher.send(it) }
|
||||
onSuccess = {
|
||||
dispatcher.send(it)
|
||||
onResult()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue