mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/19988 - Part 2: Load tab icon from BrowserIcons cache if needed for the recent tab
Co-authored-by: Jonathan Almeida <jalmeida@mozilla.com>
This commit is contained in:
parent
71ca6f7f5d
commit
756e54a037
@ -6,8 +6,11 @@ package org.mozilla.fenix.home.recenttabs.view
|
|||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import kotlinx.android.synthetic.main.recent_tabs_list_row.*
|
import kotlinx.android.synthetic.main.recent_tabs_list_row.*
|
||||||
|
import mozilla.components.browser.icons.BrowserIcons
|
||||||
import mozilla.components.browser.state.state.TabSessionState
|
import mozilla.components.browser.state.state.TabSessionState
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.ext.components
|
||||||
|
import org.mozilla.fenix.ext.loadIntoView
|
||||||
import org.mozilla.fenix.home.recenttabs.interactor.RecentTabInteractor
|
import org.mozilla.fenix.home.recenttabs.interactor.RecentTabInteractor
|
||||||
import org.mozilla.fenix.utils.view.ViewHolder
|
import org.mozilla.fenix.utils.view.ViewHolder
|
||||||
|
|
||||||
@ -15,15 +18,22 @@ import org.mozilla.fenix.utils.view.ViewHolder
|
|||||||
* View holder for a recent tab item.
|
* View holder for a recent tab item.
|
||||||
*
|
*
|
||||||
* @param interactor [RecentTabInteractor] which will have delegated to all user interactions.
|
* @param interactor [RecentTabInteractor] which will have delegated to all user interactions.
|
||||||
|
* @param icons
|
||||||
*/
|
*/
|
||||||
class RecentTabViewHolder(
|
class RecentTabViewHolder(
|
||||||
view: View,
|
view: View,
|
||||||
private val interactor: RecentTabInteractor
|
private val interactor: RecentTabInteractor,
|
||||||
|
private val icons: BrowserIcons = view.context.components.core.icons
|
||||||
) : ViewHolder(view) {
|
) : ViewHolder(view) {
|
||||||
|
|
||||||
fun bindTab(tab: TabSessionState) {
|
fun bindTab(tab: TabSessionState) {
|
||||||
recent_tab_title.text = tab.content.title
|
recent_tab_title.text = tab.content.title
|
||||||
|
|
||||||
|
if (tab.content.icon != null) {
|
||||||
recent_tab_icon.setImageBitmap(tab.content.icon)
|
recent_tab_icon.setImageBitmap(tab.content.icon)
|
||||||
|
} else {
|
||||||
|
icons.loadIntoView(recent_tab_icon, tab.content.url)
|
||||||
|
}
|
||||||
|
|
||||||
itemView.setOnClickListener {
|
itemView.setOnClickListener {
|
||||||
interactor.onRecentTabClicked(tab.id)
|
interactor.onRecentTabClicked(tab.id)
|
||||||
|
@ -6,9 +6,13 @@ package org.mozilla.fenix.home.recenttabs.view
|
|||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import io.mockk.every
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import io.mockk.verify
|
import io.mockk.verify
|
||||||
|
import kotlinx.android.synthetic.main.recent_tabs_list_row.*
|
||||||
import kotlinx.android.synthetic.main.recent_tabs_list_row.view.*
|
import kotlinx.android.synthetic.main.recent_tabs_list_row.view.*
|
||||||
|
import mozilla.components.browser.icons.BrowserIcons
|
||||||
|
import mozilla.components.browser.icons.IconRequest
|
||||||
import mozilla.components.browser.state.state.createTab
|
import mozilla.components.browser.state.state.createTab
|
||||||
import mozilla.components.support.test.robolectric.testContext
|
import mozilla.components.support.test.robolectric.testContext
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
@ -23,6 +27,7 @@ class RecentTabViewHolderTest {
|
|||||||
|
|
||||||
private lateinit var view: View
|
private lateinit var view: View
|
||||||
private lateinit var interactor: SessionControlInteractor
|
private lateinit var interactor: SessionControlInteractor
|
||||||
|
private lateinit var icons: BrowserIcons
|
||||||
|
|
||||||
private val tab = createTab(
|
private val tab = createTab(
|
||||||
url = "https://mozilla.org",
|
url = "https://mozilla.org",
|
||||||
@ -33,18 +38,23 @@ class RecentTabViewHolderTest {
|
|||||||
fun setup() {
|
fun setup() {
|
||||||
view = LayoutInflater.from(testContext).inflate(RecentTabViewHolder.LAYOUT_ID, null)
|
view = LayoutInflater.from(testContext).inflate(RecentTabViewHolder.LAYOUT_ID, null)
|
||||||
interactor = mockk(relaxed = true)
|
interactor = mockk(relaxed = true)
|
||||||
|
icons = mockk(relaxed = true)
|
||||||
|
|
||||||
|
every { icons.loadIntoView(view.recent_tab_icon, any()) } returns mockk()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `GIVEN a new recent tab on bind THEN set the title text`() {
|
fun `GIVEN a new recent tab on bind THEN set the title text and load the tab icon`() {
|
||||||
RecentTabViewHolder(view, interactor).bindTab(tab)
|
RecentTabViewHolder(view, interactor, icons).bindTab(tab)
|
||||||
|
|
||||||
assertEquals(tab.content.title, view.recent_tab_title.text)
|
assertEquals(tab.content.title, view.recent_tab_title.text)
|
||||||
|
|
||||||
|
verify { icons.loadIntoView(view.recent_tab_icon, IconRequest(tab.content.url)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `WHEN a recent tab item is clicked THEN interactor iis called`() {
|
fun `WHEN a recent tab item is clicked THEN interactor is called`() {
|
||||||
RecentTabViewHolder(view, interactor).bindTab(tab)
|
RecentTabViewHolder(view, interactor, icons).bindTab(tab)
|
||||||
|
|
||||||
view.performClick()
|
view.performClick()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user