2019-05-06 20:20:19 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +02:00
|
|
|
* 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/. */
|
2019-05-06 20:20:19 +02:00
|
|
|
|
|
|
|
package org.mozilla.fenix.home.sessioncontrol.viewholders
|
|
|
|
|
|
|
|
import android.graphics.Outline
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewOutlineProvider
|
|
|
|
import androidx.core.content.ContextCompat
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import kotlinx.android.extensions.LayoutContainer
|
|
|
|
import kotlinx.android.synthetic.main.tab_in_collection.*
|
2019-12-05 04:06:05 +01:00
|
|
|
import mozilla.components.feature.tab.collections.TabCollection
|
2019-07-08 21:45:07 +02:00
|
|
|
import mozilla.components.support.ktx.android.util.dpToFloat
|
2019-05-06 20:20:19 +02:00
|
|
|
import org.jetbrains.anko.backgroundColor
|
|
|
|
import org.mozilla.fenix.R
|
|
|
|
import org.mozilla.fenix.ext.components
|
|
|
|
import org.mozilla.fenix.ext.getColorFromAttr
|
2019-05-08 20:12:41 +02:00
|
|
|
import org.mozilla.fenix.ext.increaseTapArea
|
2019-06-26 22:40:20 +02:00
|
|
|
import org.mozilla.fenix.ext.loadIntoView
|
2019-11-15 23:25:50 +01:00
|
|
|
import org.mozilla.fenix.ext.toShortUrl
|
2019-12-05 04:06:05 +01:00
|
|
|
import org.mozilla.fenix.home.sessioncontrol.CollectionInteractor
|
2019-05-16 23:02:24 +02:00
|
|
|
import mozilla.components.feature.tab.collections.Tab as ComponentTab
|
2019-05-06 20:20:19 +02:00
|
|
|
|
|
|
|
class TabInCollectionViewHolder(
|
|
|
|
val view: View,
|
2019-12-05 04:06:05 +01:00
|
|
|
val interactor: CollectionInteractor,
|
2019-05-06 20:20:19 +02:00
|
|
|
override val containerView: View? = view
|
2019-06-26 22:40:20 +02:00
|
|
|
) : RecyclerView.ViewHolder(view), LayoutContainer {
|
2019-05-06 20:20:19 +02:00
|
|
|
|
|
|
|
lateinit var collection: TabCollection
|
|
|
|
private set
|
2019-05-16 23:02:24 +02:00
|
|
|
lateinit var tab: ComponentTab
|
2019-05-06 20:20:19 +02:00
|
|
|
private set
|
|
|
|
var isLastTab = false
|
|
|
|
|
|
|
|
init {
|
|
|
|
collection_tab_icon.clipToOutline = true
|
|
|
|
collection_tab_icon.outlineProvider = object : ViewOutlineProvider() {
|
2019-07-08 21:45:07 +02:00
|
|
|
override fun getOutline(view: View, outline: Outline?) {
|
2019-05-06 20:20:19 +02:00
|
|
|
outline?.setRoundRect(
|
|
|
|
0,
|
|
|
|
0,
|
2019-07-08 21:45:07 +02:00
|
|
|
view.width,
|
2019-05-06 20:20:19 +02:00
|
|
|
view.height,
|
2019-07-08 21:45:07 +02:00
|
|
|
TabViewHolder.favIconBorderRadiusInPx.dpToFloat(view.context.resources.displayMetrics)
|
2019-05-06 20:20:19 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 20:31:25 +02:00
|
|
|
view.setOnClickListener {
|
2019-12-05 04:06:05 +01:00
|
|
|
interactor.onCollectionOpenTabClicked(tab)
|
2019-05-20 20:31:25 +02:00
|
|
|
}
|
|
|
|
|
2019-05-08 20:12:41 +02:00
|
|
|
collection_tab_close_button.increaseTapArea(buttonIncreaseDps)
|
2019-05-06 20:20:19 +02:00
|
|
|
collection_tab_close_button.setOnClickListener {
|
2019-12-05 04:06:05 +01:00
|
|
|
interactor.onCollectionRemoveTab(collection, tab)
|
2019-05-06 20:20:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-16 23:02:24 +02:00
|
|
|
fun bindSession(collection: TabCollection, tab: ComponentTab, isLastTab: Boolean) {
|
2019-05-06 20:20:19 +02:00
|
|
|
this.collection = collection
|
|
|
|
this.tab = tab
|
|
|
|
this.isLastTab = isLastTab
|
|
|
|
updateTabUI()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun updateTabUI() {
|
2019-11-15 23:25:50 +01:00
|
|
|
collection_tab_hostname.text = tab.url.toShortUrl(view.context.components.publicSuffixList)
|
2019-06-10 22:46:55 +02:00
|
|
|
|
2019-05-06 20:20:19 +02:00
|
|
|
collection_tab_title.text = tab.title
|
2019-06-26 22:40:20 +02:00
|
|
|
collection_tab_icon.context.components.core.icons.loadIntoView(collection_tab_icon, tab.url)
|
2019-05-06 20:20:19 +02:00
|
|
|
|
|
|
|
// If I'm the last one...
|
|
|
|
if (isLastTab) {
|
|
|
|
view.background = ContextCompat.getDrawable(view.context, R.drawable.rounded_bottom_corners)
|
|
|
|
divider_line.visibility = View.GONE
|
|
|
|
} else {
|
2019-07-22 22:59:24 +02:00
|
|
|
view.backgroundColor = view.context.getColorFromAttr(R.attr.above)
|
2019-05-06 20:20:19 +02:00
|
|
|
divider_line.visibility = View.VISIBLE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
2019-05-08 20:12:41 +02:00
|
|
|
const val buttonIncreaseDps = 12
|
2019-05-06 20:20:19 +02:00
|
|
|
const val LAYOUT_ID = R.layout.tab_in_collection
|
|
|
|
}
|
|
|
|
}
|