diff options
| author | Bananeweizen <Bananeweizen@gmx.de> | 2013-12-27 16:38:46 +0100 |
|---|---|---|
| committer | Bananeweizen <Bananeweizen@gmx.de> | 2013-12-27 16:38:46 +0100 |
| commit | 120b2a27fb68831fbabbcd5b13c31695337f0fdb (patch) | |
| tree | 87d0fba2ad4c754a2de236bac97cd1c0e0944ad9 /main/src/cgeo/geocaching/list | |
| parent | 22a071b84d0c2307f7073e646e853dc8525354d2 (diff) | |
| download | cgeo-120b2a27fb68831fbabbcd5b13c31695337f0fdb.zip cgeo-120b2a27fb68831fbabbcd5b13c31695337f0fdb.tar.gz cgeo-120b2a27fb68831fbabbcd5b13c31695337f0fdb.tar.bz2 | |
refactoring: extract input dialog as reusable code
Diffstat (limited to 'main/src/cgeo/geocaching/list')
| -rw-r--r-- | main/src/cgeo/geocaching/list/StoredList.java | 49 |
1 files changed, 5 insertions, 44 deletions
diff --git a/main/src/cgeo/geocaching/list/StoredList.java b/main/src/cgeo/geocaching/list/StoredList.java index fd16347..8106073 100644 --- a/main/src/cgeo/geocaching/list/StoredList.java +++ b/main/src/cgeo/geocaching/list/StoredList.java @@ -4,6 +4,7 @@ import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.DataStore; import cgeo.geocaching.R; import cgeo.geocaching.activity.ActivityMixin; +import cgeo.geocaching.ui.dialog.Dialogs; import cgeo.geocaching.utils.RunnableWithArgument; import org.apache.commons.lang3.StringUtils; @@ -13,10 +14,6 @@ import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.res.Resources; -import android.text.Editable; -import android.text.InputType; -import android.text.TextWatcher; -import android.widget.EditText; import java.text.Collator; import java.util.ArrayList; @@ -160,50 +157,17 @@ public final class StoredList extends AbstractList { } private void handleListNameInput(final String defaultValue, int dialogTitle, int buttonTitle, final RunnableWithArgument<String> runnable) { - final EditText input = new EditText(activity); - input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_CLASS_TEXT); - input.setText(defaultValue); - - final AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(dialogTitle); - builder.setView(input); - builder.setPositiveButton(buttonTitle, new DialogInterface.OnClickListener() { + Dialogs.input(activity, dialogTitle, defaultValue, buttonTitle, new RunnableWithArgument<String>() { + @Override - public void onClick(DialogInterface dialog, int whichButton) { + public void run(final String input) { // remove whitespaces added by autocompletion of Android keyboard - String listName = StringUtils.trim(input.getText().toString()); + String listName = StringUtils.trim(input); if (StringUtils.isNotBlank(listName)) { runnable.run(listName); } } }); - builder.setNegativeButton(res.getString(R.string.list_dialog_cancel), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - dialog.dismiss(); - } - }); - final AlertDialog dialog = builder.create(); - input.addTextChangedListener(new TextWatcher() { - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - // empty - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - // empty - } - - @Override - public void afterTextChanged(Editable editable) { - enableDialogButton(dialog, editable.toString()); - } - }); - dialog.show(); - enableDialogButton(dialog, defaultValue); - input.setSelection(input.getText().length()); } public void promptForListRename(final int listId, @NonNull final Runnable runAfterRename) { @@ -218,9 +182,6 @@ public final class StoredList extends AbstractList { }); } - private static void enableDialogButton(final AlertDialog dialog, final String input) { - dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(StringUtils.isNotBlank(input)); - } } /** |
