GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit f6b84ce7 authored by Kainalu Hagiwara's avatar Kainalu Hagiwara Committed by liuche

For #12888 - Add highlight to current page in tab history.

parent 8f540c55
......@@ -5,10 +5,10 @@
package org.mozilla.fenix.tabhistory
import android.view.View
import androidx.core.text.bold
import androidx.core.text.buildSpannedString
import androidx.core.view.isVisible
import kotlinx.android.synthetic.main.tab_history_list_item.*
import mozilla.components.support.ktx.android.content.getColorFromAttr
import org.mozilla.fenix.R
import org.mozilla.fenix.library.LibrarySiteItemView
import org.mozilla.fenix.utils.view.ViewHolder
......@@ -28,15 +28,14 @@ class TabHistoryViewHolder(
history_layout.displayAs(LibrarySiteItemView.ItemType.SITE)
history_layout.overflowView.isVisible = false
history_layout.titleView.text = item.title
history_layout.urlView.text = item.url
history_layout.loadFavicon(item.url)
history_layout.titleView.text = if (item.isSelected) {
buildSpannedString {
bold { append(item.title) }
}
if (item.isSelected) {
history_layout.setBackgroundColor(history_layout.context.getColorFromAttr(R.attr.tabHistoryItemSelectedBackground))
} else {
item.title
history_layout.background = null
}
}
}
......@@ -64,6 +64,9 @@
<color name="tab_tray_item_thumbnail_icon_normal_theme">@color/tab_tray_item_thumbnail_icon_dark_theme</color>
<color name="tab_tray_selected_mask_normal_theme">@color/tab_tray_selected_mask_dark_theme</color>
<!-- Tab History -->
<color name="tab_history_item_selected_background_normal_theme">@color/tab_tray_item_selected_background_dark_theme</color>
<!--Top site colors -->
<color name="top_site_background">@color/top_site_background_dark_theme</color>
<color name="top_site_border">@color/top_site_border_dark_theme</color>
......
......@@ -66,6 +66,9 @@
<attr name="tabTrayItemSelectedBackground" format="reference" />
<attr name="tabTrayToolbarBackground" format="reference" />
<!-- Tab History -->
<attr name="tabHistoryItemSelectedBackground" format="reference" />
<declare-styleable name="TrackingProtectionCategory">
<attr name="categoryItemTitle" format="reference" />
<attr name="categoryItemDescription" format="reference" />
......
......@@ -89,6 +89,9 @@
<color name="tab_tray_item_thumbnail_icon_light_theme">@color/light_grey_60</color>
<color name="tab_tray_selected_mask_light_theme">@color/violet_70_12a</color>
<!-- Tab History -->
<color name="tab_history_item_selected_background_light_theme">@color/tab_tray_item_selected_background_light_theme</color>
<!-- Dark theme color palette -->
<color name="primary_text_dark_theme">#FBFBFE</color>
<color name="secondary_text_dark_theme">#A7A2B7</color>
......@@ -151,6 +154,9 @@
<color name="tab_tray_item_thumbnail_icon_dark_theme">@color/dark_grey_05</color>
<color name="tab_tray_selected_mask_dark_theme">@color/violet_50_32a</color>
<!-- Tab History -->
<color name="tab_history_item_selected_background_dark_theme">@color/tab_tray_item_selected_background_dark_theme</color>
<!-- Private theme color palette -->
<color name="primary_text_private_theme">#FBFBFE</color>
<color name="secondary_text_private_theme">#A7A2B7</color>
......@@ -203,6 +209,9 @@
<color name="tab_tray_heading_icon_private_theme">@color/violet_50</color>
<color name="tab_tray_heading_icon_inactive_private_theme">@color/violet_50_48a</color>
<!-- Tab History -->
<color name="tab_history_item_selected_background_private_theme">@color/tab_tray_item_selected_background_dark_theme</color>
<!-- Normal theme colors for light mode -->
<color name="primary_text_normal_theme">@color/primary_text_light_theme</color>
<color name="secondary_text_normal_theme">@color/secondary_text_light_theme</color>
......@@ -259,6 +268,9 @@
<color name="tab_tray_item_thumbnail_icon_normal_theme">@color/tab_tray_item_thumbnail_icon_light_theme</color>
<color name="tab_tray_selected_mask_normal_theme">@color/tab_tray_selected_mask_light_theme</color>
<!-- Tab History -->
<color name="tab_history_item_selected_background_normal_theme">@color/tab_history_item_selected_background_light_theme</color>
<!-- Bookmark buttons -->
<color name="bookmark_favicon_background">#DFDFE3</color>
......
......@@ -89,6 +89,9 @@
<item name="tabTrayThumbnailItemBackground">@color/tab_tray_item_thumbnail_background_normal_theme</item>
<item name="tabTrayThumbnailIcon">@color/tab_tray_item_thumbnail_icon_normal_theme</item>
<!-- Tab History -->
<item name="tabHistoryItemSelectedBackground">@color/tab_history_item_selected_background_normal_theme</item>
<!-- Drawables -->
<item name="fenixLogo">@drawable/ic_logo_wordmark_normal</item>
<item name="homeBackground">@color/foundation_normal_theme</item>
......@@ -223,6 +226,9 @@
<item name="tabTrayThumbnailItemBackground">@color/tab_tray_item_thumbnail_background_normal_theme</item>
<item name="tabTrayThumbnailIcon">@color/tab_tray_item_thumbnail_icon_normal_theme</item>
<!-- Tab History -->
<item name="tabHistoryItemSelectedBackground">@color/tab_history_item_selected_background_private_theme</item>
<!-- Drawables -->
<item name="fenixLogo">@drawable/ic_logo_wordmark_private</item>
<item name="homeBackground">@drawable/private_home_background_gradient</item>
......
/* 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/. */
package org.mozilla.fenix.tabhistory
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.widget.FrameLayout
import androidx.appcompat.view.ContextThemeWrapper
import io.mockk.MockKAnnotations
import io.mockk.impl.annotations.MockK
import kotlinx.android.synthetic.main.history_list_item.*
import mozilla.components.support.ktx.android.content.getColorFromAttr
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.R
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class TabHistoryAdapterTest {
@MockK
private lateinit var interactor: TabHistoryInteractor
private lateinit var context: Context
private lateinit var parent: FrameLayout
private lateinit var adapter: TabHistoryAdapter
private val selectedItem = TabHistoryItem(
title = "Mozilla",
url = "https://mozilla.org",
index = 0,
isSelected = true
)
private val unselectedItem = TabHistoryItem(
title = "Firefox",
url = "https://firefox.com",
index = 1,
isSelected = false
)
@Before
fun setup() {
MockKAnnotations.init(this)
context = ContextThemeWrapper(testContext, R.style.NormalTheme)
parent = FrameLayout(context)
adapter = TabHistoryAdapter(interactor)
}
@Test
fun `creates and binds view holder`() {
adapter.submitList(listOf(selectedItem, unselectedItem))
val holder = adapter.createViewHolder(parent, 0)
adapter.bindViewHolder(holder, 0)
assertEquals("Mozilla", holder.history_layout.titleView.text)
assertEquals(
context.getColorFromAttr(R.attr.tabHistoryItemSelectedBackground),
(holder.history_layout.background as ColorDrawable).color
)
adapter.bindViewHolder(holder, 1)
assertEquals("Firefox", holder.history_layout.titleView.text)
assertEquals(null, holder.history_layout.background)
}
@Test
fun `items are the same if they have matching URLs`() {
assertTrue(TabHistoryAdapter.DiffCallback.areItemsTheSame(
selectedItem,
selectedItem
))
assertTrue(TabHistoryAdapter.DiffCallback.areItemsTheSame(
unselectedItem,
unselectedItem.copy(title = "Waterbug", index = 2, isSelected = true)
))
assertFalse(TabHistoryAdapter.DiffCallback.areItemsTheSame(
unselectedItem,
unselectedItem.copy(url = "https://firefox.com/subpage")
))
}
@Test
fun `equal items have the same contents`() {
assertTrue(TabHistoryAdapter.DiffCallback.areContentsTheSame(
selectedItem,
selectedItem
))
assertFalse(TabHistoryAdapter.DiffCallback.areContentsTheSame(
selectedItem,
selectedItem.copy(title = "Waterbug", index = 2, isSelected = false)
))
assertFalse(TabHistoryAdapter.DiffCallback.areContentsTheSame(
unselectedItem,
selectedItem
))
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment