aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/list/StoredList.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/list/StoredList.java')
-rw-r--r--main/src/cgeo/geocaching/list/StoredList.java45
1 files changed, 19 insertions, 26 deletions
diff --git a/main/src/cgeo/geocaching/list/StoredList.java b/main/src/cgeo/geocaching/list/StoredList.java
index 53632a0..0ffd58a 100644
--- a/main/src/cgeo/geocaching/list/StoredList.java
+++ b/main/src/cgeo/geocaching/list/StoredList.java
@@ -24,12 +24,12 @@ import java.util.Comparator;
import java.util.List;
public final class StoredList extends AbstractList {
- public static final int TEMPORARY_LIST_ID = 0;
- public static final StoredList TEMPORARY_LIST = new StoredList(TEMPORARY_LIST_ID, "<temporary>", 0); // Never displayed
+ private static final int TEMPORARY_LIST_ID = 0;
+ public static final StoredList TEMPORARY_LIST = new StoredList(TEMPORARY_LIST_ID, "<temporary>", 0); // Never displayed
public static final int STANDARD_LIST_ID = 1;
private final int count; // this value is only valid as long as the list is not changed by other database operations
- public StoredList(int id, String title, int count) {
+ public StoredList(final int id, final String title, final int count) {
super(id, title);
this.count = count;
}
@@ -48,7 +48,7 @@ public final class StoredList extends AbstractList {
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
@@ -69,34 +69,30 @@ public final class StoredList extends AbstractList {
res = app.getResources();
}
- public void promptForListSelection(final int titleId, @NonNull final Action1<Integer> runAfterwards) {
- promptForListSelection(titleId, runAfterwards, false, -1);
- }
-
public void promptForListSelection(final int titleId, @NonNull final Action1<Integer> runAfterwards, final boolean onlyConcreteLists, final int exceptListId) {
- promptForListSelection(titleId, runAfterwards, onlyConcreteLists, exceptListId, StringUtils.EMPTY);
+ promptForListSelection(titleId, runAfterwards, onlyConcreteLists, exceptListId, ListNameMemento.EMPTY);
}
- public void promptForListSelection(final int titleId, @NonNull final Action1<Integer> runAfterwards, final boolean onlyConcreteLists, final int exceptListId, final String newListName) {
+ public void promptForListSelection(final int titleId, @NonNull final Action1<Integer> runAfterwards, final boolean onlyConcreteLists, final int exceptListId, final @NonNull ListNameMemento listNameMemento) {
final List<AbstractList> lists = getMenuLists(onlyConcreteLists, exceptListId);
final List<CharSequence> listsTitle = new ArrayList<>();
- for (AbstractList list : lists) {
+ for (final AbstractList list : lists) {
listsTitle.add(list.getTitleAndCount());
}
final CharSequence[] items = new CharSequence[listsTitle.size()];
final Activity activity = activityRef.get();
- AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+ final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(res.getString(titleId));
builder.setItems(listsTitle.toArray(items), new DialogInterface.OnClickListener() {
@Override
- public void onClick(DialogInterface dialogInterface, int itemId) {
+ public void onClick(final DialogInterface dialogInterface, final int itemId) {
final AbstractList list = lists.get(itemId);
if (list == PseudoList.NEW_LIST) {
// create new list on the fly
- promptForListCreation(runAfterwards, newListName);
+ promptForListCreation(runAfterwards, listNameMemento.getTerm());
}
else {
runAfterwards.call(lists.get(itemId).id);
@@ -106,15 +102,12 @@ public final class StoredList extends AbstractList {
builder.create().show();
}
- public static List<AbstractList> getMenuLists(boolean onlyConcreteLists, int exceptListId) {
+ public static List<AbstractList> getMenuLists(final boolean onlyConcreteLists, final int exceptListId) {
final List<AbstractList> lists = new ArrayList<>();
lists.addAll(getSortedLists());
- if (exceptListId > StoredList.TEMPORARY_LIST_ID) {
- StoredList exceptList = DataStore.getList(exceptListId);
- if (exceptList != null) {
- lists.remove(exceptList);
- }
+ if (exceptListId == StoredList.STANDARD_LIST_ID || exceptListId >= DataStore.customListIdOffset) {
+ lists.remove(DataStore.getList(exceptListId));
}
if (!onlyConcreteLists) {
@@ -138,7 +131,7 @@ public final class StoredList extends AbstractList {
Collections.sort(lists, new Comparator<StoredList>() {
@Override
- public int compare(StoredList lhs, StoredList rhs) {
+ public int compare(final StoredList lhs, final StoredList rhs) {
// have the standard list at the top
if (lhs.id == STANDARD_LIST_ID) {
return -1;
@@ -153,7 +146,7 @@ public final class StoredList extends AbstractList {
return lists;
}
- public void promptForListCreation(@NonNull final Action1<Integer> runAfterwards, String newListName) {
+ public void promptForListCreation(@NonNull final Action1<Integer> runAfterwards, final String newListName) {
handleListNameInput(newListName, R.string.list_dialog_create_title, R.string.list_dialog_create, new Action1<String>() {
// We need to update the list cache by creating a new StoredList object here.
@@ -177,7 +170,7 @@ public final class StoredList extends AbstractList {
});
}
- private void handleListNameInput(final String defaultValue, int dialogTitle, int buttonTitle, final Action1<String> runnable) {
+ private void handleListNameInput(final String defaultValue, final int dialogTitle, final int buttonTitle, final Action1<String> runnable) {
final Activity activity = activityRef.get();
if (activity == null) {
return;
@@ -187,7 +180,7 @@ public final class StoredList extends AbstractList {
@Override
public void call(final String input) {
// remove whitespaces added by autocompletion of Android keyboard
- String listName = StringUtils.trim(input);
+ final String listName = StringUtils.trim(input);
if (StringUtils.isNotBlank(listName)) {
runnable.call(listName);
}
@@ -225,8 +218,8 @@ public final class StoredList extends AbstractList {
/**
* Return the given list, if it is a concrete list. Return the default list otherwise.
*/
- public static int getConcreteList(int listId) {
- if (listId == PseudoList.ALL_LIST.id || listId == TEMPORARY_LIST_ID || listId == PseudoList.HISTORY_LIST.id) {
+ public static int getConcreteList(final int listId) {
+ if (listId == PseudoList.ALL_LIST.id || listId == TEMPORARY_LIST.id || listId == PseudoList.HISTORY_LIST.id) {
return STANDARD_LIST_ID;
}
return listId;