mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/17917: Use View binding in history screens
This commit is contained in:
parent
c0e20cf63d
commit
f4f6b18cbe
@ -28,8 +28,9 @@ enum class HistoryItemTimeGroup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class HistoryAdapter(private val historyInteractor: HistoryInteractor) :
|
class HistoryAdapter(
|
||||||
PagedListAdapter<HistoryItem, HistoryListItemViewHolder>(historyDiffCallback),
|
private val historyInteractor: HistoryInteractor,
|
||||||
|
) : PagedListAdapter<HistoryItem, HistoryListItemViewHolder>(historyDiffCallback),
|
||||||
SelectionHolder<HistoryItem> {
|
SelectionHolder<HistoryItem> {
|
||||||
|
|
||||||
private var mode: HistoryFragmentState.Mode = HistoryFragmentState.Mode.Normal
|
private var mode: HistoryFragmentState.Mode = HistoryFragmentState.Mode.Normal
|
||||||
@ -41,6 +42,7 @@ class HistoryAdapter(private val historyInteractor: HistoryInteractor) :
|
|||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HistoryListItemViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HistoryListItemViewHolder {
|
||||||
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
|
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
|
||||||
|
|
||||||
return HistoryListItemViewHolder(view, historyInteractor, this)
|
return HistoryListItemViewHolder(view, historyInteractor, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ import androidx.lifecycle.Observer
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.navigation.NavDirections
|
import androidx.navigation.NavDirections
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import kotlinx.android.synthetic.main.fragment_history.view.*
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.Dispatchers.Main
|
import kotlinx.coroutines.Dispatchers.Main
|
||||||
@ -43,6 +42,7 @@ import org.mozilla.fenix.components.FenixSnackbar
|
|||||||
import org.mozilla.fenix.components.StoreProvider
|
import org.mozilla.fenix.components.StoreProvider
|
||||||
import org.mozilla.fenix.components.history.createSynchronousPagedHistoryProvider
|
import org.mozilla.fenix.components.history.createSynchronousPagedHistoryProvider
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
|
import org.mozilla.fenix.databinding.FragmentHistoryBinding
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.nav
|
import org.mozilla.fenix.ext.nav
|
||||||
import org.mozilla.fenix.ext.requireComponents
|
import org.mozilla.fenix.ext.requireComponents
|
||||||
@ -62,13 +62,16 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), UserInteractionHandl
|
|||||||
private var _historyView: HistoryView? = null
|
private var _historyView: HistoryView? = null
|
||||||
protected val historyView: HistoryView
|
protected val historyView: HistoryView
|
||||||
get() = _historyView!!
|
get() = _historyView!!
|
||||||
|
private var _binding: FragmentHistoryBinding? = null
|
||||||
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View {
|
||||||
val view = inflater.inflate(R.layout.fragment_history, container, false)
|
_binding = FragmentHistoryBinding.inflate(inflater, container, false)
|
||||||
|
val view = binding.root
|
||||||
historyStore = StoreProvider.get(this) {
|
historyStore = StoreProvider.get(this) {
|
||||||
HistoryFragmentStore(
|
HistoryFragmentStore(
|
||||||
HistoryFragmentState(
|
HistoryFragmentState(
|
||||||
@ -102,7 +105,7 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), UserInteractionHandl
|
|||||||
historyController
|
historyController
|
||||||
)
|
)
|
||||||
_historyView = HistoryView(
|
_historyView = HistoryView(
|
||||||
view.historyLayout,
|
binding.historyLayout,
|
||||||
historyInteractor
|
historyInteractor
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -254,6 +257,7 @@ class HistoryFragment : LibraryPageFragment<HistoryItem>(), UserInteractionHandl
|
|||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
_historyView = null
|
_historyView = null
|
||||||
|
_binding = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openItem(item: HistoryItem) {
|
private fun openItem(item: HistoryItem) {
|
||||||
|
@ -5,16 +5,13 @@
|
|||||||
package org.mozilla.fenix.library.history
|
package org.mozilla.fenix.library.history
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.SimpleItemAnimator
|
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||||
import kotlinx.android.synthetic.main.component_history.*
|
|
||||||
import kotlinx.android.synthetic.main.component_history.view.*
|
|
||||||
import kotlinx.android.synthetic.main.recently_closed_nav_item.*
|
|
||||||
import mozilla.components.support.base.feature.UserInteractionHandler
|
import mozilla.components.support.base.feature.UserInteractionHandler
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.databinding.ComponentHistoryBinding
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.library.LibraryPageView
|
import org.mozilla.fenix.library.LibraryPageView
|
||||||
import org.mozilla.fenix.selection.SelectionInteractor
|
import org.mozilla.fenix.selection.SelectionInteractor
|
||||||
@ -94,8 +91,9 @@ class HistoryView(
|
|||||||
val interactor: HistoryInteractor
|
val interactor: HistoryInteractor
|
||||||
) : LibraryPageView(container), UserInteractionHandler {
|
) : LibraryPageView(container), UserInteractionHandler {
|
||||||
|
|
||||||
val view: View = LayoutInflater.from(container.context)
|
val binding = ComponentHistoryBinding.inflate(
|
||||||
.inflate(R.layout.component_history, container, true)
|
LayoutInflater.from(container.context), container, true
|
||||||
|
)
|
||||||
|
|
||||||
var mode: HistoryFragmentState.Mode = HistoryFragmentState.Mode.Normal
|
var mode: HistoryFragmentState.Mode = HistoryFragmentState.Mode.Normal
|
||||||
private set
|
private set
|
||||||
@ -104,7 +102,7 @@ class HistoryView(
|
|||||||
private val layoutManager = LinearLayoutManager(container.context)
|
private val layoutManager = LinearLayoutManager(container.context)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
view.history_list.apply {
|
binding.historyList.apply {
|
||||||
layoutManager = this@HistoryView.layoutManager
|
layoutManager = this@HistoryView.layoutManager
|
||||||
adapter = historyAdapter
|
adapter = historyAdapter
|
||||||
(itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
|
(itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false
|
||||||
@ -112,19 +110,19 @@ class HistoryView(
|
|||||||
|
|
||||||
val primaryTextColor =
|
val primaryTextColor =
|
||||||
ThemeManager.resolveAttribute(R.attr.primaryText, context)
|
ThemeManager.resolveAttribute(R.attr.primaryText, context)
|
||||||
view.swipe_refresh.setColorSchemeColors(primaryTextColor)
|
binding.swipeRefresh.setColorSchemeColors(primaryTextColor)
|
||||||
view.swipe_refresh.setOnRefreshListener {
|
binding.swipeRefresh.setOnRefreshListener {
|
||||||
interactor.onRequestSync()
|
interactor.onRequestSync()
|
||||||
view.history_list.scrollToPosition(0)
|
binding.historyList.scrollToPosition(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun update(state: HistoryFragmentState) {
|
fun update(state: HistoryFragmentState) {
|
||||||
val oldMode = mode
|
val oldMode = mode
|
||||||
|
|
||||||
view.progress_bar.isVisible = state.isDeletingItems
|
binding.progressBar.isVisible = state.isDeletingItems
|
||||||
view.swipe_refresh.isRefreshing = state.mode === HistoryFragmentState.Mode.Syncing
|
binding.swipeRefresh.isRefreshing = state.mode === HistoryFragmentState.Mode.Syncing
|
||||||
view.swipe_refresh.isEnabled =
|
binding.swipeRefresh.isEnabled =
|
||||||
state.mode === HistoryFragmentState.Mode.Normal || state.mode === HistoryFragmentState.Mode.Syncing
|
state.mode === HistoryFragmentState.Mode.Normal || state.mode === HistoryFragmentState.Mode.Syncing
|
||||||
mode = state.mode
|
mode = state.mode
|
||||||
|
|
||||||
@ -164,24 +162,24 @@ class HistoryView(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateEmptyState(userHasHistory: Boolean) {
|
fun updateEmptyState(userHasHistory: Boolean) {
|
||||||
history_list.isVisible = userHasHistory
|
binding.historyList.isVisible = userHasHistory
|
||||||
history_empty_view.isVisible = !userHasHistory
|
binding.historyEmptyView.isVisible = !userHasHistory
|
||||||
recently_closed_nav_empty.apply {
|
with(binding.recentlyClosedNavEmpty) {
|
||||||
setOnClickListener {
|
recentlyClosedNav.setOnClickListener {
|
||||||
interactor.onRecentlyClosedClicked()
|
interactor.onRecentlyClosedClicked()
|
||||||
}
|
}
|
||||||
val numRecentTabs = view.context.components.core.store.state.closedTabs.size
|
val numRecentTabs = recentlyClosedNav.context.components.core.store.state.closedTabs.size
|
||||||
recently_closed_tabs_description.text = String.format(
|
recentlyClosedTabsDescription.text = String.format(
|
||||||
view.context.getString(
|
context.getString(
|
||||||
if (numRecentTabs == 1)
|
if (numRecentTabs == 1)
|
||||||
R.string.recently_closed_tab else R.string.recently_closed_tabs
|
R.string.recently_closed_tab else R.string.recently_closed_tabs
|
||||||
),
|
),
|
||||||
numRecentTabs
|
numRecentTabs
|
||||||
)
|
)
|
||||||
isVisible = !userHasHistory
|
recentlyClosedNav.isVisible = !userHasHistory
|
||||||
}
|
}
|
||||||
if (!userHasHistory) {
|
if (!userHasHistory) {
|
||||||
history_empty_view.announceForAccessibility(context.getString(R.string.history_empty_message))
|
binding.historyEmptyView.announceForAccessibility(context.getString(R.string.history_empty_message))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,13 +5,10 @@
|
|||||||
package org.mozilla.fenix.library.history.viewholders
|
package org.mozilla.fenix.library.history.viewholders
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import kotlinx.android.synthetic.main.history_list_item.view.*
|
|
||||||
import kotlinx.android.synthetic.main.library_site_item.view.*
|
|
||||||
import kotlinx.android.synthetic.main.recently_closed_nav_item.view.*
|
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.databinding.HistoryListItemBinding
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.hideAndDisable
|
import org.mozilla.fenix.ext.hideAndDisable
|
||||||
import org.mozilla.fenix.ext.showAndEnable
|
import org.mozilla.fenix.ext.showAndEnable
|
||||||
@ -30,11 +27,12 @@ class HistoryListItemViewHolder(
|
|||||||
) : RecyclerView.ViewHolder(view) {
|
) : RecyclerView.ViewHolder(view) {
|
||||||
|
|
||||||
private var item: HistoryItem? = null
|
private var item: HistoryItem? = null
|
||||||
|
private val binding = HistoryListItemBinding.bind(view)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setupMenu()
|
setupMenu()
|
||||||
|
|
||||||
itemView.delete_button.setOnClickListener {
|
binding.deleteButton.setOnClickListener {
|
||||||
val selected = selectionHolder.selectedItems
|
val selected = selectionHolder.selectedItems
|
||||||
if (selected.isEmpty()) {
|
if (selected.isEmpty()) {
|
||||||
historyInteractor.onDeleteAll()
|
historyInteractor.onDeleteAll()
|
||||||
@ -43,7 +41,7 @@ class HistoryListItemViewHolder(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
itemView.findViewById<ConstraintLayout>(R.id.recently_closed_nav).setOnClickListener {
|
binding.recentlyClosedNavEmpty.recentlyClosedNav.setOnClickListener {
|
||||||
historyInteractor.onRecentlyClosedClicked()
|
historyInteractor.onRecentlyClosedClicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,30 +54,30 @@ class HistoryListItemViewHolder(
|
|||||||
isPendingDeletion: Boolean = false
|
isPendingDeletion: Boolean = false
|
||||||
) {
|
) {
|
||||||
if (isPendingDeletion) {
|
if (isPendingDeletion) {
|
||||||
itemView.history_layout.visibility = View.GONE
|
binding.historyLayout.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
itemView.history_layout.visibility = View.VISIBLE
|
binding.historyLayout.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
itemView.history_layout.titleView.text = item.title
|
binding.historyLayout.titleView.text = item.title
|
||||||
itemView.history_layout.urlView.text = item.url
|
binding.historyLayout.urlView.text = item.url
|
||||||
|
|
||||||
toggleTopContent(showDeleteButton, mode === HistoryFragmentState.Mode.Normal)
|
toggleTopContent(showDeleteButton, mode === HistoryFragmentState.Mode.Normal)
|
||||||
|
|
||||||
val headerText = timeGroup?.humanReadable(itemView.context)
|
val headerText = timeGroup?.humanReadable(itemView.context)
|
||||||
toggleHeader(headerText)
|
toggleHeader(headerText)
|
||||||
|
|
||||||
itemView.history_layout.setSelectionInteractor(item, selectionHolder, historyInteractor)
|
binding.historyLayout.setSelectionInteractor(item, selectionHolder, historyInteractor)
|
||||||
itemView.history_layout.changeSelected(item in selectionHolder.selectedItems)
|
binding.historyLayout.changeSelected(item in selectionHolder.selectedItems)
|
||||||
|
|
||||||
if (this.item?.url != item.url) {
|
if (this.item?.url != item.url) {
|
||||||
itemView.history_layout.loadFavicon(item.url)
|
binding.historyLayout.loadFavicon(item.url)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode is HistoryFragmentState.Mode.Editing) {
|
if (mode is HistoryFragmentState.Mode.Editing) {
|
||||||
itemView.overflow_menu.hideAndDisable()
|
binding.historyLayout.overflowView.hideAndDisable()
|
||||||
} else {
|
} else {
|
||||||
itemView.overflow_menu.showAndEnable()
|
binding.historyLayout.overflowView.showAndEnable()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.item = item
|
this.item = item
|
||||||
@ -87,10 +85,10 @@ class HistoryListItemViewHolder(
|
|||||||
|
|
||||||
private fun toggleHeader(headerText: String?) {
|
private fun toggleHeader(headerText: String?) {
|
||||||
if (headerText != null) {
|
if (headerText != null) {
|
||||||
itemView.header_title.visibility = View.VISIBLE
|
binding.headerTitle.visibility = View.VISIBLE
|
||||||
itemView.header_title.text = headerText
|
binding.headerTitle.text = headerText
|
||||||
} else {
|
} else {
|
||||||
itemView.header_title.visibility = View.GONE
|
binding.headerTitle.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,11 +96,11 @@ class HistoryListItemViewHolder(
|
|||||||
showTopContent: Boolean,
|
showTopContent: Boolean,
|
||||||
isNormalMode: Boolean
|
isNormalMode: Boolean
|
||||||
) {
|
) {
|
||||||
itemView.delete_button.isVisible = showTopContent
|
binding.deleteButton.isVisible = showTopContent
|
||||||
itemView.findViewById<ConstraintLayout>(R.id.recently_closed_nav).isVisible = showTopContent
|
binding.recentlyClosedNavEmpty.recentlyClosedNav.isVisible = showTopContent
|
||||||
|
|
||||||
if (showTopContent) {
|
if (showTopContent) {
|
||||||
itemView.delete_button.run {
|
binding.deleteButton.run {
|
||||||
if (isNormalMode) {
|
if (isNormalMode) {
|
||||||
isEnabled = true
|
isEnabled = true
|
||||||
alpha = 1f
|
alpha = 1f
|
||||||
@ -112,14 +110,14 @@ class HistoryListItemViewHolder(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val numRecentTabs = itemView.context.components.core.store.state.closedTabs.size
|
val numRecentTabs = itemView.context.components.core.store.state.closedTabs.size
|
||||||
itemView.recently_closed_tabs_description.text = String.format(
|
binding.recentlyClosedNavEmpty.recentlyClosedTabsDescription.text = String.format(
|
||||||
itemView.context.getString(
|
itemView.context.getString(
|
||||||
if (numRecentTabs == 1)
|
if (numRecentTabs == 1)
|
||||||
R.string.recently_closed_tab else R.string.recently_closed_tabs
|
R.string.recently_closed_tab else R.string.recently_closed_tabs
|
||||||
),
|
),
|
||||||
numRecentTabs
|
numRecentTabs
|
||||||
)
|
)
|
||||||
itemView.findViewById<ConstraintLayout>(R.id.recently_closed_nav).run {
|
binding.recentlyClosedNavEmpty.recentlyClosedNav.run {
|
||||||
if (isNormalMode) {
|
if (isNormalMode) {
|
||||||
isEnabled = true
|
isEnabled = true
|
||||||
alpha = 1f
|
alpha = 1f
|
||||||
@ -143,7 +141,7 @@ class HistoryListItemViewHolder(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
itemView.history_layout.attachMenu(historyMenu.menuController)
|
binding.historyLayout.attachMenu(historyMenu.menuController)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<include layout="@layout/recently_closed_nav_item" />
|
<include
|
||||||
|
android:id="@+id/recently_closed_nav_empty"
|
||||||
|
layout="@layout/recently_closed_nav_item" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/header_title"
|
android:id="@+id/header_title"
|
||||||
|
Loading…
Reference in New Issue
Block a user