diff --git a/app/src/main/java/com/eleith/calchoochoo/MapSearchActivity.java b/app/src/main/java/com/eleith/calchoochoo/MapSearchActivity.java index 39cfc6b..31e23a2 100644 --- a/app/src/main/java/com/eleith/calchoochoo/MapSearchActivity.java +++ b/app/src/main/java/com/eleith/calchoochoo/MapSearchActivity.java @@ -18,7 +18,7 @@ import com.eleith.calchoochoo.utils.RxBusMessage.RxMessageKeys; import com.eleith.calchoochoo.utils.RxBusMessage.RxMessageLocation; import com.eleith.calchoochoo.utils.RxBusMessage.RxMessageStops; import com.eleith.calchoochoo.utils.StopUtils; -import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.maps.model.LatLng; import org.parceler.Parcels; @@ -37,12 +37,11 @@ public class MapSearchActivity extends AppCompatActivity { private ArrayList stops; private Location location; private ChooChooDrawer chooChooDrawer; + private LatLng myDefaultLatLng = new LatLng(37.3860517, -122.0838511); @Inject RxBus rxBus; @Inject - GoogleApiClient googleApiClient; - @Inject ChooChooRouterManager chooChooRouterManager; @Inject ChooChooLoader chooChooLoader; @@ -71,16 +70,13 @@ public class MapSearchActivity extends AppCompatActivity { if (stops == null) { chooChooLoader.loadParentStops(); } - - deviceLocation.requestLocationUpdates(); deviceLocation.requestLocation(); + deviceLocation.listenForLocationUpdates(); } @Override protected void onStart() { super.onStart(); - googleApiClient.connect(); - if (subscription.isUnsubscribed()) { subscription = rxBus.observeEvents(RxMessage.class).subscribe(handleRxMessages()); } @@ -88,14 +84,15 @@ public class MapSearchActivity extends AppCompatActivity { if (subscriptionLocation.isUnsubscribed()) { subscriptionLocation = rxBus.observeEvents(RxMessageLocation.class).take(1).subscribe(handleRxLocationMessages()); } + deviceLocation.listenForLocationUpdates(); } @Override protected void onStop() { super.onStop(); - googleApiClient.disconnect(); subscription.unsubscribe(); subscriptionLocation.unsubscribe(); + deviceLocation.stopListeningForLocationUpdates(); } @Override @@ -106,7 +103,6 @@ public class MapSearchActivity extends AppCompatActivity { @Override protected void onResume() { super.onResume(); - googleApiClient.reconnect(); } @Override @@ -172,6 +168,11 @@ public class MapSearchActivity extends AppCompatActivity { @Override public void call(RxMessageLocation rxMessage) { location = rxMessage.getMessage(); + if (location == null) { + location = new Location("default"); + location.setLongitude(myDefaultLatLng.longitude); + location.setLatitude(myDefaultLatLng.latitude); + } initializeFragments(); } }; diff --git a/app/src/main/java/com/eleith/calchoochoo/StopActivity.java b/app/src/main/java/com/eleith/calchoochoo/StopActivity.java index 5b6e8dd..e153c6c 100644 --- a/app/src/main/java/com/eleith/calchoochoo/StopActivity.java +++ b/app/src/main/java/com/eleith/calchoochoo/StopActivity.java @@ -42,8 +42,6 @@ public class StopActivity extends AppCompatActivity { @Inject RxBus rxBus; @Inject - GoogleApiClient googleApiClient; - @Inject ChooChooRouterManager chooChooRouterManager; @Inject ChooChooLoader chooChooLoader; @@ -80,7 +78,6 @@ public class StopActivity extends AppCompatActivity { @Override protected void onStart() { super.onStart(); - googleApiClient.connect(); if (subscription.isUnsubscribed()) { subscription = rxBus.observeEvents(RxMessage.class).subscribe(new HandleRxMessages()); } @@ -89,7 +86,6 @@ public class StopActivity extends AppCompatActivity { @Override protected void onStop() { super.onStop(); - googleApiClient.disconnect(); subscription.unsubscribe(); } @@ -101,7 +97,6 @@ public class StopActivity extends AppCompatActivity { @Override protected void onResume() { super.onResume(); - googleApiClient.reconnect(); } @Override diff --git a/app/src/main/java/com/eleith/calchoochoo/StopSearchActivity.java b/app/src/main/java/com/eleith/calchoochoo/StopSearchActivity.java index 03284fe..864c11f 100644 --- a/app/src/main/java/com/eleith/calchoochoo/StopSearchActivity.java +++ b/app/src/main/java/com/eleith/calchoochoo/StopSearchActivity.java @@ -39,8 +39,6 @@ public class StopSearchActivity extends AppCompatActivity { @Inject RxBus rxBus; @Inject - GoogleApiClient googleApiClient; - @Inject ChooChooRouterManager chooChooRouterManager; @Inject ChooChooLoader chooChooLoader; @@ -66,13 +64,11 @@ public class StopSearchActivity extends AppCompatActivity { @Override protected void onStart() { super.onStart(); - googleApiClient.connect(); } @Override protected void onStop() { super.onStop(); - googleApiClient.disconnect(); subscription.unsubscribe(); subscriptionLocation.unsubscribe(); KeyboardUtils.hide(this); @@ -86,7 +82,6 @@ public class StopSearchActivity extends AppCompatActivity { @Override protected void onResume() { super.onResume(); - googleApiClient.reconnect(); } @Override diff --git a/app/src/main/java/com/eleith/calchoochoo/TripActivity.java b/app/src/main/java/com/eleith/calchoochoo/TripActivity.java index b8155df..f824bf2 100644 --- a/app/src/main/java/com/eleith/calchoochoo/TripActivity.java +++ b/app/src/main/java/com/eleith/calchoochoo/TripActivity.java @@ -61,8 +61,6 @@ public class TripActivity extends AppCompatActivity { @Inject RxBus rxBus; @Inject - GoogleApiClient googleApiClient; - @Inject ChooChooRouterManager chooChooRouterManager; @Inject ChooChooLoader chooChooLoader; @@ -151,7 +149,6 @@ public class TripActivity extends AppCompatActivity { @Override protected void onStart() { super.onStart(); - googleApiClient.connect(); if (subscription.isUnsubscribed()) { subscription = rxBus.observeEvents(RxMessage.class).subscribe(new HandleRxMessages()); } @@ -160,7 +157,6 @@ public class TripActivity extends AppCompatActivity { @Override protected void onStop() { super.onStop(); - googleApiClient.disconnect(); subscription.unsubscribe(); } @@ -172,7 +168,6 @@ public class TripActivity extends AppCompatActivity { @Override protected void onResume() { super.onResume(); - googleApiClient.reconnect(); } @Override diff --git a/app/src/main/java/com/eleith/calchoochoo/TripFilterActivity.java b/app/src/main/java/com/eleith/calchoochoo/TripFilterActivity.java index 074b276..b61d146 100644 --- a/app/src/main/java/com/eleith/calchoochoo/TripFilterActivity.java +++ b/app/src/main/java/com/eleith/calchoochoo/TripFilterActivity.java @@ -47,8 +47,6 @@ public class TripFilterActivity extends AppCompatActivity { @Inject RxBus rxBus; @Inject - GoogleApiClient googleApiClient; - @Inject ChooChooRouterManager chooChooRouterManager; @Inject ChooChooLoader chooChooLoader; @@ -99,14 +97,12 @@ public class TripFilterActivity extends AppCompatActivity { @Override protected void onStart() { super.onStart(); - googleApiClient.connect(); subscription = rxBus.observeEvents(RxMessage.class).subscribe(handleRxMessage()); } @Override protected void onStop() { super.onStop(); - googleApiClient.disconnect(); fabShow(); if (subscriptionTrips != null) { subscriptionTrips.unsubscribe(); @@ -122,7 +118,6 @@ public class TripFilterActivity extends AppCompatActivity { @Override protected void onResume() { super.onResume(); - googleApiClient.reconnect(); } @Override diff --git a/app/src/main/java/com/eleith/calchoochoo/dagger/AppModule.java b/app/src/main/java/com/eleith/calchoochoo/dagger/AppModule.java index 9e45c1e..acd3c0f 100644 --- a/app/src/main/java/com/eleith/calchoochoo/dagger/AppModule.java +++ b/app/src/main/java/com/eleith/calchoochoo/dagger/AppModule.java @@ -31,12 +31,4 @@ public class AppModule { public Context provideApplicationContext() { return application; } - - @Provides - @Singleton - GoogleApiClient providesGoogleApiClient(Context context) { - return new GoogleApiClient.Builder(context) - .addApi(LocationServices.API) - .build(); - } } diff --git a/app/src/main/java/com/eleith/calchoochoo/dagger/ChooChooModule.java b/app/src/main/java/com/eleith/calchoochoo/dagger/ChooChooModule.java index 6910ae7..7c0ec6f 100644 --- a/app/src/main/java/com/eleith/calchoochoo/dagger/ChooChooModule.java +++ b/app/src/main/java/com/eleith/calchoochoo/dagger/ChooChooModule.java @@ -68,7 +68,7 @@ public class ChooChooModule { @ChooChooScope @Provides - DeviceLocation providesDeviceLocation(RxBus rxBus, GoogleApiClient googleApiClient) { - return new DeviceLocation(rxBus, googleApiClient, activity); + DeviceLocation providesDeviceLocation(RxBus rxBus) { + return new DeviceLocation(rxBus, activity); } } diff --git a/app/src/main/java/com/eleith/calchoochoo/dagger/ChooChooWidgetConfigureModule.java b/app/src/main/java/com/eleith/calchoochoo/dagger/ChooChooWidgetConfigureModule.java index e543365..5435ed9 100644 --- a/app/src/main/java/com/eleith/calchoochoo/dagger/ChooChooWidgetConfigureModule.java +++ b/app/src/main/java/com/eleith/calchoochoo/dagger/ChooChooWidgetConfigureModule.java @@ -31,7 +31,7 @@ public class ChooChooWidgetConfigureModule { @ChooChooWidgetConfigureScope @Provides - DeviceLocation providesDeviceLocation(RxBus rxBus, GoogleApiClient googleApiClient) { - return new DeviceLocation(rxBus, googleApiClient, chooChooWidgetConfigure); + DeviceLocation providesDeviceLocation(RxBus rxBus) { + return new DeviceLocation(rxBus, chooChooWidgetConfigure); } } diff --git a/app/src/main/java/com/eleith/calchoochoo/fragments/MapSearchFragment.java b/app/src/main/java/com/eleith/calchoochoo/fragments/MapSearchFragment.java index 9a845c7..c058cac 100644 --- a/app/src/main/java/com/eleith/calchoochoo/fragments/MapSearchFragment.java +++ b/app/src/main/java/com/eleith/calchoochoo/fragments/MapSearchFragment.java @@ -16,7 +16,6 @@ import com.eleith.calchoochoo.R; import com.eleith.calchoochoo.data.ChooChooLoader; import com.eleith.calchoochoo.data.Stop; import com.eleith.calchoochoo.utils.BundleKeys; -import com.eleith.calchoochoo.utils.DeviceLocation; import com.eleith.calchoochoo.utils.DrawableUtils; import com.eleith.calchoochoo.utils.MapUtils; import com.eleith.calchoochoo.utils.RxBus; @@ -54,7 +53,6 @@ public class MapSearchFragment extends Fragment implements OnMapReadyCallback { private ArrayList stops = null; private Location lastLocation; private Marker locationMarker; - private LatLng myDefaultLatLng = new LatLng(37.04, -121.6); private Subscription subscriptionRxBus; @Inject @@ -63,8 +61,6 @@ public class MapSearchFragment extends Fragment implements OnMapReadyCallback { ChooChooRouterManager chooChooRouterManager; @Inject ChooChooLoader chooChooLoader; - @Inject - DeviceLocation deviceLocation; @BindView(R.id.map_search_input) EditText mapSearchInput; @@ -132,12 +128,6 @@ public class MapSearchFragment extends Fragment implements OnMapReadyCallback { MapUtils.moveMapToLocation(lastLocation, googleMap, new CameraPosition.Builder().zoom(13)); setMyLocationMarker(lastLocation); - } else { - myLatLng = myDefaultLatLng; - cameraBuilder.target(myLatLng); - CameraPosition cameraPosition = cameraBuilder.build(); - googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); - googleMap.setOnMarkerClickListener(new OnMarkerClickListener()); } subscriptionRxBus = rxBus.observeEvents(RxMessage.class).subscribe(handleRxMessages()); @@ -200,6 +190,9 @@ public class MapSearchFragment extends Fragment implements OnMapReadyCallback { @Override public void onStart() { super.onStart(); + if (subscriptionRxBus != null && subscriptionRxBus.isUnsubscribed()) { + subscriptionRxBus = rxBus.observeEvents(RxMessage.class).subscribe(handleRxMessages()); + } } @Override @@ -224,6 +217,10 @@ public class MapSearchFragment extends Fragment implements OnMapReadyCallback { @Override public void onSaveInstanceState(Bundle outState) { googleMapView.onSaveInstanceState(outState); + + outState.putParcelable(BundleKeys.STOPS, Parcels.wrap(stops)); + outState.putParcelable(BundleKeys.LOCATION, lastLocation); + super.onSaveInstanceState(outState); } @@ -250,9 +247,11 @@ public class MapSearchFragment extends Fragment implements OnMapReadyCallback { LatLng myLatLng = new LatLng(lastLocation.getLatitude(), lastLocation.getLongitude()); CameraPosition cameraPosition = new CameraPosition.Builder().zoom(13).target(myLatLng).build(); googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); - } else if (rxMessage.isMessageValidFor(RxMessageKeys.MY_LOCATION_UPDATE)) { + } else if (rxMessage.isMessageValidFor(RxMessageKeys.MY_LOCATION_UPDATE) || rxMessage.isMessageValidFor(RxMessageKeys.MY_LOCATION)) { Location location = ((RxMessageLocation) rxMessage).getMessage(); - setMyLocationMarker(location); + if (location != null) { + setMyLocationMarker(location); + } } } }; diff --git a/app/src/main/java/com/eleith/calchoochoo/utils/DeviceLocation.java b/app/src/main/java/com/eleith/calchoochoo/utils/DeviceLocation.java index b068e96..2fce3b1 100644 --- a/app/src/main/java/com/eleith/calchoochoo/utils/DeviceLocation.java +++ b/app/src/main/java/com/eleith/calchoochoo/utils/DeviceLocation.java @@ -15,7 +15,6 @@ import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.location.LocationRequest; import com.google.android.gms.location.LocationServices; -import com.google.android.gms.maps.model.LatLng; import javax.inject.Inject; @@ -28,56 +27,46 @@ public class DeviceLocation private RxBus rxBus; private GoogleApiClient googleApiClient; private Activity activity; - private Boolean googleApiClientReady = false; private int requestedUpdates = 0; private int requestedLocation = 0; private Boolean requestingUpdates = false; - private LatLng myDefaultLatLng = new LatLng(37.04, -121.6); @Inject - public DeviceLocation(RxBus rxBus, GoogleApiClient googleApiClient, Activity activity) { + public DeviceLocation(RxBus rxBus, Activity activity) { this.rxBus = rxBus; - this.googleApiClient = googleApiClient; this.activity = activity; + googleApiClient = new GoogleApiClient.Builder(activity).addApi(LocationServices.API).build(); googleApiClient.registerConnectionFailedListener(this); googleApiClient.registerConnectionCallbacks(this); } + private void connectGoogleApiClient() { + if (!googleApiClient.isConnected() && !googleApiClient.isConnecting()) { + googleApiClient.connect(); + } + } + public void requestLocation() { - if (googleApiClientReady) { + if (googleApiClient.isConnected()) { if (android.os.Build.VERSION.SDK_INT >= 23) { if (activity.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient); - if (location != null) { - onLocationChanged(location); - } else { - location = new Location("default"); - location.setLatitude(myDefaultLatLng.latitude); - location.setLongitude(myDefaultLatLng.longitude); - onLocationChanged(location); - } - return; + sendLastLocation(location); } else { activity.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, Permissions.READ_GPS); } + } else { + Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient); + sendLastLocation(location); } } else { - Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient); - if (location != null) { - onLocationChanged(location); - } else { - location = new Location("default"); - location.setLatitude(myDefaultLatLng.latitude); - location.setLongitude(myDefaultLatLng.longitude); - onLocationChanged(location); - } - return; + requestedLocation++; + connectGoogleApiClient(); } - requestedLocation++; } - public void requestLocationUpdates() { - if (googleApiClientReady) { + public void listenForLocationUpdates() { + if (googleApiClient.isConnected()) { if (android.os.Build.VERSION.SDK_INT >= 23) { if (activity.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { if (!requestingUpdates) { @@ -88,7 +77,6 @@ public class DeviceLocation LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this); requestingUpdates = true; } - return; } else { activity.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, Permissions.READ_GPS); } @@ -101,19 +89,22 @@ public class DeviceLocation LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this); requestingUpdates = true; } - return; } + } else { + requestedUpdates++; + connectGoogleApiClient(); } - requestedUpdates++; + } + + public void stopListeningForLocationUpdates() { + requestingUpdates = false; + googleApiClient.disconnect(); } @Override public void onConnected(@Nullable Bundle bundle) { - googleApiClientReady = true; - requestingUpdates = false; - if (requestedUpdates > 0) { - requestLocationUpdates(); + listenForLocationUpdates(); } if (requestedLocation > 0) { @@ -123,19 +114,23 @@ public class DeviceLocation @Override public void onConnectionSuspended(int i) { - googleApiClientReady = false; } @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { - googleApiClientReady = false; } @Override public void onLocationChanged(Location location) { - if (location != null) { - rxBus.send(new RxMessageLocation(RxMessageKeys.MY_LOCATION_UPDATE, location)); + rxBus.send(new RxMessageLocation(RxMessageKeys.MY_LOCATION_UPDATE, location)); + } + + private void sendLastLocation(Location location) { + requestedLocation--; + if (requestedUpdates == 0 && !requestingUpdates && requestedLocation == 0) { + googleApiClient.disconnect(); } + rxBus.send(new RxMessageLocation(RxMessageKeys.MY_LOCATION, location)); } @Override @@ -144,7 +139,7 @@ public class DeviceLocation case Permissions.READ_GPS: { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (requestedUpdates > 0) { - requestLocationUpdates(); + listenForLocationUpdates(); } else if (requestedLocation > 0) { requestLocation(); } @@ -154,5 +149,4 @@ public class DeviceLocation } } } - } diff --git a/misc/CT-GTFS-updated.zip b/misc/CT-GTFS-updated.zip new file mode 100644 index 0000000..ff45bfd Binary files /dev/null and b/misc/CT-GTFS-updated.zip differ diff --git a/misc/calchoochoo.svg b/misc/calchoochoo.svg new file mode 100644 index 0000000..f0ecada --- /dev/null +++ b/misc/calchoochoo.svg @@ -0,0 +1,135 @@ + +image/svg+xml \ No newline at end of file diff --git a/misc/emoji_u1f682.svg b/misc/emoji_u1f682.svg new file mode 100644 index 0000000..8b87b24 --- /dev/null +++ b/misc/emoji_u1f682.svg @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/misc/emoji_u1f683.svg b/misc/emoji_u1f683.svg new file mode 100644 index 0000000..976a89d --- /dev/null +++ b/misc/emoji_u1f683.svg @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + +