2019-08-01 22:44:52 +02: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.viewholders
|
|
|
|
|
|
|
|
import android.view.View
|
2019-12-17 05:35:36 +01:00
|
|
|
import androidx.appcompat.content.res.AppCompatResources
|
2020-02-06 17:14:32 +01:00
|
|
|
import androidx.core.content.ContextCompat
|
2019-08-01 22:44:52 +02:00
|
|
|
import mozilla.components.concept.storage.BookmarkNode
|
|
|
|
import org.mozilla.fenix.R
|
2019-10-11 08:02:22 +02:00
|
|
|
import org.mozilla.fenix.ext.hideAndDisable
|
|
|
|
import org.mozilla.fenix.ext.showAndEnable
|
2019-08-01 22:44:52 +02:00
|
|
|
import org.mozilla.fenix.library.LibrarySiteItemView
|
2019-08-04 00:23:15 +02:00
|
|
|
import org.mozilla.fenix.library.SelectionHolder
|
2020-08-04 20:28:40 +02:00
|
|
|
import org.mozilla.fenix.library.bookmarks.BookmarkFragmentState
|
2019-08-01 22:44:52 +02:00
|
|
|
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,
|
2019-08-04 00:23:15 +02:00
|
|
|
interactor: BookmarkViewInteractor,
|
|
|
|
private val selectionHolder: SelectionHolder<BookmarkNode>
|
2019-08-01 22:44:52 +02:00
|
|
|
) : BookmarkNodeViewHolder(view, interactor) {
|
|
|
|
|
2020-07-14 19:21:40 +02:00
|
|
|
override var item: BookmarkNode? = null
|
|
|
|
|
2020-08-04 20:28:40 +02:00
|
|
|
override fun bind(
|
|
|
|
item: BookmarkNode,
|
|
|
|
mode: BookmarkFragmentState.Mode
|
|
|
|
) {
|
2020-07-14 19:21:40 +02:00
|
|
|
this.item = item
|
2019-08-01 22:44:52 +02:00
|
|
|
|
|
|
|
containerView.displayAs(LibrarySiteItemView.ItemType.FOLDER)
|
|
|
|
|
2019-08-04 00:23:15 +02:00
|
|
|
setSelectionListeners(item, selectionHolder)
|
2019-08-01 22:44:52 +02:00
|
|
|
|
|
|
|
if (!item.inRoots()) {
|
|
|
|
setupMenu(item)
|
2020-08-04 20:28:40 +02:00
|
|
|
if (mode is BookmarkFragmentState.Mode.Selecting) {
|
2019-10-11 08:02:22 +02:00
|
|
|
containerView.overflowView.hideAndDisable()
|
2020-08-04 20:28:40 +02:00
|
|
|
} else {
|
|
|
|
containerView.overflowView.showAndEnable()
|
2019-09-12 22:56:39 +02:00
|
|
|
}
|
2019-08-01 22:44:52 +02:00
|
|
|
} else {
|
|
|
|
containerView.overflowView.visibility = View.GONE
|
|
|
|
}
|
|
|
|
|
2019-08-04 00:23:15 +02:00
|
|
|
containerView.changeSelected(item in selectionHolder.selectedItems)
|
2019-12-19 08:44:32 +01:00
|
|
|
containerView.iconView.setImageDrawable(
|
|
|
|
AppCompatResources.getDrawable(
|
|
|
|
containerView.context,
|
|
|
|
R.drawable.ic_folder_icon
|
|
|
|
)?.apply {
|
|
|
|
setTint(
|
|
|
|
ContextCompat.getColor(
|
|
|
|
containerView.context,
|
|
|
|
R.color.primary_text_light_theme
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
2019-08-01 22:44:52 +02:00
|
|
|
containerView.titleView.text = item.title
|
|
|
|
}
|
|
|
|
}
|