2019-03-21 20:41:41 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.fenix.library.bookmarks
|
|
|
|
|
2019-05-18 12:01:10 +02:00
|
|
|
import android.util.TypedValue
|
2019-03-21 20:41:41 +01:00
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
2019-05-18 12:01:10 +02:00
|
|
|
import androidx.constraintlayout.widget.ConstraintSet
|
2019-04-11 06:30:15 +02:00
|
|
|
import androidx.core.content.ContextCompat
|
2019-03-21 20:41:41 +01:00
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import io.reactivex.Observer
|
|
|
|
import kotlinx.android.extensions.LayoutContainer
|
|
|
|
import kotlinx.android.synthetic.main.bookmark_row.*
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.Job
|
|
|
|
import kotlinx.coroutines.launch
|
2019-04-04 22:40:39 +02:00
|
|
|
import mozilla.appservices.places.BookmarkRoot
|
2019-03-21 20:41:41 +01:00
|
|
|
import mozilla.components.browser.icons.IconRequest
|
|
|
|
import mozilla.components.browser.menu.BrowserMenu
|
|
|
|
import mozilla.components.concept.storage.BookmarkNode
|
|
|
|
import mozilla.components.concept.storage.BookmarkNodeType
|
|
|
|
import org.mozilla.fenix.R
|
2019-05-31 00:49:58 +02:00
|
|
|
import org.mozilla.fenix.ThemeManager
|
2019-04-02 23:55:48 +02:00
|
|
|
import org.mozilla.fenix.ext.components
|
2019-04-04 22:40:39 +02:00
|
|
|
import org.mozilla.fenix.ext.increaseTapArea
|
2019-03-21 20:41:41 +01:00
|
|
|
import kotlin.coroutines.CoroutineContext
|
|
|
|
|
2019-04-04 22:40:39 +02:00
|
|
|
class BookmarkAdapter(val emptyView: View, val actionEmitter: Observer<BookmarkAction>) :
|
|
|
|
RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
2019-03-21 20:41:41 +01:00
|
|
|
|
|
|
|
private var tree: List<BookmarkNode> = listOf()
|
|
|
|
private var mode: BookmarkState.Mode = BookmarkState.Mode.Normal
|
2019-06-24 19:10:49 +02:00
|
|
|
val selected: Set<BookmarkNode>
|
|
|
|
get() = (mode as? BookmarkState.Mode.Selecting)?.selectedItems ?: setOf()
|
2019-04-04 22:40:39 +02:00
|
|
|
private var isFirstRun = true
|
2019-03-21 20:41:41 +01:00
|
|
|
|
|
|
|
lateinit var job: Job
|
|
|
|
|
|
|
|
fun updateData(tree: BookmarkNode?, mode: BookmarkState.Mode) {
|
2019-06-24 19:10:49 +02:00
|
|
|
this.tree = tree?.children ?: listOf()
|
2019-04-04 22:40:39 +02:00
|
|
|
isFirstRun = if (isFirstRun) false else {
|
|
|
|
emptyView.visibility = if (this.tree.isEmpty()) View.VISIBLE else View.GONE
|
|
|
|
false
|
|
|
|
}
|
2019-03-21 20:41:41 +01:00
|
|
|
this.mode = mode
|
|
|
|
notifyDataSetChanged()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
|
|
|
val view = LayoutInflater.from(parent.context).inflate(R.layout.bookmark_row, parent, false)
|
|
|
|
|
|
|
|
return when (viewType) {
|
2019-04-25 17:09:19 +02:00
|
|
|
BookmarkItemViewHolder.viewType.ordinal -> BookmarkItemViewHolder(
|
2019-03-21 20:41:41 +01:00
|
|
|
view, actionEmitter, job
|
|
|
|
)
|
2019-04-25 17:09:19 +02:00
|
|
|
BookmarkFolderViewHolder.viewType.ordinal -> BookmarkFolderViewHolder(
|
2019-04-11 06:30:15 +02:00
|
|
|
view, actionEmitter, job
|
2019-03-21 20:41:41 +01:00
|
|
|
)
|
2019-04-25 17:09:19 +02:00
|
|
|
BookmarkSeparatorViewHolder.viewType.ordinal -> BookmarkSeparatorViewHolder(
|
2019-04-11 06:30:15 +02:00
|
|
|
view, actionEmitter, job
|
2019-03-21 20:41:41 +01:00
|
|
|
)
|
|
|
|
else -> throw IllegalStateException("ViewType $viewType does not match to a ViewHolder")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getItemViewType(position: Int): Int {
|
|
|
|
return when (tree[position].type) {
|
|
|
|
BookmarkNodeType.ITEM -> ViewType.ITEM.ordinal
|
|
|
|
BookmarkNodeType.FOLDER -> ViewType.FOLDER.ordinal
|
|
|
|
BookmarkNodeType.SEPARATOR -> ViewType.SEPARATOR.ordinal
|
|
|
|
else -> throw IllegalStateException("Item $tree[position] does not match to a ViewType")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
|
|
|
|
super.onAttachedToRecyclerView(recyclerView)
|
|
|
|
job = Job()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
|
|
|
|
super.onDetachedFromRecyclerView(recyclerView)
|
|
|
|
job.cancel()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getItemCount(): Int = tree.size
|
|
|
|
|
|
|
|
@SuppressWarnings("ComplexMethod")
|
|
|
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
|
|
|
|
|
|
|
when (holder) {
|
2019-04-25 17:09:19 +02:00
|
|
|
is BookmarkItemViewHolder -> holder.bind(
|
2019-04-11 06:30:15 +02:00
|
|
|
tree[position],
|
|
|
|
mode,
|
|
|
|
tree[position] in selected
|
|
|
|
)
|
2019-04-25 17:09:19 +02:00
|
|
|
is BookmarkFolderViewHolder -> holder.bind(
|
2019-04-11 06:30:15 +02:00
|
|
|
tree[position],
|
|
|
|
mode,
|
|
|
|
tree[position] in selected
|
|
|
|
)
|
2019-04-25 17:09:19 +02:00
|
|
|
is BookmarkSeparatorViewHolder -> holder.bind(
|
2019-04-11 06:30:15 +02:00
|
|
|
tree[position], mode,
|
|
|
|
tree[position] in selected
|
|
|
|
)
|
2019-03-21 20:41:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-11 06:30:15 +02:00
|
|
|
open class BookmarkNodeViewHolder(
|
2019-03-21 20:41:41 +01:00
|
|
|
view: View,
|
|
|
|
val actionEmitter: Observer<BookmarkAction>,
|
|
|
|
private val job: Job,
|
|
|
|
override val containerView: View? = view
|
|
|
|
) :
|
|
|
|
RecyclerView.ViewHolder(view), LayoutContainer, CoroutineScope {
|
|
|
|
|
|
|
|
override val coroutineContext: CoroutineContext
|
|
|
|
get() = Dispatchers.Main + job
|
|
|
|
|
2019-04-11 06:30:15 +02:00
|
|
|
open fun bind(item: BookmarkNode, mode: BookmarkState.Mode, selected: Boolean) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BookmarkItemViewHolder(
|
|
|
|
view: View,
|
|
|
|
actionEmitter: Observer<BookmarkAction>,
|
|
|
|
job: Job,
|
|
|
|
override val containerView: View? = view
|
|
|
|
) :
|
|
|
|
BookmarkNodeViewHolder(view, actionEmitter, job, containerView) {
|
|
|
|
|
2019-04-30 22:21:59 +02:00
|
|
|
@Suppress("ComplexMethod")
|
2019-04-11 06:30:15 +02:00
|
|
|
override fun bind(item: BookmarkNode, mode: BookmarkState.Mode, selected: Boolean) {
|
2019-03-21 20:41:41 +01:00
|
|
|
|
2019-05-18 14:27:55 +02:00
|
|
|
val shiftTwoDp = TypedValue.applyDimension(
|
|
|
|
TypedValue.COMPLEX_UNIT_DIP, TWO_DIGIT_MARGIN, containerView!!.context.resources.displayMetrics
|
2019-05-18 12:01:10 +02:00
|
|
|
).toInt()
|
2019-06-24 19:10:49 +02:00
|
|
|
val params = bookmark_title.layoutParams as ViewGroup.MarginLayoutParams
|
2019-05-18 14:27:55 +02:00
|
|
|
params.topMargin = shiftTwoDp
|
2019-06-24 19:10:49 +02:00
|
|
|
bookmark_title.layoutParams = params
|
2019-05-18 12:01:10 +02:00
|
|
|
|
2019-03-21 20:41:41 +01:00
|
|
|
bookmark_favicon.visibility = View.VISIBLE
|
|
|
|
bookmark_title.visibility = View.VISIBLE
|
2019-05-18 12:01:10 +02:00
|
|
|
bookmark_url.visibility = View.VISIBLE
|
2019-03-21 20:41:41 +01:00
|
|
|
bookmark_overflow.visibility = View.VISIBLE
|
|
|
|
bookmark_separator.visibility = View.GONE
|
|
|
|
bookmark_layout.isClickable = true
|
|
|
|
|
2019-05-27 19:04:17 +02:00
|
|
|
val bookmarkItemMenu = BookmarkItemMenu(containerView.context, item) {
|
2019-04-04 22:40:39 +02:00
|
|
|
when (it) {
|
|
|
|
is BookmarkItemMenu.Item.Edit -> {
|
|
|
|
actionEmitter.onNext(BookmarkAction.Edit(item))
|
|
|
|
}
|
|
|
|
is BookmarkItemMenu.Item.Select -> {
|
|
|
|
actionEmitter.onNext(BookmarkAction.Select(item))
|
|
|
|
}
|
|
|
|
is BookmarkItemMenu.Item.Copy -> {
|
|
|
|
actionEmitter.onNext(BookmarkAction.Copy(item))
|
|
|
|
}
|
|
|
|
is BookmarkItemMenu.Item.Share -> {
|
|
|
|
actionEmitter.onNext(BookmarkAction.Share(item))
|
|
|
|
}
|
|
|
|
is BookmarkItemMenu.Item.OpenInNewTab -> {
|
|
|
|
actionEmitter.onNext(BookmarkAction.OpenInNewTab(item))
|
|
|
|
}
|
|
|
|
is BookmarkItemMenu.Item.OpenInPrivateTab -> {
|
|
|
|
actionEmitter.onNext(BookmarkAction.OpenInPrivateTab(item))
|
|
|
|
}
|
|
|
|
is BookmarkItemMenu.Item.Delete -> {
|
|
|
|
actionEmitter.onNext(BookmarkAction.Delete(item))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bookmark_overflow.increaseTapArea(bookmarkOverflowExtraDips)
|
2019-03-21 20:41:41 +01:00
|
|
|
bookmark_overflow.setOnClickListener {
|
2019-06-10 17:58:18 +02:00
|
|
|
bookmarkItemMenu.menuBuilder.build(containerView.context).show(anchor = it)
|
2019-03-21 20:41:41 +01:00
|
|
|
}
|
2019-04-30 22:21:59 +02:00
|
|
|
bookmark_title.text = if (item.title.isNullOrBlank()) item.url else item.title
|
2019-05-18 12:01:10 +02:00
|
|
|
bookmark_url.text = item.url
|
2019-04-11 06:30:15 +02:00
|
|
|
updateUrl(item, mode, selected)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun updateUrl(item: BookmarkNode, mode: BookmarkState.Mode, selected: Boolean) {
|
|
|
|
setClickListeners(mode, item, selected)
|
|
|
|
|
|
|
|
setColorsAndIcons(selected, item)
|
2019-03-21 20:41:41 +01:00
|
|
|
}
|
|
|
|
|
2019-04-11 06:30:15 +02:00
|
|
|
private fun setColorsAndIcons(selected: Boolean, item: BookmarkNode) {
|
|
|
|
val backgroundTint =
|
2019-04-16 17:03:22 +02:00
|
|
|
if (selected) {
|
2019-05-31 00:49:58 +02:00
|
|
|
ThemeManager.resolveAttribute(R.attr.accentHighContrast, containerView!!.context)
|
2019-04-16 17:03:22 +02:00
|
|
|
} else {
|
2019-05-31 00:49:58 +02:00
|
|
|
ThemeManager.resolveAttribute(R.attr.neutral, containerView!!.context)
|
2019-04-16 17:03:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
val backgroundTintList = ContextCompat.getColorStateList(containerView.context, backgroundTint)
|
2019-04-11 06:30:15 +02:00
|
|
|
bookmark_favicon.backgroundTintList = backgroundTintList
|
|
|
|
if (selected) bookmark_favicon.setImageResource(R.drawable.mozac_ic_check)
|
|
|
|
|
|
|
|
if (!selected && item.url?.startsWith("http") == true) {
|
|
|
|
launch(Dispatchers.IO) {
|
2019-05-15 16:59:07 +02:00
|
|
|
val bitmap = bookmark_layout.context.components.core.icons
|
2019-04-11 06:30:15 +02:00
|
|
|
.loadIcon(IconRequest(item.url!!)).await().bitmap
|
|
|
|
launch(Dispatchers.Main) {
|
|
|
|
bookmark_favicon.setImageBitmap(bitmap)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun setClickListeners(
|
|
|
|
mode: BookmarkState.Mode,
|
|
|
|
item: BookmarkNode,
|
|
|
|
selected: Boolean
|
|
|
|
) {
|
2019-03-21 20:41:41 +01:00
|
|
|
bookmark_layout.setOnClickListener {
|
|
|
|
if (mode == BookmarkState.Mode.Normal) {
|
|
|
|
actionEmitter.onNext(BookmarkAction.Open(item))
|
|
|
|
} else {
|
2019-04-11 06:30:15 +02:00
|
|
|
if (selected) actionEmitter.onNext(BookmarkAction.Deselect(item)) else actionEmitter.onNext(
|
|
|
|
BookmarkAction.Select(item)
|
|
|
|
)
|
2019-03-21 20:41:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bookmark_layout.setOnLongClickListener {
|
|
|
|
if (mode == BookmarkState.Mode.Normal) {
|
2019-04-11 06:30:15 +02:00
|
|
|
if (selected) actionEmitter.onNext(BookmarkAction.Deselect(item)) else actionEmitter.onNext(
|
|
|
|
BookmarkAction.Select(item)
|
|
|
|
)
|
2019-03-21 20:41:41 +01:00
|
|
|
true
|
|
|
|
} else false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
2019-05-18 14:27:55 +02:00
|
|
|
internal const val TWO_DIGIT_MARGIN = 2F
|
2019-05-18 12:01:10 +02:00
|
|
|
|
2019-04-25 17:09:19 +02:00
|
|
|
val viewType = ViewType.ITEM
|
2019-03-21 20:41:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BookmarkFolderViewHolder(
|
|
|
|
view: View,
|
2019-04-11 06:30:15 +02:00
|
|
|
actionEmitter: Observer<BookmarkAction>,
|
|
|
|
job: Job,
|
2019-03-21 20:41:41 +01:00
|
|
|
override val containerView: View? = view
|
|
|
|
) :
|
2019-04-11 06:30:15 +02:00
|
|
|
BookmarkNodeViewHolder(view, actionEmitter, job, containerView) {
|
|
|
|
|
|
|
|
override fun bind(item: BookmarkNode, mode: BookmarkState.Mode, selected: Boolean) {
|
2019-03-21 20:41:41 +01:00
|
|
|
|
2019-05-18 12:01:10 +02:00
|
|
|
val constraintSet = ConstraintSet()
|
|
|
|
constraintSet.clone(bookmark_layout)
|
2019-05-18 12:34:02 +02:00
|
|
|
constraintSet.connect(
|
|
|
|
bookmark_title.id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM
|
|
|
|
)
|
|
|
|
constraintSet.applyTo(bookmark_layout)
|
2019-05-18 12:01:10 +02:00
|
|
|
|
2019-03-21 20:41:41 +01:00
|
|
|
bookmark_favicon.setImageResource(R.drawable.ic_folder_icon)
|
|
|
|
bookmark_favicon.visibility = View.VISIBLE
|
|
|
|
bookmark_title.visibility = View.VISIBLE
|
2019-05-18 12:01:10 +02:00
|
|
|
bookmark_url.visibility = View.GONE
|
2019-03-21 20:41:41 +01:00
|
|
|
bookmark_overflow.visibility = View.VISIBLE
|
|
|
|
bookmark_separator.visibility = View.GONE
|
|
|
|
bookmark_layout.isClickable = true
|
2019-04-11 06:30:15 +02:00
|
|
|
|
|
|
|
setClickListeners(mode, item, selected)
|
|
|
|
|
|
|
|
setMenu(item, containerView!!)
|
|
|
|
|
2019-04-16 17:03:22 +02:00
|
|
|
val backgroundTint = if (selected) {
|
2019-05-31 00:49:58 +02:00
|
|
|
ThemeManager.resolveAttribute(R.attr.accentHighContrast, containerView.context)
|
2019-04-16 17:03:22 +02:00
|
|
|
} else {
|
2019-05-31 00:49:58 +02:00
|
|
|
ThemeManager.resolveAttribute(R.attr.neutral, containerView.context)
|
2019-04-16 17:03:22 +02:00
|
|
|
}
|
|
|
|
|
2019-04-11 06:30:15 +02:00
|
|
|
val backgroundTintList = ContextCompat.getColorStateList(containerView.context, backgroundTint)
|
|
|
|
bookmark_favicon.backgroundTintList = backgroundTintList
|
|
|
|
val res = if (selected) R.drawable.mozac_ic_check else R.drawable.ic_folder_icon
|
|
|
|
bookmark_favicon.setImageResource(res)
|
|
|
|
|
|
|
|
bookmark_title?.text = item.title
|
2019-03-21 20:41:41 +01:00
|
|
|
}
|
|
|
|
|
2019-04-11 06:30:15 +02:00
|
|
|
private fun setMenu(
|
|
|
|
item: BookmarkNode,
|
|
|
|
containerView: View
|
|
|
|
) {
|
|
|
|
val bookmarkItemMenu = BookmarkItemMenu(containerView.context, item) {
|
2019-04-04 22:40:39 +02:00
|
|
|
when (it) {
|
|
|
|
is BookmarkItemMenu.Item.Edit -> {
|
2019-04-11 06:30:15 +02:00
|
|
|
actionEmitter.onNext(BookmarkAction.Edit(item))
|
2019-04-04 22:40:39 +02:00
|
|
|
}
|
|
|
|
is BookmarkItemMenu.Item.Select -> {
|
2019-04-11 06:30:15 +02:00
|
|
|
actionEmitter.onNext(BookmarkAction.Select(item))
|
2019-04-04 22:40:39 +02:00
|
|
|
}
|
|
|
|
is BookmarkItemMenu.Item.Delete -> {
|
2019-04-11 06:30:15 +02:00
|
|
|
actionEmitter.onNext(BookmarkAction.Delete(item))
|
2019-04-04 22:40:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-25 17:09:19 +02:00
|
|
|
if (!item.inRoots()) {
|
2019-04-04 22:40:39 +02:00
|
|
|
bookmark_overflow.increaseTapArea(bookmarkOverflowExtraDips)
|
|
|
|
bookmark_overflow.setOnClickListener {
|
|
|
|
bookmarkItemMenu.menuBuilder.build(containerView.context).show(
|
|
|
|
anchor = it,
|
|
|
|
orientation = BrowserMenu.Orientation.DOWN
|
|
|
|
)
|
|
|
|
}
|
2019-04-25 17:09:19 +02:00
|
|
|
bookmark_layout.setOnLongClickListener(null)
|
2019-04-04 22:40:39 +02:00
|
|
|
} else {
|
|
|
|
bookmark_overflow.visibility = View.GONE
|
2019-03-21 20:41:41 +01:00
|
|
|
}
|
2019-04-11 06:30:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun setClickListeners(
|
|
|
|
mode: BookmarkState.Mode,
|
|
|
|
item: BookmarkNode,
|
|
|
|
selected: Boolean
|
|
|
|
) {
|
2019-03-21 20:41:41 +01:00
|
|
|
bookmark_layout.setOnClickListener {
|
2019-04-11 06:30:15 +02:00
|
|
|
if (mode == BookmarkState.Mode.Normal) {
|
|
|
|
actionEmitter.onNext(BookmarkAction.Expand(item))
|
|
|
|
} else {
|
|
|
|
if (selected) actionEmitter.onNext(BookmarkAction.Deselect(item)) else actionEmitter.onNext(
|
|
|
|
BookmarkAction.Select(item)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bookmark_layout.setOnLongClickListener {
|
2019-04-25 17:09:19 +02:00
|
|
|
if (mode == BookmarkState.Mode.Normal && !item.inRoots()) {
|
2019-04-11 06:30:15 +02:00
|
|
|
if (selected) actionEmitter.onNext(BookmarkAction.Deselect(item)) else actionEmitter.onNext(
|
|
|
|
BookmarkAction.Select(item)
|
|
|
|
)
|
|
|
|
true
|
|
|
|
} else false
|
2019-03-21 20:41:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
2019-04-25 17:09:19 +02:00
|
|
|
val viewType = ViewType.FOLDER
|
2019-03-21 20:41:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BookmarkSeparatorViewHolder(
|
|
|
|
view: View,
|
2019-04-11 06:30:15 +02:00
|
|
|
actionEmitter: Observer<BookmarkAction>,
|
|
|
|
job: Job,
|
2019-03-21 20:41:41 +01:00
|
|
|
override val containerView: View? = view
|
2019-04-11 06:30:15 +02:00
|
|
|
) : BookmarkNodeViewHolder(view, actionEmitter, job, containerView) {
|
|
|
|
|
|
|
|
override fun bind(item: BookmarkNode, mode: BookmarkState.Mode, selected: Boolean) {
|
2019-03-21 20:41:41 +01:00
|
|
|
|
|
|
|
bookmark_favicon.visibility = View.GONE
|
|
|
|
bookmark_title.visibility = View.GONE
|
2019-05-18 12:01:10 +02:00
|
|
|
bookmark_url.visibility = View.GONE
|
2019-04-04 22:40:39 +02:00
|
|
|
bookmark_overflow.increaseTapArea(bookmarkOverflowExtraDips)
|
2019-03-21 20:41:41 +01:00
|
|
|
bookmark_overflow.visibility = View.VISIBLE
|
|
|
|
bookmark_separator.visibility = View.VISIBLE
|
|
|
|
bookmark_layout.isClickable = false
|
|
|
|
|
2019-04-11 06:30:15 +02:00
|
|
|
val bookmarkItemMenu = BookmarkItemMenu(containerView!!.context, item) {
|
2019-04-04 22:40:39 +02:00
|
|
|
when (it) {
|
|
|
|
is BookmarkItemMenu.Item.Delete -> {
|
2019-04-11 06:30:15 +02:00
|
|
|
actionEmitter.onNext(BookmarkAction.Delete(item))
|
2019-04-04 22:40:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-21 20:41:41 +01:00
|
|
|
bookmark_overflow.setOnClickListener {
|
2019-04-04 22:40:39 +02:00
|
|
|
bookmarkItemMenu.menuBuilder.build(containerView.context).show(
|
2019-03-21 20:41:41 +01:00
|
|
|
anchor = it,
|
|
|
|
orientation = BrowserMenu.Orientation.DOWN
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
2019-04-25 17:09:19 +02:00
|
|
|
val viewType = ViewType.SEPARATOR
|
2019-03-21 20:41:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 22:40:39 +02:00
|
|
|
companion object {
|
2019-04-19 06:44:15 +02:00
|
|
|
private const val bookmarkOverflowExtraDips = 16
|
2019-04-04 22:40:39 +02:00
|
|
|
}
|
|
|
|
|
2019-03-21 20:41:41 +01:00
|
|
|
enum class ViewType {
|
|
|
|
ITEM, FOLDER, SEPARATOR
|
|
|
|
}
|
|
|
|
}
|
2019-04-25 17:09:19 +02:00
|
|
|
|
|
|
|
fun BookmarkNode.inRoots() = enumValues<BookmarkRoot>().any { it.id == guid }
|