From 752ad05506ca3e2bc3b11515c1e3720f2ed9352f Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sun, 1 Jun 2014 09:51:55 +0200 Subject: fix #3933: switching list leads to onloadfinished of current loader --- main/src/cgeo/geocaching/CacheListActivity.java | 16 ++++------------ .../loaders/OfflineGeocacheListLoader.java | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 21 deletions(-) (limited to 'main') diff --git a/main/src/cgeo/geocaching/CacheListActivity.java b/main/src/cgeo/geocaching/CacheListActivity.java index 1441dd9..46e2a0e 100644 --- a/main/src/cgeo/geocaching/CacheListActivity.java +++ b/main/src/cgeo/geocaching/CacheListActivity.java @@ -59,6 +59,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import rx.Subscription; import rx.functions.Action1; @@ -786,13 +787,8 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA public void showFilterMenu(final View view) { new FilterUserInterface(this).selectFilter(new Action1() { @Override - public void call(final IFilter selectedFilter) { - if (selectedFilter != null) { - setFilter(selectedFilter); - } else { - // clear filter - setFilter(null); - } + public void call(@Nullable final IFilter selectedFilter) { + setFilter(selectedFilter); } }); } @@ -1375,11 +1371,7 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA showFooterLoadingCaches(); DataStore.moveToList(adapter.getCheckedCaches(), listId); - currentLoader = (OfflineGeocacheListLoader) getSupportLoaderManager().initLoader(CacheListType.OFFLINE.getLoaderId(), new Bundle(), this); - currentLoader.reset(); - ((OfflineGeocacheListLoader) currentLoader).setListId(listId); - ((OfflineGeocacheListLoader) currentLoader).setSearchCenter(coords); - currentLoader.startLoading(); + currentLoader = (OfflineGeocacheListLoader) getSupportLoaderManager().restartLoader(CacheListType.OFFLINE.getLoaderId(), OfflineGeocacheListLoader.getBundleForList(listId), this); invalidateOptionsMenuCompatible(); } diff --git a/main/src/cgeo/geocaching/loaders/OfflineGeocacheListLoader.java b/main/src/cgeo/geocaching/loaders/OfflineGeocacheListLoader.java index b80a1b8..0d5af6a 100644 --- a/main/src/cgeo/geocaching/loaders/OfflineGeocacheListLoader.java +++ b/main/src/cgeo/geocaching/loaders/OfflineGeocacheListLoader.java @@ -1,18 +1,20 @@ package cgeo.geocaching.loaders; import cgeo.geocaching.DataStore; +import cgeo.geocaching.Intents; import cgeo.geocaching.SearchResult; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.settings.Settings; import android.content.Context; +import android.os.Bundle; public class OfflineGeocacheListLoader extends AbstractSearchLoader { - private int listId; - private Geopoint searchCenter; + private final int listId; + private final Geopoint searchCenter; - public OfflineGeocacheListLoader(Context context, Geopoint searchCenter, int listId) { + public OfflineGeocacheListLoader(final Context context, final Geopoint searchCenter, final int listId) { super(context); this.searchCenter = searchCenter; this.listId = listId; @@ -23,12 +25,14 @@ public class OfflineGeocacheListLoader extends AbstractSearchLoader { return DataStore.getBatchOfStoredCaches(searchCenter, Settings.getCacheType(), listId); } - public void setListId(int listId) { - this.listId = listId; - } - - public void setSearchCenter(Geopoint searchCenter) { - this.searchCenter = searchCenter; + /** + * @param listId + * @return the bundle needed for querying the LoaderManager for the offline list with the given id + */ + public static Bundle getBundleForList(final int listId) { + final Bundle bundle = new Bundle(); + bundle.putInt(Intents.EXTRA_LIST_ID, listId); + return bundle; } } -- cgit v1.1