1
0
Fork 0

Fixes #745: Integrate Browser-Icons component for favicons

master
Colin Lee 2019-02-28 14:46:39 -06:00 committed by Jeff Boek
parent 77189a00a0
commit dfd3e93d17
4 changed files with 37 additions and 3 deletions

View File

@ -173,6 +173,7 @@ dependencies {
implementation Deps.mozilla_browser_awesomebar implementation Deps.mozilla_browser_awesomebar
implementation Deps.mozilla_feature_downloads implementation Deps.mozilla_feature_downloads
implementation Deps.mozilla_browser_domains implementation Deps.mozilla_browser_domains
implementation Deps.mozilla_browser_icons
implementation Deps.mozilla_browser_engine_gecko_nightly implementation Deps.mozilla_browser_engine_gecko_nightly
implementation Deps.mozilla_browser_session implementation Deps.mozilla_browser_session
implementation Deps.mozilla_browser_storage_sync implementation Deps.mozilla_browser_storage_sync

View File

@ -13,13 +13,24 @@ import androidx.recyclerview.widget.RecyclerView
import io.reactivex.Observer import io.reactivex.Observer
import kotlinx.android.extensions.LayoutContainer import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.tab_list_row.* import kotlinx.android.synthetic.main.tab_list_row.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import mozilla.components.browser.icons.BrowserIcons
import mozilla.components.browser.icons.IconRequest
import org.mozilla.fenix.DefaultThemeManager import org.mozilla.fenix.DefaultThemeManager
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.increaseTapArea import org.mozilla.fenix.ext.increaseTapArea
import kotlin.coroutines.CoroutineContext
class TabsAdapter(private val actionEmitter: Observer<TabsAction>) : class TabsAdapter(private val actionEmitter: Observer<TabsAction>) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() { RecyclerView.Adapter<RecyclerView.ViewHolder>() {
lateinit var job: Job
var sessions = listOf<SessionViewState>() var sessions = listOf<SessionViewState>()
set(value) { set(value) {
val diffResult = DiffUtil.calculateDiff(TabsDiffCallback(field, value), true) val diffResult = DiffUtil.calculateDiff(TabsDiffCallback(field, value), true)
@ -29,7 +40,17 @@ class TabsAdapter(private val actionEmitter: Observer<TabsAction>) :
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false) val view = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
return TabViewHolder(view, actionEmitter) return TabViewHolder(view, actionEmitter, job)
}
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
super.onAttachedToRecyclerView(recyclerView)
job = Job()
}
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
super.onDetachedFromRecyclerView(recyclerView)
job.cancel()
} }
override fun getItemViewType(position: Int) = TabViewHolder.LAYOUT_ID override fun getItemViewType(position: Int) = TabViewHolder.LAYOUT_ID
@ -56,9 +77,13 @@ class TabsAdapter(private val actionEmitter: Observer<TabsAction>) :
private class TabViewHolder( private class TabViewHolder(
val view: View, val view: View,
actionEmitter: Observer<TabsAction>, actionEmitter: Observer<TabsAction>,
val job: Job,
override val containerView: View? = view override val containerView: View? = view
) : ) :
RecyclerView.ViewHolder(view), LayoutContainer { RecyclerView.ViewHolder(view), LayoutContainer, CoroutineScope {
override val coroutineContext: CoroutineContext
get() = Dispatchers.IO + job
var session: SessionViewState? = null var session: SessionViewState? = null
@ -83,6 +108,13 @@ class TabsAdapter(private val actionEmitter: Observer<TabsAction>) :
fun updateUrl(url: String) { fun updateUrl(url: String) {
text_url.text = url text_url.text = url
launch(IO) {
val bitmap = BrowserIcons(favicon_image.context)
.loadIcon(IconRequest(url)).await().bitmap
launch(Main) {
favicon_image.setImageBitmap(bitmap)
}
}
} }
fun updateSelected(selected: Boolean) { fun updateSelected(selected: Boolean) {

View File

@ -63,7 +63,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="100dp" android:layout_height="100dp"
android:background="@drawable/session_background" android:background="@drawable/session_background"
android:contentDescription="TODO" android:focusable="false"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"

View File

@ -66,6 +66,7 @@ object Deps {
const val mozilla_browser_awesomebar = "org.mozilla.components:browser-awesomebar:${Versions.mozilla_android_components}" const val mozilla_browser_awesomebar = "org.mozilla.components:browser-awesomebar:${Versions.mozilla_android_components}"
const val mozilla_browser_engine_gecko_nightly = "org.mozilla.components:browser-engine-gecko-nightly:${Versions.mozilla_android_components}" const val mozilla_browser_engine_gecko_nightly = "org.mozilla.components:browser-engine-gecko-nightly:${Versions.mozilla_android_components}"
const val mozilla_browser_domains = "org.mozilla.components:browser-domains:${Versions.mozilla_android_components}" const val mozilla_browser_domains = "org.mozilla.components:browser-domains:${Versions.mozilla_android_components}"
const val mozilla_browser_icons = "org.mozilla.components:browser-icons:${Versions.mozilla_android_components}"
const val mozilla_browser_search = "org.mozilla.components:browser-search:${Versions.mozilla_android_components}" const val mozilla_browser_search = "org.mozilla.components:browser-search:${Versions.mozilla_android_components}"
const val mozilla_browser_session = "org.mozilla.components:browser-session:${Versions.mozilla_android_components}" const val mozilla_browser_session = "org.mozilla.components:browser-session:${Versions.mozilla_android_components}"
const val mozilla_browser_tabstray = "org.mozilla.components:browser-tabstray:${Versions.mozilla_android_components}" const val mozilla_browser_tabstray = "org.mozilla.components:browser-tabstray:${Versions.mozilla_android_components}"