M Android/src/main/java/com/gindin/zmanim/android/location/resolvers/AndroidResolver.java +2 -8
@@ 36,15 36,9 @@ class AndroidResolver
}
- @Override
- public void onDestroy() {
- // Nothing to destroy here...
- }
-
-
@SuppressWarnings( "FeatureEnvy" )
@Nullable
- protected ZmanimLocation resolveFromCoordinatesInBackground( @NotNull ZmanimLocation location ) {
+ protected ZmanimLocation resolveFromCoordinates( @NotNull ZmanimLocation location ) {
if ( !Geocoder.isPresent() ) {
return null;
@@ 81,7 75,7 @@ class AndroidResolver
@Nullable
@SuppressWarnings( "FeatureEnvy" )
- protected ZmanimLocation resolveFromNameInBackground( @NotNull ZmanimLocation location ) {
+ protected ZmanimLocation resolveFromName( @NotNull ZmanimLocation location ) {
ZmanimLocation resolved = null;
M Android/src/main/java/com/gindin/zmanim/android/location/resolvers/CachedLocationResolver.java +10 -3
@@ 85,12 85,19 @@ class CachedLocationResolver
}
};
+ }
+
+
+ @Override
+ public void start() {
+ super.start();
+
eventBus.addHandler( locationAcquiredHandler );
}
@Override
- public void onDestroy() {
+ public void stop() {
eventBus.removeHandler( locationAcquiredHandler );
}
@@ 98,7 105,7 @@ class CachedLocationResolver
@Nullable
@Override
- protected ZmanimLocation resolveFromCoordinatesInBackground( @NotNull ZmanimLocation zmanimLocation ) {
+ protected ZmanimLocation resolveFromCoordinates( @NotNull ZmanimLocation zmanimLocation ) {
return findCachedMatch( zmanimLocation );
}
@@ 106,7 113,7 @@ class CachedLocationResolver
@Nullable
@Override
- protected ZmanimLocation resolveFromNameInBackground( @NotNull ZmanimLocation zmanimLocation ) {
+ protected ZmanimLocation resolveFromName( @NotNull ZmanimLocation zmanimLocation ) {
return findCachedMatch( zmanimLocation );
}
M Android/src/main/java/com/gindin/zmanim/android/location/resolvers/JsonQueryingResolver.java +2 -2
@@ 61,7 61,7 @@ abstract class JsonQueryingResolver
@Nullable
@Override
- protected final ZmanimLocation resolveFromCoordinatesInBackground( @NotNull ZmanimLocation zmanimLocation ) {
+ protected final ZmanimLocation resolveFromCoordinates( @NotNull ZmanimLocation zmanimLocation ) {
List<Pair<String,String>> params = new ArrayList<Pair<String, String>>();
fillInLatitudeAndLongitude( Double.toString( zmanimLocation.getLatitude() ),
@@ 73,7 73,7 @@ abstract class JsonQueryingResolver
@Nullable
@Override
- protected final ZmanimLocation resolveFromNameInBackground( @NotNull ZmanimLocation zmanimLocation ) {
+ protected final ZmanimLocation resolveFromName( @NotNull ZmanimLocation zmanimLocation ) {
List<Pair<String,String>> params = new ArrayList<Pair<String, String>>();
fillInSearch( zmanimLocation, params );
M Android/src/main/java/com/gindin/zmanim/android/location/resolvers/LocationResolver.java +16 -24
@@ 16,7 16,6 @@ import org.jetbrains.annotations.Nullabl
import android.content.Context;
import android.location.Address;
-import android.os.AsyncTask;
import java.util.Collections;
import java.util.List;
@@ 109,10 108,15 @@ abstract class LocationResolver {
}
+ public void start() {
+ }
+
+
/**
* Called when the resolver is being destroyed.
*/
- public abstract void onDestroy();
+ public void stop() {
+ }
final void resolve(
@@ 120,27 124,15 @@ abstract class LocationResolver {
@NotNull final List<LocationResolver> nextResolvers
) {
- AsyncTask<ZmanimLocation, Void, ZmanimLocation> task = new AsyncTask<ZmanimLocation, Void, ZmanimLocation>() {
- @Override
- protected ZmanimLocation doInBackground( ZmanimLocation... zmanimLocations ) {
+ final ZmanimLocation zmanimLocation;
+ if ( location.hasCoordinates() ) {
+ zmanimLocation = resolveFromCoordinates( location );
+ }
+ else {
+ zmanimLocation = resolveFromName( location );
+ }
- if ( location.hasCoordinates() ) {
- return resolveFromCoordinatesInBackground( zmanimLocations[0] );
- }
- else {
- return resolveFromNameInBackground( zmanimLocations[0] );
- }
- }
-
-
- @Override
- protected void onPostExecute( ZmanimLocation resolvedLocation ) {
- super.onPostExecute( resolvedLocation );
- handlePostExecute( location, resolvedLocation, nextResolvers );
- }
- };
-
- task.execute( location );
+ handlePostExecute( location, zmanimLocation, nextResolvers );
}
@@ 151,7 143,7 @@ abstract class LocationResolver {
* @return An actual ZmanimLocation that has been properly resolved, or null if resolution failed.
*/
@Nullable
- protected abstract ZmanimLocation resolveFromCoordinatesInBackground( @NotNull ZmanimLocation zmanimLocation );
+ protected abstract ZmanimLocation resolveFromCoordinates( @NotNull ZmanimLocation zmanimLocation );
/**
* This method, guaranteed to be run on a background thread, must perform whatever actions necessary to resolve the
@@ 160,7 152,7 @@ abstract class LocationResolver {
* @return An actual ZmanimLocation that has been properly resolved, or null if resolution failed.
*/
@Nullable
- protected abstract ZmanimLocation resolveFromNameInBackground( @NotNull ZmanimLocation zmanimLocation );
+ protected abstract ZmanimLocation resolveFromName( @NotNull ZmanimLocation zmanimLocation );
private void handlePostExecute(
M Android/src/main/java/com/gindin/zmanim/android/location/resolvers/LocationToAddressConverter.java +17 -1
@@ 18,6 18,7 @@ import android.location.Geocoder;
import android.os.AsyncTask;
import javax.inject.Inject;
+import javax.inject.Singleton;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
@@ 27,6 28,7 @@ import java.util.List;
/**
* Listens for RawLocationAcquiredEvent and PlaceAcquiredEvent and starts the process of translating to an address.
*/
+@Singleton
public class LocationToAddressConverter {
@@ 42,6 44,8 @@ public class LocationToAddressConverter
private final LocationAcquiredEvent.Handler locationAcquiredHandler;
private final PlaceAcquiredEvent.Handler placeAcquiredHandler;
+ private boolean isStarted = false;
+
@Inject
public LocationToAddressConverter(
@@ 117,8 121,18 @@ public class LocationToAddressConverter
public void start() {
+ if ( isStarted ) {
+ return;
+ }
+
eventBus.addHandler( locationAcquiredHandler );
eventBus.addHandler( placeAcquiredHandler );
+
+ for ( LocationResolver resolver : orderedResolvers ) {
+ resolver.start();
+ }
+
+ isStarted = true;
}
@@ 128,8 142,10 @@ public class LocationToAddressConverter
eventBus.removeHandler( placeAcquiredHandler );
for ( LocationResolver resolver : orderedResolvers ) {
- resolver.onDestroy();
+ resolver.stop();
}
+
+ isStarted = false;
}
M Android/src/main/java/com/gindin/zmanim/android/location/resolvers/MapQuestResolver.java +0 -6
@@ 33,12 33,6 @@ class MapQuestResolver
@Override
- public void onDestroy() {
-
- }
-
-
- @Override
protected void fillInLatitudeAndLongitude(
String latitude,
String longitude,
M Android/src/main/java/com/gindin/zmanim/android/location/resolvers/NominatimResolver.java +0 -6
@@ 58,12 58,6 @@ class NominatimResolver
@Override
- public void onDestroy() {
-
- }
-
-
- @Override
protected void fillInLatitudeAndLongitude(
String latitude,
String longitude,
M Android/src/main/java/com/gindin/zmanim/android/location/resolvers/PassthroughResolver.java +2 -8
@@ 26,18 26,12 @@ class PassthroughResolver
}
- @Override
- public void onDestroy() {
-
- }
-
-
/**
* Since we couldn't resolve this any other way, then the resolution here is just to leave it alone.
*/
@Nullable
@Override
- protected ZmanimLocation resolveFromCoordinatesInBackground( @NotNull ZmanimLocation zmanimLocation ) {
+ protected ZmanimLocation resolveFromCoordinates( @NotNull ZmanimLocation zmanimLocation ) {
return zmanimLocation;
}
@@ 47,7 41,7 @@ class PassthroughResolver
*/
@Nullable
@Override
- protected ZmanimLocation resolveFromNameInBackground( @NotNull ZmanimLocation zmanimLocation ) {
+ protected ZmanimLocation resolveFromName( @NotNull ZmanimLocation zmanimLocation ) {
return zmanimLocation;
}
M Android/src/test/java/com/gindin/zmanim/android/location/resolvers/UT_CachedLocationResolver.java +2 -2
@@ 53,7 53,7 @@ public class UT_CachedLocationResolver {
.inTimeZone( TimeZone.getTimeZone( "America/Los_Angeles" ) )
.build();
- ZmanimLocation resolvedLocation = cachedLocationResolver.resolveFromCoordinatesInBackground( location2 );
+ ZmanimLocation resolvedLocation = cachedLocationResolver.resolveFromCoordinates( location2 );
Assert.assertEquals( location, resolvedLocation );
}
@@ 78,7 78,7 @@ public class UT_CachedLocationResolver {
.build();
// The caching resolver won't know about this other location, so it'll return null.
- ZmanimLocation resolvedLocation = cachedLocationResolver.resolveFromCoordinatesInBackground( location2 );
+ ZmanimLocation resolvedLocation = cachedLocationResolver.resolveFromCoordinates( location2 );
Assert.assertNull( resolvedLocation );
}
M Android/src/test/java/com/gindin/zmanim/android/location/resolvers/UT_MapQuestResolver.java +2 -2
@@ 58,7 58,7 @@ public class UT_MapQuestResolver {
.atLongitude( longitude )
.build();
- ZmanimLocation resolved = resolver.resolveFromCoordinatesInBackground( unresolved );
+ ZmanimLocation resolved = resolver.resolveFromCoordinates( unresolved );
Assert.assertNotNull( resolved );
Assert.assertEquals( expectedLocationName, resolved.getLocationName() );
}
@@ 75,7 75,7 @@ public class UT_MapQuestResolver {
.locationName( name )
.build();
- ZmanimLocation resolved = resolver.resolveFromNameInBackground( unresolved );
+ ZmanimLocation resolved = resolver.resolveFromName( unresolved );
Assert.assertNotNull(resolved );
Assert.assertEquals( expectedLocationName, resolved.getLocationName() );
Assert.assertEquals( expectedLatitude, resolved.getLatitude(), 0 );
M Android/src/test/java/com/gindin/zmanim/android/location/resolvers/UT_NominatimResolver.java +2 -2
@@ 58,7 58,7 @@ public class UT_NominatimResolver {
.atLongitude( longitude )
.build();
- ZmanimLocation resolved = resolver.resolveFromCoordinatesInBackground( unresolved );
+ ZmanimLocation resolved = resolver.resolveFromCoordinates( unresolved );
Assert.assertNotNull( resolved );
Assert.assertEquals( expectedLocationName, resolved.getLocationName() );
}
@@ 75,7 75,7 @@ public class UT_NominatimResolver {
.locationName( name )
.build();
- ZmanimLocation resolved = resolver.resolveFromNameInBackground( unresolved );
+ ZmanimLocation resolved = resolver.resolveFromName( unresolved );
if ( expectedLocationName == null ) {
Assert.assertNull( resolved );
}