Issue #18443: Move viewholders to separate files and package

upstream-sync
Jonathan Almeida 3 years ago committed by Jonathan Almeida
parent 917783a141
commit 26c176a75e

@ -11,17 +11,20 @@ import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import org.mozilla.fenix.tabstray.browser.BrowserTabsAdapter
import org.mozilla.fenix.tabstray.browser.BrowserTrayInteractor
import org.mozilla.fenix.tabstray.viewholders.AbstractTrayViewHolder
import org.mozilla.fenix.tabstray.viewholders.NormalBrowserTabViewHolder
import org.mozilla.fenix.tabstray.viewholders.PrivateBrowserTabViewHolder
class TrayPagerAdapter(
val context: Context,
val interactor: TabsTrayInteractor,
val browserInteractor: BrowserTrayInteractor
) : RecyclerView.Adapter<TrayViewHolder>() {
) : RecyclerView.Adapter<AbstractTrayViewHolder>() {
private val normalAdapter by lazy { BrowserTabsAdapter(context, browserInteractor) }
private val privateAdapter by lazy { BrowserTabsAdapter(context, browserInteractor) }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TrayViewHolder {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AbstractTrayViewHolder {
val itemView = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
return when (viewType) {
@ -37,7 +40,7 @@ class TrayPagerAdapter(
}
}
override fun onBindViewHolder(viewHolder: TrayViewHolder, position: Int) {
override fun onBindViewHolder(viewHolder: AbstractTrayViewHolder, position: Int) {
val adapter = when (position) {
POSITION_NORMAL_TABS -> normalAdapter
POSITION_PRIVATE_TABS -> privateAdapter

@ -0,0 +1,23 @@
/* 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.tabstray.viewholders
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import org.mozilla.fenix.tabstray.TrayPagerAdapter
/**
* An abstract [RecyclerView.ViewHolder] for [TrayPagerAdapter] items.
*/
abstract class AbstractTrayViewHolder constructor(
override val containerView: View
) : RecyclerView.ViewHolder(containerView), LayoutContainer {
abstract fun bind(
adapter: RecyclerView.Adapter<out RecyclerView.ViewHolder>,
layoutManager: RecyclerView.LayoutManager
)
}

@ -0,0 +1,36 @@
/* 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.tabstray.viewholders
import android.view.View
import androidx.annotation.CallSuper
import androidx.recyclerview.widget.RecyclerView
import org.mozilla.fenix.R
import org.mozilla.fenix.tabstray.TabsTrayInteractor
import org.mozilla.fenix.tabstray.browser.BaseBrowserTrayList
/**
* A shared view holder for browser tabs tray list.
*/
abstract class BaseBrowserTabViewHolder(
containerView: View,
interactor: TabsTrayInteractor
) : AbstractTrayViewHolder(containerView) {
protected val trayList: BaseBrowserTrayList = itemView.findViewById(R.id.tray_list_item)
init {
trayList.interactor = interactor
}
@CallSuper
override fun bind(
adapter: RecyclerView.Adapter<out RecyclerView.ViewHolder>,
layoutManager: RecyclerView.LayoutManager
) {
trayList.layoutManager = layoutManager
trayList.adapter = adapter
}
}

@ -2,59 +2,26 @@
* 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.tabstray
package org.mozilla.fenix.tabstray.viewholders
import android.view.View
import androidx.annotation.CallSuper
import androidx.recyclerview.selection.SelectionPredicates
import androidx.recyclerview.selection.SelectionTracker
import androidx.recyclerview.selection.StableIdKeyProvider
import androidx.recyclerview.selection.StorageStrategy
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import org.mozilla.fenix.R
import org.mozilla.fenix.tabstray.browser.BaseBrowserTrayList
import org.mozilla.fenix.tabstray.TabsTrayInteractor
import org.mozilla.fenix.tabstray.browser.BrowserTabsAdapter
import org.mozilla.fenix.tabstray.browser.TabsDetailsLookup
import org.mozilla.fenix.tabstray.browser.TabsItemKeyProvider
/**
* Base [RecyclerView.ViewHolder] for [TrayPagerAdapter] items.
* View holder for the normal tabs tray list.
*/
abstract class TrayViewHolder constructor(
override val containerView: View
) : RecyclerView.ViewHolder(containerView), LayoutContainer {
abstract fun bind(
adapter: RecyclerView.Adapter<out RecyclerView.ViewHolder>,
layoutManager: RecyclerView.LayoutManager
)
}
abstract class BrowserTabViewHolder(
containerView: View,
interactor: TabsTrayInteractor
) : TrayViewHolder(containerView) {
protected val trayList: BaseBrowserTrayList = itemView.findViewById(R.id.tray_list_item)
init {
trayList.interactor = interactor
}
@CallSuper
override fun bind(
adapter: RecyclerView.Adapter<out RecyclerView.ViewHolder>,
layoutManager: RecyclerView.LayoutManager
) {
trayList.layoutManager = layoutManager
trayList.adapter = adapter
}
}
class NormalBrowserTabViewHolder(
containerView: View,
interactor: TabsTrayInteractor
) : BrowserTabViewHolder(containerView, interactor) {
) : BaseBrowserTabViewHolder(containerView, interactor) {
private lateinit var selectionTracker: SelectionTracker<Long>
@ -87,12 +54,3 @@ class NormalBrowserTabViewHolder(
const val LAYOUT_ID = R.layout.normal_browser_tray_list
}
}
class PrivateBrowserTabViewHolder(
containerView: View,
interactor: TabsTrayInteractor
) : BrowserTabViewHolder(containerView, interactor) {
companion object {
const val LAYOUT_ID = R.layout.private_browser_tray_list
}
}

@ -0,0 +1,21 @@
/* 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.tabstray.viewholders
import android.view.View
import org.mozilla.fenix.R
import org.mozilla.fenix.tabstray.TabsTrayInteractor
/**
* View holder for the private tabs tray list.
*/
class PrivateBrowserTabViewHolder(
containerView: View,
interactor: TabsTrayInteractor
) : BaseBrowserTabViewHolder(containerView, interactor) {
companion object {
const val LAYOUT_ID = R.layout.private_browser_tray_list
}
}
Loading…
Cancel
Save