From 0154c81f816b1f7c16082394cde7a06ca16abeaf Mon Sep 17 00:00:00 2001
From: Jocelyne <38375996+joc-a@users.noreply.github.com>
Date: Fri, 2 Oct 2020 02:42:50 +0300
Subject: [PATCH] For #10107: Show Today and Yesterday labels in History
(#15415)
---
.../java/org/mozilla/fenix/ui/robots/HistoryRobot.kt | 6 +++---
.../mozilla/fenix/library/history/HistoryAdapter.kt | 11 ++++++++---
app/src/main/res/values/strings.xml | 4 ++++
3 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HistoryRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HistoryRobot.kt
index 85cfd7fe9..72d62ec06 100644
--- a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HistoryRobot.kt
+++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HistoryRobot.kt
@@ -42,7 +42,7 @@ class HistoryRobot {
fun verifyVisitedTimeTitle() {
mDevice.waitNotNull(
Until.findObject(
- By.text("Last 24 hours")
+ By.text("Today")
),
waitingTime
)
@@ -99,7 +99,7 @@ class HistoryRobot {
}
fun openThreeDotMenu(interact: ThreeDotMenuHistoryItemRobot.() -> Unit):
- ThreeDotMenuHistoryItemRobot.Transition {
+ ThreeDotMenuHistoryItemRobot.Transition {
threeDotMenu().click()
@@ -143,7 +143,7 @@ private fun assertEmptyHistoryView() =
.check(matches(withText("No history here")))
private fun assertVisitedTimeTitle() =
- onView(withId(R.id.header_title)).check(matches(withText("Last 24 hours")))
+ onView(withId(R.id.header_title)).check(matches(withText("Today")))
private fun assertTestPageTitle(title: String) = testPageTitle()
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
diff --git a/app/src/main/java/org/mozilla/fenix/library/history/HistoryAdapter.kt b/app/src/main/java/org/mozilla/fenix/library/history/HistoryAdapter.kt
index 7a0b33b1a..e82bac914 100644
--- a/app/src/main/java/org/mozilla/fenix/library/history/HistoryAdapter.kt
+++ b/app/src/main/java/org/mozilla/fenix/library/history/HistoryAdapter.kt
@@ -17,10 +17,11 @@ import java.util.Calendar
import java.util.Date
enum class HistoryItemTimeGroup {
- Today, ThisWeek, ThisMonth, Older;
+ Today, Yesterday, ThisWeek, ThisMonth, Older;
fun humanReadable(context: Context): String = when (this) {
- Today -> context.getString(R.string.history_24_hours)
+ Today -> context.getString(R.string.history_today)
+ Yesterday -> context.getString(R.string.history_yesterday)
ThisWeek -> context.getString(R.string.history_7_days)
ThisMonth -> context.getString(R.string.history_30_days)
Older -> context.getString(R.string.history_older)
@@ -81,11 +82,14 @@ class HistoryAdapter(private val historyInteractor: HistoryInteractor) :
companion object {
private const val zeroDays = 0
+ private const val oneDay = 1
private const val sevenDays = 7
private const val thirtyDays = 30
- private val oneDayAgo = getDaysAgo(zeroDays).time
+ private val zeroDaysAgo = getDaysAgo(zeroDays).time
+ private val oneDayAgo = getDaysAgo(oneDay).time
private val sevenDaysAgo = getDaysAgo(sevenDays).time
private val thirtyDaysAgo = getDaysAgo(thirtyDays).time
+ private val yesterdayRange = LongRange(oneDayAgo, zeroDaysAgo)
private val lastWeekRange = LongRange(sevenDaysAgo, oneDayAgo)
private val lastMonthRange = LongRange(thirtyDaysAgo, sevenDaysAgo)
@@ -99,6 +103,7 @@ class HistoryAdapter(private val historyInteractor: HistoryInteractor) :
private fun timeGroupForHistoryItem(item: HistoryItem): HistoryItemTimeGroup {
return when {
DateUtils.isToday(item.visitedAt) -> HistoryItemTimeGroup.Today
+ yesterdayRange.contains(item.visitedAt) -> HistoryItemTimeGroup.Yesterday
lastWeekRange.contains(item.visitedAt) -> HistoryItemTimeGroup.ThisWeek
lastMonthRange.contains(item.visitedAt) -> HistoryItemTimeGroup.ThisMonth
else -> HistoryItemTimeGroup.Older
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 1465e3623..2d744301e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -643,6 +643,10 @@
Delete %1$d items
+
+ Today
+
+ Yesterday
Last 24 hours