mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-11 02:13:30 +09:00
Refact | Title holders inheritance (#695)
This commit is contained in:
parent
22b9fe6ad4
commit
44cfc0c821
14 changed files with 228 additions and 267 deletions
|
@ -776,11 +776,15 @@ open class PageFragment :
|
|||
|
||||
private fun resetDocumentTitle(state: ViewState.Success) {
|
||||
state.blocks.firstOrNull { view ->
|
||||
view is BlockView.Title || view is BlockView.ProfileTitle
|
||||
view is BlockView.Title.Document || view is BlockView.Title.Profile
|
||||
}?.let { view ->
|
||||
when (view) {
|
||||
is BlockView.Title -> resetTopToolbarTitle(view.text, view.emoji, view.image)
|
||||
is BlockView.ProfileTitle -> resetTopToolbarTitle(view.text, null, view.image)
|
||||
is BlockView.Title.Document -> resetTopToolbarTitle(
|
||||
view.text,
|
||||
view.emoji,
|
||||
view.image
|
||||
)
|
||||
is BlockView.Title.Profile -> resetTopToolbarTitle(view.text, null, view.image)
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,8 +79,8 @@ abstract class BlockActionToolbar : Fragment() {
|
|||
|
||||
when (val block = getBlock()) {
|
||||
is BlockView.Paragraph -> addButtons(view, ACTIONS.TEXT)
|
||||
is BlockView.Title -> addButtons(view, ACTIONS.TEXT)
|
||||
is BlockView.ProfileTitle -> addButtons(view, ACTIONS.TEXT)
|
||||
is BlockView.Title.Document -> addButtons(view, ACTIONS.TEXT)
|
||||
is BlockView.Title.Profile -> addButtons(view, ACTIONS.TEXT)
|
||||
is BlockView.Header.One -> addButtons(view, ACTIONS.TEXT)
|
||||
is BlockView.Header.Two -> addButtons(view, ACTIONS.TEXT)
|
||||
is BlockView.Header.Three -> addButtons(view, ACTIONS.TEXT)
|
||||
|
|
|
@ -8,8 +8,8 @@ object BlockActionToolbarFactory {
|
|||
|
||||
fun newInstance(block: BlockView, dimensions: BlockDimensions) = when (block) {
|
||||
is BlockView.Paragraph -> newInstance(block, dimensions)
|
||||
is BlockView.Title -> TODO()
|
||||
is BlockView.ProfileTitle -> TODO()
|
||||
is BlockView.Title.Document -> TODO()
|
||||
is BlockView.Title.Profile -> TODO()
|
||||
is BlockView.Header.One -> newInstance(block, dimensions)
|
||||
is BlockView.Header.Two -> newInstance(block, dimensions)
|
||||
is BlockView.Header.Three -> newInstance(block, dimensions)
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.content.res.ColorStateList
|
|||
import android.text.Editable
|
||||
import android.view.View
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.postDelayed
|
||||
import com.agileburo.anytype.core_ui.extensions.avatarColor
|
||||
|
@ -26,51 +28,18 @@ import kotlinx.android.synthetic.main.item_block_title.view.title
|
|||
import kotlinx.android.synthetic.main.item_block_title_profile.view.*
|
||||
import timber.log.Timber
|
||||
|
||||
class Title(view: View) : BlockViewHolder(view), TextHolder {
|
||||
|
||||
private val icon = itemView.documentIconContainer
|
||||
private val image = itemView.imageIcon
|
||||
private val emoji = itemView.emojiIcon
|
||||
sealed class Title(view: View) : BlockViewHolder(view), TextHolder {
|
||||
|
||||
abstract val icon: FrameLayout
|
||||
abstract val image: ImageView
|
||||
override val root: View = itemView
|
||||
override val content: TextInputWidget = itemView.title
|
||||
|
||||
init {
|
||||
content.setSpannableFactory(DefaultSpannableFactory())
|
||||
}
|
||||
|
||||
fun bind(
|
||||
item: BlockView.Title,
|
||||
onTitleTextChanged: (Editable) -> Unit,
|
||||
onFocusChanged: (String, Boolean) -> Unit,
|
||||
onPageIconClicked: () -> Unit
|
||||
onFocusChanged: (String, Boolean) -> Unit
|
||||
) {
|
||||
|
||||
Timber.d("Binding title view: $item")
|
||||
|
||||
item.image?.let { url ->
|
||||
image.visible()
|
||||
Glide
|
||||
.with(image)
|
||||
.load(url)
|
||||
.centerInside()
|
||||
.circleCrop()
|
||||
.into(image)
|
||||
} ?: apply { image.setImageDrawable(null) }
|
||||
|
||||
try {
|
||||
if (item.emoji != null) {
|
||||
Glide
|
||||
.with(emoji)
|
||||
.load(Emojifier.uri(item.emoji))
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.into(emoji)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
Timber.e(e, "Could not set emoji icon")
|
||||
}
|
||||
|
||||
|
||||
setImage(item)
|
||||
if (item.mode == BlockView.Mode.READ) {
|
||||
enableReadOnlyMode()
|
||||
content.setText(item.text, TextView.BufferType.EDITABLE)
|
||||
|
@ -85,10 +54,21 @@ class Title(view: View) : BlockViewHolder(view), TextHolder {
|
|||
onFocusChanged(item.id, hasFocus)
|
||||
if (hasFocus) showKeyboard()
|
||||
}
|
||||
icon.setOnClickListener { onPageIconClicked() }
|
||||
}
|
||||
}
|
||||
|
||||
open fun setImage(item: BlockView.Title) {
|
||||
item.image?.let { url ->
|
||||
image.visible()
|
||||
Glide
|
||||
.with(image)
|
||||
.load(url)
|
||||
.centerInside()
|
||||
.circleCrop()
|
||||
.into(image)
|
||||
} ?: apply { image.setImageDrawable(null) }
|
||||
}
|
||||
|
||||
private fun showKeyboard() {
|
||||
content.postDelayed(KEYBOARD_SHOW_DELAY) {
|
||||
imm().showSoftInput(content, InputMethodManager.SHOW_IMPLICIT)
|
||||
|
@ -99,7 +79,6 @@ class Title(view: View) : BlockViewHolder(view), TextHolder {
|
|||
payloads: List<BlockViewDiffUtil.Payload>,
|
||||
item: BlockView.Title
|
||||
) {
|
||||
|
||||
Timber.d("Processing change payload $payloads for $item")
|
||||
|
||||
payloads.forEach { payload ->
|
||||
|
@ -138,131 +117,101 @@ class Title(view: View) : BlockViewHolder(view), TextHolder {
|
|||
onNonEmptyBlockBackspaceClicked: () -> Unit
|
||||
) = Unit
|
||||
|
||||
/**
|
||||
* Mention is not used in Title
|
||||
*/
|
||||
override fun getMentionImageSizeAndPadding(): Pair<Int, Int> = Pair(0, 0)
|
||||
|
||||
companion object {
|
||||
private const val EMPTY_EMOJI = ""
|
||||
}
|
||||
}
|
||||
class Document(view: View) : Title(view) {
|
||||
|
||||
class ProfileTitle(view: View) : BlockViewHolder(view), TextHolder {
|
||||
override val icon: FrameLayout = itemView.documentIconContainer
|
||||
override val image: ImageView = itemView.imageIcon
|
||||
private val emoji: ImageView = itemView.emojiIcon
|
||||
|
||||
private val icon = itemView.documentIconContainer
|
||||
private val iconText = itemView.imageText
|
||||
private val image = itemView.imageIcon
|
||||
override val root: View = itemView
|
||||
override val content: TextInputWidget = itemView.title
|
||||
|
||||
override val root: View = itemView
|
||||
override val content: TextInputWidget = itemView.title
|
||||
|
||||
init {
|
||||
content.setSpannableFactory(DefaultSpannableFactory())
|
||||
}
|
||||
|
||||
fun bind(
|
||||
item: BlockView.ProfileTitle,
|
||||
onTitleTextChanged: (Editable) -> Unit,
|
||||
onFocusChanged: (String, Boolean) -> Unit,
|
||||
onProfileIconClicked: () -> Unit
|
||||
) {
|
||||
|
||||
Timber.d("Binding profile title view: $item")
|
||||
|
||||
item.image?.let { url ->
|
||||
image.visible()
|
||||
Glide
|
||||
.with(image)
|
||||
.load(url)
|
||||
.centerInside()
|
||||
.circleCrop()
|
||||
.into(image)
|
||||
} ?: apply {
|
||||
val pos = item.text?.firstDigitByHash() ?: 0
|
||||
icon.backgroundTintList = ColorStateList.valueOf(itemView.context.avatarColor(pos))
|
||||
setIconText(item.text)
|
||||
image.setImageDrawable(null)
|
||||
init {
|
||||
content.setSpannableFactory(DefaultSpannableFactory())
|
||||
}
|
||||
|
||||
if (item.mode == BlockView.Mode.READ) {
|
||||
enableReadOnlyMode()
|
||||
content.setText(item.text, TextView.BufferType.EDITABLE)
|
||||
} else {
|
||||
enableEditMode()
|
||||
if (item.isFocused) setCursor(item)
|
||||
focus(item.isFocused)
|
||||
content.setText(item.text, TextView.BufferType.EDITABLE)
|
||||
setCursor(item)
|
||||
setupTextWatcher({ _, editable -> onTitleTextChanged(editable) }, item)
|
||||
content.setOnFocusChangeListener { _, hasFocus ->
|
||||
onFocusChanged(item.id, hasFocus)
|
||||
if (hasFocus) showKeyboard()
|
||||
fun bind(
|
||||
item: BlockView.Title.Document,
|
||||
onTitleTextChanged: (Editable) -> Unit,
|
||||
onFocusChanged: (String, Boolean) -> Unit,
|
||||
onPageIconClicked: () -> Unit
|
||||
) {
|
||||
super.bind(
|
||||
item = item,
|
||||
onTitleTextChanged = onTitleTextChanged,
|
||||
onFocusChanged = onFocusChanged
|
||||
)
|
||||
setEmoji(item)
|
||||
if (item.mode == BlockView.Mode.EDIT) {
|
||||
icon.setOnClickListener { onPageIconClicked() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun setEmoji(item: BlockView.Title.Document) {
|
||||
try {
|
||||
if (item.emoji != null) {
|
||||
Glide
|
||||
.with(emoji)
|
||||
.load(Emojifier.uri(item.emoji))
|
||||
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||
.into(emoji)
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
Timber.e(e, "Could not set emoji icon")
|
||||
}
|
||||
icon.setOnClickListener { onProfileIconClicked() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun showKeyboard() {
|
||||
content.postDelayed(KEYBOARD_SHOW_DELAY) {
|
||||
imm().showSoftInput(content, InputMethodManager.SHOW_IMPLICIT)
|
||||
class Profile(view: View) : Title(view) {
|
||||
|
||||
override val icon: FrameLayout = itemView.documentIconContainer
|
||||
override val image: ImageView = itemView.imageIcon
|
||||
override val content: TextInputWidget = itemView.title
|
||||
|
||||
private val iconText = itemView.imageText
|
||||
|
||||
init {
|
||||
content.setSpannableFactory(DefaultSpannableFactory())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mention is not used in ProfileTitle
|
||||
*/
|
||||
override fun getMentionImageSizeAndPadding(): Pair<Int, Int> = Pair(0, 0)
|
||||
fun bind(
|
||||
item: BlockView.Title.Profile,
|
||||
onTitleTextChanged: (Editable) -> Unit,
|
||||
onFocusChanged: (String, Boolean) -> Unit,
|
||||
onProfileIconClicked: () -> Unit
|
||||
) {
|
||||
Timber.d("Binding profile title view: $item")
|
||||
super.bind(item, onTitleTextChanged, onFocusChanged)
|
||||
if (item.mode == BlockView.Mode.EDIT) {
|
||||
icon.setOnClickListener { onProfileIconClicked() }
|
||||
}
|
||||
}
|
||||
|
||||
fun processPayloads(
|
||||
payloads: List<BlockViewDiffUtil.Payload>,
|
||||
item: BlockView.ProfileTitle
|
||||
) {
|
||||
|
||||
Timber.d("Processing change payload $payloads for $item")
|
||||
|
||||
payloads.forEach { payload ->
|
||||
if (payload.changes.contains(BlockViewDiffUtil.TEXT_CHANGED)) {
|
||||
override fun setImage(item: BlockView.Title) {
|
||||
item.image?.let { url ->
|
||||
image.visible()
|
||||
Glide
|
||||
.with(image)
|
||||
.load(url)
|
||||
.centerInside()
|
||||
.circleCrop()
|
||||
.into(image)
|
||||
} ?: apply {
|
||||
val pos = item.text?.firstDigitByHash() ?: 0
|
||||
icon.backgroundTintList = ColorStateList.valueOf(itemView.context.avatarColor(pos))
|
||||
setIconText(item.text)
|
||||
content.pauseTextWatchers {
|
||||
if (content.text.toString() != item.text) {
|
||||
content.setText(item.text, TextView.BufferType.EDITABLE)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (payload.isCursorChanged) {
|
||||
if (item.isFocused) setCursor(item)
|
||||
}
|
||||
if (payload.focusChanged()) {
|
||||
focus(item.isFocused)
|
||||
}
|
||||
if (payload.readWriteModeChanged()) {
|
||||
if (item.mode == BlockView.Mode.EDIT)
|
||||
enableEditMode()
|
||||
else
|
||||
enableTitleReadOnlyMode()
|
||||
image.setImageDrawable(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun focus(focused: Boolean) {
|
||||
if (focused) {
|
||||
content.requestFocus()
|
||||
showKeyboard()
|
||||
} else
|
||||
content.clearFocus()
|
||||
}
|
||||
|
||||
override fun enableBackspaceDetector(
|
||||
onEmptyBlockBackspaceClicked: () -> Unit,
|
||||
onNonEmptyBlockBackspaceClicked: () -> Unit
|
||||
) = Unit
|
||||
|
||||
private fun setIconText(name: String?) {
|
||||
if (name.isNullOrEmpty()) {
|
||||
iconText.text = ""
|
||||
} else {
|
||||
iconText.text = name.first().toUpperCase().toString()
|
||||
private fun setIconText(name: String?) {
|
||||
if (name.isNullOrEmpty()) {
|
||||
iconText.text = ""
|
||||
} else {
|
||||
iconText.text = name.first().toUpperCase().toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -94,7 +94,7 @@ class BlockAdapter(
|
|||
)
|
||||
}
|
||||
HOLDER_TITLE -> {
|
||||
Title(
|
||||
Title.Document(
|
||||
view = inflater.inflate(
|
||||
R.layout.item_block_title,
|
||||
parent,
|
||||
|
@ -103,7 +103,7 @@ class BlockAdapter(
|
|||
)
|
||||
}
|
||||
HOLDER_PROFILE_TITLE -> {
|
||||
ProfileTitle(
|
||||
Title.Profile(
|
||||
view = inflater.inflate(
|
||||
R.layout.item_block_title_profile,
|
||||
parent,
|
||||
|
@ -425,16 +425,16 @@ class BlockAdapter(
|
|||
clicked = onClickListener
|
||||
)
|
||||
}
|
||||
is Title -> {
|
||||
is Title.Document -> {
|
||||
holder.processPayloads(
|
||||
payloads = payloads.typeOf(),
|
||||
item = blocks[position] as BlockView.Title
|
||||
)
|
||||
}
|
||||
is ProfileTitle -> {
|
||||
is Title.Profile -> {
|
||||
holder.processPayloads(
|
||||
payloads = payloads.typeOf(),
|
||||
item = blocks[position] as BlockView.ProfileTitle
|
||||
item = blocks[position] as BlockView.Title.Profile
|
||||
)
|
||||
}
|
||||
is BlockViewHolder.Numbered -> {
|
||||
|
@ -614,17 +614,17 @@ class BlockAdapter(
|
|||
onMentionEvent = onMentionEvent
|
||||
)
|
||||
}
|
||||
is Title -> {
|
||||
is Title.Document -> {
|
||||
holder.bind(
|
||||
item = blocks[position] as BlockView.Title,
|
||||
item = blocks[position] as BlockView.Title.Document,
|
||||
onTitleTextChanged = onTitleTextChanged,
|
||||
onFocusChanged = onFocusChanged,
|
||||
onPageIconClicked = onPageIconClicked
|
||||
)
|
||||
}
|
||||
is ProfileTitle -> {
|
||||
is Title.Profile -> {
|
||||
holder.bind(
|
||||
item = blocks[position] as BlockView.ProfileTitle,
|
||||
item = blocks[position] as BlockView.Title.Profile,
|
||||
onTitleTextChanged = onTitleTextChanged,
|
||||
onFocusChanged = onFocusChanged,
|
||||
onProfileIconClicked = onProfileIconClicked
|
||||
|
@ -842,7 +842,7 @@ class BlockAdapter(
|
|||
}
|
||||
}
|
||||
|
||||
if (holder is Title || holder is ProfileTitle) {
|
||||
if (holder is Title.Document || holder is Title.Profile) {
|
||||
holder.enableEnterKeyDetector(
|
||||
onEndLineEnterClicked = { editable ->
|
||||
onEndLineEnterTitleClicked(editable)
|
||||
|
@ -898,7 +898,7 @@ class BlockAdapter(
|
|||
}
|
||||
)
|
||||
|
||||
if (holder is Title || holder is ProfileTitle)
|
||||
if (holder is Title.Document || holder is Title.Profile)
|
||||
holder.setOnClickListener { onTitleTextInputClicked() }
|
||||
else
|
||||
holder.setOnClickListener { onTextInputClicked(blocks[holder.adapterPosition].id) }
|
||||
|
|
|
@ -139,42 +139,50 @@ sealed class BlockView : ViewType, Parcelable {
|
|||
override val body: String get() = text
|
||||
}
|
||||
|
||||
sealed class Title : BlockView(), Focusable, Cursor, Permission {
|
||||
|
||||
abstract val image: String?
|
||||
abstract var text: String?
|
||||
|
||||
@Parcelize
|
||||
data class Document(
|
||||
override val id: String,
|
||||
override val isFocused: Boolean,
|
||||
override var text: String?,
|
||||
val emoji: String? = null,
|
||||
override val image: String? = null,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val cursor: Int? = null
|
||||
) : BlockView.Title() {
|
||||
override fun getViewType() = HOLDER_TITLE
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-model for a profile title block.
|
||||
* @property id block's id
|
||||
* @property text text content (i.e. title text)
|
||||
* @property image image as a page's logo (if present)
|
||||
*/
|
||||
@Parcelize
|
||||
data class Profile(
|
||||
override val id: String,
|
||||
override val isFocused: Boolean,
|
||||
override var text: String?,
|
||||
override val image: String? = null,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val cursor: Int? = null
|
||||
) : BlockView.Title() {
|
||||
override fun getViewType() = HOLDER_PROFILE_TITLE
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-model for a title block.
|
||||
* @property id block's id
|
||||
* @property text text content (i.e. title text)
|
||||
* @property emoji emoji as a page's logo (if present)
|
||||
*/
|
||||
@Parcelize
|
||||
data class Title(
|
||||
override val id: String,
|
||||
override val isFocused: Boolean,
|
||||
var text: String?,
|
||||
val emoji: String? = null,
|
||||
val image: String? = null,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val cursor: Int? = null
|
||||
) : BlockView(), Focusable, Cursor, Permission {
|
||||
override fun getViewType() = HOLDER_TITLE
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-model for a profile title block.
|
||||
* @property id block's id
|
||||
* @property text text content (i.e. title text)
|
||||
* @property image image as a page's logo (if present)
|
||||
*/
|
||||
@Parcelize
|
||||
data class ProfileTitle(
|
||||
override val id: String,
|
||||
override val isFocused: Boolean,
|
||||
var text: String?,
|
||||
val image: String? = null,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val cursor: Int? = null
|
||||
) : BlockView(), Focusable, Cursor, Permission {
|
||||
override fun getViewType() = HOLDER_PROFILE_TITLE
|
||||
}
|
||||
|
||||
sealed class Header() : BlockView(), Text, Markup, Cursor, Focusable, Indentable, Permission,
|
||||
Selectable, Alignable {
|
||||
|
|
|
@ -34,12 +34,12 @@ class BlockViewDiffUtil(
|
|||
|
||||
val changes = mutableListOf<Int>()
|
||||
|
||||
if (newBlock is BlockView.Title && oldBlock is BlockView.Title) {
|
||||
if (newBlock is BlockView.Title.Document && oldBlock is BlockView.Title.Document) {
|
||||
if (newBlock.text != oldBlock.text)
|
||||
changes.add(TEXT_CHANGED)
|
||||
}
|
||||
|
||||
if (newBlock is BlockView.ProfileTitle && oldBlock is BlockView.ProfileTitle) {
|
||||
if (newBlock is BlockView.Title.Profile && oldBlock is BlockView.Title.Profile) {
|
||||
if (newBlock.text != oldBlock.text)
|
||||
changes.add(TEXT_CHANGED)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.agileburo.anytype.core_ui.common.ThemeColor
|
||||
import com.agileburo.anytype.core_ui.features.editor.holders.*
|
||||
import com.agileburo.anytype.core_ui.features.editor.holders.Title.Document
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockAdapter
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockView
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewDiffUtil
|
||||
|
@ -24,7 +25,6 @@ import com.agileburo.anytype.core_ui.features.page.BlockViewDiffUtil.Companion.S
|
|||
import com.agileburo.anytype.core_ui.features.page.BlockViewDiffUtil.Companion.TEXT_CHANGED
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewDiffUtil.Companion.TEXT_COLOR_CHANGED
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewHolder
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewHolder.Companion.FOCUS_TIMEOUT_MILLIS
|
||||
import com.agileburo.anytype.core_ui.tools.ClipboardInterceptor
|
||||
import com.agileburo.anytype.core_utils.ext.dimen
|
||||
import com.agileburo.anytype.core_utils.ext.hexColorCode
|
||||
|
@ -389,7 +389,7 @@ class BlockAdapterTest {
|
|||
|
||||
// Setup
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
text = MockDataFactory.randomString(),
|
||||
id = MockDataFactory.randomUuid(),
|
||||
isFocused = false,
|
||||
|
@ -413,7 +413,7 @@ class BlockAdapterTest {
|
|||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
check(holder is Title)
|
||||
check(holder is Document)
|
||||
|
||||
// Testing
|
||||
|
||||
|
@ -651,7 +651,7 @@ class BlockAdapterTest {
|
|||
@Test
|
||||
fun `should create title view holder`() {
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
text = MockDataFactory.randomString(),
|
||||
id = MockDataFactory.randomUuid(),
|
||||
isFocused = MockDataFactory.randomBoolean()
|
||||
|
@ -668,7 +668,7 @@ class BlockAdapterTest {
|
|||
val holder = adapter.onCreateViewHolder(recycler, BlockViewHolder.HOLDER_TITLE)
|
||||
|
||||
assertEquals(
|
||||
expected = Title::class,
|
||||
expected = Document::class,
|
||||
actual = holder::class
|
||||
)
|
||||
}
|
||||
|
@ -678,7 +678,7 @@ class BlockAdapterTest {
|
|||
|
||||
// Setup
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
text = MockDataFactory.randomString(),
|
||||
id = MockDataFactory.randomUuid(),
|
||||
isFocused = MockDataFactory.randomBoolean()
|
||||
|
@ -698,7 +698,7 @@ class BlockAdapterTest {
|
|||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
check(holder is Title)
|
||||
check(holder is Document)
|
||||
|
||||
val text = holder.content.text.toString()
|
||||
|
||||
|
@ -713,7 +713,7 @@ class BlockAdapterTest {
|
|||
|
||||
// Setup
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
text = MockDataFactory.randomString(),
|
||||
id = MockDataFactory.randomUuid(),
|
||||
isFocused = MockDataFactory.randomBoolean()
|
||||
|
@ -735,7 +735,7 @@ class BlockAdapterTest {
|
|||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
check(holder is Title)
|
||||
check(holder is Document)
|
||||
|
||||
// Testing
|
||||
|
||||
|
@ -766,7 +766,7 @@ class BlockAdapterTest {
|
|||
|
||||
val events = mutableListOf<Pair<String, Boolean>>()
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
text = MockDataFactory.randomString(),
|
||||
id = MockDataFactory.randomUuid(),
|
||||
isFocused = false
|
||||
|
@ -789,7 +789,7 @@ class BlockAdapterTest {
|
|||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
check(holder is Title)
|
||||
check(holder is Document)
|
||||
|
||||
// Testing
|
||||
|
||||
|
@ -815,7 +815,7 @@ class BlockAdapterTest {
|
|||
|
||||
val events = mutableListOf<Pair<String, String>>()
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
text = MockDataFactory.randomString(),
|
||||
id = MockDataFactory.randomUuid(),
|
||||
isFocused = MockDataFactory.randomBoolean()
|
||||
|
@ -840,10 +840,10 @@ class BlockAdapterTest {
|
|||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
check(holder is Title)
|
||||
check(holder is Document)
|
||||
|
||||
Robolectric.getForegroundThreadScheduler().apply {
|
||||
advanceBy(FOCUS_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
|
||||
advanceBy(BlockViewHolder.FOCUS_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
|
||||
}
|
||||
|
||||
assertEquals(
|
||||
|
@ -1495,7 +1495,7 @@ class BlockAdapterTest {
|
|||
|
||||
// Setup
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
text = MockDataFactory.randomString(),
|
||||
id = MockDataFactory.randomUuid(),
|
||||
isFocused = false
|
||||
|
@ -1517,7 +1517,7 @@ class BlockAdapterTest {
|
|||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
check(holder is Title)
|
||||
check(holder is Document)
|
||||
|
||||
// Testing
|
||||
|
||||
|
@ -1549,7 +1549,7 @@ class BlockAdapterTest {
|
|||
|
||||
// Setup
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
text = MockDataFactory.randomString(),
|
||||
id = MockDataFactory.randomUuid(),
|
||||
isFocused = true
|
||||
|
@ -1571,7 +1571,7 @@ class BlockAdapterTest {
|
|||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
check(holder is Title)
|
||||
check(holder is Document)
|
||||
|
||||
// Testing
|
||||
|
||||
|
@ -1605,7 +1605,7 @@ class BlockAdapterTest {
|
|||
|
||||
val events = mutableListOf<Editable>()
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
text = MockDataFactory.randomString(),
|
||||
id = MockDataFactory.randomUuid(),
|
||||
isFocused = true
|
||||
|
@ -1628,7 +1628,7 @@ class BlockAdapterTest {
|
|||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
check(holder is Title)
|
||||
check(holder is Document)
|
||||
|
||||
// Testing
|
||||
|
||||
|
@ -1648,7 +1648,7 @@ class BlockAdapterTest {
|
|||
|
||||
val txt = MockDataFactory.randomString()
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
text = MockDataFactory.randomString(),
|
||||
id = MockDataFactory.randomUuid(),
|
||||
cursor = txt.length,
|
||||
|
@ -1671,7 +1671,7 @@ class BlockAdapterTest {
|
|||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
check(holder is Title)
|
||||
check(holder is Document)
|
||||
|
||||
// Testing
|
||||
|
||||
|
@ -1877,7 +1877,7 @@ class BlockAdapterTest {
|
|||
|
||||
// Setup
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
text = MockDataFactory.randomString(),
|
||||
id = MockDataFactory.randomUuid(),
|
||||
mode = BlockView.Mode.READ,
|
||||
|
@ -1898,7 +1898,7 @@ class BlockAdapterTest {
|
|||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
check(holder is Title)
|
||||
check(holder is Document)
|
||||
|
||||
assertEquals(
|
||||
expected = InputType.TYPE_NULL,
|
||||
|
@ -1918,7 +1918,7 @@ class BlockAdapterTest {
|
|||
|
||||
// Setup
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
text = MockDataFactory.randomString(),
|
||||
id = MockDataFactory.randomUuid(),
|
||||
mode = BlockView.Mode.EDIT,
|
||||
|
@ -1939,7 +1939,7 @@ class BlockAdapterTest {
|
|||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
check(holder is Title)
|
||||
check(holder is Document)
|
||||
|
||||
assertEquals(
|
||||
expected = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS,
|
||||
|
@ -1957,7 +1957,7 @@ class BlockAdapterTest {
|
|||
|
||||
// Setup
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
text = MockDataFactory.randomString(),
|
||||
id = MockDataFactory.randomUuid(),
|
||||
mode = BlockView.Mode.EDIT,
|
||||
|
@ -1980,7 +1980,7 @@ class BlockAdapterTest {
|
|||
|
||||
adapter.onBindViewHolder(holder, 0)
|
||||
|
||||
check(holder is Title)
|
||||
check(holder is Document)
|
||||
|
||||
// Testing
|
||||
|
||||
|
|
|
@ -417,7 +417,7 @@ class BlockViewDiffUtilTest {
|
|||
|
||||
val text = MockDataFactory.randomString()
|
||||
|
||||
val oldBlock = BlockView.Title(
|
||||
val oldBlock = BlockView.Title.Document(
|
||||
id = id,
|
||||
text = text,
|
||||
isFocused = false
|
||||
|
@ -491,7 +491,7 @@ class BlockViewDiffUtilTest {
|
|||
|
||||
val text = MockDataFactory.randomString()
|
||||
|
||||
val oldBlock = BlockView.Title(
|
||||
val oldBlock = BlockView.Title.Document(
|
||||
id = id,
|
||||
text = text,
|
||||
mode = BlockView.Mode.EDIT,
|
||||
|
@ -716,7 +716,7 @@ class BlockViewDiffUtilTest {
|
|||
|
||||
val id = MockDataFactory.randomUuid()
|
||||
|
||||
val oldBlock = BlockView.Title(
|
||||
val oldBlock = BlockView.Title.Document(
|
||||
id = id,
|
||||
text = MockDataFactory.randomString(),
|
||||
cursor = null,
|
||||
|
|
|
@ -236,7 +236,7 @@ class DefaultBlockViewRenderer(
|
|||
val type = (root.content as? Content.Smart)?.type
|
||||
result.add(
|
||||
if (type == Content.Smart.Type.PROFILE) {
|
||||
BlockView.ProfileTitle(
|
||||
BlockView.Title.Profile(
|
||||
mode = viewMode,
|
||||
id = anchor,
|
||||
isFocused = isFocused,
|
||||
|
@ -247,7 +247,7 @@ class DefaultBlockViewRenderer(
|
|||
cursor = cursor
|
||||
)
|
||||
} else {
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
mode = viewMode,
|
||||
id = anchor,
|
||||
isFocused = isFocused,
|
||||
|
@ -521,7 +521,7 @@ class DefaultBlockViewRenderer(
|
|||
content: Content.Text,
|
||||
root: Block,
|
||||
focus: Focus
|
||||
): BlockView.Title = BlockView.Title(
|
||||
): BlockView.Title.Document = BlockView.Title.Document(
|
||||
mode = if (mode == EditorMode.EDITING) BlockView.Mode.EDIT else BlockView.Mode.READ,
|
||||
id = block.id,
|
||||
text = content.text,
|
||||
|
|
|
@ -137,7 +137,7 @@ class DefaultBlockViewRendererTest {
|
|||
}
|
||||
|
||||
val expected = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = page.id,
|
||||
isFocused = false,
|
||||
text = null,
|
||||
|
@ -238,7 +238,7 @@ class DefaultBlockViewRendererTest {
|
|||
}
|
||||
|
||||
val expected = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = page.id,
|
||||
isFocused = false,
|
||||
text = null,
|
||||
|
@ -321,7 +321,7 @@ class DefaultBlockViewRendererTest {
|
|||
}
|
||||
|
||||
val expected = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = page.id,
|
||||
isFocused = false,
|
||||
text = null,
|
||||
|
@ -384,7 +384,7 @@ class DefaultBlockViewRendererTest {
|
|||
}
|
||||
|
||||
val expected = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = page.id,
|
||||
isFocused = false,
|
||||
text = null,
|
||||
|
@ -457,7 +457,7 @@ class DefaultBlockViewRendererTest {
|
|||
}
|
||||
|
||||
val expected = listOf(
|
||||
BlockView.ProfileTitle(
|
||||
BlockView.Title.Profile(
|
||||
id = page.id,
|
||||
isFocused = false,
|
||||
text = name,
|
||||
|
@ -530,7 +530,7 @@ class DefaultBlockViewRendererTest {
|
|||
}
|
||||
|
||||
val expected = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = page.id,
|
||||
isFocused = false,
|
||||
text = name,
|
||||
|
@ -602,7 +602,7 @@ class DefaultBlockViewRendererTest {
|
|||
}
|
||||
|
||||
val expected = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = page.id,
|
||||
isFocused = false,
|
||||
text = name,
|
||||
|
@ -692,7 +692,7 @@ class DefaultBlockViewRendererTest {
|
|||
}
|
||||
|
||||
val expected = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = page.id,
|
||||
isFocused = false,
|
||||
text = null,
|
||||
|
@ -803,7 +803,7 @@ class DefaultBlockViewRendererTest {
|
|||
}
|
||||
|
||||
val expected = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = page.id,
|
||||
isFocused = false,
|
||||
text = null,
|
||||
|
@ -911,7 +911,7 @@ class DefaultBlockViewRendererTest {
|
|||
}
|
||||
|
||||
val expected = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = page.id,
|
||||
isFocused = false,
|
||||
text = null,
|
||||
|
@ -1031,7 +1031,7 @@ class DefaultBlockViewRendererTest {
|
|||
}
|
||||
|
||||
val expected = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = page.id,
|
||||
isFocused = false,
|
||||
text = null,
|
||||
|
|
|
@ -235,7 +235,7 @@ class PageViewModelTest {
|
|||
|
||||
val expected = ViewState.Success(
|
||||
blocks = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
isFocused = false,
|
||||
id = root,
|
||||
text = null
|
||||
|
@ -452,7 +452,7 @@ class PageViewModelTest {
|
|||
val expected =
|
||||
ViewState.Success(
|
||||
listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
isFocused = false,
|
||||
id = root,
|
||||
text = null
|
||||
|
@ -598,7 +598,7 @@ class PageViewModelTest {
|
|||
|
||||
val beforeUpdate = ViewState.Success(
|
||||
listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
isFocused = false,
|
||||
id = root,
|
||||
text = null
|
||||
|
@ -717,7 +717,7 @@ class PageViewModelTest {
|
|||
|
||||
val firstTimeExpected = ViewState.Success(
|
||||
listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
isFocused = false,
|
||||
id = root,
|
||||
text = null
|
||||
|
@ -756,7 +756,7 @@ class PageViewModelTest {
|
|||
|
||||
val secondTimeExpected = ViewState.Success(
|
||||
listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
isFocused = false,
|
||||
id = root,
|
||||
text = null
|
||||
|
@ -867,7 +867,7 @@ class PageViewModelTest {
|
|||
|
||||
val firstTimeExpected = ViewState.Success(
|
||||
listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
isFocused = false,
|
||||
id = page.id,
|
||||
text = null
|
||||
|
@ -916,7 +916,7 @@ class PageViewModelTest {
|
|||
|
||||
val secondTimeExpected = ViewState.Success(
|
||||
listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
isFocused = false,
|
||||
id = page.id,
|
||||
text = null
|
||||
|
@ -1096,7 +1096,7 @@ class PageViewModelTest {
|
|||
|
||||
val state = ViewState.Success(
|
||||
listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
isFocused = false,
|
||||
id = root,
|
||||
text = null
|
||||
|
@ -1480,7 +1480,7 @@ class PageViewModelTest {
|
|||
testObserver.assertValue(
|
||||
ViewState.Success(
|
||||
blocks = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
isFocused = false,
|
||||
id = root,
|
||||
text = null
|
||||
|
@ -1499,7 +1499,7 @@ class PageViewModelTest {
|
|||
testObserver.assertValue(
|
||||
ViewState.Success(
|
||||
blocks = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
isFocused = false,
|
||||
id = root,
|
||||
text = null
|
||||
|
@ -1725,7 +1725,7 @@ class PageViewModelTest {
|
|||
testObserver.assertValue(
|
||||
ViewState.Success(
|
||||
blocks = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
isFocused = false,
|
||||
id = root,
|
||||
text = null
|
||||
|
@ -1757,7 +1757,7 @@ class PageViewModelTest {
|
|||
testObserver.assertValue(
|
||||
ViewState.Success(
|
||||
blocks = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
isFocused = false,
|
||||
id = root,
|
||||
text = null
|
||||
|
@ -2332,7 +2332,7 @@ class PageViewModelTest {
|
|||
|
||||
val before = ViewState.Success(
|
||||
blocks = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = root,
|
||||
text = null,
|
||||
isFocused = false
|
||||
|
@ -2373,7 +2373,7 @@ class PageViewModelTest {
|
|||
|
||||
val after = ViewState.Success(
|
||||
blocks = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = root,
|
||||
text = null,
|
||||
isFocused = false
|
||||
|
@ -3946,7 +3946,7 @@ class PageViewModelTest {
|
|||
|
||||
val testObserver = vm.state.test()
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
id = root,
|
||||
text = null,
|
||||
isFocused = false
|
||||
|
@ -4122,7 +4122,7 @@ class PageViewModelTest {
|
|||
|
||||
val testObserver = vm.state.test()
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
id = root,
|
||||
text = null,
|
||||
isFocused = false
|
||||
|
@ -4440,7 +4440,7 @@ class PageViewModelTest {
|
|||
|
||||
val testObserver = vm.state.test()
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
id = root,
|
||||
text = null,
|
||||
isFocused = false
|
||||
|
@ -4557,7 +4557,7 @@ class PageViewModelTest {
|
|||
|
||||
val testObserver = vm.state.test()
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
id = root,
|
||||
text = null,
|
||||
isFocused = false
|
||||
|
@ -4682,7 +4682,7 @@ class PageViewModelTest {
|
|||
|
||||
val testObserver = vm.state.test()
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
id = root,
|
||||
text = null,
|
||||
isFocused = false
|
||||
|
@ -4826,7 +4826,7 @@ class PageViewModelTest {
|
|||
|
||||
val testObserver = vm.state.test()
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
id = root,
|
||||
text = null,
|
||||
isFocused = false
|
||||
|
@ -4969,7 +4969,7 @@ class PageViewModelTest {
|
|||
|
||||
val testObserver = vm.state.test()
|
||||
|
||||
val title = BlockView.Title(
|
||||
val title = BlockView.Title.Document(
|
||||
id = root,
|
||||
text = null,
|
||||
isFocused = false
|
||||
|
|
|
@ -117,7 +117,7 @@ class EditorMentionTest : EditorPresentationTestSetup() {
|
|||
assertValue(
|
||||
ViewState.Success(
|
||||
blocks = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = root,
|
||||
isFocused = false,
|
||||
text = null,
|
||||
|
|
|
@ -128,7 +128,7 @@ class EditorMultiSelectModeTest : EditorPresentationTestSetup() {
|
|||
assertValue(
|
||||
ViewState.Success(
|
||||
blocks = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = root,
|
||||
isFocused = false,
|
||||
text = null,
|
||||
|
@ -162,7 +162,7 @@ class EditorMultiSelectModeTest : EditorPresentationTestSetup() {
|
|||
assertValue(
|
||||
ViewState.Success(
|
||||
blocks = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = root,
|
||||
isFocused = false,
|
||||
text = null,
|
||||
|
@ -228,7 +228,7 @@ class EditorMultiSelectModeTest : EditorPresentationTestSetup() {
|
|||
assertValue(
|
||||
ViewState.Success(
|
||||
blocks = listOf(
|
||||
BlockView.Title(
|
||||
BlockView.Title.Document(
|
||||
id = root,
|
||||
isFocused = false,
|
||||
text = null,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue