1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-1015 Editor | Analytics | Description split (#141)

This commit is contained in:
Konstantin Ivanov 2023-07-07 12:57:34 +02:00 committed by GitHub
parent 79f5603a7e
commit f71e37cc7c
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 92 deletions

View file

@ -474,16 +474,6 @@ class BlockAdapter(
ItemBlockDescriptionBinding.inflate(inflater, parent, false)
).apply {
with(content) {
enableEnterKeyDetector(
onEnterClicked = { range ->
onDescriptionEnterKeyListener(
views = views,
textView = content,
range = range,
onKeyPressedEvent = onKeyPressedEvent
)
}
)
addTextChangedListener(
DefaultTextWatcher { editable ->
val pos = bindingAdapterPosition

View file

@ -2,7 +2,6 @@ package com.anytypeio.anytype.core_ui.features.editor.holders.text
import android.view.Gravity
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.anytypeio.anytype.core_ui.R
import com.anytypeio.anytype.core_ui.databinding.ItemBlockDescriptionBinding
import com.anytypeio.anytype.core_ui.features.editor.BlockViewDiffUtil
@ -115,27 +114,6 @@ class Description(val binding: ItemBlockDescriptionBinding) : BlockViewHolder(bi
binding.tvBlockDescription.enableEditMode()
}
fun onDescriptionEnterKeyListener(
views: List<BlockView>,
textView: TextView,
range: IntRange,
onKeyPressedEvent: (KeyPressedEvent) -> Unit
) {
val pos = bindingAdapterPosition
val text = textView.text.toString()
if (pos != RecyclerView.NO_POSITION) {
val view = views[pos]
check(view is BlockView.Title)
onKeyPressedEvent.invoke(
KeyPressedEvent.OnDescriptionBlockEnterKeyEvent(
target = view.id,
text = text,
range = range
)
)
}
}
private fun setupContentPadding(isTodoLayout: Boolean) {
if (isTodoLayout) {
val lr = itemView.context.dimen(R.dimen.dp_40).toInt()

View file

@ -1366,12 +1366,14 @@ class EditorViewModel(
text: String,
range: IntRange
) {
Timber.d("onSplitObjectDescription, target:[$target] text:[$text] range:[$range]")
proceedWithSplitEvent(
target = target,
text = text,
range = range,
marks = emptyList()
)
viewModelScope.sendAnalyticsSetDescriptionEvent(analytics, analyticsContext)
}
private fun proceedWithEnterEvent(
@ -5333,14 +5335,6 @@ class EditorViewModel(
)
viewModelScope.sendAnalyticsSetTitleEvent(analytics, analyticsContext)
}
is KeyPressedEvent.OnDescriptionBlockEnterKeyEvent -> {
proceedWithDescriptionEnterClicked(
description = event.target,
text = event.text,
range = event.range
)
viewModelScope.sendAnalyticsSetDescriptionEvent(analytics, analyticsContext)
}
}
}
@ -5376,14 +5370,6 @@ class EditorViewModel(
)
}
}
private fun proceedWithDescriptionEnterClicked(
description: Id,
text: String,
range: IntRange
) {
proceedWithSplitEvent(description, range, text, emptyList())
}
//endregion
//region MULTI-SELECT

View file

@ -1,6 +1,5 @@
package com.anytypeio.anytype.presentation.editor.editor
import android.text.Editable
import com.anytypeio.anytype.core_models.Id
sealed class KeyPressedEvent {
@ -10,11 +9,4 @@ sealed class KeyPressedEvent {
val text: String,
val range: IntRange
) : KeyPressedEvent()
data class OnDescriptionBlockEnterKeyEvent(
val target: Id,
val text: String,
val range: IntRange
) : KeyPressedEvent()
}

View file

@ -1391,12 +1391,10 @@ class EditorSplitTest : EditorPresentationTestSetup() {
hasFocus = true
)
vm.onKeyPressedEvent(
KeyPressedEvent.OnDescriptionBlockEnterKeyEvent(
target = description.id,
text = description.content<Block.Content.Text>().text,
range = range
)
vm.onSplitObjectDescription(
target = description.id,
text = description.content<Block.Content.Text>().text,
range = range
)
coroutineTestRule.advanceTime(EditorViewModel.TEXT_CHANGES_DEBOUNCE_DURATION)
@ -1467,12 +1465,10 @@ class EditorSplitTest : EditorPresentationTestSetup() {
hasFocus = true
)
vm.onKeyPressedEvent(
KeyPressedEvent.OnDescriptionBlockEnterKeyEvent(
target = description.id,
text = description.content<Block.Content.Text>().text,
range = range
)
vm.onSplitObjectDescription(
target = description.id,
text = description.content<Block.Content.Text>().text,
range = range
)
coroutineTestRule.advanceTime(EditorViewModel.TEXT_CHANGES_DEBOUNCE_DURATION)
@ -1543,12 +1539,10 @@ class EditorSplitTest : EditorPresentationTestSetup() {
hasFocus = true
)
vm.onKeyPressedEvent(
KeyPressedEvent.OnDescriptionBlockEnterKeyEvent(
target = description.id,
text = description.content<Block.Content.Text>().text,
range = range
)
vm.onSplitObjectDescription(
target = description.id,
text = description.content<Block.Content.Text>().text,
range = range
)
coroutineTestRule.advanceTime(EditorViewModel.TEXT_CHANGES_DEBOUNCE_DURATION)
@ -1621,12 +1615,10 @@ class EditorSplitTest : EditorPresentationTestSetup() {
hasFocus = true
)
vm.onKeyPressedEvent(
KeyPressedEvent.OnDescriptionBlockEnterKeyEvent(
target = description.id,
text = description.content<Block.Content.Text>().text,
range = range
)
vm.onSplitObjectDescription(
target = description.id,
text = description.content<Block.Content.Text>().text,
range = range
)
coroutineTestRule.advanceTime(EditorViewModel.TEXT_CHANGES_DEBOUNCE_DURATION)
@ -1696,12 +1688,10 @@ class EditorSplitTest : EditorPresentationTestSetup() {
hasFocus = true
)
vm.onKeyPressedEvent(
KeyPressedEvent.OnDescriptionBlockEnterKeyEvent(
target = description.id,
text = description.content<Block.Content.Text>().text,
range = range
)
vm.onSplitObjectDescription(
target = description.id,
text = description.content<Block.Content.Text>().text,
range = range
)
coroutineTestRule.advanceTime(EditorViewModel.TEXT_CHANGES_DEBOUNCE_DURATION)
@ -1771,12 +1761,10 @@ class EditorSplitTest : EditorPresentationTestSetup() {
hasFocus = true
)
vm.onKeyPressedEvent(
KeyPressedEvent.OnDescriptionBlockEnterKeyEvent(
target = description.id,
text = description.content<Block.Content.Text>().text,
range = range
)
vm.onSplitObjectDescription(
target = description.id,
text = description.content<Block.Content.Text>().text,
range = range
)
coroutineTestRule.advanceTime(EditorViewModel.TEXT_CHANGES_DEBOUNCE_DURATION)