diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2014-10-05 10:46:52 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2014-10-05 10:46:52 +0200 |
| commit | 34905d520cb033bf3abdb6d11d3bffd1a5e7be7e (patch) | |
| tree | 9b551e4ae62aa26cd5d76c417dc075cc37a99fb8 | |
| parent | c2857679c87e0e4d92e4cbfd37f9461fd04c556e (diff) | |
| download | cgeo-34905d520cb033bf3abdb6d11d3bffd1a5e7be7e.zip cgeo-34905d520cb033bf3abdb6d11d3bffd1a5e7be7e.tar.gz cgeo-34905d520cb033bf3abdb6d11d3bffd1a5e7be7e.tar.bz2 | |
refactoring: split list name memento into separate class
| -rw-r--r-- | main/src/cgeo/geocaching/CacheListActivity.java | 24 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/list/ListNameMemento.java | 21 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/list/StoredList.java | 6 |
3 files changed, 33 insertions, 18 deletions
diff --git a/main/src/cgeo/geocaching/CacheListActivity.java b/main/src/cgeo/geocaching/CacheListActivity.java index 716f100..956b9da 100644 --- a/main/src/cgeo/geocaching/CacheListActivity.java +++ b/main/src/cgeo/geocaching/CacheListActivity.java @@ -23,6 +23,7 @@ import cgeo.geocaching.filter.FilterUserInterface; import cgeo.geocaching.filter.IFilter; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.list.AbstractList; +import cgeo.geocaching.list.ListNameMemento; import cgeo.geocaching.list.PseudoList; import cgeo.geocaching.list.StoredList; import cgeo.geocaching.loaders.AbstractSearchLoader; @@ -155,6 +156,7 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA private ContextMenuInfo lastMenuInfo; private String contextMenuGeocode = ""; private Subscription resumeSubscription; + private final ListNameMemento listNameMemento = new ListNameMemento(); // FIXME: This method has mostly been replaced by the loaders. But it still contains a license agreement check. public void handleCachesLoaded() { @@ -373,7 +375,6 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA } }; private AbstractSearchLoader currentLoader; - private String newListName = StringUtils.EMPTY; public CacheListActivity() { super(true); @@ -701,7 +702,7 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA invalidateOptionsMenuCompatible(); return false; case R.id.menu_create_list: - new StoredList.UserInterface(this).promptForListCreation(getListSwitchingRunnable(), newListName); + new StoredList.UserInterface(this).promptForListCreation(getListSwitchingRunnable(), listNameMemento.getTerm()); refreshSpinnerAdapter(); invalidateOptionsMenuCompatible(); return false; @@ -910,7 +911,7 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA adapter.setSelectMode(false); refreshCurrentList(); } - }, true, listId, newListName); + }, true, listId, listNameMemento); break; case R.id.menu_store_cache: case R.id.menu_refresh: @@ -1086,7 +1087,7 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA } refreshStoredInternal(caches); } - }, true, StoredList.TEMPORARY_LIST.id, newListName); + }, true, StoredList.TEMPORARY_LIST.id, listNameMemento); } else { if (type != CacheListType.OFFLINE) { for (final Geocache geocache : caches) { @@ -1621,13 +1622,13 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA break; case KEYWORD: final String keyword = extras.getString(Intents.EXTRA_KEYWORD); - rememberTerm(keyword); + title = listNameMemento.rememberTerm(keyword); loader = new KeywordGeocacheListLoader(app, keyword); break; case ADDRESS: final String address = extras.getString(Intents.EXTRA_ADDRESS); if (StringUtils.isNotBlank(address)) { - rememberTerm(address); + title = listNameMemento.rememberTerm(address); } else { title = coords.toString(); } @@ -1640,12 +1641,12 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA break; case FINDER: final String username = extras.getString(Intents.EXTRA_USERNAME); - rememberTerm(username); + title = listNameMemento.rememberTerm(username); loader = new FinderGeocacheListLoader(app, username); break; case OWNER: final String ownerName = extras.getString(Intents.EXTRA_USERNAME); - rememberTerm(ownerName); + title = listNameMemento.rememberTerm(ownerName); loader = new OwnerGeocacheListLoader(app, ownerName); break; case MAP: @@ -1674,13 +1675,6 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA return loader; } - private void rememberTerm(final String term) { - // set the title of the activity - title = term; - // and remember this term for potential use in list creation - newListName = term; - } - @Override public void onLoadFinished(final Loader<SearchResult> arg0, final SearchResult searchIn) { // The database search was moved into the UI call intentionally. If this is done before the runOnUIThread, diff --git a/main/src/cgeo/geocaching/list/ListNameMemento.java b/main/src/cgeo/geocaching/list/ListNameMemento.java new file mode 100644 index 0000000..6d5d481 --- /dev/null +++ b/main/src/cgeo/geocaching/list/ListNameMemento.java @@ -0,0 +1,21 @@ +package cgeo.geocaching.list; + +import org.apache.commons.lang3.StringUtils; + +/** + * Memento to remember list name suggestions from search terms. + */ +public class ListNameMemento { + public static final ListNameMemento EMPTY = new ListNameMemento(); + private String newListName = StringUtils.EMPTY; + + public String rememberTerm(final String term) { + newListName = term; + return term; + } + + public String getTerm() { + return newListName; + } + +} diff --git a/main/src/cgeo/geocaching/list/StoredList.java b/main/src/cgeo/geocaching/list/StoredList.java index abb6af1..4291a0a 100644 --- a/main/src/cgeo/geocaching/list/StoredList.java +++ b/main/src/cgeo/geocaching/list/StoredList.java @@ -70,10 +70,10 @@ public final class StoredList extends AbstractList { } 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<>(); @@ -92,7 +92,7 @@ public final class StoredList extends AbstractList { 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); |
