Commit 49c3c636 authored by Hung Vu's avatar Hung Vu Committed by Commit Bot

[Location suggestion] Update UI to show not enough space.

This CL changes the UI behavior when a storage that doesn't have enough space for the download is chosen, a "not enough space" error text will be prompted below the storage name. All implementations are wrapped in feature flag.

Bug: 1118207
Change-Id: I6e9e6c497d4b2b97dbda32faa98314731c6244f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2436312
Commit-Queue: Hung Vu <vuhung@google.com>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814489}
parent e7cf32e7
......@@ -26,47 +26,78 @@
android:id="@+id/subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/download_dialog_subtitle_margin_bottom"
android:layout_marginBottom="@dimen/download_dialog_subtitle_margin_bottom"
android:textAppearance="@style/TextAppearance.TextMedium.Secondary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:orientation="vertical">
<org.chromium.ui.widget.ChromeImageView
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_drive_file_24dp"
app:tint="@color/default_icon_color"
style="@style/ListItemStartIcon" />
android:orientation="horizontal">
<org.chromium.ui.widget.ChromeImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_drive_file_24dp"
app:tint="@color/default_icon_color"
style="@style/ListItemStartIcon" />
<org.chromium.components.browser_ui.widget.text.AlertDialogEditText
android:id="@+id/file_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.TextLarge.Primary"
android:singleLine="true" />
<org.chromium.components.browser_ui.widget.text.AlertDialogEditText
android:id="@+id/file_name"
</LinearLayout>
<TextView
android:id="@+id/file_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.TextLarge.Primary"
android:singleLine="true" />
android:layout_marginStart="@dimen/download_dialog_location_space_margin_start"
android:textAppearance="@style/TextAppearance.TextSmall.Primary"
android:visibility="gone"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:orientation="vertical">
<org.chromium.ui.widget.ChromeImageView
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_folder_blue_24dp"
app:tint="@color/default_icon_color"
style="@style/ListItemStartIcon" />
android:orientation="horizontal">
<org.chromium.ui.widget.ChromeImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_folder_blue_24dp"
app:tint="@color/default_icon_color"
style="@style/ListItemStartIcon" />
<Spinner
android:id="@+id/file_location"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@android:style/Widget.EditText"/>
</LinearLayout>
<Spinner
android:id="@+id/file_location"
<TextView
android:id="@+id/location_available_space"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@android:style/Widget.EditText"/>
android:layout_marginStart="@dimen/download_dialog_location_space_margin_start"
android:maxLines="2"
android:textAppearance="@style/TextAppearance.TextSmall.Primary"
android:visibility="gone"/>
</LinearLayout>
......
......@@ -6,6 +6,6 @@
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/text"
android:id="@+id/title"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.TextLarge.Primary" />
\ No newline at end of file
android:textAppearance="@style/TextAppearance.TextLarge.Primary" />
......@@ -9,4 +9,5 @@
<dimen name="download_dialog_radio_button_margin_start">-5dp</dimen>
<dimen name="download_dialog_checkbox_margin_start">-5dp</dimen>
<dimen name="download_dialog_checkbox_margin_top">16dp</dimen>
<dimen name="download_dialog_location_space_margin_start">49dp</dimen>
</resources>
......@@ -9,6 +9,7 @@ import static org.chromium.chrome.browser.download.settings.DownloadDirectoryAda
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
......@@ -17,13 +18,17 @@ import android.widget.Spinner;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import org.chromium.chrome.browser.download.DirectoryOption;
import org.chromium.chrome.browser.download.DownloadDialogBridge;
import org.chromium.chrome.browser.download.DownloadLocationDialogType;
import org.chromium.chrome.browser.download.DownloadPromptStatus;
import org.chromium.chrome.browser.download.R;
import org.chromium.chrome.browser.download.StringUtils;
import org.chromium.chrome.browser.download.settings.DownloadDirectoryAdapter;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.components.browser_ui.util.DownloadUtils;
import org.chromium.components.browser_ui.widget.text.AlertDialogEditText;
......@@ -39,7 +44,9 @@ public class DownloadLocationCustomView
private TextView mTitle;
private TextView mSubtitleView;
private AlertDialogEditText mFileName;
private TextView mFileSize;
private Spinner mFileLocation;
private TextView mLocationAvailableSpace;
private CheckBox mDontShowAgain;
private @DownloadLocationDialogType int mDialogType;
private long mTotalBytes;
......@@ -56,7 +63,9 @@ public class DownloadLocationCustomView
mTitle = findViewById(R.id.title);
mSubtitleView = findViewById(R.id.subtitle);
mFileName = findViewById(R.id.file_name);
mFileSize = findViewById(R.id.file_size);
mFileLocation = findViewById(R.id.file_location);
mLocationAvailableSpace = findViewById(R.id.location_available_space);
mDontShowAgain = findViewById(R.id.show_again_checkbox);
}
......@@ -81,12 +90,7 @@ public class DownloadLocationCustomView
mSubtitleView.setText(
DownloadUtils.getStringForBytes(getContext(), totalBytes));
} else {
// Hide the subtitle and adjust the bottom margin.
mSubtitleView.setVisibility(View.GONE);
MarginLayoutParams titleMargin = (MarginLayoutParams) mTitle.getLayoutParams();
titleMargin.bottomMargin = getResources().getDimensionPixelSize(
R.dimen.download_dialog_subtitle_margin_bottom);
setLayoutParams(titleMargin);
hideSubtitle();
}
break;
......@@ -107,10 +111,10 @@ public class DownloadLocationCustomView
break;
case DownloadLocationDialogType.LOCATION_SUGGESTION:
// TODO(vuhung): Add download and storage info to subtitle.
// Right now this subtitle is just a placeholder.
// Putting name too long subtitle here to differentiate with default dialog.
mSubtitleView.setText(R.string.download_location_name_too_long);
// Show the location available space underneath the spinner.
mLocationAvailableSpace.setVisibility(View.VISIBLE);
setFileSize(totalBytes);
hideSubtitle();
break;
}
......@@ -151,6 +155,50 @@ public class DownloadLocationCustomView
return mDontShowAgain != null && mDontShowAgain.isChecked();
}
/**
* Hide the subtitle and adjust the bottom margin.
*/
private void hideSubtitle() {
mSubtitleView.setVisibility(View.GONE);
MarginLayoutParams titleMargin = (MarginLayoutParams) mTitle.getLayoutParams();
titleMargin.bottomMargin = getResources().getDimensionPixelSize(
R.dimen.download_dialog_subtitle_margin_bottom);
mTitle.setLayoutParams(titleMargin);
}
/**
* Show the file size below the file name.
* @param totalBytes The total bytes of the download.
*/
private void setFileSize(long totalBytes) {
mFileSize.setVisibility(View.VISIBLE);
mFileSize.setText(DownloadUtils.getStringForBytes(getContext(), totalBytes));
}
/**
* Show the available space below the file location spinner.
* @param availableSpace The available space of the file location.
*/
private void setLocationAvailableSpace(long availableSpace) {
String locationAvailableSpaceText =
StringUtils.getAvailableBytesForUi(getContext(), availableSpace);
int textColor = ContextCompat.getColor(getContext(), R.color.default_text_color);
int barColor = ContextCompat.getColor(getContext(), R.color.explanation_text_color);
// Show not enough space and change color to error.
if (availableSpace < mTotalBytes) {
locationAvailableSpaceText = getContext().getResources().getString(
R.string.download_manager_list_item_description, locationAvailableSpaceText,
getContext().getText(R.string.download_location_not_enough_space));
textColor = ContextCompat.getColor(getContext(), R.color.input_underline_error_color);
barColor = ContextCompat.getColor(getContext(), R.color.input_underline_error_color);
}
mLocationAvailableSpace.setText(locationAvailableSpaceText);
mLocationAvailableSpace.setTextColor(textColor);
DrawableCompat.setTint(mFileLocation.getBackground().mutate(), barColor);
}
// DownloadDirectoryAdapter.Delegate implementation.
@Override
public void onDirectoryOptionsUpdated() {
......@@ -166,6 +214,23 @@ public class DownloadLocationCustomView
mFileLocation.setAdapter(mDirectoryAdapter);
mFileLocation.setSelection(selectedItemId);
// Show "not enough space" error text the new chosen storage doesn't have enough space.
if (ChromeFeatureList.isEnabled(ChromeFeatureList.SMART_SUGGESTION_FOR_LARGE_DOWNLOADS)) {
mFileLocation.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(
AdapterView<?> parent, View view, int position, long id) {
DirectoryOption option = (DirectoryOption) mDirectoryAdapter.getItem(position);
setLocationAvailableSpace(option.availableSpace);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// No callback. Only update listeners when an actual option is selected.
}
});
}
}
@Override
......
......@@ -103,7 +103,7 @@ public class DownloadDirectoryAdapter extends ArrayAdapter<Object> {
DirectoryOption directoryOption = (DirectoryOption) getItem(position);
if (directoryOption == null) return view;
TextView titleText = (TextView) view.findViewById(R.id.text);
TextView titleText = (TextView) view.findViewById(R.id.title);
titleText.setText(directoryOption.name);
// ModalDialogView may do a measure pass on the view hierarchy to limit the layout inside
......
......@@ -2373,7 +2373,7 @@ To change this setting, <ph name="BEGIN_LINK">&lt;resetlink&gt;</ph>reset sync<p
<message name="IDS_DOWNLOAD_MANAGER_SEARCH" desc="Placeholder text for the input field that allows users to search downloads.">
Search your downloads
</message>
<message name="IDS_DOWNLOAD_MANAGER_LIST_ITEM_DESCRIPTION" desc="Text containing the download list item description.">
<message name="IDS_DOWNLOAD_MANAGER_LIST_ITEM_DESCRIPTION" desc="Text containing the download list item description. This is also used warn user that the current download location does not have enough space.">
<ph name="FILE_SIZE">%1$s<ex>1.56 MB</ex></ph> <ph name="SEPARATOR"></ph> <ph name="DESCRIPTION">%2$s<ex>www.example.com</ex></ph>
</message>
<message name="IDS_DOWNLOAD_MANAGER_LIST_ITEM_DESCRIPTION_NO_SIZE" desc="Text containing the download list item description.">
......
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