aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/CacheDetailActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/CacheDetailActivity.java')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java59
1 files changed, 33 insertions, 26 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index d3ab633..8375734 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -18,7 +18,6 @@ import cgeo.geocaching.connector.IConnector;
import cgeo.geocaching.connector.gc.GCConnector;
import cgeo.geocaching.connector.gc.GCConstants;
import cgeo.geocaching.enumerations.CacheAttribute;
-import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
import cgeo.geocaching.enumerations.WaypointType;
@@ -61,15 +60,16 @@ import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
-import org.eclipse.jdt.annotation.Nullable;
import rx.Observable;
import rx.Observable.OnSubscribe;
import rx.Subscriber;
+import rx.Subscription;
import rx.android.observables.AndroidObservable;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.subscriptions.CompositeSubscription;
+import rx.subscriptions.Subscriptions;
import android.R.color;
import android.app.AlertDialog;
@@ -171,6 +171,9 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
*/
private Waypoint selectedWaypoint;
+ private boolean requireGeodata;
+ private Subscription geoDataSubscription = Subscriptions.empty();
+
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState, R.layout.cachedetail_activity);
@@ -235,7 +238,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
finish();
return;
}
- } else if (uriHost.contains("opencaching.de")) {
+ } else if (uriHost.contains("opencaching.de") || uriHost.contains("opencaching.fr")) {
if (StringUtils.startsWith(uriPath, "/oc")) {
geocode = uriPath.substring(1).toUpperCase(Locale.US);
} else {
@@ -263,7 +266,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
// If we open this cache from a search, let's properly initialize the title bar, even if we don't have cache details
- updateTitleBar(geocode, name, null);
+ setCacheTitleBar(geocode, name, null);
final LoadCacheHandler loadCacheHandler = new LoadCacheHandler(this, progress);
@@ -293,8 +296,11 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
if (getPage(position) == Page.IMAGES) {
loadCacheImages();
}
+ requireGeodata = getPage(position) == Page.DETAILS;
+ startOrStopGeoDataListener();
}
});
+ requireGeodata = pageToOpen == 1;
final String realGeocode = geocode;
final String realGuid = guid;
@@ -323,9 +329,17 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
outState.putInt(STATE_PAGE_INDEX, getCurrentItem());
}
+ private void startOrStopGeoDataListener() {
+ geoDataSubscription.unsubscribe();
+ if (requireGeodata) {
+ geoDataSubscription = locationUpdater.start(GeoDirHandler.UPDATE_GEODATA);
+ }
+ }
+
@Override
public void onResume() {
- super.onResume(locationUpdater.start(GeoDirHandler.UPDATE_GEODATA));
+ super.onResume();
+ startOrStopGeoDataListener();
if (refreshOnResume) {
notifyDataSetChanged();
@@ -334,6 +348,12 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
}
@Override
+ public void onPause() {
+ geoDataSubscription.unsubscribe();
+ super.onPause();
+ }
+
+ @Override
public void onDestroy() {
createSubscriptions.unsubscribe();
super.onDestroy();
@@ -591,7 +611,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
// allow cache to notify CacheDetailActivity when it changes so it can be reloaded
cache.setChangeNotificationHandler(new ChangeNotificationHandler(this, progress));
- updateTitleBar(cache.getGeocode(), cache.getName(), cache.getType());
+ setCacheTitleBar(cache);
// reset imagesList so Images view page will be redrawn
imagesList = null;
@@ -604,19 +624,6 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
Settings.addCacheToHistory(cache.getGeocode());
}
- private void updateTitleBar(@Nullable final String geocode, @Nullable final String name, @Nullable final CacheType type) {
- if (StringUtils.isNotBlank(name)) {
- setTitle(StringUtils.isNotBlank(geocode) ? name + " (" + geocode + ")" : name);
- } else {
- setTitle(StringUtils.isNotBlank(geocode) ? geocode : res.getString(R.string.cache));
- }
- if (type != null) {
- getSupportActionBar().setIcon(getResources().getDrawable(type.markerId));
- } else {
- getSupportActionBar().setIcon(android.R.color.transparent);
- }
- }
-
/**
* Tries to navigate to the {@link Geocache} of this activity using the default navigation tool.
*/
@@ -910,9 +917,9 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
public void call(final Integer selectedListId) {
storeCache(selectedListId, new StoreCacheHandler(CacheDetailActivity.this, progress));
}
- }, true, StoredList.TEMPORARY_LIST_ID);
+ }, true, StoredList.TEMPORARY_LIST.id);
} else {
- storeCache(StoredList.TEMPORARY_LIST_ID, new StoreCacheHandler(this, progress));
+ storeCache(StoredList.TEMPORARY_LIST.id, new StoreCacheHandler(this, progress));
}
}
@@ -2223,7 +2230,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
if (UPDATE_LOAD_PROGRESS_DETAIL == msg.what && msg.obj instanceof String) {
updateStatusMsg(R.string.cache_dialog_offline_save_message, (String) msg.obj);
} else {
- notifyDatasetChanged(activityRef);
+ notifyDataSetChanged(activityRef);
}
}
}
@@ -2239,7 +2246,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
if (UPDATE_LOAD_PROGRESS_DETAIL == msg.what && msg.obj instanceof String) {
updateStatusMsg(R.string.cache_dialog_refresh_message, (String) msg.obj);
} else {
- notifyDatasetChanged(activityRef);
+ notifyDataSetChanged(activityRef);
}
}
}
@@ -2252,7 +2259,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
@Override
public void handleMessage(final Message msg) {
- notifyDatasetChanged(activityRef);
+ notifyDataSetChanged(activityRef);
}
}
@@ -2267,12 +2274,12 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
if (msg.what == MESSAGE_FAILED) {
super.handleMessage(msg);
} else {
- notifyDatasetChanged(activityRef);
+ notifyDataSetChanged(activityRef);
}
}
}
- private static void notifyDatasetChanged(final WeakReference<AbstractActivity> activityRef) {
+ private static void notifyDataSetChanged(final WeakReference<AbstractActivity> activityRef) {
final CacheDetailActivity activity = ((CacheDetailActivity) activityRef.get());
if (activity != null) {
activity.notifyDataSetChanged();