mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-12 02:30:25 +09:00
parent
44cfc0c821
commit
ee097e37b0
17 changed files with 321 additions and 257 deletions
|
@ -99,19 +99,19 @@ abstract class BlockActionToolbar : Fragment() {
|
|||
is BlockView.Contact -> TODO()
|
||||
is BlockView.File.View -> addButtons(view, ACTIONS.FILE)
|
||||
is BlockView.File.Upload -> addButtons(view, ACTIONS.FILE)
|
||||
is BlockView.File.Placeholder -> addButtons(view, ACTIONS.FILE)
|
||||
is BlockView.MediaPlaceholder.File -> addButtons(view, ACTIONS.FILE)
|
||||
is BlockView.File.Error -> addButtons(view, ACTIONS.FILE)
|
||||
is BlockView.Video.View -> addButtons(view, ACTIONS.VIDEO_PICTURE)
|
||||
is BlockView.Video.Upload -> addButtons(view, ACTIONS.VIDEO_PICTURE)
|
||||
is BlockView.Video.Placeholder -> addButtons(view, ACTIONS.VIDEO_PICTURE)
|
||||
is BlockView.MediaPlaceholder.Video -> addButtons(view, ACTIONS.VIDEO_PICTURE)
|
||||
is BlockView.Video.Error -> addButtons(view, ACTIONS.VIDEO_PICTURE)
|
||||
is BlockView.Page -> addButtons(view, ACTIONS.PAGE)
|
||||
is BlockView.Divider -> addButtons(view, ACTIONS.DIVIDER)
|
||||
is BlockView.Bookmark.Placeholder -> addButtons(view, ACTIONS.BOOKMARK)
|
||||
is BlockView.MediaPlaceholder.Bookmark -> addButtons(view, ACTIONS.BOOKMARK)
|
||||
is BlockView.Bookmark.View -> addButtons(view, ACTIONS.BOOKMARK)
|
||||
is BlockView.Bookmark.Error -> addButtons(view, ACTIONS.BOOKMARK)
|
||||
is BlockView.Picture.View -> addButtons(view, ACTIONS.VIDEO_PICTURE)
|
||||
is BlockView.Picture.Placeholder -> addButtons(view, ACTIONS.VIDEO_PICTURE)
|
||||
is BlockView.MediaPlaceholder.Picture -> addButtons(view, ACTIONS.VIDEO_PICTURE)
|
||||
is BlockView.Picture.Error -> addButtons(view, ACTIONS.VIDEO_PICTURE)
|
||||
is BlockView.Picture.Upload -> addButtons(view, ACTIONS.VIDEO_PICTURE)
|
||||
BlockView.Footer -> TODO()
|
||||
|
|
|
@ -22,19 +22,19 @@ object BlockActionToolbarFactory {
|
|||
is BlockView.Contact -> TODO()
|
||||
is BlockView.File.View -> newInstance(block, dimensions)
|
||||
is BlockView.File.Upload -> newInstance(block, dimensions)
|
||||
is BlockView.File.Placeholder -> newInstance(block, dimensions)
|
||||
is BlockView.MediaPlaceholder.File -> newInstance(block, dimensions)
|
||||
is BlockView.File.Error -> newInstance(block, dimensions)
|
||||
is BlockView.Video.View -> newInstance(block, dimensions)
|
||||
is BlockView.Video.Upload -> newInstance(block, dimensions)
|
||||
is BlockView.Video.Placeholder -> newInstance(block, dimensions)
|
||||
is BlockView.MediaPlaceholder.Video -> newInstance(block, dimensions)
|
||||
is BlockView.Video.Error -> newInstance(block, dimensions)
|
||||
is BlockView.Page -> newInstance(block, dimensions)
|
||||
is BlockView.Divider -> newInstance(block, dimensions)
|
||||
is BlockView.Bookmark.Placeholder -> newInstance(block, dimensions)
|
||||
is BlockView.MediaPlaceholder.Bookmark -> newInstance(block, dimensions)
|
||||
is BlockView.Bookmark.View -> newInstance(block, dimensions)
|
||||
is BlockView.Bookmark.Error -> newInstance(block, dimensions)
|
||||
is BlockView.Picture.View -> newInstance(block, dimensions)
|
||||
is BlockView.Picture.Placeholder -> newInstance(block, dimensions)
|
||||
is BlockView.MediaPlaceholder.Picture -> newInstance(block, dimensions)
|
||||
is BlockView.Picture.Error -> newInstance(block, dimensions)
|
||||
is BlockView.Picture.Upload -> newInstance(block, dimensions)
|
||||
BlockView.Footer -> TODO()
|
||||
|
@ -145,6 +145,17 @@ object BlockActionToolbarFactory {
|
|||
)
|
||||
}
|
||||
|
||||
fun newInstance(
|
||||
block: BlockView.MediaPlaceholder,
|
||||
dimensions: BlockDimensions
|
||||
): PlaceholderActionToolbar =
|
||||
PlaceholderActionToolbar().apply {
|
||||
arguments = bundleOf(
|
||||
BlockActionToolbar.ARG_BLOCK to block,
|
||||
BlockActionToolbar.ARG_BLOCK_DIMENSIONS to dimensions
|
||||
)
|
||||
}
|
||||
|
||||
fun newInstance(block: BlockView.Picture, dimensions: BlockDimensions): PictureBlockActionToolbar =
|
||||
PictureBlockActionToolbar().apply {
|
||||
arguments = bundleOf(
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package com.agileburo.anytype.ui.page.modals.actions
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import com.agileburo.anytype.R
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockView
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewHolder.Companion.HOLDER_BOOKMARK_PLACEHOLDER
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewHolder.Companion.HOLDER_FILE_PLACEHOLDER
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewHolder.Companion.HOLDER_PICTURE_PLACEHOLDER
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewHolder.Companion.HOLDER_VIDEO_PLACEHOLDER
|
||||
|
||||
class PlaceholderActionToolbar : BlockActionToolbar() {
|
||||
|
||||
lateinit var block: BlockView.MediaPlaceholder
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
block = arguments?.getParcelable(ARG_BLOCK)!!
|
||||
}
|
||||
|
||||
override fun blockLayout() =
|
||||
when (block.getViewType()) {
|
||||
HOLDER_PICTURE_PLACEHOLDER -> R.layout.item_block_picture_placeholder_preview
|
||||
HOLDER_VIDEO_PLACEHOLDER -> R.layout.item_block_video_empty_preview
|
||||
HOLDER_FILE_PLACEHOLDER -> R.layout.item_block_file_placeholder_preview
|
||||
HOLDER_BOOKMARK_PLACEHOLDER -> R.layout.item_block_bookmark_placeholder
|
||||
else -> R.layout.item_block_picture_uploading_preview
|
||||
}
|
||||
|
||||
override fun getBlock(): BlockView = block
|
||||
|
||||
override fun initUi(view: View, colorView: ImageView?, backgroundView: ImageView?) {
|
||||
}
|
||||
}
|
|
@ -15,18 +15,18 @@ fun BlockView.updateSelection(newSelection: Boolean) = when (this) {
|
|||
is BlockView.Toggle -> copy(isSelected = newSelection)
|
||||
is BlockView.File.View -> copy(isSelected = newSelection)
|
||||
is BlockView.File.Upload -> copy(isSelected = newSelection)
|
||||
is BlockView.File.Placeholder -> copy(isSelected = newSelection)
|
||||
is BlockView.MediaPlaceholder.File -> copy(isSelected = newSelection)
|
||||
is BlockView.File.Error -> copy(isSelected = newSelection)
|
||||
is BlockView.Video.View -> copy(isSelected = newSelection)
|
||||
is BlockView.Video.Upload -> copy(isSelected = newSelection)
|
||||
is BlockView.Video.Placeholder -> copy(isSelected = newSelection)
|
||||
is BlockView.MediaPlaceholder.File -> copy(isSelected = newSelection)
|
||||
is BlockView.Video.Error -> copy(isSelected = newSelection)
|
||||
is BlockView.Page -> copy(isSelected = newSelection)
|
||||
is BlockView.Bookmark.Placeholder -> copy(isSelected = newSelection)
|
||||
is BlockView.MediaPlaceholder.Bookmark -> copy(isSelected = newSelection)
|
||||
is BlockView.Bookmark.View -> copy(isSelected = newSelection)
|
||||
is BlockView.Bookmark.Error -> copy(isSelected = newSelection)
|
||||
is BlockView.Picture.View -> copy(isSelected = newSelection)
|
||||
is BlockView.Picture.Placeholder -> copy(isSelected = newSelection)
|
||||
is BlockView.MediaPlaceholder.Picture -> copy(isSelected = newSelection)
|
||||
is BlockView.Picture.Error -> copy(isSelected = newSelection)
|
||||
is BlockView.Picture.Upload -> copy(isSelected = newSelection)
|
||||
else -> this
|
||||
|
|
|
@ -1,171 +0,0 @@
|
|||
package com.agileburo.anytype.core_ui.features.editor.holders
|
||||
|
||||
import android.view.View
|
||||
import com.agileburo.anytype.core_ui.R
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockView
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewDiffUtil
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewHolder
|
||||
import com.agileburo.anytype.core_ui.features.page.ListenerType
|
||||
import com.agileburo.anytype.core_ui.widgets.text.EditorLongClickListener
|
||||
import com.agileburo.anytype.core_utils.ext.dimen
|
||||
import com.agileburo.anytype.core_utils.ext.indentize
|
||||
import kotlinx.android.synthetic.main.item_block_bookmark_placeholder.view.*
|
||||
|
||||
class FilePlaceholder(view: View) : BlockViewHolder(view), BlockViewHolder.IndentableHolder {
|
||||
|
||||
fun bind(
|
||||
item: BlockView.File.Placeholder,
|
||||
clicked: (ListenerType) -> Unit
|
||||
) {
|
||||
indentize(item)
|
||||
with(itemView) {
|
||||
isSelected = item.isSelected
|
||||
setOnClickListener { clicked(ListenerType.File.Placeholder(item.id)) }
|
||||
setOnLongClickListener(
|
||||
EditorLongClickListener(
|
||||
t = item.id,
|
||||
click = { onBlockLongClick(itemView, it, clicked) }
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun indentize(item: BlockView.Indentable) {
|
||||
itemView.indentize(
|
||||
indent = item.indent,
|
||||
defIndent = dimen(R.dimen.indent),
|
||||
margin = dimen(R.dimen.bookmark_default_margin_start)
|
||||
)
|
||||
}
|
||||
|
||||
fun processChangePayload(payloads: List<BlockViewDiffUtil.Payload>, item: BlockView) {
|
||||
check(item is BlockView.File.Placeholder) { "Expected a file placeholder block, but was: $item" }
|
||||
payloads.forEach { payload ->
|
||||
if (payload.changes.contains(BlockViewDiffUtil.SELECTION_CHANGED)) {
|
||||
itemView.isSelected = item.isSelected
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VideoPlaceholder(view: View) : BlockViewHolder(view), BlockViewHolder.IndentableHolder {
|
||||
|
||||
fun bind(
|
||||
item: BlockView.Video.Placeholder,
|
||||
clicked: (ListenerType) -> Unit
|
||||
) {
|
||||
indentize(item)
|
||||
with(itemView) {
|
||||
isSelected = item.isSelected
|
||||
setOnClickListener { clicked(ListenerType.Video.Placeholder(item.id)) }
|
||||
setOnLongClickListener(
|
||||
EditorLongClickListener(
|
||||
t = item.id,
|
||||
click = { onBlockLongClick(itemView, it, clicked) }
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun indentize(item: BlockView.Indentable) {
|
||||
itemView.indentize(
|
||||
indent = item.indent,
|
||||
defIndent = dimen(R.dimen.indent),
|
||||
margin = dimen(R.dimen.bookmark_default_margin_start)
|
||||
)
|
||||
}
|
||||
|
||||
fun processChangePayload(payloads: List<BlockViewDiffUtil.Payload>, item: BlockView) {
|
||||
check(item is BlockView.Video.Placeholder) { "Expected a video placeholder block, but was: $item" }
|
||||
payloads.forEach { payload ->
|
||||
if (payload.changes.contains(BlockViewDiffUtil.SELECTION_CHANGED)) {
|
||||
itemView.isSelected = item.isSelected
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BookmarkPlaceholder(view: View) : BlockViewHolder(view), BlockViewHolder.IndentableHolder {
|
||||
|
||||
private val root = itemView.bookmarkPlaceholderRoot
|
||||
|
||||
fun bind(
|
||||
item: BlockView.Bookmark.Placeholder,
|
||||
clicked: (ListenerType) -> Unit
|
||||
) {
|
||||
indentize(item)
|
||||
select(item.isSelected)
|
||||
with(root) {
|
||||
setOnClickListener {
|
||||
clicked(ListenerType.Bookmark.Placeholder(item.id))
|
||||
}
|
||||
setOnLongClickListener(
|
||||
EditorLongClickListener(
|
||||
t = item.id,
|
||||
click = { onBlockLongClick(itemView, it, clicked) }
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun indentize(item: BlockView.Indentable) {
|
||||
root.indentize(
|
||||
indent = item.indent,
|
||||
defIndent = dimen(R.dimen.indent),
|
||||
margin = dimen(R.dimen.bookmark_default_margin_start)
|
||||
)
|
||||
}
|
||||
|
||||
fun processChangePayload(
|
||||
payloads: List<BlockViewDiffUtil.Payload>,
|
||||
item: BlockView
|
||||
) {
|
||||
check(item is BlockView.Bookmark.Placeholder) { "Expected a bookmark placeholder block, but was: $item" }
|
||||
payloads.forEach { payload ->
|
||||
if (payload.selectionChanged()) {
|
||||
select(item.isSelected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun select(isSelected: Boolean) {
|
||||
root.isSelected = isSelected
|
||||
}
|
||||
}
|
||||
|
||||
class ImagePlaceholder(view: View) : BlockViewHolder(view), BlockViewHolder.IndentableHolder {
|
||||
|
||||
fun bind(
|
||||
item: BlockView.Picture.Placeholder,
|
||||
clicked: (ListenerType) -> Unit
|
||||
) {
|
||||
indentize(item)
|
||||
with(itemView) {
|
||||
isSelected = item.isSelected
|
||||
setOnClickListener { clicked(ListenerType.Picture.Placeholder(item.id)) }
|
||||
setOnLongClickListener(
|
||||
EditorLongClickListener(
|
||||
t = item.id,
|
||||
click = { onBlockLongClick(itemView, it, clicked) }
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun indentize(item: BlockView.Indentable) {
|
||||
itemView.indentize(
|
||||
indent = item.indent,
|
||||
defIndent = dimen(R.dimen.indent),
|
||||
margin = dimen(R.dimen.bookmark_default_margin_start)
|
||||
)
|
||||
}
|
||||
|
||||
fun processChangePayload(payloads: List<BlockViewDiffUtil.Payload>, item: BlockView) {
|
||||
check(item is BlockView.Picture.Placeholder) { "Expected a picture placeholder block, but was: $item" }
|
||||
payloads.forEach { payload ->
|
||||
if (payload.changes.contains(BlockViewDiffUtil.SELECTION_CHANGED)) {
|
||||
itemView.isSelected = item.isSelected
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.agileburo.anytype.core_ui.features.editor.holders.placeholders
|
||||
|
||||
import android.view.View
|
||||
import com.agileburo.anytype.core_ui.R
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockView
|
||||
import com.agileburo.anytype.core_ui.features.page.ListenerType
|
||||
import com.agileburo.anytype.core_utils.ext.dimen
|
||||
import com.agileburo.anytype.core_utils.ext.indentize
|
||||
import kotlinx.android.synthetic.main.item_block_bookmark_placeholder.view.*
|
||||
|
||||
class BookmarkPlaceholder(view: View) : MediaPlaceholder(view) {
|
||||
|
||||
override val root: View = itemView.bookmarkPlaceholderRoot
|
||||
|
||||
override fun placeholderClick(target: String, clicked: (ListenerType) -> Unit) {
|
||||
clicked(ListenerType.Bookmark.Placeholder(target))
|
||||
}
|
||||
|
||||
override fun indentize(item: BlockView.Indentable) {
|
||||
root.indentize(
|
||||
indent = item.indent,
|
||||
defIndent = dimen(R.dimen.indent),
|
||||
margin = dimen(R.dimen.bookmark_default_margin_start)
|
||||
)
|
||||
}
|
||||
|
||||
override fun select(isSelected: Boolean) {
|
||||
root.isSelected = isSelected
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.agileburo.anytype.core_ui.features.editor.holders.placeholders
|
||||
|
||||
import android.view.View
|
||||
import com.agileburo.anytype.core_ui.R
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockView
|
||||
import com.agileburo.anytype.core_ui.features.page.ListenerType
|
||||
import com.agileburo.anytype.core_utils.ext.dimen
|
||||
import com.agileburo.anytype.core_utils.ext.indentize
|
||||
import kotlinx.android.synthetic.main.item_block_file_placeholder.view.*
|
||||
|
||||
class FilePlaceholder(view: View) : MediaPlaceholder(view) {
|
||||
|
||||
override val root: View = itemView.filePlaceholderRoot
|
||||
|
||||
override fun placeholderClick(target: String, clicked: (ListenerType) -> Unit) {
|
||||
clicked(ListenerType.File.Placeholder(target))
|
||||
}
|
||||
|
||||
override fun indentize(item: BlockView.Indentable) {
|
||||
root.indentize(
|
||||
indent = item.indent,
|
||||
defIndent = dimen(R.dimen.indent),
|
||||
margin = dimen(R.dimen.bookmark_default_margin_start)
|
||||
)
|
||||
}
|
||||
|
||||
override fun select(isSelected: Boolean) {
|
||||
root.isSelected = isSelected
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.agileburo.anytype.core_ui.features.editor.holders.placeholders
|
||||
|
||||
import android.view.View
|
||||
import com.agileburo.anytype.core_ui.features.page.*
|
||||
import com.agileburo.anytype.core_ui.widgets.text.EditorLongClickListener
|
||||
import com.agileburo.anytype.core_utils.ext.PopupExtensions
|
||||
|
||||
abstract class MediaPlaceholder(view: View) : BlockViewHolder(view),
|
||||
BlockViewHolder.IndentableHolder {
|
||||
|
||||
abstract val root: View
|
||||
abstract fun placeholderClick(target: String, clicked: (ListenerType) -> Unit)
|
||||
abstract override fun indentize(item: BlockView.Indentable)
|
||||
abstract fun select(isSelected: Boolean)
|
||||
|
||||
fun bind(
|
||||
item: BlockView.MediaPlaceholder,
|
||||
clicked: (ListenerType) -> Unit
|
||||
) {
|
||||
indentize(item)
|
||||
select(item.isSelected)
|
||||
with(root) {
|
||||
setOnClickListener { placeholderClick(item.id, clicked) }
|
||||
setOnLongClickListener(
|
||||
EditorLongClickListener(
|
||||
t = item.id,
|
||||
click = { placeholderLongClick(root, it, clicked) }
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun processChangePayload(payloads: List<BlockViewDiffUtil.Payload>, item: BlockView) {
|
||||
check(item is BlockView.MediaPlaceholder) { "Expected a media placeholder, but was: $item" }
|
||||
payloads.forEach { payload ->
|
||||
if (payload.isSelectionChanged) {
|
||||
select(item.isSelected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun placeholderLongClick(root: View, target: String, clicked: (ListenerType) -> Unit) {
|
||||
val rect = PopupExtensions.calculateRectInWindow(root)
|
||||
val dimensions = BlockDimensions(
|
||||
left = rect.left,
|
||||
top = rect.top,
|
||||
bottom = rect.bottom,
|
||||
right = rect.right,
|
||||
height = root.height,
|
||||
width = root.width
|
||||
)
|
||||
clicked(ListenerType.LongClick(target, dimensions))
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.agileburo.anytype.core_ui.features.editor.holders.placeholders
|
||||
|
||||
import android.view.View
|
||||
import com.agileburo.anytype.core_ui.R
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockView
|
||||
import com.agileburo.anytype.core_ui.features.page.ListenerType
|
||||
import com.agileburo.anytype.core_utils.ext.dimen
|
||||
import com.agileburo.anytype.core_utils.ext.indentize
|
||||
|
||||
class PicturePlaceholder(view: View) : MediaPlaceholder(view) {
|
||||
|
||||
override val root: View = itemView
|
||||
|
||||
override fun placeholderClick(target: String, clicked: (ListenerType) -> Unit) {
|
||||
clicked(ListenerType.Picture.Placeholder(target))
|
||||
}
|
||||
|
||||
override fun indentize(item: BlockView.Indentable) {
|
||||
root.indentize(
|
||||
indent = item.indent,
|
||||
defIndent = dimen(R.dimen.indent),
|
||||
margin = dimen(R.dimen.bookmark_default_margin_start)
|
||||
)
|
||||
}
|
||||
|
||||
override fun select(isSelected: Boolean) {
|
||||
root.isSelected = isSelected
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.agileburo.anytype.core_ui.features.editor.holders.placeholders
|
||||
|
||||
import android.view.View
|
||||
import com.agileburo.anytype.core_ui.R
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockView
|
||||
import com.agileburo.anytype.core_ui.features.page.ListenerType
|
||||
import com.agileburo.anytype.core_utils.ext.dimen
|
||||
import com.agileburo.anytype.core_utils.ext.indentize
|
||||
|
||||
class VideoPlaceholder(view: View) : MediaPlaceholder(view) {
|
||||
|
||||
override val root: View = itemView
|
||||
|
||||
override fun placeholderClick(target: String, clicked: (ListenerType) -> Unit) {
|
||||
clicked(ListenerType.Video.Placeholder(target))
|
||||
}
|
||||
|
||||
override fun indentize(item: BlockView.Indentable) {
|
||||
root.indentize(
|
||||
indent = item.indent,
|
||||
defIndent = dimen(R.dimen.indent),
|
||||
margin = dimen(R.dimen.bookmark_default_margin_start)
|
||||
)
|
||||
}
|
||||
|
||||
override fun select(isSelected: Boolean) {
|
||||
root.isSelected = isSelected
|
||||
}
|
||||
}
|
|
@ -8,6 +8,10 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import com.agileburo.anytype.core_ui.R
|
||||
import com.agileburo.anytype.core_ui.common.Markup
|
||||
import com.agileburo.anytype.core_ui.features.editor.holders.*
|
||||
import com.agileburo.anytype.core_ui.features.editor.holders.placeholders.BookmarkPlaceholder
|
||||
import com.agileburo.anytype.core_ui.features.editor.holders.placeholders.FilePlaceholder
|
||||
import com.agileburo.anytype.core_ui.features.editor.holders.placeholders.PicturePlaceholder
|
||||
import com.agileburo.anytype.core_ui.features.editor.holders.placeholders.VideoPlaceholder
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewHolder.Companion.HOLDER_BOOKMARK
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewHolder.Companion.HOLDER_BOOKMARK_ERROR
|
||||
import com.agileburo.anytype.core_ui.features.page.BlockViewHolder.Companion.HOLDER_BOOKMARK_PLACEHOLDER
|
||||
|
@ -317,7 +321,7 @@ class BlockAdapter(
|
|||
)
|
||||
}
|
||||
HOLDER_PICTURE_PLACEHOLDER -> {
|
||||
ImagePlaceholder(
|
||||
PicturePlaceholder(
|
||||
view = inflater.inflate(
|
||||
R.layout.item_block_picture_placeholder,
|
||||
parent,
|
||||
|
@ -521,7 +525,7 @@ class BlockAdapter(
|
|||
item = blocks[position]
|
||||
)
|
||||
}
|
||||
is ImagePlaceholder -> {
|
||||
is PicturePlaceholder -> {
|
||||
holder.processChangePayload(
|
||||
payloads = payloads.typeOf(),
|
||||
item = blocks[position]
|
||||
|
@ -730,7 +734,7 @@ class BlockAdapter(
|
|||
}
|
||||
is FilePlaceholder -> {
|
||||
holder.bind(
|
||||
item = blocks[position] as BlockView.File.Placeholder,
|
||||
item = blocks[position] as BlockView.MediaPlaceholder.File,
|
||||
clicked = onClickListener
|
||||
)
|
||||
}
|
||||
|
@ -748,7 +752,7 @@ class BlockAdapter(
|
|||
}
|
||||
is VideoPlaceholder -> {
|
||||
holder.bind(
|
||||
item = blocks[position] as BlockView.Video.Placeholder,
|
||||
item = blocks[position] as BlockView.MediaPlaceholder.File,
|
||||
clicked = onClickListener
|
||||
)
|
||||
}
|
||||
|
@ -772,7 +776,7 @@ class BlockAdapter(
|
|||
}
|
||||
is BookmarkPlaceholder -> {
|
||||
holder.bind(
|
||||
item = blocks[position] as BlockView.Bookmark.Placeholder,
|
||||
item = blocks[position] as BlockView.MediaPlaceholder.Bookmark,
|
||||
clicked = onClickListener
|
||||
)
|
||||
}
|
||||
|
@ -788,9 +792,9 @@ class BlockAdapter(
|
|||
clicked = onClickListener
|
||||
)
|
||||
}
|
||||
is ImagePlaceholder -> {
|
||||
is PicturePlaceholder -> {
|
||||
holder.bind(
|
||||
item = blocks[position] as BlockView.Picture.Placeholder,
|
||||
item = blocks[position] as BlockView.MediaPlaceholder.Picture,
|
||||
clicked = onClickListener
|
||||
)
|
||||
}
|
||||
|
|
|
@ -428,6 +428,68 @@ sealed class BlockView : ViewType, Parcelable {
|
|||
override fun getViewType() = HOLDER_CONTACT
|
||||
}
|
||||
|
||||
sealed class MediaPlaceholder : BlockView(), Indentable, Parcelable, Selectable, Permission {
|
||||
abstract override val id: String
|
||||
abstract override val indent: Int
|
||||
abstract override val mode: Mode
|
||||
abstract override val isSelected: Boolean
|
||||
|
||||
/**
|
||||
* UI-model for block containing file, with state EMPTY.
|
||||
* @property id block's id
|
||||
*/
|
||||
@Parcelize
|
||||
data class File(
|
||||
override val id: String,
|
||||
override val indent: Int,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val isSelected: Boolean = false
|
||||
) : MediaPlaceholder() {
|
||||
override fun getViewType() = HOLDER_FILE_PLACEHOLDER
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-model for block containing video, with state EMPTY.
|
||||
* @property id block's id
|
||||
*/
|
||||
@Parcelize
|
||||
data class Video(
|
||||
override val id: String,
|
||||
override val indent: Int,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val isSelected: Boolean = false
|
||||
) : MediaPlaceholder() {
|
||||
override fun getViewType() = HOLDER_VIDEO_PLACEHOLDER
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-model for a bookmark placeholder (used when bookmark url is not set)
|
||||
*/
|
||||
@Parcelize
|
||||
data class Bookmark(
|
||||
override val id: String,
|
||||
override val indent: Int,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val isSelected: Boolean = false
|
||||
) : MediaPlaceholder() {
|
||||
override fun getViewType() = HOLDER_BOOKMARK_PLACEHOLDER
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-model for block containing image, with state EMPTY.
|
||||
*/
|
||||
@Parcelize
|
||||
data class Picture(
|
||||
override val id: String,
|
||||
override val indent: Int,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val isSelected: Boolean = false
|
||||
) : MediaPlaceholder() {
|
||||
override fun getViewType() = HOLDER_PICTURE_PLACEHOLDER
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-models for blocks containing files.
|
||||
* @property id block's id
|
||||
|
@ -469,20 +531,6 @@ sealed class BlockView : ViewType, Parcelable {
|
|||
override fun getViewType() = HOLDER_FILE_UPLOAD
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-model for block containing file, with state EMPTY.
|
||||
* @property id block's id
|
||||
*/
|
||||
@Parcelize
|
||||
data class Placeholder(
|
||||
override val id: String,
|
||||
override val indent: Int,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val isSelected: Boolean = false
|
||||
) : BlockView.File(id) {
|
||||
override fun getViewType() = HOLDER_FILE_PLACEHOLDER
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-model for block containing file, with state ERROR.
|
||||
* @property id block's id
|
||||
|
@ -538,20 +586,6 @@ sealed class BlockView : ViewType, Parcelable {
|
|||
override fun getViewType() = HOLDER_VIDEO_UPLOAD
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-model for block containing video, with state EMPTY.
|
||||
* @property id block's id
|
||||
*/
|
||||
@Parcelize
|
||||
data class Placeholder(
|
||||
override val id: String,
|
||||
override val indent: Int,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val isSelected: Boolean = false
|
||||
) : BlockView.Video(id) {
|
||||
override fun getViewType() = HOLDER_VIDEO_PLACEHOLDER
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-model for block containing video, with state ERROR.
|
||||
* @property id block's id
|
||||
|
@ -608,19 +642,6 @@ sealed class BlockView : ViewType, Parcelable {
|
|||
override val id: String
|
||||
) : BlockView(), Indentable, Parcelable, Selectable, Permission {
|
||||
|
||||
/**
|
||||
* UI-model for a bookmark placeholder (used when bookmark url is not set)
|
||||
*/
|
||||
@Parcelize
|
||||
data class Placeholder(
|
||||
override val id: String,
|
||||
override val indent: Int,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val isSelected: Boolean = false
|
||||
) : Bookmark(id = id) {
|
||||
override fun getViewType() = HOLDER_BOOKMARK_PLACEHOLDER
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-model for a bookmark view.
|
||||
* @property title website's title
|
||||
|
@ -686,19 +707,6 @@ sealed class BlockView : ViewType, Parcelable {
|
|||
override fun getViewType() = HOLDER_PICTURE
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-model for block containing image, with state EMPTY.
|
||||
*/
|
||||
@Parcelize
|
||||
data class Placeholder(
|
||||
override val id: String,
|
||||
override val indent: Int,
|
||||
override val mode: Mode = Mode.EDIT,
|
||||
override val isSelected: Boolean = false
|
||||
) : BlockView.Picture(id) {
|
||||
override fun getViewType() = HOLDER_PICTURE_PLACEHOLDER
|
||||
}
|
||||
|
||||
/**
|
||||
* UI-model for block containing image, with state ERROR.
|
||||
*/
|
||||
|
|
|
@ -14,6 +14,10 @@ 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.editor.holders.placeholders.BookmarkPlaceholder
|
||||
import com.agileburo.anytype.core_ui.features.editor.holders.placeholders.FilePlaceholder
|
||||
import com.agileburo.anytype.core_ui.features.editor.holders.placeholders.PicturePlaceholder
|
||||
import com.agileburo.anytype.core_ui.features.editor.holders.placeholders.VideoPlaceholder
|
||||
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
|
||||
|
@ -1053,7 +1057,7 @@ class BlockAdapterTest {
|
|||
@Test
|
||||
fun `should apply indent to file placeholder view`() {
|
||||
|
||||
val view = BlockView.File.Placeholder(
|
||||
val view = BlockView.MediaPlaceholder.File(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
indent = MockDataFactory.randomInt()
|
||||
)
|
||||
|
@ -1178,7 +1182,7 @@ class BlockAdapterTest {
|
|||
@Test
|
||||
fun `should apply indent to video placeholder view`() {
|
||||
|
||||
val view = BlockView.Video.Placeholder(
|
||||
val view = BlockView.MediaPlaceholder.File(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
indent = MockDataFactory.randomInt()
|
||||
)
|
||||
|
@ -1337,7 +1341,7 @@ class BlockAdapterTest {
|
|||
@Test
|
||||
fun `should apply indent to bookmark placeholder view`() {
|
||||
|
||||
val view = BlockView.Bookmark.Placeholder(
|
||||
val view = BlockView.MediaPlaceholder.Bookmark(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
indent = MockDataFactory.randomInt()
|
||||
)
|
||||
|
@ -1402,7 +1406,7 @@ class BlockAdapterTest {
|
|||
@Test
|
||||
fun `should apply indent to picture placeholder view`() {
|
||||
|
||||
val view = BlockView.Picture.Placeholder(
|
||||
val view = BlockView.MediaPlaceholder.Picture(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
indent = MockDataFactory.randomInt()
|
||||
)
|
||||
|
@ -1420,7 +1424,7 @@ class BlockAdapterTest {
|
|||
|
||||
adapter.bindViewHolder(holder, 0)
|
||||
|
||||
check(holder is ImagePlaceholder)
|
||||
check(holder is PicturePlaceholder)
|
||||
|
||||
val actual = holder.itemView.marginLeft
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ class BlockViewTest {
|
|||
|
||||
@Test
|
||||
fun `should return video block with view type Empty`() {
|
||||
val block = BlockView.Video.Placeholder(
|
||||
val block = BlockView.MediaPlaceholder.Video(
|
||||
id = MockDataFactory.randomUuid(),
|
||||
indent = MockDataFactory.randomInt()
|
||||
)
|
||||
|
|
|
@ -20,7 +20,7 @@ fun Block.Content.File.toPictureView(
|
|||
indent: Int,
|
||||
mode: BlockView.Mode
|
||||
): BlockView = when (state) {
|
||||
Block.Content.File.State.EMPTY -> BlockView.Picture.Placeholder(
|
||||
Block.Content.File.State.EMPTY -> BlockView.MediaPlaceholder.Picture(
|
||||
id = id,
|
||||
indent = indent,
|
||||
mode = mode
|
||||
|
@ -54,7 +54,7 @@ fun Block.Content.File.toVideoView(
|
|||
indent: Int,
|
||||
mode: BlockView.Mode
|
||||
): BlockView = when (state) {
|
||||
Block.Content.File.State.EMPTY -> BlockView.Video.Placeholder(
|
||||
Block.Content.File.State.EMPTY -> BlockView.MediaPlaceholder.File(
|
||||
id = id,
|
||||
indent = indent,
|
||||
mode = mode
|
||||
|
@ -88,7 +88,7 @@ fun Block.Content.File.toFileView(
|
|||
indent: Int,
|
||||
mode: BlockView.Mode
|
||||
): BlockView = when (state) {
|
||||
Block.Content.File.State.EMPTY -> BlockView.File.Placeholder(
|
||||
Block.Content.File.State.EMPTY -> BlockView.MediaPlaceholder.File(
|
||||
id = id,
|
||||
indent = indent,
|
||||
mode = mode
|
||||
|
|
|
@ -480,7 +480,7 @@ class DefaultBlockViewRenderer(
|
|||
mode = if (mode == EditorMode.EDITING) BlockView.Mode.EDIT else BlockView.Mode.READ
|
||||
)
|
||||
}
|
||||
} ?: BlockView.Bookmark.Placeholder(
|
||||
} ?: BlockView.MediaPlaceholder.Bookmark(
|
||||
id = block.id,
|
||||
indent = indent,
|
||||
mode = if (mode == EditorMode.EDITING) BlockView.Mode.EDIT else BlockView.Mode.READ
|
||||
|
|
|
@ -81,7 +81,7 @@ class MapperExtensionKtTest {
|
|||
|
||||
)
|
||||
|
||||
val expected = BlockView.File.Placeholder(id = id, indent = indent)
|
||||
val expected = BlockView.MediaPlaceholder.File(id = id, indent = indent)
|
||||
val actual = block.toFileView(id, urlBuilder, indent, mode)
|
||||
|
||||
assertEquals(expected, actual)
|
||||
|
@ -220,7 +220,7 @@ class MapperExtensionKtTest {
|
|||
|
||||
)
|
||||
|
||||
val expected = BlockView.Picture.Placeholder(id = id, indent = indent)
|
||||
val expected = BlockView.MediaPlaceholder.Picture(id = id, indent = indent)
|
||||
val actual = block.toPictureView(id, urlBuilder, indent, mode)
|
||||
|
||||
assertEquals(expected, actual)
|
||||
|
@ -409,7 +409,7 @@ class MapperExtensionKtTest {
|
|||
type = type
|
||||
)
|
||||
|
||||
val expected = BlockView.Video.Placeholder(
|
||||
val expected = BlockView.MediaPlaceholder.File(
|
||||
id = id,
|
||||
indent = indent
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue