[fenix] Issue https://github.com/mozilla-mobile/fenix/issues/2379 - Use LibrarySiteItemView in history
parent
47e7928dd9
commit
d4200df79c
@ -0,0 +1,64 @@
|
|||||||
|
/* 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.viewholders
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import mozilla.components.concept.storage.BookmarkNode
|
||||||
|
import org.jetbrains.anko.image
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.library.LibrarySiteItemView
|
||||||
|
import org.mozilla.fenix.library.bookmarks.BookmarkState
|
||||||
|
import org.mozilla.fenix.library.bookmarks.BookmarkViewInteractor
|
||||||
|
import org.mozilla.fenix.library.bookmarks.inRoots
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a folder with other bookmarks inside.
|
||||||
|
*/
|
||||||
|
class BookmarkFolderViewHolder(
|
||||||
|
view: LibrarySiteItemView,
|
||||||
|
interactor: BookmarkViewInteractor
|
||||||
|
) : BookmarkNodeViewHolder(view, interactor) {
|
||||||
|
|
||||||
|
override fun bind(item: BookmarkNode, mode: BookmarkState.Mode, selected: Boolean) {
|
||||||
|
|
||||||
|
containerView.displayAs(LibrarySiteItemView.ItemType.FOLDER)
|
||||||
|
|
||||||
|
setClickListeners(mode, item, selected)
|
||||||
|
|
||||||
|
if (!item.inRoots()) {
|
||||||
|
setupMenu(item)
|
||||||
|
} else {
|
||||||
|
containerView.overflowView.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
containerView.changeSelected(selected)
|
||||||
|
containerView.iconView.image = containerView.context.getDrawable(R.drawable.ic_folder_icon)?.apply {
|
||||||
|
setTint(ContextCompat.getColor(containerView.context, R.color.primary_text_light_theme))
|
||||||
|
}
|
||||||
|
containerView.titleView.text = item.title
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setClickListeners(
|
||||||
|
mode: BookmarkState.Mode,
|
||||||
|
item: BookmarkNode,
|
||||||
|
selected: Boolean
|
||||||
|
) {
|
||||||
|
containerView.setOnClickListener {
|
||||||
|
when {
|
||||||
|
mode == BookmarkState.Mode.Normal -> interactor.expand(item)
|
||||||
|
selected -> interactor.deselect(item)
|
||||||
|
else -> interactor.select(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
containerView.setOnLongClickListener {
|
||||||
|
if (mode == BookmarkState.Mode.Normal && !item.inRoots()) {
|
||||||
|
interactor.select(item)
|
||||||
|
true
|
||||||
|
} else false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/* 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.viewholders
|
||||||
|
|
||||||
|
import mozilla.components.concept.storage.BookmarkNode
|
||||||
|
import org.mozilla.fenix.library.LibrarySiteItemView
|
||||||
|
import org.mozilla.fenix.library.bookmarks.BookmarkState
|
||||||
|
import org.mozilla.fenix.library.bookmarks.BookmarkViewInteractor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a bookmarked website in the bookmarks page.
|
||||||
|
*/
|
||||||
|
class BookmarkItemViewHolder(
|
||||||
|
view: LibrarySiteItemView,
|
||||||
|
interactor: BookmarkViewInteractor
|
||||||
|
) : BookmarkNodeViewHolder(view, interactor) {
|
||||||
|
|
||||||
|
override fun bind(item: BookmarkNode, mode: BookmarkState.Mode, selected: Boolean) {
|
||||||
|
|
||||||
|
containerView.displayAs(LibrarySiteItemView.ItemType.SITE)
|
||||||
|
|
||||||
|
setupMenu(item)
|
||||||
|
containerView.titleView.text = if (item.title.isNullOrBlank()) item.url else item.title
|
||||||
|
containerView.urlView.text = item.url
|
||||||
|
|
||||||
|
setClickListeners(mode, item, selected)
|
||||||
|
containerView.changeSelected(selected)
|
||||||
|
setColorsAndIcons(item.url)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setColorsAndIcons(url: String?) {
|
||||||
|
if (url != null && url.startsWith("http")) {
|
||||||
|
containerView.loadFavicon(url)
|
||||||
|
} else {
|
||||||
|
containerView.iconView.setImageDrawable(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setClickListeners(
|
||||||
|
mode: BookmarkState.Mode,
|
||||||
|
item: BookmarkNode,
|
||||||
|
selected: Boolean
|
||||||
|
) {
|
||||||
|
containerView.setOnClickListener {
|
||||||
|
when {
|
||||||
|
mode == BookmarkState.Mode.Normal -> interactor.open(item)
|
||||||
|
selected -> interactor.deselect(item)
|
||||||
|
else -> interactor.select(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
containerView.setOnLongClickListener {
|
||||||
|
if (mode == BookmarkState.Mode.Normal) {
|
||||||
|
interactor.select(item)
|
||||||
|
true
|
||||||
|
} else false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
/* 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.viewholders
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import kotlinx.android.extensions.LayoutContainer
|
||||||
|
import mozilla.components.browser.menu.BrowserMenu
|
||||||
|
import mozilla.components.concept.storage.BookmarkNode
|
||||||
|
import org.mozilla.fenix.library.LibrarySiteItemView
|
||||||
|
import org.mozilla.fenix.library.bookmarks.BookmarkItemMenu
|
||||||
|
import org.mozilla.fenix.library.bookmarks.BookmarkState
|
||||||
|
import org.mozilla.fenix.library.bookmarks.BookmarkViewInteractor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for bookmark node view holders.
|
||||||
|
*/
|
||||||
|
abstract class BookmarkNodeViewHolder(
|
||||||
|
override val containerView: LibrarySiteItemView,
|
||||||
|
val interactor: BookmarkViewInteractor
|
||||||
|
) :
|
||||||
|
RecyclerView.ViewHolder(containerView), LayoutContainer {
|
||||||
|
|
||||||
|
abstract fun bind(item: BookmarkNode, mode: BookmarkState.Mode, selected: Boolean)
|
||||||
|
|
||||||
|
protected fun setupMenu(item: BookmarkNode) {
|
||||||
|
val bookmarkItemMenu = BookmarkItemMenu(containerView.context, item) {
|
||||||
|
when (it) {
|
||||||
|
BookmarkItemMenu.Item.Edit -> interactor.edit(item)
|
||||||
|
BookmarkItemMenu.Item.Select -> interactor.select(item)
|
||||||
|
BookmarkItemMenu.Item.Copy -> interactor.copy(item)
|
||||||
|
BookmarkItemMenu.Item.Share -> interactor.share(item)
|
||||||
|
BookmarkItemMenu.Item.OpenInNewTab -> interactor.openInNewTab(item)
|
||||||
|
BookmarkItemMenu.Item.OpenInPrivateTab -> interactor.openInPrivateTab(item)
|
||||||
|
BookmarkItemMenu.Item.Delete -> interactor.delete(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
containerView.overflowView.setOnClickListener {
|
||||||
|
bookmarkItemMenu.menuBuilder.build(containerView.context).show(
|
||||||
|
anchor = it,
|
||||||
|
orientation = BrowserMenu.Orientation.DOWN
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
/* 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.viewholders
|
||||||
|
|
||||||
|
import mozilla.components.concept.storage.BookmarkNode
|
||||||
|
import org.mozilla.fenix.library.LibrarySiteItemView
|
||||||
|
import org.mozilla.fenix.library.bookmarks.BookmarkState
|
||||||
|
import org.mozilla.fenix.library.bookmarks.BookmarkViewInteractor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple view holder for dividers in the bookmarks list.
|
||||||
|
*/
|
||||||
|
class BookmarkSeparatorViewHolder(
|
||||||
|
view: LibrarySiteItemView,
|
||||||
|
interactor: BookmarkViewInteractor
|
||||||
|
) : BookmarkNodeViewHolder(view, interactor) {
|
||||||
|
|
||||||
|
override fun bind(item: BookmarkNode, mode: BookmarkState.Mode, selected: Boolean) {
|
||||||
|
containerView.displayAs(LibrarySiteItemView.ItemType.SEPARATOR)
|
||||||
|
setupMenu(item)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue