Commit 04f5e459 authored by Hesen Zhang's avatar Hesen Zhang Committed by Commit Bot

Added TextWatcher for empty input edit text


> Disable OK button when filename edit text is empty, otherwise reset to enabled.

Bug: 924751
Change-Id: I8138fe41a65c69f5f9e3ac59c2483fdd6667d09f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1548371Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Commit-Queue: Hesen Zhang <hesen@google.com>
Cr-Commit-Position: refs/heads/master@{#649703}
parent bc87a99e
......@@ -42,6 +42,10 @@ public class RenameDialogCoordinator {
.build();
mOnClickEventCallback = onClickCallback;
mOnDismissEventCallback = dismissCallback;
mRenameDialogCustomView.setEmptyInputObserver((result) -> {
mRenameDialogModel.set(ModalDialogProperties.POSITIVE_BUTTON_DISABLED, result);
});
}
public void destroy() {
......
......@@ -7,13 +7,16 @@ package org.chromium.chrome.browser.download.home.rename;
import static android.content.Context.INPUT_METHOD_SERVICE;
import android.content.Context;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ScrollView;
import android.widget.TextView;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.widget.AlertDialogEditText;
import org.chromium.chrome.download.R;
import org.chromium.components.offline_items_collection.RenameResult;
......@@ -24,6 +27,7 @@ import org.chromium.components.offline_items_collection.RenameResult;
public class RenameDialogCustomView extends ScrollView {
private TextView mSubtitleView;
private AlertDialogEditText mFileName;
private Callback</*Empty*/ Boolean> mEmptyFileNameObserver;
public RenameDialogCustomView(Context context, AttributeSet attrs) {
super(context, attrs);
......@@ -35,6 +39,26 @@ public class RenameDialogCustomView extends ScrollView {
super.onFinishInflate();
mSubtitleView = findViewById(R.id.subtitle);
mFileName = findViewById(R.id.file_name);
mFileName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {}
@Override
public void afterTextChanged(Editable s) {
if (mEmptyFileNameObserver == null) return;
mEmptyFileNameObserver.onResult(getTargetName().isEmpty());
}
});
}
/**
* @param callback Callback to run when edit text is empty.
*/
public void setEmptyInputObserver(Callback<Boolean> callback) {
mEmptyFileNameObserver = callback;
}
/**
......
......@@ -158,9 +158,6 @@ public class RenameDialogManager {
if (isPositiveButton) {
mLastAttemptedName = mRenameDialogCoordinator.getCurSuggestedName();
// TODO(hesen): Have a TextWatcher on the input, and disable OK button if it's empty.
if (TextUtils.isEmpty(mLastAttemptedName)) return;
if (TextUtils.equals(mLastAttemptedName, mOriginalName)) {
processDialogState(RenameDialogState.RENAME_DIALOG_CANCEL,
DialogDismissalCause.POSITIVE_BUTTON_CLICKED);
......
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