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
|
2019-12-06 04:54:32 +01:00
|
|
|
import androidx.appcompat.content.res.AppCompatResources
|
2020-05-12 23:05:08 +02:00
|
|
|
import kotlinx.android.synthetic.main.list_element.*
|
2019-12-05 04:06:05 +01:00
|
|
|
import mozilla.components.feature.tab.collections.TabCollection
|
2020-02-06 17:14:32 +01:00
|
|
|
import mozilla.components.support.ktx.android.content.getColorFromAttr
|
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.mozilla.fenix.R
|
2020-07-07 02:09:42 +02:00
|
|
|
import org.mozilla.fenix.utils.view.ViewHolder
|
2019-05-06 20:20:19 +02:00
|
|
|
import org.mozilla.fenix.ext.components
|
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(
|
2020-05-12 23:05:08 +02:00
|
|
|
view: View,
|
2019-12-05 04:06:05 +01:00
|
|
|
val interactor: CollectionInteractor,
|
2020-05-12 23:05:08 +02:00
|
|
|
private val differentLastItem: Boolean = false
|
|
|
|
) : ViewHolder(view) {
|
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
|
2020-03-12 14:16:23 +01:00
|
|
|
var isLastItem = false
|
2019-05-06 20:20:19 +02:00
|
|
|
|
|
|
|
init {
|
2020-03-12 14:16:23 +01:00
|
|
|
list_item_favicon.clipToOutline = true
|
|
|
|
list_item_favicon.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,
|
2020-06-05 19:59:08 +02:00
|
|
|
FAV_ICON_BORDER_RADIUS_IN_DP.dpToFloat(view.context.resources.displayMetrics)
|
2019-05-06 20:20:19 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 23:05:08 +02:00
|
|
|
itemView.setOnClickListener {
|
2019-12-05 04:06:05 +01:00
|
|
|
interactor.onCollectionOpenTabClicked(tab)
|
2019-05-20 20:31:25 +02:00
|
|
|
}
|
|
|
|
|
2020-03-12 14:16:23 +01:00
|
|
|
list_item_action_button.increaseTapArea(buttonIncreaseDps)
|
|
|
|
list_item_action_button.setOnClickListener {
|
2020-07-14 10:42:02 +02:00
|
|
|
interactor.onCollectionRemoveTab(collection, tab, wasSwiped = false)
|
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
|
2020-03-12 14:16:23 +01:00
|
|
|
this.isLastItem = isLastTab
|
2019-05-06 20:20:19 +02:00
|
|
|
updateTabUI()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun updateTabUI() {
|
2020-05-12 23:05:08 +02:00
|
|
|
val context = itemView.context
|
|
|
|
list_item_url.text = tab.url.toShortUrl(context.components.publicSuffixList)
|
2019-06-10 22:46:55 +02:00
|
|
|
|
2020-03-11 19:21:48 +01:00
|
|
|
list_element_title.text = tab.title
|
2020-03-12 14:16:23 +01:00
|
|
|
list_item_favicon.context.components.core.icons.loadIntoView(list_item_favicon, tab.url)
|
2019-05-06 20:20:19 +02:00
|
|
|
|
2020-03-12 14:16:23 +01:00
|
|
|
// If last item and we want to change UI for it
|
|
|
|
if (isLastItem && differentLastItem) {
|
2020-05-12 23:05:08 +02:00
|
|
|
itemView.background = AppCompatResources.getDrawable(context, R.drawable.rounded_bottom_corners)
|
2019-05-06 20:20:19 +02:00
|
|
|
} else {
|
2020-05-12 23:05:08 +02:00
|
|
|
itemView.setBackgroundColor(context.getColorFromAttr(R.attr.above))
|
2019-05-06 20:20:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
2019-05-08 20:12:41 +02:00
|
|
|
const val buttonIncreaseDps = 12
|
2020-03-11 19:21:48 +01:00
|
|
|
const val LAYOUT_ID = R.layout.list_element
|
2020-06-05 19:59:08 +02:00
|
|
|
const val FAV_ICON_BORDER_RADIUS_IN_DP = 4
|
2019-05-06 20:20:19 +02:00
|
|
|
}
|
|
|
|
}
|