diff options
Diffstat (limited to 'main/src/cgeo/geocaching/StoredList.java')
| -rw-r--r-- | main/src/cgeo/geocaching/StoredList.java | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/main/src/cgeo/geocaching/StoredList.java b/main/src/cgeo/geocaching/StoredList.java index cdff1cb..5a6f132 100644 --- a/main/src/cgeo/geocaching/StoredList.java +++ b/main/src/cgeo/geocaching/StoredList.java @@ -1,6 +1,6 @@ package cgeo.geocaching; -import cgeo.geocaching.activity.IAbstractActivity; +import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.utils.RunnableWithArgument; import org.apache.commons.lang3.StringUtils; @@ -34,28 +34,54 @@ public class StoredList { return title + " [" + count + "]"; } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof StoredList)) { + return false; + } + return id == ((StoredList) obj).id; + } + public static class UserInterface { - private final IAbstractActivity activity; + private final Activity activity; private final cgeoapplication app; private final Resources res; - public UserInterface(final IAbstractActivity activity) { + public UserInterface(final Activity activity) { this.activity = activity; app = cgeoapplication.getInstance(); res = app.getResources(); } public void promptForListSelection(final int titleId, final RunnableWithArgument<Integer> runAfterwards) { - promptForListSelection(titleId, runAfterwards, false); + promptForListSelection(titleId, runAfterwards, false, -1); } - public void promptForListSelection(final int titleId, final RunnableWithArgument<Integer> runAfterwards, final boolean onlyMoveTargets) { - final List<StoredList> lists = app.getLists(); + public void promptForListSelection(final int titleId, final RunnableWithArgument<Integer> runAfterwards, final boolean onlyMoveTargets, final int exceptListId) { + final List<StoredList> lists = cgData.getLists(); if (lists == null) { return; } + if (exceptListId > StoredList.TEMPORARY_LIST_ID) { + StoredList exceptList = cgData.getList(exceptListId); + if (exceptList != null) { + lists.remove(exceptList); + } + } + final List<CharSequence> listsTitle = new ArrayList<CharSequence>(); for (StoredList list : lists) { listsTitle.add(list.getTitleAndCount()); @@ -67,7 +93,7 @@ public class StoredList { final CharSequence[] items = new CharSequence[listsTitle.size()]; - AlertDialog.Builder builder = new AlertDialog.Builder((Activity) activity); + AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(res.getString(titleId)); builder.setItems(listsTitle.toArray(items), new DialogInterface.OnClickListener() { @Override @@ -94,23 +120,23 @@ public class StoredList { @Override public void run(final String listName) { - final int newId = app.createList(listName); + final int newId = cgData.createList(listName); if (newId >= cgData.customListIdOffset) { - activity.showToast(res.getString(R.string.list_dialog_create_ok)); + ActivityMixin.showToast(activity, res.getString(R.string.list_dialog_create_ok)); if (runAfterwards != null) { runAfterwards.run(newId); } } else { - activity.showToast(res.getString(R.string.list_dialog_create_err)); + ActivityMixin.showToast(activity, res.getString(R.string.list_dialog_create_err)); } } }); } private void handleListNameInput(final String defaultValue, int dialogTitle, int buttonTitle, final RunnableWithArgument<String> runnable) { - final AlertDialog.Builder alert = new AlertDialog.Builder((Activity) activity); - final View view = ((Activity) activity).getLayoutInflater().inflate(R.layout.list_create_dialog, null); + final AlertDialog.Builder alert = new AlertDialog.Builder(activity); + final View view = activity.getLayoutInflater().inflate(R.layout.list_create_dialog, null); final EditText input = (EditText) view.findViewById(R.id.text); input.setText(defaultValue); @@ -137,12 +163,12 @@ public class StoredList { } public void promptForListRename(final int listId, final Runnable runAfterRename) { - final StoredList list = app.getList(listId); + final StoredList list = cgData.getList(listId); handleListNameInput(list.title, R.string.list_dialog_rename_title, R.string.list_dialog_rename, new RunnableWithArgument<String>() { @Override public void run(final String listName) { - app.renameList(listId, listName); + cgData.renameList(listId, listName); if (runAfterRename != null) { runAfterRename.run(); } |
