Don't disable "Done" button when it cannot be pressed

Show an error on tap instead. According to a11y guidelines this is preferrable.

Fixes: 369942776
Test: atest ZenModeEditDonePreferenceControllerTest
Flag: android.app.modes_ui
Change-Id: Ib5e47a4151c1515e5085a776d538a27c2ef41574
This commit is contained in:
Matías Hernández
2024-10-07 17:01:52 +02:00
parent aad13d8836
commit 73c7ee115b
2 changed files with 27 additions and 22 deletions

View File

@@ -17,7 +17,9 @@
package com.android.settings.notification.modes;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -32,6 +34,7 @@ class ZenModeEditDonePreferenceController extends AbstractZenModePreferenceContr
private final Runnable mConfirmSave;
@Nullable private Button mButton;
private boolean mHasValidName;
ZenModeEditDonePreferenceController(@NonNull Context context, @NonNull String key,
Runnable confirmSave) {
@@ -46,15 +49,22 @@ class ZenModeEditDonePreferenceController extends AbstractZenModePreferenceContr
if (pref != null) {
mButton = pref.findViewById(R.id.done);
if (mButton != null) {
mButton.setOnClickListener(v -> mConfirmSave.run());
mButton.setOnClickListener(this::onButtonClick);
}
}
}
private void onButtonClick(View view) {
if (mHasValidName) {
mConfirmSave.run();
} else {
Toast.makeText(mContext, R.string.zen_mode_edit_name_empty_error, Toast.LENGTH_SHORT)
.show();
}
}
@Override
void updateState(Preference preference, @NonNull ZenMode zenMode) {
if (mButton != null) {
mButton.setEnabled(!zenMode.getName().isBlank());
}
mHasValidName = !zenMode.getName().isBlank();
}
}