[fenix] For https://github.com/mozilla-mobile/fenix/issues/1843 - Displays tabs on the tab selection screen
parent
e5dd755493
commit
2218b5872f
@ -0,0 +1,86 @@
|
||||
package org.mozilla.fenix.collections
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.reactivex.Observer
|
||||
import kotlinx.android.synthetic.main.collection_tab_list_row.view.*
|
||||
import kotlinx.android.synthetic.main.tab_list_row.*
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
import mozilla.components.browser.icons.IconRequest
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.components
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
|
||||
class CollectionCreationTabListAdapter(
|
||||
val actionEmitter: Observer<CollectionCreationAction>
|
||||
) : RecyclerView.Adapter<TabViewHolder>() {
|
||||
|
||||
|
||||
private var data: List<Tab> = listOf()
|
||||
private lateinit var job: Job
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TabViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(TabViewHolder.LAYOUT_ID, parent, false)
|
||||
|
||||
return TabViewHolder(view, actionEmitter, job)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: TabViewHolder, position: Int) {
|
||||
holder.bind(data[position])
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = data.size
|
||||
|
||||
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView)
|
||||
job = Job()
|
||||
}
|
||||
|
||||
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
|
||||
super.onDetachedFromRecyclerView(recyclerView)
|
||||
job.cancel()
|
||||
}
|
||||
|
||||
fun updateData(tabs: List<Tab>) {
|
||||
data = tabs
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
class TabViewHolder(
|
||||
val view: View,
|
||||
actionEmitter: Observer<CollectionCreationAction>,
|
||||
val job: Job
|
||||
) :
|
||||
RecyclerView.ViewHolder(view), CoroutineScope {
|
||||
|
||||
override val coroutineContext: CoroutineContext
|
||||
get() = Dispatchers.IO + job
|
||||
|
||||
var tab: Tab? = null
|
||||
|
||||
init { }
|
||||
|
||||
fun bind(tab: Tab) {
|
||||
this.tab = tab
|
||||
|
||||
view.hostname.text = tab.hostname
|
||||
view.tab_title.text = tab.title
|
||||
launch(Dispatchers.IO) {
|
||||
val bitmap = view.favicon_image.context.components.utils.icons
|
||||
.loadIcon(IconRequest(tab.url)).await().bitmap
|
||||
launch(Dispatchers.Main) {
|
||||
view.favicon_image.setImageBitmap(bitmap)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val LAYOUT_ID = R.layout.collection_tab_list_row
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package org.mozilla.fenix.collections
|
||||
|
||||
/* 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/. */
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
|
||||
class CreateCollectionViewModel: ViewModel() {
|
||||
var tabs = listOf<Tab>()
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/collection_item_tab"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:clickable="true"
|
||||
android:clipToPadding="false"
|
||||
android:focusable="true"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
app:cardBackgroundColor="?above"
|
||||
app:cardCornerRadius="@dimen/tab_corner_radius"
|
||||
app:cardElevation="5dp">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/favicon_image"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_margin="8dp"
|
||||
android:adjustViewBounds="true"
|
||||
android:importantForAccessibility="no"
|
||||
android:scaleType="fitCenter"
|
||||
app:layout_constraintDimensionRatio="1:1"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/hostname"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:ellipsize="none"
|
||||
android:singleLine="true"
|
||||
android:textColor="?secondaryText"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toStartOf="@id/close_tab_button"
|
||||
app:layout_constraintStart_toEndOf="@id/favicon_image"
|
||||
app:layout_constraintTop_toTopOf="@id/favicon_image" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tab_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="2"
|
||||
android:minLines="2"
|
||||
android:textColor="?primaryText"
|
||||
android:textSize="15sp"
|
||||
app:layout_constraintStart_toEndOf="@id/favicon_image"
|
||||
app:layout_constraintEnd_toEndOf="@id/hostname"
|
||||
app:layout_constraintTop_toBottomOf="@id/hostname"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</androidx.cardview.widget.CardView>
|
Loading…
Reference in New Issue