Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
add error check to editText
Browse files Browse the repository at this point in the history
  • Loading branch information
KenMizz committed Feb 13, 2021
1 parent 9bd3f14 commit 73363b8
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 7 deletions.
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 21 additions & 7 deletions app/src/main/java/kenmizz/onesentence/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
Expand Down Expand Up @@ -135,17 +137,29 @@ public void syncAllSharedPrefs() {
}

public void addSentenceDialog() {
MaterialAlertDialogBuilder dialog = new MaterialAlertDialogBuilder(this);
final MaterialAlertDialogBuilder dialog = new MaterialAlertDialogBuilder(this);
View view = LayoutInflater.from(this).inflate(R.layout.sentence_edittext, null);
final TextInputEditText editText = view.findViewById(R.id.sentenceAddEditText);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if(sentencesList.contains(charSequence.toString())) {
editText.setError(charSequence.toString() + getString(R.string.sentenceExists));
}
}

@Override
public void afterTextChanged(Editable editable) {

}
});
dialog.setView(view);
dialog.setTitle(R.string.newsentence)
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
//TODO: dont dissmiss
}
})
.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
<string name="no">算了</string>
<string name="set_setence_notification">你确定你想要设置 sentence 为常驻通知吗?</string>
<string name="coolapk">酷安</string>
<string name="sentenceExists">已经存在。</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
<string name="no">NO</string>
<string name="set_setence_notification">You sure you want to set sentence as notification?</string>
<string name="coolapk">CoolApk</string>
<string name="sentenceExists">already exists.</string>
</resources>

0 comments on commit 73363b8

Please sign in to comment.