Commit 22579b1f authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download location: move storage info out of toolbar.

The storage info string currently lives inside the toolbar. The text
may be clipped on certain devices, or when using large font in
accessibility setting.

This CL moves the storage string out of toolbar.

Bug: 849973, 852254
Change-Id: I518cdb30e021e2ffeefee4db6b2328a2d15597a1
Reviewed-on: https://chromium-review.googlesource.com/1102167
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568248}
parent d7f85be5
......@@ -10,28 +10,10 @@
android:layout_height="match_parent"
style="@style/ModernToolbar" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="@color/dark_mode_tint"
android:layout_centerVertical="true" />
<TextView
android:id="@+id/storage_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@style/BlackDisabledText2"
android:layout_below="@id/spinner"
android:paddingTop="9dp"
android:maxLines="1" />
</RelativeLayout>
app:backgroundTint="@color/dark_mode_tint" />
</org.chromium.chrome.browser.download.ui.DownloadManagerToolbar>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/download_storage_summary"
android:paddingStart="@dimen/list_item_default_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@style/BlackDisabledText2"
android:maxLines="1"
android:paddingBottom="8dp" />
\ No newline at end of file
......@@ -11,6 +11,7 @@ import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
......@@ -206,8 +207,11 @@ public class DownloadHistoryAdapter extends DateDividedAdapter
private BackendProvider mBackendProvider;
private @DownloadFilter.Type int mFilter = DownloadFilter.FILTER_ALL;
private String mSearchQuery = EMPTY_QUERY;
// TODO(xingliu): Remove deprecated storage info. See https://crbug/853260.
private SpaceDisplay mSpaceDisplay;
private StorageSummary mStorageSummary;
private HeaderItem mSpaceDisplayHeaderItem;
private HeaderItem mStorageSummaryHeaderItem;
private boolean mIsSearching;
private boolean mShouldShowStorageInfoHeader;
private boolean mShouldPrefetchSectionExpand;
......@@ -413,6 +417,13 @@ public class DownloadHistoryAdapter extends DateDividedAdapter
View view = mSpaceDisplay.getViewContainer();
registerAdapterDataObserver(mSpaceDisplay);
mSpaceDisplayHeaderItem = new HeaderItem(0, view);
if (ChromeFeatureList.isEnabled(ChromeFeatureList.DOWNLOADS_LOCATION_CHANGE)) {
View storageSummaryView = LayoutInflater.from(ContextUtils.getApplicationContext())
.inflate(R.layout.download_storage_summary, null);
mStorageSummary = new StorageSummary((TextView) storageSummaryView);
mStorageSummaryHeaderItem = new HeaderItem(0, storageSummaryView);
}
}
/** Called when a new DownloadItem has been created by the native DownloadManager. */
......@@ -634,7 +645,10 @@ public class DownloadHistoryAdapter extends DateDividedAdapter
filter(mFilter, mSearchQuery, mOfflineItems, filteredTimedItems, prefetchedItems);
clear(false);
if (!filteredTimedItems.isEmpty() && !mIsSearching && mShouldShowStorageInfoHeader) {
if (ChromeFeatureList.isEnabled(ChromeFeatureList.DOWNLOADS_LOCATION_CHANGE)) {
setHeaders(mStorageSummaryHeaderItem);
} else if (!filteredTimedItems.isEmpty() && !mIsSearching && mShouldShowStorageInfoHeader) {
setHeaders(mSpaceDisplayHeaderItem);
}
......
......@@ -25,7 +25,6 @@ public class DownloadManagerToolbar extends SelectableListToolbar<DownloadHistor
implements DownloadUiObserver {
private Spinner mSpinner;
private DownloadManagerUi mManager;
private StorageSummary mStorageSummary;
private int mInfoMenuItemId;
......@@ -50,9 +49,6 @@ public class DownloadManagerToolbar extends SelectableListToolbar<DownloadHistor
mSpinner = findViewById(R.id.spinner);
mSpinner.setAdapter(adapter);
mSpinner.setOnItemSelectedListener(adapter);
// Initialize the storage summary.
mStorageSummary = new StorageSummary(findViewById(R.id.storage_summary));
}
/**
......
......@@ -66,8 +66,10 @@ public class StorageSummary {
// Set the storage summary to the view.
Context context = mView.getContext();
long usedSpace = mDirectoryOption.totalSpace - mDirectoryOption.availableSpace;
if (usedSpace < 0) usedSpace = 0;
String storageSummary = context.getString(R.string.download_manager_ui_space_using,
DownloadUtils.getStringForBytes(context, mDirectoryOption.availableSpace),
DownloadUtils.getStringForBytes(context, usedSpace),
DownloadUtils.getStringForBytes(context, mDirectoryOption.totalSpace));
mView.setText(storageSummary);
}
......
......@@ -131,6 +131,11 @@ public class DownloadActivityTest {
DownloadPromptStatus.DONT_SHOW);
});
HashMap<String, Boolean> features = new HashMap<String, Boolean>();
features.put(ChromeFeatureList.DOWNLOADS_LOCATION_CHANGE, false);
features.put(ChromeFeatureList.DOWNLOAD_HOME_SHOW_STORAGE_INFO, false);
ChromeFeatureList.setTestFeatures(features);
mStubbedProvider = new StubbedProvider();
DownloadManagerUi.setProviderForTests(mStubbedProvider);
......
......@@ -22,6 +22,7 @@ import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.download.DownloadItem;
import org.chromium.chrome.browser.download.ui.StubbedProvider.StubbedDownloadDelegate;
import org.chromium.chrome.browser.download.ui.StubbedProvider.StubbedOfflineContentProvider;
......@@ -31,6 +32,7 @@ import org.chromium.components.offline_items_collection.ContentId;
import org.chromium.components.offline_items_collection.OfflineItem;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
/**
......@@ -108,6 +110,11 @@ public class DownloadHistoryAdapterTest {
mOfflineContentProvider = mBackendProvider.getOfflineContentProvider();
Editor editor = ContextUtils.getAppSharedPreferences().edit();
editor.putBoolean(PREF_SHOW_STORAGE_INFO_HEADER, true).apply();
HashMap<String, Boolean> features = new HashMap<String, Boolean>();
features.put(ChromeFeatureList.DOWNLOADS_LOCATION_CHANGE, false);
features.put(ChromeFeatureList.DOWNLOAD_HOME_SHOW_STORAGE_INFO, false);
ChromeFeatureList.setTestFeatures(features);
}
private void initializeAdapter(boolean showOffTheRecord, boolean hasHeader) throws Exception {
......
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