Commit 86ca67f5 authored by megjablon's avatar megjablon Committed by Commit bot

Data savings on overflow menu should use most recent data collection start date

Data savings on the overflow menu should show the date Data Saver was
first turned on or last reset if that date is more recent than 30 days ago.
The icon color should also be reset when Data Saver is re-enabled.

BUG=716491, 715803

Review-Url: https://codereview.chromium.org/2849563004
Cr-Commit-Position: refs/heads/master@{#468202}
parent b1bd0bcd
...@@ -68,6 +68,8 @@ public class DataReductionProxySettings { ...@@ -68,6 +68,8 @@ public class DataReductionProxySettings {
private static final String DATA_REDUCTION_HAS_EVER_BEEN_ENABLED_PREF = private static final String DATA_REDUCTION_HAS_EVER_BEEN_ENABLED_PREF =
"BANDWIDTH_REDUCTION_PROXY_HAS_EVER_BEEN_ENABLED"; "BANDWIDTH_REDUCTION_PROXY_HAS_EVER_BEEN_ENABLED";
public static final String DATA_REDUCTION_FIRST_ENABLED_TIME =
"BANDWIDTH_REDUCTION_FIRST_ENABLED_TIME";
private static final String PARAM_PERSISTENT_MENU_ITEM_ENABLED = "persistent_menu_item_enabled"; private static final String PARAM_PERSISTENT_MENU_ITEM_ENABLED = "persistent_menu_item_enabled";
...@@ -155,6 +157,15 @@ public class DataReductionProxySettings { ...@@ -155,6 +157,15 @@ public class DataReductionProxySettings {
* data reduction statistics if this is the first time the SPDY proxy has been enabled. * data reduction statistics if this is the first time the SPDY proxy has been enabled.
*/ */
public void setDataReductionProxyEnabled(Context context, boolean enabled) { public void setDataReductionProxyEnabled(Context context, boolean enabled) {
if (enabled
&& ContextUtils.getAppSharedPreferences().getLong(
DATA_REDUCTION_FIRST_ENABLED_TIME, 0)
== 0) {
ContextUtils.getAppSharedPreferences()
.edit()
.putLong(DATA_REDUCTION_FIRST_ENABLED_TIME, System.currentTimeMillis())
.apply();
}
ContextUtils.getAppSharedPreferences().edit() ContextUtils.getAppSharedPreferences().edit()
.putBoolean(DATA_REDUCTION_ENABLED_PREF, enabled).apply(); .putBoolean(DATA_REDUCTION_ENABLED_PREF, enabled).apply();
nativeSetDataReductionProxyEnabled(mNativeDataReductionProxySettings, enabled); nativeSetDataReductionProxyEnabled(mNativeDataReductionProxySettings, enabled);
...@@ -202,6 +213,15 @@ public class DataReductionProxySettings { ...@@ -202,6 +213,15 @@ public class DataReductionProxySettings {
return nativeGetDataReductionLastUpdateTime(mNativeDataReductionProxySettings); return nativeGetDataReductionLastUpdateTime(mNativeDataReductionProxySettings);
} }
/**
* Returns the time that the proxy was first enabled. If data saving statistics are cleared,
* this is set to the reset time.
* @return The time that the proxy was first enabled in milliseconds since the epoch.
*/
public long getDataReductionProxyFirstEnabledTime() {
return ContextUtils.getAppSharedPreferences().getLong(DATA_REDUCTION_FIRST_ENABLED_TIME, 0);
}
/** /**
* Clears all data saving statistics. * Clears all data saving statistics.
*/ */
...@@ -209,6 +229,10 @@ public class DataReductionProxySettings { ...@@ -209,6 +229,10 @@ public class DataReductionProxySettings {
// When the data saving statistics are cleared, reset the snackbar promo that tells the user // When the data saving statistics are cleared, reset the snackbar promo that tells the user
// how much data they have saved using Data Saver so far. // how much data they have saved using Data Saver so far.
DataReductionPromoUtils.saveSnackbarPromoDisplayed(0); DataReductionPromoUtils.saveSnackbarPromoDisplayed(0);
ContextUtils.getAppSharedPreferences()
.edit()
.putLong(DATA_REDUCTION_FIRST_ENABLED_TIME, System.currentTimeMillis())
.apply();
nativeClearDataSavingStatistics(mNativeDataReductionProxySettings); nativeClearDataSavingStatistics(mNativeDataReductionProxySettings);
} }
......
...@@ -53,12 +53,17 @@ public class DataReductionMainMenuFooter extends FrameLayout implements View.OnC ...@@ -53,12 +53,17 @@ public class DataReductionMainMenuFooter extends FrameLayout implements View.OnC
DataReductionProxySettings.getInstance() DataReductionProxySettings.getInstance()
.getContentLengthSavedInHistorySummary()); .getContentLengthSavedInHistorySummary());
long millisSinceEpoch = long chartStartDateInMillisSinceEpoch =
DataReductionProxySettings.getInstance().getDataReductionLastUpdateTime() DataReductionProxySettings.getInstance().getDataReductionLastUpdateTime()
- DateUtils.DAY_IN_MILLIS * ChartDataUsageView.DAYS_IN_CHART; - DateUtils.DAY_IN_MILLIS * ChartDataUsageView.DAYS_IN_CHART;
long firstEnabledInMillisSinceEpoch = DataReductionProxySettings.getInstance()
.getDataReductionProxyFirstEnabledTime();
long mostRecentTime = chartStartDateInMillisSinceEpoch > firstEnabledInMillisSinceEpoch
? chartStartDateInMillisSinceEpoch
: firstEnabledInMillisSinceEpoch;
final int flags = DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_NO_YEAR; final int flags = DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_NO_YEAR;
String date = String date = DateUtils.formatDateTime(getContext(), mostRecentTime, flags).toString();
DateUtils.formatDateTime(getContext(), millisSinceEpoch, flags).toString();
itemText.setText( itemText.setText(
getContext().getString(R.string.data_reduction_saved_label, dataSaved)); getContext().getString(R.string.data_reduction_saved_label, dataSaved));
...@@ -67,6 +72,12 @@ public class DataReductionMainMenuFooter extends FrameLayout implements View.OnC ...@@ -67,6 +72,12 @@ public class DataReductionMainMenuFooter extends FrameLayout implements View.OnC
int lightActiveColor = ApiCompatibilityUtils.getColor( int lightActiveColor = ApiCompatibilityUtils.getColor(
getContext().getResources(), R.color.light_active_color); getContext().getResources(), R.color.light_active_color);
itemText.setTextColor(lightActiveColor); itemText.setTextColor(lightActiveColor);
// Reset the icon to blue.
ImageView icon = (ImageView) findViewById(R.id.chart_icon);
LayerDrawable layers = (LayerDrawable) icon.getDrawable();
Drawable chart = layers.findDrawableByLayerId(R.id.main_menu_chart);
chart.setColorFilter(null);
} else { } else {
DataReductionProxyUma.dataReductionProxyUIAction( DataReductionProxyUma.dataReductionProxyUIAction(
DataReductionProxyUma.ACTION_MAIN_MENU_DISPLAYED_OFF); DataReductionProxyUma.ACTION_MAIN_MENU_DISPLAYED_OFF);
......
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