Commit d2f6e082 authored by Joy Ming's avatar Joy Ming Committed by Commit Bot

[Downloads location] Small UI/string changes.

Some clean-up UI/string changes:

* Change "No SD card found" to "SD card not found" in case the user had
another SD card but we weren't able to find one of them.
* Include a "No available download locations" message to be shown on the
settings page in the corner case where the user has no download options.
* Increase the size of the title text for the download location spinner
preference (same as other preferences).

Bug: 792775
Change-Id: I8c0a972f793b263ce59c090906e64192477c67b4
Reviewed-on: https://chromium-review.googlesource.com/1022521Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Joy Ming <jming@chromium.org>
Cr-Commit-Position: refs/heads/master@{#552869}
parent fb0c86e6
......@@ -15,7 +15,8 @@
<TextView
android:id="@+id/title"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
android:layout_width="match_parent"
style="@style/PreferenceTitle" />
<Spinner
android:id="@+id/spinner"
......
......@@ -73,6 +73,7 @@ public class DownloadDirectoryAdapter extends ArrayAdapter<Object> {
private List<DirectoryOption> mCanonicalOptions = new ArrayList<>();
private List<DirectoryOption> mAdditionalOptions = new ArrayList<>();
private List<DirectoryOption> mErrorOptions = new ArrayList<>();
public DownloadDirectoryAdapter(@NonNull Context context) {
super(context, android.R.layout.simple_spinner_item);
......@@ -85,12 +86,18 @@ public class DownloadDirectoryAdapter extends ArrayAdapter<Object> {
@Override
public int getCount() {
return mCanonicalOptions.size() + mAdditionalOptions.size();
return mCanonicalOptions.size() + mAdditionalOptions.size() + mErrorOptions.size();
}
@Nullable
@Override
public Object getItem(int position) {
if (!mErrorOptions.isEmpty()) {
assert position == 0;
assert getCount() == 1;
return mErrorOptions.get(position);
}
if (position < mCanonicalOptions.size()) {
return mCanonicalOptions.get(position);
} else {
......@@ -147,7 +154,11 @@ public class DownloadDirectoryAdapter extends ArrayAdapter<Object> {
} else {
TextViewCompat.setTextAppearance(titleText, R.style.BlackDisabledText1);
TextViewCompat.setTextAppearance(summaryText, R.style.BlackDisabledText3);
summaryText.setText(mContext.getText(R.string.download_location_not_enough_space));
if (mErrorOptions.isEmpty()) {
summaryText.setText(mContext.getText(R.string.download_location_not_enough_space));
} else {
summaryText.setVisibility(View.GONE);
}
}
TintedImageView imageView = (TintedImageView) view.findViewById(R.id.icon_view);
......@@ -167,6 +178,7 @@ public class DownloadDirectoryAdapter extends ArrayAdapter<Object> {
* NO_SELECTED_ITEM_ID if no item matches the default path.
*/
public int getSelectedItemId() {
if (!mErrorOptions.isEmpty()) return 0;
String defaultLocation = PrefServiceBridge.getInstance().getDownloadDefaultDirectory();
for (int i = 0; i < getCount(); i++) {
DirectoryOption option = (DirectoryOption) getItem(i);
......@@ -194,13 +206,19 @@ public class DownloadDirectoryAdapter extends ArrayAdapter<Object> {
}
}
// TODO(jming): Update behavior with UX suggestions.
throw new AssertionError("No selected item ID.");
// Display an option that says there are no available download locations.
adjustErrorDirectoryOption();
return 0;
}
boolean hasAvailableLocations() {
return mErrorOptions.isEmpty();
}
private void refreshData() {
setCanonicalDirectoryOptions();
setAdditionalDirectoryOptions();
adjustErrorDirectoryOption();
}
private void setCanonicalDirectoryOptions() {
......@@ -243,4 +261,14 @@ public class DownloadDirectoryAdapter extends ArrayAdapter<Object> {
numOtherAdditionalDirectories++;
}
}
private void adjustErrorDirectoryOption() {
if ((mCanonicalOptions.size() + mAdditionalOptions.size()) > 0) {
mErrorOptions.clear();
} else {
mErrorOptions.add(new DirectoryOption(
mContext.getString(R.string.download_location_no_available_locations), null,
0));
}
}
}
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.preferences.download;
import static org.chromium.chrome.browser.preferences.download.DownloadDirectoryAdapter.NO_SELECTED_ITEM_ID;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
......@@ -48,6 +49,12 @@ public class DownloadPreferences
if (selectedItemId == NO_SELECTED_ITEM_ID) {
selectedItemId = mDirectoryAdapter.getFirstSelectableItemId();
}
mDirectoryAdapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
mLocationChangePref.setEnabled(mDirectoryAdapter.hasAvailableLocations());
}
});
mLocationChangePref.setAdapter(mDirectoryAdapter, selectedItemId);
updateData();
......@@ -92,9 +99,11 @@ public class DownloadPreferences
} else if (PREF_LOCATION_CHANGE.equals(preference.getKey())) {
DownloadDirectoryAdapter.DirectoryOption option =
(DownloadDirectoryAdapter.DirectoryOption) newValue;
PrefServiceBridge.getInstance().setDownloadAndSaveFileDefaultDirectory(
option.getLocation().getAbsolutePath());
updateData();
if (option.getLocation() != null) {
PrefServiceBridge.getInstance().setDownloadAndSaveFileDefaultDirectory(
option.getLocation().getAbsolutePath());
updateData();
}
}
return true;
}
......
......@@ -1234,10 +1234,13 @@ To obtain new licenses, connect to the internet and play your downloaded content
Download to default folder?
</message>
<message name="IDS_DOWNLOAD_LOCATION_NO_SD_CARD" desc="Title for download location dialog in the case that the SD card is not found.">
No SD card found
SD card not found
</message>
<message name="IDS_DOWNLOAD_LOCATION_NO_SD_CARD_SNACKBAR" desc="Text for the snackbar that shows up in downloads home to let the user know that since the SD card is not found, some of the files may be missing.">
No SD card found. Some of your files may be missing.
SD card not found. Some of your files may be missing.
</message>
<message name="IDS_DOWNLOAD_LOCATION_NO_AVAILABLE_LOCATIONS" desc="Text that indicates to the user that there are no download locations available.">
No available download locations
</message>
<!-- About Chrome preferences -->
......
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