You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.1 KiB
Kotlin
60 lines
2.1 KiB
Kotlin
/* 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
|
|
|
|
import android.content.Context
|
|
import android.view.LayoutInflater
|
|
import android.view.ViewGroup
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
import org.mozilla.fenix.tabstray.BrowserTabViewHolder.Companion.LAYOUT_ID_NORMAL_TAB
|
|
import org.mozilla.fenix.tabstray.BrowserTabViewHolder.Companion.LAYOUT_ID_PRIVATE_TAB
|
|
import org.mozilla.fenix.tabtray.FenixTabsAdapter
|
|
|
|
class TrayPagerAdapter(
|
|
context: Context,
|
|
val interactor: TabsTrayInteractor
|
|
) : RecyclerView.Adapter<TrayViewHolder>() {
|
|
|
|
private val normalAdapter by lazy { FenixTabsAdapter(context) }
|
|
private val privateAdapter by lazy { FenixTabsAdapter(context) }
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TrayViewHolder {
|
|
val itemView = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
|
|
|
|
return when (viewType) {
|
|
LAYOUT_ID_NORMAL_TAB -> BrowserTabViewHolder(itemView, interactor)
|
|
LAYOUT_ID_PRIVATE_TAB -> BrowserTabViewHolder(itemView, interactor)
|
|
else -> throw IllegalStateException("Unknown viewType.")
|
|
}
|
|
}
|
|
|
|
override fun onBindViewHolder(viewHolder: TrayViewHolder, position: Int) {
|
|
val adapter = when (position) {
|
|
POSITION_NORMAL_TABS -> normalAdapter
|
|
POSITION_PRIVATE_TABS -> privateAdapter
|
|
else -> throw IllegalStateException("View type does not exist.")
|
|
}
|
|
|
|
viewHolder.bind(adapter)
|
|
}
|
|
|
|
override fun getItemViewType(position: Int): Int {
|
|
return when (position) {
|
|
POSITION_NORMAL_TABS -> LAYOUT_ID_NORMAL_TAB
|
|
POSITION_PRIVATE_TABS -> LAYOUT_ID_PRIVATE_TAB
|
|
else -> throw IllegalStateException("Unknown position.")
|
|
}
|
|
}
|
|
|
|
override fun getItemCount(): Int = TRAY_TABS_COUNT
|
|
|
|
companion object {
|
|
const val TRAY_TABS_COUNT = 2
|
|
|
|
const val POSITION_NORMAL_TABS = 0
|
|
const val POSITION_PRIVATE_TABS = 1
|
|
}
|
|
}
|