Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3043)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsGroupView.java

Issue 1540663002: Prettier "last synced" times on the recent tabs page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: happened just now Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsRowAdapter.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsGroupView.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsGroupView.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsGroupView.java
index 9f1f26f3f70c0b74c6a2179b38716be774ecd53f..5e497c011ce24ad1fe90bc5a2439e19a59b92829 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsGroupView.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsGroupView.java
@@ -19,8 +19,6 @@ import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSession;
import org.chromium.chrome.browser.widget.TintedDrawable;
import org.chromium.ui.base.DeviceFormFactor;
-import java.util.concurrent.TimeUnit;
-
/**
* Header view shown above each group of items on the Recent Tabs page. Shows the name of the
* group (e.g. "Recently closed" or "Jim's Laptop"), an icon, last synced time, and a button to
@@ -36,7 +34,6 @@ public class RecentTabsGroupView extends RelativeLayout {
private ImageView mExpandCollapseIcon;
private TextView mDeviceLabel;
private TextView mTimeLabel;
- private long mInitializationTimestamp;
private int mDeviceLabelExpandedColor;
private int mDeviceLabelCollapsedColor;
private int mTimeLabelExpandedColor;
@@ -81,15 +78,6 @@ public class RecentTabsGroupView extends RelativeLayout {
}
/**
- * Initialize the state of the group view. Should be called immediatly after object creation.
- *
- * @param initializationTimestamp The timestamp to compute the time since last session sync.
- */
- public void initialize(long initializationTimestamp) {
- mInitializationTimestamp = initializationTimestamp;
- }
-
- /**
* Configures the view for currently open tabs.
*
* @param isExpanded Whether the view is expanded or collapsed.
@@ -171,27 +159,28 @@ public class RecentTabsGroupView extends RelativeLayout {
mTimeLabel.setTextColor(isExpanded ? mTimeLabelExpandedColor : mTimeLabelCollapsedColor);
}
- private String getTimeString(ForeignSession session) {
- long sessionModifiedTimeSeconds =
- TimeUnit.SECONDS.convert(session.modifiedTime, TimeUnit.MILLISECONDS);
- long timeDelta = mInitializationTimestamp - sessionModifiedTimeSeconds;
- timeDelta = timeDelta > 0 ? timeDelta : 0;
+ private CharSequence getTimeString(ForeignSession session) {
+ long timeDeltaMs = System.currentTimeMillis() - session.modifiedTime;
+ if (timeDeltaMs < 0) timeDeltaMs = 0;
- long daysElapsed = timeDelta / (24L * 60L * 60L);
- long hoursElapsed = timeDelta / (60L * 60L);
- long minutesElapsed = timeDelta / 60L;
+ int daysElapsed = (int) (timeDeltaMs / (24L * 60L * 60L * 1000L));
+ int hoursElapsed = (int) (timeDeltaMs / (60L * 60L * 1000L));
+ int minutesElapsed = (int) (timeDeltaMs / (60L * 1000L));
- Resources resources = getContext().getResources();
+ Resources res = getResources();
+ String relativeTime;
if (daysElapsed > 0L) {
- return resources.getString(R.string.ntp_recent_tabs_last_synced_days, daysElapsed);
+ relativeTime = res.getQuantityString(R.plurals.n_days_ago, daysElapsed, daysElapsed);
} else if (hoursElapsed > 0L) {
- return resources.getString(R.string.ntp_recent_tabs_last_synced_hours, hoursElapsed);
+ relativeTime = res.getQuantityString(R.plurals.n_hours_ago, hoursElapsed, hoursElapsed);
} else if (minutesElapsed > 0L) {
- return resources.getString(
- R.string.ntp_recent_tabs_last_synced_minutes, minutesElapsed);
+ relativeTime = res.getQuantityString(R.plurals.n_minutes_ago, minutesElapsed,
+ minutesElapsed);
} else {
- return resources.getString(R.string.ntp_recent_tabs_last_synced_just_now);
+ relativeTime = res.getString(R.string.just_now);
}
+
+ return getResources().getString(R.string.ntp_recent_tabs_last_synced, relativeTime);
}
/**
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsRowAdapter.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698