diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2014-04-13 13:50:31 +0200 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2014-04-13 13:55:28 +0200 |
commit | 52671d45a0571abd484165ad4702b57facf624b8 (patch) | |
tree | bc2cbf506dba3253a0b94323587819ab8f94878e | |
parent | 19503d405a6194b2074f792d2fadc3eb031d9a0f (diff) | |
download | cgeo-52671d45a0571abd484165ad4702b57facf624b8.zip cgeo-52671d45a0571abd484165ad4702b57facf624b8.tar.gz cgeo-52671d45a0571abd484165ad4702b57facf624b8.tar.bz2 |
fix #3756: NPE when changing map source
-rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 12 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/maps/MapProviderFactory.java | 5 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/settings/Settings.java | 1 |
3 files changed, 12 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index f06a42f..9f2f89e 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -42,6 +42,7 @@ import cgeo.geocaching.utils.Log; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.eclipse.jdt.annotation.NonNull; import rx.Scheduler; import rx.Subscription; import rx.functions.Action1; @@ -785,15 +786,16 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto /** * Restart the current activity if the map provider has changed, or change the map source if needed. * - * @param mapSource + * @param newSource * the new map source, which can be the same as the current one * @return true if a restart is needed, false otherwise */ - private boolean changeMapSource(final MapSource mapSource) { - final boolean restartRequired = !MapProviderFactory.isSameActivity(MapProviderFactory.getMapSource(currentSourceId), mapSource); + private boolean changeMapSource(@NonNull final MapSource newSource) { + final MapSource oldSource = MapProviderFactory.getMapSource(currentSourceId); + final boolean restartRequired = oldSource == null || !MapProviderFactory.isSameActivity(oldSource, newSource); - Settings.setMapSource(mapSource); - currentSourceId = mapSource.getNumericalId(); + Settings.setMapSource(newSource); + currentSourceId = newSource.getNumericalId(); if (restartRequired) { mapRestart(); diff --git a/main/src/cgeo/geocaching/maps/MapProviderFactory.java b/main/src/cgeo/geocaching/maps/MapProviderFactory.java index b928a1e..890274d 100644 --- a/main/src/cgeo/geocaching/maps/MapProviderFactory.java +++ b/main/src/cgeo/geocaching/maps/MapProviderFactory.java @@ -10,6 +10,8 @@ import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.Log; import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; import android.view.Menu; import android.view.SubMenu; @@ -51,7 +53,7 @@ public class MapProviderFactory { return mapSources; } - public static boolean isSameActivity(final MapSource source1, final MapSource source2) { + public static boolean isSameActivity(@NonNull final MapSource source1, @NonNull final MapSource source2) { final MapProvider provider1 = source1.getMapProvider(); final MapProvider provider2 = source2.getMapProvider(); return provider1 == provider2 && provider1.isSameActivity(source1, source2); @@ -75,6 +77,7 @@ public class MapProviderFactory { * @param id the map source id * @return the map source, or <tt>null</tt> if <tt>id</tt> does not correspond to a registered map source */ + @Nullable public static MapSource getMapSource(int id) { for (MapSource mapSource : mapSources) { if (mapSource.getNumericalId() == id) { diff --git a/main/src/cgeo/geocaching/settings/Settings.java b/main/src/cgeo/geocaching/settings/Settings.java index 59140ba..7a4dfdd 100644 --- a/main/src/cgeo/geocaching/settings/Settings.java +++ b/main/src/cgeo/geocaching/settings/Settings.java @@ -599,6 +599,7 @@ public class Settings { putInt(R.string.pref_lastmaplon, mapViewCenter.getLongitudeE6()); } + @NonNull public static synchronized MapSource getMapSource() { if (mapSource != null) { return mapSource; |