diff options
Diffstat (limited to 'main')
51 files changed, 332 insertions, 183 deletions
diff --git a/main/.factorypath b/main/.factorypath index 323bc61..0ba9bff 100644 --- a/main/.factorypath +++ b/main/.factorypath @@ -1,4 +1,4 @@ <factorypath> - <factorypathentry kind="WKSPJAR" id="/cgeo/libs/butterknife-4.0.1.jar" enabled="true" runInBatchMode="false"/> + <factorypathentry kind="WKSPJAR" id="/cgeo/libs/butterknife-5.0.0.jar" enabled="true" runInBatchMode="false"/> <factorypathentry kind="WKSPJAR" id="/cgeo/compile-libs/androidannotations-3.0.1.jar" enabled="true" runInBatchMode="false"/> </factorypath> diff --git a/main/cgeo.iml b/main/cgeo.iml index 83ec399..5781d97 100644 --- a/main/cgeo.iml +++ b/main/cgeo.iml @@ -54,6 +54,7 @@ <jarDirectory url="file://$MODULE_DIR$/libs" recursive="false" /> </library> </orderEntry> + <orderEntry type="module" module-name="mapswithme-api" exported="" /> </component> </module> diff --git a/main/libs/butterknife-4.0.1.jar b/main/libs/butterknife-4.0.1.jar Binary files differdeleted file mode 100644 index e048516..0000000 --- a/main/libs/butterknife-4.0.1.jar +++ /dev/null diff --git a/main/libs/butterknife-5.0.0.jar b/main/libs/butterknife-5.0.0.jar Binary files differnew file mode 100644 index 0000000..a08482d --- /dev/null +++ b/main/libs/butterknife-5.0.0.jar diff --git a/main/libs/commons-io-2.4.jar.properties b/main/libs/commons-io-2.4.jar.properties new file mode 100644 index 0000000..d160263 --- /dev/null +++ b/main/libs/commons-io-2.4.jar.properties @@ -0,0 +1,2 @@ +src=src/commons-io-2.4-sources.jar +doc=src/commons-io-2.4-javadoc.jar
\ No newline at end of file diff --git a/main/libs/commons-lang3-3.2.1.jar b/main/libs/commons-lang3-3.2.1.jar Binary files differdeleted file mode 100644 index 6bf4f93..0000000 --- a/main/libs/commons-lang3-3.2.1.jar +++ /dev/null diff --git a/main/libs/commons-lang3-3.2.1.jar.properties b/main/libs/commons-lang3-3.2.1.jar.properties deleted file mode 100644 index 7a8b7da..0000000 --- a/main/libs/commons-lang3-3.2.1.jar.properties +++ /dev/null @@ -1 +0,0 @@ -src=src/commons-lang3-3.2.1-sources.jar
\ No newline at end of file diff --git a/main/libs/commons-lang3-3.3.2.jar b/main/libs/commons-lang3-3.3.2.jar Binary files differnew file mode 100644 index 0000000..bb06979 --- /dev/null +++ b/main/libs/commons-lang3-3.3.2.jar diff --git a/main/libs/commons-lang3-3.3.2.jar.properties b/main/libs/commons-lang3-3.3.2.jar.properties new file mode 100644 index 0000000..0885ede --- /dev/null +++ b/main/libs/commons-lang3-3.3.2.jar.properties @@ -0,0 +1 @@ +doc=src/commons-lang3-3.3.2-javadoc.jar
\ No newline at end of file diff --git a/main/libs/rxjava-android-0.17.5.jar b/main/libs/rxjava-android-0.17.6.jar Binary files differindex 42b7f16..b840d42 100644 --- a/main/libs/rxjava-android-0.17.5.jar +++ b/main/libs/rxjava-android-0.17.6.jar diff --git a/main/libs/rxjava-async-util-0.17.5.jar b/main/libs/rxjava-async-util-0.17.6.jar Binary files differindex bc71622..2947fe3 100644 --- a/main/libs/rxjava-async-util-0.17.5.jar +++ b/main/libs/rxjava-async-util-0.17.6.jar diff --git a/main/libs/rxjava-core-0.17.5.jar b/main/libs/rxjava-core-0.17.6.jar Binary files differindex 5a54704..33d8801 100644 --- a/main/libs/rxjava-core-0.17.5.jar +++ b/main/libs/rxjava-core-0.17.6.jar diff --git a/main/libs/src/commons-io-2.4-javadoc.jar b/main/libs/src/commons-io-2.4-javadoc.jar Binary files differnew file mode 100644 index 0000000..e388f28 --- /dev/null +++ b/main/libs/src/commons-io-2.4-javadoc.jar diff --git a/main/libs/src/commons-io-2.4-sources.jar b/main/libs/src/commons-io-2.4-sources.jar Binary files differnew file mode 100644 index 0000000..f4ebc7b --- /dev/null +++ b/main/libs/src/commons-io-2.4-sources.jar diff --git a/main/libs/src/commons-lang3-3.2.1-sources.jar b/main/libs/src/commons-lang3-3.2.1-sources.jar Binary files differdeleted file mode 100644 index efe36e8..0000000 --- a/main/libs/src/commons-lang3-3.2.1-sources.jar +++ /dev/null diff --git a/main/libs/src/commons-lang3-3.3.2-javadoc.jar b/main/libs/src/commons-lang3-3.3.2-javadoc.jar Binary files differnew file mode 100644 index 0000000..bd2f422 --- /dev/null +++ b/main/libs/src/commons-lang3-3.3.2-javadoc.jar diff --git a/main/project.properties b/main/project.properties index 6d3329d..a761287 100644 --- a/main/project.properties +++ b/main/project.properties @@ -12,3 +12,4 @@ proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project. # Project target. target=Google Inc.:Google APIs:19 +android.library.reference.1=../mapswithme-api diff --git a/main/res/values-lt/strings.xml b/main/res/values-lt/strings.xml index 40b4fb4..3f44f64 100644 --- a/main/res/values-lt/strings.xml +++ b/main/res/values-lt/strings.xml @@ -559,7 +559,7 @@ <string name="cache_personal_note_upload">Įkelti</string> <string name="cache_personal_note_uploading">Įkeliama asmeninė pastaba</string> <string name="cache_personal_note_upload_done">Asmeninė pastaba įkelta</string> - <string name="cache_personal_note_upload_cancelled">Atšauktas asmeninės pastabos įkėlimas</string> + <string name="cache_personal_note_upload_cancelled">Asmeninės pastabos įkėlimas atšauktas</string> <string name="cache_personal_note_unstored">Slėptuvė neišsaugota</string> <string name="cache_personal_note_store">Rašyti asmeninę pastabą galima tik išsaugotos slėptuvės aprašyme.</string> <string name="cache_description">Aprašymas</string> @@ -787,7 +787,7 @@ <string name="search_tb_hint">Keliauninko identifikavimas</string> <string name="search_tb_button">Ieškoti keliauninko</string> <string name="search_destination">Tikslas</string> - <string name="search_direction_rel">Nuo šios pozicijos</string> + <string name="search_direction_rel">Nuo šios vietos</string> <string name="search_address_started">Ieškoma vietų</string> <string name="search_address_result">Rastos vietos</string> <string name="search_own_caches">Ieškoti mano slėptuvių</string> @@ -835,7 +835,7 @@ <string name="destination_set">Nustatyti tikslą</string> <string name="navigation_direct_navigation">Tiesioginė navigacija</string> <string name="navigation_target">Tikslas</string> - <string name="err_nav_no_coordinates">Negalima pradėti navigacijos, nenurodytos koordinatės</string> + <string name="err_nav_no_coordinates">Be koordinačių navigacijos pradėti neįmanoma</string> <string name="license">Licencija</string> <string name="license_show">Rodyti licenciją</string> <string name="license_dismiss">Atmesti</string> @@ -872,7 +872,7 @@ <string name="export_fieldnotes_creating">Kuriami Lauko užrašai…</string> <string name="export_gpx">GPX</string> <string name="export_gpx_info">GPX failas bus eksportuotas į %1$s su dabartine data ir laiku failo pavadinime.</string> - <string name="export_gpx_to">Siųsti eksportuotą GPX į</string> + <string name="export_gpx_to">Siųsti eksportuotą GPX</string> <string name="attribute_dogs_yes">Galima su šunimi</string> <string name="attribute_dogs_no">Negalima su šunimi</string> <string name="attribute_bicycles_yes">Galima su dviračiu</string> @@ -961,7 +961,7 @@ <string name="attribute_skiis_no">Lygumų slidės nereikalingos</string> <string name="attribute_s_tool_yes">Reikalingi specialūs įrankiai</string> <string name="attribute_s_tool_no">Specialūs įrankiai nereikalingi</string> - <string name="attribute_wirelessbeacon_yes">Yra belaidžio ryšio švyturys</string> + <string name="attribute_wirelessbeacon_yes">Yra bevielio ryšio švyturys</string> <string name="attribute_wirelessbeacon_no">Belaidžio ryšio švyturio nėra</string> <string name="attribute_treeclimbing_yes">Reikia lipti į medį</string> <string name="attribute_treeclimbing_no">Į medį lipti nereikia</string> diff --git a/main/res/values/changelog_master.xml b/main/res/values/changelog_master.xml index 1e3c3d4..cff468e 100644 --- a/main/res/values/changelog_master.xml +++ b/main/res/values/changelog_master.xml @@ -2,5 +2,11 @@ <resources> <!-- changelog for the master branch --> <string name="changelog_master" translatable="false"> + <b>Next feature release:</b>\n + <b>New features:</b>\n + \n + <b>Bugfixing:</b>\n + \n + \n </string> </resources> diff --git a/main/res/values/ids.xml b/main/res/values/ids.xml index 8539275..e8cb74b 100644 --- a/main/res/values/ids.xml +++ b/main/res/values/ids.xml @@ -24,5 +24,6 @@ <item name="cache_app_show_static_maps" type="id"/> <item name="cache_app_locus" type="id"/> <item name="cache_app_pebble" type="id"/> - + <item name="cache_app_mapswithme" type="id"/> + </resources>
\ No newline at end of file diff --git a/main/res/values/preference_keys.xml b/main/res/values/preference_keys.xml index 91b2c67..6036be3 100644 --- a/main/res/values/preference_keys.xml +++ b/main/res/values/preference_keys.xml @@ -137,6 +137,7 @@ <string name="pref_navigation_menu_gcc">navigationGcc</string> <string name="pref_navigation_menu_where_you_go">navigationWhereYouGo</string> <string name="pref_navigation_menu_pebble">navigationPebble</string> + <string name="pref_navigation_menu_mapswithme">navigationMapsWithMe</string> <string name="pref_ocpl_tokensecret">ocpl_tokensecret</string> <string name="pref_ocpl_tokenpublic">ocpl_tokenpublic</string> <string name="pref_temp_ocpl_token_secret">ocpl-temp-token-secret</string> diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml index 62c3bbf..2aa3d00 100644 --- a/main/res/values/strings.xml +++ b/main/res/values/strings.xml @@ -24,6 +24,7 @@ <string name="letterbox">Letterbox Hybrid</string> <string name="event">Event Cache</string> <string name="mega">Mega-Event Cache</string> + <string name="giga">Giga-Event Cache</string> <string name="earth">Earthcache</string> <string name="cito">Cache In Trash Out Event</string> <string name="webcam">Webcam Cache</string> @@ -320,6 +321,7 @@ <string name="caches_move_all">Move all</string> <string name="caches_map_locus">Locus</string> <string name="caches_map_locus_export">Export to Locus</string> + <string name="caches_map_mapswithme">MapsWithMe</string> <string name="caches_recaptcha_title">reCAPTCHA</string> <string name="caches_recaptcha_explanation">Please enter the text you see in the image. This enables downloading of cache coordinates, which can be disabled in Settings.</string> <string name="caches_recaptcha_hint">Text from image</string> @@ -709,6 +711,7 @@ <string name="cache_menu_cachebeacon">Cache Beacon</string> <string name="cache_menu_navigon">Navigon</string> <string name="cache_menu_pebble">Pebble</string> + <string name="cache_menu_mapswithme">MapsWithMe</string> <string name="cache_status">Status</string> <string name="cache_status_offline_log">Saved Log</string> <string name="cache_status_found">Found</string> diff --git a/main/res/xml/preferences.xml b/main/res/xml/preferences.xml index fb17fb8..d550dc8 100644 --- a/main/res/xml/preferences.xml +++ b/main/res/xml/preferences.xml @@ -666,6 +666,11 @@ android:enabled="false" android:key="@string/pref_navigation_menu_pebble" android:title="@string/cache_menu_pebble" /> + <CheckBoxPreference + android:defaultValue="true" + android:enabled="false" + android:key="@string/pref_navigation_menu_mapswithme" + android:title="@string/cache_menu_mapswithme" /> </PreferenceScreen> </PreferenceCategory> </PreferenceScreen> diff --git a/main/src/cgeo/geocaching/AbstractPopupActivity.java b/main/src/cgeo/geocaching/AbstractPopupActivity.java index 683579f..b2e1a15 100644 --- a/main/src/cgeo/geocaching/AbstractPopupActivity.java +++ b/main/src/cgeo/geocaching/AbstractPopupActivity.java @@ -14,12 +14,13 @@ import cgeo.geocaching.settings.Settings; import cgeo.geocaching.ui.CacheDetailsCreator; import cgeo.geocaching.ui.LoggingUI; import cgeo.geocaching.utils.Log; -import cgeo.geocaching.utils.RxUtils; import org.apache.commons.lang3.StringUtils; import rx.Observable; +import rx.android.observables.AndroidObservable; import rx.functions.Action1; import rx.functions.Func0; +import rx.schedulers.Schedulers; import android.graphics.Rect; import android.os.Bundle; @@ -79,13 +80,13 @@ public abstract class AbstractPopupActivity extends AbstractActivity implements if (!cache.supportsGCVote()) { return; } - RxUtils.subscribeOnIOThenUI(Observable.defer(new Func0<Observable<GCVoteRating>>() { + AndroidObservable.bindActivity(this, Observable.defer(new Func0<Observable<GCVoteRating>>() { @Override public Observable<GCVoteRating> call() { final GCVoteRating rating = GCVote.getRating(cache.getGuid(), geocode); return rating != null ? Observable.just(rating) : Observable.<GCVoteRating>empty(); } - }), new Action1<GCVoteRating>() { + })).subscribe(new Action1<GCVoteRating>() { @Override public void call(final GCVoteRating rating) { cache.setRating(rating.getRating()); @@ -93,7 +94,7 @@ public abstract class AbstractPopupActivity extends AbstractActivity implements DataStore.saveChangedCache(cache); details.addRating(cache); } - }); + }, Schedulers.io()); } protected void init() { @@ -255,7 +256,7 @@ public abstract class AbstractPopupActivity extends AbstractActivity implements * @param view * unused here but needed since this method is referenced from XML layout */ - public final void goDefaultNavigation(@SuppressWarnings("unused") View view) { + public final void goDefaultNavigation(View view) { navigateTo(); finish(); } diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index a8fa8ee..e76a773 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -8,6 +8,7 @@ import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.activity.AbstractViewPagerActivity; import cgeo.geocaching.activity.Progress; import cgeo.geocaching.apps.cache.navi.NavigationAppFactory; +import cgeo.geocaching.apps.cachelist.MapsWithMeCacheListApp; import cgeo.geocaching.compatibility.Compatibility; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.IConnector; @@ -45,7 +46,6 @@ import cgeo.geocaching.utils.CryptUtils; import cgeo.geocaching.utils.ImageUtils; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.MatcherWrapper; -import cgeo.geocaching.utils.RxUtils; import cgeo.geocaching.utils.SimpleCancellableHandler; import cgeo.geocaching.utils.SimpleHandler; import cgeo.geocaching.utils.TextUtils; @@ -56,14 +56,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 rx.Observable; import rx.Observable.OnSubscribe; import rx.Observer; import rx.Scheduler.Inner; import rx.Subscriber; -import rx.Subscription; +import rx.android.observables.AndroidObservable; import rx.functions.Action1; import rx.schedulers.Schedulers; +import rx.subscriptions.CompositeSubscription; import android.R.color; import android.app.AlertDialog; @@ -168,7 +170,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc private TextView cacheDistanceView; protected ImagesList imagesList; - private Subscription imagesSubscription; + private CompositeSubscription createSubscriptions; /** * waypoint selected in context menu. This variable will be gone when the waypoint context menu is a fragment. */ @@ -178,6 +180,8 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState, R.layout.cachedetail_activity); + createSubscriptions = new CompositeSubscription(); + // set title in code, as the activity needs a hard coded title due to the intent filters setTitle(res.getString(R.string.cache)); @@ -195,6 +199,11 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc guid = extras.getString(Intents.EXTRA_GUID); } + // integration with MapsWithMe + if (StringUtils.isEmpty(geocode)) { + geocode = MapsWithMeCacheListApp.getCacheFromMapsWithMe(this, getIntent()); + } + // try to get data from URI if (geocode == null && guid == null && uri != null) { final String uriHost = uri.getHost().toLowerCase(Locale.US); @@ -330,9 +339,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc @Override public void onDestroy() { - if (imagesList != null) { - imagesSubscription.unsubscribe(); - } + createSubscriptions.unsubscribe(); super.onDestroy(); } @@ -649,7 +656,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc return; } imagesList = new ImagesList(this, cache.getGeocode()); - imagesSubscription = imagesList.loadImages(imageView, cache.getImages(), false); + createSubscriptions.add(imagesList.loadImages(imageView, cache.getImages(), false)); } public static void startActivity(final Context context, final String geocode) { @@ -878,7 +885,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc view = (ScrollView) getLayoutInflater().inflate(R.layout.cachedetail_details_page, null); // Start loading preview map - RxUtils.subscribeOnIOThenUI(previewMap, new Action1<BitmapDrawable>() { + AndroidObservable.bindActivity(CacheDetailActivity.this, previewMap).subscribe(new Action1<BitmapDrawable>() { @Override public void call(final BitmapDrawable image) { final Bitmap bitmap = image.getBitmap(); @@ -888,7 +895,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc view.findViewById(R.id.map_preview_box).setVisibility(View.VISIBLE); } } - }); + }, Schedulers.io()); detailsList = (LinearLayout) view.findViewById(R.id.details_list); final CacheDetailsCreator details = new CacheDetailsCreator(CacheDetailActivity.this, detailsList); @@ -1605,7 +1612,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc } }); - RxUtils.subscribeOnIOThenUI(producer, new Observer<Spanned>() { + AndroidObservable.bindActivity(this, producer).subscribe(new Observer<Spanned>() { @Override public void onCompleted() { if (null != loadingIndicatorView) { @@ -1668,7 +1675,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc } descriptionView.setBackgroundResource(backcolor); } - }); + }, Schedulers.io()); } private class WaypointsViewCreator extends AbstractCachingPageViewCreator<ListView> { diff --git a/main/src/cgeo/geocaching/CacheListActivity.java b/main/src/cgeo/geocaching/CacheListActivity.java index b2404d9..0aec119 100644 --- a/main/src/cgeo/geocaching/CacheListActivity.java +++ b/main/src/cgeo/geocaching/CacheListActivity.java @@ -1384,7 +1384,7 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA * @param view * unused here but needed since this method is referenced from XML layout */ - public void goMap(@SuppressWarnings("unused") View view) { + public void goMap(View view) { if (!cacheToShow()) { return; } diff --git a/main/src/cgeo/geocaching/DataStore.java b/main/src/cgeo/geocaching/DataStore.java index 7e676b0..623301b 100644 --- a/main/src/cgeo/geocaching/DataStore.java +++ b/main/src/cgeo/geocaching/DataStore.java @@ -21,15 +21,16 @@ import cgeo.geocaching.ui.dialog.Dialogs; import cgeo.geocaching.utils.FileUtils; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.MiscUtils; -import cgeo.geocaching.utils.RxUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.NonNull; +import rx.android.observables.AndroidObservable; import rx.functions.Action1; import rx.functions.Func0; import rx.functions.Func1; +import rx.schedulers.Schedulers; import rx.util.async.Async; import android.app.Activity; @@ -393,7 +394,7 @@ public class DataStore { */ public static void moveDatabase(final Activity fromActivity) { final ProgressDialog dialog = ProgressDialog.show(fromActivity, fromActivity.getString(R.string.init_dbmove_dbmove), fromActivity.getString(R.string.init_dbmove_running), true, false); - RxUtils.subscribeOnIOThenUI(Async.fromCallable(new Func0<Boolean>() { + AndroidObservable.bindActivity(fromActivity, Async.fromCallable(new Func0<Boolean>() { @Override public Boolean call() { if (!LocalStorage.isExternalStorageAvailable()) { @@ -418,14 +419,14 @@ public class DataStore { init(); return true; } - }), new Action1<Boolean>() { + })).subscribe(new Action1<Boolean>() { @Override public void call(final Boolean success) { dialog.dismiss(); final String message = success ? fromActivity.getString(R.string.init_dbmove_success) : fromActivity.getString(R.string.init_dbmove_failed); Dialogs.message(fromActivity, R.string.init_dbmove_dbmove, message); } - }); + }, Schedulers.io()); } private static File databasePath(final boolean internal) { diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index a224e4e..1ed699e 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -25,6 +25,7 @@ import cgeo.geocaching.list.StoredList; import cgeo.geocaching.network.HtmlImage; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.CancellableHandler; +import cgeo.geocaching.utils.DateUtils; import cgeo.geocaching.utils.ImageUtils; import cgeo.geocaching.utils.LazyInitializedList; import cgeo.geocaching.utils.Log; @@ -34,12 +35,14 @@ import cgeo.geocaching.utils.MatcherWrapper; import cgeo.geocaching.utils.UncertainProperty; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; + import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.Predicate; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.Nullable; + import rx.Scheduler; import rx.Scheduler.Inner; import rx.Subscription; @@ -177,7 +180,7 @@ public class Geocache implements ICache, IWaypoint { * * @param gpxParser */ - public Geocache(@SuppressWarnings("unused") GPXParser gpxParser) { + public Geocache(GPXParser gpxParser) { setReliableLatLon(true); setAttributes(Collections.<String> emptyList()); setWaypoints(Collections.<Waypoint> emptyList(), false); @@ -1806,4 +1809,23 @@ public class Geocache implements ICache, IWaypoint { return (getType().applyDistanceRule() || hasUserModifiedCoords()) && getConnector() == GCConnector.getInstance(); } + public LogType getDefaultLogType() { + if (isEventCache()) { + final Date eventDate = getHiddenDate(); + boolean expired = DateUtils.isPastEvent(this); + + if (hasOwnLog(LogType.WILL_ATTEND) || expired || (eventDate != null && DateUtils.daysSince(eventDate.getTime()) == 0)) { + return hasOwnLog(LogType.ATTENDED) ? LogType.NOTE : LogType.ATTENDED; + } + return LogType.WILL_ATTEND; + } + if (isFound()) { + return LogType.NOTE; + } + if (getType() == CacheType.WEBCAM) { + return LogType.WEBCAM_PHOTO_TAKEN; + } + return LogType.FOUND_IT; + } + } diff --git a/main/src/cgeo/geocaching/LogCacheActivity.java b/main/src/cgeo/geocaching/LogCacheActivity.java index 0f65a1d..a1368cc 100644 --- a/main/src/cgeo/geocaching/LogCacheActivity.java +++ b/main/src/cgeo/geocaching/LogCacheActivity.java @@ -3,7 +3,6 @@ package cgeo.geocaching; import cgeo.geocaching.connector.ILoggingManager; import cgeo.geocaching.connector.ImageResult; import cgeo.geocaching.connector.LogResult; -import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.LogTypeTrackable; @@ -341,25 +340,10 @@ public class LogCacheActivity extends AbstractLoggingActivity implements DateDia private void setDefaultValues() { date = Calendar.getInstance(); rating = GCVote.NO_RATING; - if (cache.isEventCache()) { - final Date eventDate = cache.getHiddenDate(); - boolean expired = DateUtils.isPastEvent(cache); - - if (cache.hasOwnLog(LogType.WILL_ATTEND) || expired) { - typeSelected = cache.hasOwnLog(LogType.ATTENDED) ? LogType.NOTE : LogType.ATTENDED; - } else { - typeSelected = LogType.WILL_ATTEND; - } - // it this is an attended event log, use the event date by default instead of the current date - if (expired && typeSelected == LogType.ATTENDED) { - date.setTime(eventDate); - } - } else { - if (cache.isFound()) { - typeSelected = LogType.NOTE; - } else { - typeSelected = cache.getType() == CacheType.WEBCAM ? LogType.WEBCAM_PHOTO_TAKEN : LogType.FOUND_IT; - } + typeSelected = cache.getDefaultLogType(); + // it this is an attended event log, use the event date by default instead of the current date + if (cache.isEventCache() && DateUtils.isPastEvent(cache) && typeSelected == LogType.ATTENDED) { + date.setTime(cache.getHiddenDate()); } text = null; imageCaption = StringUtils.EMPTY; diff --git a/main/src/cgeo/geocaching/MainActivity.java b/main/src/cgeo/geocaching/MainActivity.java index b82614b..42dd58d 100644 --- a/main/src/cgeo/geocaching/MainActivity.java +++ b/main/src/cgeo/geocaching/MainActivity.java @@ -21,7 +21,6 @@ import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.ui.dialog.Dialogs; import cgeo.geocaching.utils.DatabaseBackupUtils; import cgeo.geocaching.utils.Log; -import cgeo.geocaching.utils.RxUtils; import cgeo.geocaching.utils.Version; import com.google.zxing.integration.android.IntentIntegrator; @@ -30,7 +29,9 @@ import org.apache.commons.lang3.StringUtils; import rx.Observable; import rx.Observable.OnSubscribe; import rx.Subscriber; +import rx.android.observables.AndroidObservable; import rx.functions.Action1; +import rx.schedulers.Schedulers; import rx.subscriptions.Subscriptions; import android.app.AlertDialog; @@ -551,13 +552,13 @@ public class MainActivity extends AbstractActivity { } } }); - RxUtils.subscribeOnIOThenUI(address.onErrorResumeNext(Observable.from(geo.getCoords().toString())), - new Action1<String>() { + AndroidObservable.bindActivity(MainActivity.this, address.onErrorResumeNext(Observable.from(geo.getCoords().toString()))) + .subscribe(new Action1<String>() { @Override public void call(final String address) { navLocation.setText(address); } - }); + }, Schedulers.io()); } } else { navLocation.setText(geo.getCoords().toString()); @@ -569,7 +570,7 @@ public class MainActivity extends AbstractActivity { * @param v * unused here but needed since this method is referenced from XML layout */ - public void cgeoFindOnMap(@SuppressWarnings("unused") final View v) { + public void cgeoFindOnMap(final View v) { findOnMap.setPressed(true); CGeoMap.startActivityLiveMap(this); } @@ -578,7 +579,7 @@ public class MainActivity extends AbstractActivity { * @param v * unused here but needed since this method is referenced from XML layout */ - public void cgeoFindNearest(@SuppressWarnings("unused") final View v) { + public void cgeoFindNearest(final View v) { if (app.currentGeo().getCoords() == null) { return; } @@ -591,7 +592,7 @@ public class MainActivity extends AbstractActivity { * @param v * unused here but needed since this method is referenced from XML layout */ - public void cgeoFindByOffline(@SuppressWarnings("unused") final View v) { + public void cgeoFindByOffline(final View v) { findByOffline.setPressed(true); CacheListActivity.startActivityOffline(this); } @@ -600,7 +601,7 @@ public class MainActivity extends AbstractActivity { * @param v * unused here but needed since this method is referenced from XML layout */ - public void cgeoSearch(@SuppressWarnings("unused") final View v) { + public void cgeoSearch(final View v) { advanced.setPressed(true); startActivity(new Intent(this, SearchActivity.class)); } @@ -609,7 +610,7 @@ public class MainActivity extends AbstractActivity { * @param v * unused here but needed since this method is referenced from XML layout */ - public void cgeoPoint(@SuppressWarnings("unused") final View v) { + public void cgeoPoint(final View v) { any.setPressed(true); startActivity(new Intent(this, NavigateAnyPointActivity.class)); } @@ -618,7 +619,7 @@ public class MainActivity extends AbstractActivity { * @param v * unused here but needed since this method is referenced from XML layout */ - public void cgeoFilter(@SuppressWarnings("unused") final View v) { + public void cgeoFilter(final View v) { filter.setPressed(true); filter.performClick(); } @@ -627,7 +628,7 @@ public class MainActivity extends AbstractActivity { * @param v * unused here but needed since this method is referenced from XML layout */ - public void cgeoNavSettings(@SuppressWarnings("unused") final View v) { + public void cgeoNavSettings(final View v) { startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } @@ -708,7 +709,7 @@ public class MainActivity extends AbstractActivity { * @param view * unused here but needed since this method is referenced from XML layout */ - public void showAbout(@SuppressWarnings("unused") final View view) { + public void showAbout(final View view) { startActivity(new Intent(this, AboutActivity.class)); } @@ -716,7 +717,7 @@ public class MainActivity extends AbstractActivity { * @param view * unused here but needed since this method is referenced from XML layout */ - public void goSearch(@SuppressWarnings("unused") final View view) { + public void goSearch(final View view) { onSearchRequested(); } diff --git a/main/src/cgeo/geocaching/PocketQueryList.java b/main/src/cgeo/geocaching/PocketQueryList.java index e748b29..2ac137f 100644 --- a/main/src/cgeo/geocaching/PocketQueryList.java +++ b/main/src/cgeo/geocaching/PocketQueryList.java @@ -2,13 +2,14 @@ package cgeo.geocaching; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.connector.gc.GCParser; -import cgeo.geocaching.utils.RxUtils; import org.apache.commons.collections4.CollectionUtils; import rx.Observable; import rx.Observable.OnSubscribe; import rx.Subscriber; +import rx.android.observables.AndroidObservable; import rx.functions.Action1; +import rx.schedulers.Schedulers; import android.app.Activity; import android.app.AlertDialog; @@ -45,19 +46,19 @@ public final class PocketQueryList { public static void promptForListSelection(final Activity activity, final Action1<PocketQueryList> runAfterwards) { final Dialog waitDialog = ProgressDialog.show(activity, activity.getString(R.string.search_pocket_title), activity.getString(R.string.search_pocket_loading), true, true); - RxUtils.subscribeOnIOThenUI(Observable.create(new OnSubscribe<List<PocketQueryList>>() { + AndroidObservable.bindActivity(activity, Observable.create(new OnSubscribe<List<PocketQueryList>>() { @Override public void call(final Subscriber<? super List<PocketQueryList>> subscriber) { subscriber.onNext(GCParser.searchPocketQueryList()); subscriber.onCompleted(); } - }), new Action1<List<PocketQueryList>>() { + })).subscribe(new Action1<List<PocketQueryList>>() { @Override public void call(final List<PocketQueryList> pocketQueryLists) { waitDialog.dismiss(); selectFromPocketQueries(activity, pocketQueryLists, runAfterwards); } - }); + }, Schedulers.io()); } private static void selectFromPocketQueries(final Activity activity, final List<PocketQueryList> pocketQueryList, final Action1<PocketQueryList> runAfterwards) { if (CollectionUtils.isEmpty(pocketQueryList)) { diff --git a/main/src/cgeo/geocaching/StatusFragment.java b/main/src/cgeo/geocaching/StatusFragment.java index a59316f..f8552d7 100644 --- a/main/src/cgeo/geocaching/StatusFragment.java +++ b/main/src/cgeo/geocaching/StatusFragment.java @@ -3,10 +3,11 @@ package cgeo.geocaching; import cgeo.geocaching.network.StatusUpdater; import cgeo.geocaching.network.StatusUpdater.Status; import cgeo.geocaching.utils.Log; -import cgeo.geocaching.utils.RxUtils; import rx.Subscription; +import rx.android.observables.AndroidObservable; import rx.functions.Action1; +import rx.schedulers.Schedulers; import android.content.Intent; import android.content.res.Resources; @@ -30,53 +31,53 @@ public class StatusFragment extends Fragment { final ViewGroup statusGroup = (ViewGroup) inflater.inflate(R.layout.status, container, false); final ImageView statusIcon = (ImageView) statusGroup.findViewById(R.id.status_icon); final TextView statusMessage = (TextView) statusGroup.findViewById(R.id.status_message); - statusSubscription = RxUtils.subscribeOnIOThenUI(StatusUpdater.latestStatus, new Action1<Status>() { - @Override - public void call(final Status status) { - if (status == null) { - statusGroup.setVisibility(View.INVISIBLE); - return; - } + statusSubscription = AndroidObservable.bindFragment(this, StatusUpdater.latestStatus).subscribe(new Action1<Status>() { + @Override + public void call(final Status status) { + if (status == null) { + statusGroup.setVisibility(View.INVISIBLE); + return; + } - final Resources res = getResources(); - final String packageName = getActivity().getPackageName(); + final Resources res = getResources(); + final String packageName = getActivity().getPackageName(); - if (status.icon != null) { - final int iconId = res.getIdentifier(status.icon, "drawable", packageName); - if (iconId != 0) { - statusIcon.setImageResource(iconId); - statusIcon.setVisibility(View.VISIBLE); - } else { - Log.w("StatusHandler: could not find icon corresponding to @drawable/" + status.icon); - statusIcon.setVisibility(View.GONE); - } - } else { - statusIcon.setVisibility(View.GONE); - } + if (status.icon != null) { + final int iconId = res.getIdentifier(status.icon, "drawable", packageName); + if (iconId != 0) { + statusIcon.setImageResource(iconId); + statusIcon.setVisibility(View.VISIBLE); + } else { + Log.w("StatusHandler: could not find icon corresponding to @drawable/" + status.icon); + statusIcon.setVisibility(View.GONE); + } + } else { + statusIcon.setVisibility(View.GONE); + } - String message = status.message; - if (status.messageId != null) { - final int messageId = res.getIdentifier(status.messageId, "string", packageName); - if (messageId != 0) { - message = res.getString(messageId); - } - } + String message = status.message; + if (status.messageId != null) { + final int messageId = res.getIdentifier(status.messageId, "string", packageName); + if (messageId != 0) { + message = res.getString(messageId); + } + } - statusMessage.setText(message); - statusGroup.setVisibility(View.VISIBLE); + statusMessage.setText(message); + statusGroup.setVisibility(View.VISIBLE); - if (status.url != null) { - statusGroup.setOnClickListener(new OnClickListener() { - @Override - public void onClick(final View v) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(status.url))); + if (status.url != null) { + statusGroup.setOnClickListener(new OnClickListener() { + @Override + public void onClick(final View v) { + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(status.url))); + } + }); + } else { + statusGroup.setClickable(false); } - }); - } else { - statusGroup.setClickable(false); - } - } - }); + } + }, Schedulers.io()); return statusGroup; } diff --git a/main/src/cgeo/geocaching/TrackableActivity.java b/main/src/cgeo/geocaching/TrackableActivity.java index a14a397..81d23c9 100644 --- a/main/src/cgeo/geocaching/TrackableActivity.java +++ b/main/src/cgeo/geocaching/TrackableActivity.java @@ -20,12 +20,12 @@ import cgeo.geocaching.ui.UserNameClickListener; import cgeo.geocaching.ui.logs.TrackableLogsViewCreator; import cgeo.geocaching.utils.HtmlUtils; import cgeo.geocaching.utils.Log; -import cgeo.geocaching.utils.RxUtils; import cgeo.geocaching.utils.UnknownTagsHandler; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; +import rx.android.observables.AndroidObservable; import rx.android.observables.ViewObservable; import rx.functions.Action1; @@ -524,7 +524,7 @@ public class TrackableActivity extends AbstractViewPagerActivity<TrackableActivi } }); - RxUtils.subscribeThenUI(new HtmlImage(geocode, true, 0, false).fetchDrawable(trackable.getImage()), new Action1<BitmapDrawable>() { + AndroidObservable.bindActivity(TrackableActivity.this, new HtmlImage(geocode, true, 0, false).fetchDrawable(trackable.getImage())).subscribe(new Action1<BitmapDrawable>() { @Override public void call(final BitmapDrawable bitmapDrawable) { trackableImage.setImageDrawable(bitmapDrawable); diff --git a/main/src/cgeo/geocaching/apps/cache/navi/MapsWithMeApp.java b/main/src/cgeo/geocaching/apps/cache/navi/MapsWithMeApp.java new file mode 100644 index 0000000..ea5aebb --- /dev/null +++ b/main/src/cgeo/geocaching/apps/cache/navi/MapsWithMeApp.java @@ -0,0 +1,43 @@ +package cgeo.geocaching.apps.cache.navi; + +import cgeo.geocaching.Geocache; +import cgeo.geocaching.R; +import cgeo.geocaching.Waypoint; +import cgeo.geocaching.geopoint.Geopoint; + +import com.mapswithme.maps.api.MapsWithMeApi; + +import android.app.Activity; + +public class MapsWithMeApp extends AbstractPointNavigationApp { + + protected MapsWithMeApp() { + super(getString(R.string.cache_menu_mapswithme), R.id.cache_app_mapswithme, null); + } + + @Override + public void navigate(Activity activity, Geopoint coords) { + navigate(activity, coords, getString(R.string.unknown)); + } + + @Override + public void navigate(Activity activity, Geocache cache) { + navigate(activity, cache.getCoords(), cache.getName()); + } + + private static void navigate(Activity activity, Geopoint coords, String label) { + MapsWithMeApi.showPointOnMap(activity, coords.getLatitude(), coords.getLongitude(), label); + } + + @Override + public void navigate(Activity activity, Waypoint waypoint) { + navigate(activity, waypoint.getCoords(), waypoint.getName()); + } + + @Override + public boolean isInstalled() { + // the library can handle the app not being installed + return true; + } + +} diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java index bf0e776..3177a29 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java @@ -72,7 +72,8 @@ public final class NavigationAppFactory extends AbstractAppFactory { CACHE_BEACON(new CacheBeaconApp(), 14, R.string.pref_navigation_menu_cache_beacon), GCC(new GccApp(), 15, R.string.pref_navigation_menu_gcc), WHERE_YOU_GO(new WhereYouGoApp(), 16, R.string.pref_navigation_menu_where_you_go), - PEBBLE(new PebbleApp(), 17, R.string.pref_navigation_menu_pebble); + PEBBLE(new PebbleApp(), 17, R.string.pref_navigation_menu_pebble), + MAPSWITHME(new MapsWithMeApp(), 22, R.string.pref_navigation_menu_mapswithme); NavigationAppsEnum(final App app, final int id, final int preferenceKey) { this.app = app; diff --git a/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java b/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java index 4df9d26..8212111 100644 --- a/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java +++ b/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java @@ -21,7 +21,8 @@ public final class CacheListAppFactory extends AbstractAppFactory { public static final CacheListApp[] apps = { new InternalCacheListMap(), new LocusShowCacheListApp(), - new LocusExportCacheListApp() + new LocusExportCacheListApp(), + new MapsWithMeCacheListApp() }; } diff --git a/main/src/cgeo/geocaching/apps/cachelist/MapsWithMeCacheListApp.java b/main/src/cgeo/geocaching/apps/cachelist/MapsWithMeCacheListApp.java new file mode 100644 index 0000000..e22d358 --- /dev/null +++ b/main/src/cgeo/geocaching/apps/cachelist/MapsWithMeCacheListApp.java @@ -0,0 +1,65 @@ +package cgeo.geocaching.apps.cachelist; + +import cgeo.geocaching.CacheDetailActivity; +import cgeo.geocaching.Geocache; +import cgeo.geocaching.R; +import cgeo.geocaching.SearchResult; +import cgeo.geocaching.apps.AbstractApp; + +import com.mapswithme.maps.api.MWMPoint; +import com.mapswithme.maps.api.MWMResponse; +import com.mapswithme.maps.api.MapsWithMeApi; + +import org.eclipse.jdt.annotation.Nullable; + +import android.app.Activity; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; + +import java.util.List; + +public class MapsWithMeCacheListApp extends AbstractApp implements CacheListApp { + + protected MapsWithMeCacheListApp() { + super(getString(R.string.caches_map_mapswithme), R.id.cache_app_mapswithme, Intent.ACTION_VIEW); + } + + @Override + public boolean invoke(List<Geocache> caches, Activity activity, SearchResult search) { + final MWMPoint[] points = new MWMPoint[caches.size()]; + for (int i = 0; i < points.length; i++) { + Geocache geocache = caches.get(i); + points[i] = new MWMPoint(geocache.getCoords().getLatitude(), geocache.getCoords().getLongitude(), geocache.getName(), geocache.getGeocode()); + } + MapsWithMeApi.showPointsOnMap(activity, null, getPendingIntent(activity), points); + return true; + } + + @Override + public boolean isInstalled() { + // API can handle installing on the fly + return true; + } + + /** + * get cache code from an invocation of MapsWithMe + * + * @return + */ + @Nullable + public static String getCacheFromMapsWithMe(final Context context, final Intent intent) { + final MWMResponse mwmResponse = MWMResponse.extractFromIntent(context, intent); + if (mwmResponse != null) { + final MWMPoint point = mwmResponse.getPoint(); + return point.getId(); + } + return null; + } + + private static PendingIntent getPendingIntent(Context context) { + final Intent intent = new Intent(context, CacheDetailActivity.class); + return PendingIntent.getActivity(context, 0, intent, 0); + } + +} diff --git a/main/src/cgeo/geocaching/connector/gc/RecaptchaHandler.java b/main/src/cgeo/geocaching/connector/gc/RecaptchaHandler.java index 280069f..7cced74 100644 --- a/main/src/cgeo/geocaching/connector/gc/RecaptchaHandler.java +++ b/main/src/cgeo/geocaching/connector/gc/RecaptchaHandler.java @@ -4,12 +4,13 @@ import cgeo.geocaching.R; import cgeo.geocaching.loaders.RecaptchaReceiver; import cgeo.geocaching.network.Network; import cgeo.geocaching.utils.Log; -import cgeo.geocaching.utils.RxUtils; import org.apache.commons.io.IOUtils; import rx.Observable; +import rx.android.observables.AndroidObservable; import rx.functions.Action1; import rx.functions.Func0; +import rx.schedulers.Schedulers; import android.app.Activity; import android.app.AlertDialog; @@ -56,7 +57,7 @@ public class RecaptchaHandler extends Handler { return Observable.empty(); } }); - RxUtils.subscribeOnIOThenUI(captcha, new Action1<Bitmap>() { + AndroidObservable.bindActivity(activity, captcha).subscribe(new Action1<Bitmap>() { @Override public void call(final Bitmap bitmap) { imageView.setImageBitmap(bitmap); @@ -66,7 +67,7 @@ public class RecaptchaHandler extends Handler { public void call(final Throwable throwable) { // Do nothing } - }); + }, Schedulers.io()); reloadButton.setEnabled(true); } diff --git a/main/src/cgeo/geocaching/enumerations/CacheType.java b/main/src/cgeo/geocaching/enumerations/CacheType.java index 35fe7a1..fee5b3c 100644 --- a/main/src/cgeo/geocaching/enumerations/CacheType.java +++ b/main/src/cgeo/geocaching/enumerations/CacheType.java @@ -19,7 +19,8 @@ public enum CacheType { MYSTERY("mystery", "Unknown Cache", "40861821-1835-4e11-b666-8d41064d03fe", R.string.mystery, R.drawable.type_mystery), LETTERBOX("letterbox", "Letterbox hybrid", "4bdd8fb2-d7bc-453f-a9c5-968563b15d24", R.string.letterbox, R.drawable.type_letterbox), EVENT("event", "Event Cache", "69eb8534-b718-4b35-ae3c-a856a55b0874", R.string.event, R.drawable.type_event), - MEGA_EVENT("mega", "Mega-event Cache", "69eb8535-b718-4b35-ae3c-a856a55b0874", R.string.mega, R.drawable.type_mega), + MEGA_EVENT("mega", "Mega-Event Cache", "69eb8535-b718-4b35-ae3c-a856a55b0874", R.string.mega, R.drawable.type_mega), + GIGA_EVENT("giga", "Giga-Event Cache", "51420629-5739-4945-8bdd-ccfd434c0ead", R.string.giga, R.drawable.type_mega), // icon missing EARTH("earth", "Earthcache", "c66f5cf3-9523-4549-b8dd-759cd2f18db8", R.string.earth, R.drawable.type_earth), CITO("cito", "Cache in Trash out Event", "57150806-bc1a-42d6-9cf0-538d171a2d22", R.string.cito, R.drawable.type_cito), WEBCAM("webcam", "Webcam Cache", "31d2ae3c-c358-4b5f-8dcd-2185bf472d3d", R.string.webcam, R.drawable.type_webcam), @@ -89,7 +90,7 @@ public enum CacheType { } public boolean isEvent() { - return EVENT == this || MEGA_EVENT == this || CITO == this || LOSTANDFOUND == this || BLOCK_PARTY == this || GPS_EXHIBIT == this; + return EVENT == this || MEGA_EVENT == this || CITO == this || GIGA_EVENT == this || LOSTANDFOUND == this || BLOCK_PARTY == this || GPS_EXHIBIT == this; } @Override diff --git a/main/src/cgeo/geocaching/files/AbstractFileListActivity.java b/main/src/cgeo/geocaching/files/AbstractFileListActivity.java index 35e6265..07b4fb4 100644 --- a/main/src/cgeo/geocaching/files/AbstractFileListActivity.java +++ b/main/src/cgeo/geocaching/files/AbstractFileListActivity.java @@ -121,6 +121,7 @@ public abstract class AbstractFileListActivity<T extends ArrayAdapter<File>> ext } + @SuppressWarnings("static-method") protected boolean requireFiles() { return true; } diff --git a/main/src/cgeo/geocaching/filter/AttributeFilter.java b/main/src/cgeo/geocaching/filter/AttributeFilter.java index 6f0d5da..552a48c 100644 --- a/main/src/cgeo/geocaching/filter/AttributeFilter.java +++ b/main/src/cgeo/geocaching/filter/AttributeFilter.java @@ -1,14 +1,11 @@ package cgeo.geocaching.filter; import cgeo.geocaching.CgeoApplication; -import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; import cgeo.geocaching.R; -import cgeo.geocaching.enumerations.LoadFlags.LoadFlag; import android.content.res.Resources; -import java.util.EnumSet; import java.util.LinkedList; import java.util.List; @@ -29,11 +26,7 @@ class AttributeFilter extends AbstractFilter { @Override public boolean accepts(final Geocache cache) { - Geocache fullCache = DataStore.loadCache(cache.getGeocode(), EnumSet.of(LoadFlag.LOAD_ATTRIBUTES)); - if (fullCache == null) { - fullCache = cache; - } - return fullCache.getAttributes().contains(attribute); + return cache.getAttributes().contains(attribute); } public static class Factory implements IFilterFactory { diff --git a/main/src/cgeo/geocaching/list/StoredList.java b/main/src/cgeo/geocaching/list/StoredList.java index 7e2a83c..e557fc8 100644 --- a/main/src/cgeo/geocaching/list/StoredList.java +++ b/main/src/cgeo/geocaching/list/StoredList.java @@ -147,6 +147,8 @@ public final class StoredList extends AbstractList { public void promptForListCreation(@NonNull final Action1<Integer> runAfterwards, 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. + @SuppressWarnings("unused") @Override public void call(final String listName) { final int newId = DataStore.createList(listName); diff --git a/main/src/cgeo/geocaching/sensors/DirectionProvider.java b/main/src/cgeo/geocaching/sensors/DirectionProvider.java index 788d5bd..ff4a439 100644 --- a/main/src/cgeo/geocaching/sensors/DirectionProvider.java +++ b/main/src/cgeo/geocaching/sensors/DirectionProvider.java @@ -30,6 +30,7 @@ public class DirectionProvider { private int count = 0; private SensorManager sensorManager; + @Override public void onSensorChanged(final SensorEvent event) { subject.onNext(event.values[0]); @@ -50,23 +51,52 @@ public class DirectionProvider { //Log.i(Settings.tag, "Compass' accuracy is low (" + accuracy + ")"); } - // This will be removed when using a new location service. Until then, it is okay to be used. - @SuppressWarnings("deprecation") @Override public void start(final Context context, final Handler handler) { + if (!hasSensor(context)) { + return; + } if (++count == 1) { - sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); - sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL, handler); + Sensor orientationSensor = getOrientationSensor(context); + sensorManager.registerListener(this, orientationSensor, SensorManager.SENSOR_DELAY_NORMAL, handler); } } @Override public void stop() { + if (!hasSensor) { + return; + } if (--count == 0) { sensorManager.unregisterListener(this); } } + /** + * Assume that there is an orientation sensor, unless we have really checked that + */ + private boolean hasSensor = true; + + /** + * Flag for one time check if there is a sensor. + */ + private boolean hasSensorChecked = false; + + public boolean hasSensor(Context context) { + if (hasSensorChecked == false) { + hasSensor = getOrientationSensor(context) != null; + hasSensorChecked = true; + } + return hasSensor; + } + + // This will be removed when using a new location service. Until then, it is okay to be used. + @SuppressWarnings("deprecation") + private Sensor getOrientationSensor(final Context context) { + sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); + return sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); + } + } private static final StartableHandlerThread handlerThread = diff --git a/main/src/cgeo/geocaching/sensors/GeoDirHandler.java b/main/src/cgeo/geocaching/sensors/GeoDirHandler.java index c10cb48..0f30142 100644 --- a/main/src/cgeo/geocaching/sensors/GeoDirHandler.java +++ b/main/src/cgeo/geocaching/sensors/GeoDirHandler.java @@ -4,6 +4,7 @@ import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.settings.Settings; import org.apache.commons.lang3.tuple.ImmutablePair; + import rx.Observable; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; @@ -37,7 +38,7 @@ public abstract class GeoDirHandler { * * @param geoData the new geographical data */ - public void updateGeoData(@SuppressWarnings("unused") final IGeoData geoData) { + public void updateGeoData(final IGeoData geoData) { } /** @@ -46,7 +47,7 @@ public abstract class GeoDirHandler { * * @param direction the new direction */ - public void updateDirection(@SuppressWarnings("unused") final float direction) { + public void updateDirection(final float direction) { } /** @@ -59,7 +60,7 @@ public abstract class GeoDirHandler { * If the device goes fast enough, or if the compass use is not enabled in the settings, * the GPS direction information will be used instead of the compass one. */ - public void updateGeoDir(@SuppressWarnings("unused") final IGeoData geoData, @SuppressWarnings("unused") final float direction) { + public void updateGeoDir(final IGeoData geoData, final float direction) { } private static Observable<Float> fixedDirection() { diff --git a/main/src/cgeo/geocaching/settings/AbstractCheckCredentialsPreference.java b/main/src/cgeo/geocaching/settings/AbstractCheckCredentialsPreference.java index 298270b..917c9c4 100644 --- a/main/src/cgeo/geocaching/settings/AbstractCheckCredentialsPreference.java +++ b/main/src/cgeo/geocaching/settings/AbstractCheckCredentialsPreference.java @@ -5,12 +5,13 @@ import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.network.Cookies; import cgeo.geocaching.ui.dialog.Dialogs; -import cgeo.geocaching.utils.RxUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; +import rx.android.observables.AndroidObservable; import rx.functions.Action1; import rx.functions.Func0; +import rx.schedulers.Schedulers; import rx.util.async.Async; import android.app.ProgressDialog; @@ -64,12 +65,12 @@ public abstract class AbstractCheckCredentialsPreference extends AbstractClickab loginDialog.setCancelable(false); Cookies.clearCookies(); - RxUtils.subscribeOnIOThenUI(Async.start(new Func0<ImmutablePair<StatusCode, ? extends Drawable>>() { + AndroidObservable.bindActivity(activity, Async.start(new Func0<ImmutablePair<StatusCode, ? extends Drawable>>() { @Override public ImmutablePair<StatusCode, ? extends Drawable> call() { return login(); } - }), new Action1<ImmutablePair<StatusCode, ? extends Drawable>>() { + })).subscribe(new Action1<ImmutablePair<StatusCode, ? extends Drawable>>() { @Override public void call(final ImmutablePair<StatusCode, ? extends Drawable> loginInfo) { loginDialog.dismiss(); @@ -85,7 +86,7 @@ public abstract class AbstractCheckCredentialsPreference extends AbstractClickab } activity.initBasicMemberPreferences(); } - }); + }, Schedulers.io()); return false; // no shared preference has to be changed } diff --git a/main/src/cgeo/geocaching/settings/RegisterSend2CgeoPreference.java b/main/src/cgeo/geocaching/settings/RegisterSend2CgeoPreference.java index 1b18438..cc2de9f 100644 --- a/main/src/cgeo/geocaching/settings/RegisterSend2CgeoPreference.java +++ b/main/src/cgeo/geocaching/settings/RegisterSend2CgeoPreference.java @@ -6,13 +6,14 @@ import cgeo.geocaching.network.Network; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.ui.dialog.Dialogs; import cgeo.geocaching.utils.Log; -import cgeo.geocaching.utils.RxUtils; import ch.boye.httpclientandroidlib.HttpResponse; import org.apache.commons.lang3.StringUtils; import rx.Observable; +import rx.android.observables.AndroidObservable; import rx.functions.Action1; import rx.functions.Func0; +import rx.schedulers.Schedulers; import android.app.ProgressDialog; import android.content.Context; @@ -52,7 +53,7 @@ public class RegisterSend2CgeoPreference extends AbstractClickablePreference { activity.getString(R.string.init_sendToCgeo_registering), true); progressDialog.setCancelable(false); - RxUtils.subscribeOnIOThenUI(Observable.defer(new Func0<Observable<Integer>>() { + AndroidObservable.bindActivity(activity, Observable.defer(new Func0<Observable<Integer>>() { @Override public Observable<Integer> call() { final String nam = StringUtils.defaultString(deviceName); @@ -74,7 +75,7 @@ public class RegisterSend2CgeoPreference extends AbstractClickablePreference { return Observable.empty(); } - }).firstOrDefault(0), new Action1<Integer>() { + }).firstOrDefault(0)).subscribe(new Action1<Integer>() { @Override public void call(final Integer pin) { progressDialog.dismiss(); @@ -86,7 +87,7 @@ public class RegisterSend2CgeoPreference extends AbstractClickablePreference { Dialogs.message(activity, R.string.init_sendToCgeo, R.string.init_sendToCgeo_register_fail); } } - }); + }, Schedulers.io()); return true; } diff --git a/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java b/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java index 2b171b4..968dce5 100644 --- a/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java +++ b/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java @@ -34,12 +34,13 @@ public abstract class AbstractCacheComparator implements CacheComparator { /** * Check necessary preconditions (like missing fields) before running the comparison itself. * Caches not filling the conditions will be placed last, sorted by Geocode. - * + * * The default returns <code>true</code> and can be overridden if needed in child classes. - * + * * @param cache * @return <code>true</code> if the cache holds the necessary data to be compared meaningfully */ + @SuppressWarnings("static-method") protected boolean canCompare(final Geocache cache) { return true; } diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java index d827e3e..0d90d9f 100644 --- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java +++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java @@ -377,7 +377,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { final boolean lightSkin = Settings.isLightSkin(); - final TouchListener touchListener = new TouchListener(cache, v); + final TouchListener touchListener = new TouchListener(cache); v.setOnClickListener(touchListener); v.setOnLongClickListener(touchListener); v.setOnTouchListener(touchListener); @@ -541,7 +541,7 @@ public class CacheListAdapter extends ArrayAdapter<Geocache> { private final Geocache cache; private final GestureDetector gestureDetector; - public TouchListener(final Geocache cache, final View view) { + public TouchListener(final Geocache cache) { this.cache = cache; gestureDetector = new GestureDetector(getContext(), new FlingGesture(cache)); } diff --git a/main/src/cgeo/geocaching/ui/ImagesList.java b/main/src/cgeo/geocaching/ui/ImagesList.java index d1b2a64..785be55 100644 --- a/main/src/cgeo/geocaching/ui/ImagesList.java +++ b/main/src/cgeo/geocaching/ui/ImagesList.java @@ -6,11 +6,11 @@ import cgeo.geocaching.files.LocalStorage; import cgeo.geocaching.list.StoredList; import cgeo.geocaching.network.HtmlImage; import cgeo.geocaching.utils.Log; -import cgeo.geocaching.utils.RxUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import rx.Subscription; +import rx.android.observables.AndroidObservable; import rx.functions.Action0; import rx.functions.Action1; import rx.subscriptions.CompositeSubscription; @@ -118,7 +118,7 @@ public class ImagesList { final ImageView imageView = (ImageView) inflater.inflate(R.layout.image_item, null); assert(imageView != null); - subscriptions.add(RxUtils.subscribeThenUI(imgGetter.fetchDrawable(img.getUrl()), new Action1<BitmapDrawable>() { + subscriptions.add(AndroidObservable.bindActivity(activity, imgGetter.fetchDrawable(img.getUrl())).subscribe(new Action1<BitmapDrawable>() { @Override public void call(final BitmapDrawable image) { display(imageView, image, img, rowView); diff --git a/main/src/cgeo/geocaching/utils/ImageUtils.java b/main/src/cgeo/geocaching/utils/ImageUtils.java index e226703..ffb7bf3 100644 --- a/main/src/cgeo/geocaching/utils/ImageUtils.java +++ b/main/src/cgeo/geocaching/utils/ImageUtils.java @@ -273,9 +273,11 @@ public final class ImageUtils { /** * Decode a base64-encoded string and save the result into a stream. - * - * @param inString the encoded string - * @param outFile the file to save the decoded result into + * + * @param inString + * the encoded string + * @param out + * the stream to save the decoded result into */ public static void decodeBase64ToStream(final String inString, final OutputStream out) throws IOException { Base64InputStream in = null; diff --git a/main/src/cgeo/geocaching/utils/RxUtils.java b/main/src/cgeo/geocaching/utils/RxUtils.java index 9926bab..8e7864c 100644 --- a/main/src/cgeo/geocaching/utils/RxUtils.java +++ b/main/src/cgeo/geocaching/utils/RxUtils.java @@ -1,11 +1,6 @@ package cgeo.geocaching.utils; -import rx.Observable; -import rx.Observer; import rx.Scheduler; -import rx.Subscription; -import rx.android.schedulers.AndroidSchedulers; -import rx.functions.Action1; import rx.schedulers.Schedulers; import java.util.concurrent.LinkedBlockingQueue; @@ -20,32 +15,4 @@ public class RxUtils { final static private int cores = Runtime.getRuntime().availableProcessors(); public final static Scheduler computationScheduler = Schedulers.executor(new ThreadPoolExecutor(1, cores, 5, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>())); - public static <T> Subscription subscribeThenUI(final Observable<T> observable, final Observer<T> observer) { - return observable.observeOn(AndroidSchedulers.mainThread()).subscribe(observer); - } - - public static <T> Subscription subscribeThenUI(final Observable<T> observable, final Action1<T> action) { - return observable.observeOn(AndroidSchedulers.mainThread()).subscribe(action); - } - - public static <T> Subscription subscribeThenUI(final Observable<T> observable, final Action1<T> action, final Action1<Throwable> onError) { - return observable.observeOn(AndroidSchedulers.mainThread()).subscribe(action, onError); - } - - public static <T> Observable<T> onIO(final Observable<T> observable) { - return observable.subscribeOn(Schedulers.io()); - } - - public static <T> Subscription subscribeOnIOThenUI(final Observable<T> observable, final Observer<T> observer) { - return subscribeThenUI(onIO(observable), observer); - } - - public static <T> Subscription subscribeOnIOThenUI(final Observable<T> observable, final Action1<T> action) { - return subscribeThenUI(onIO(observable), action); - } - - public static <T> Subscription subscribeOnIOThenUI(final Observable<T> observable, final Action1<T> action, final Action1<Throwable> onError) { - return subscribeThenUI(onIO(observable), action, onError); - } - } |
