Skip to content

Commit

Permalink
Fix await on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
pluscubed committed Apr 21, 2016
1 parent 7d3f28a commit bd8f8ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions app/src/main/java/com/pluscubed/velociraptor/FloatingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.os.IBinder;
import android.os.Looper;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
Expand All @@ -43,6 +44,8 @@
import com.crashlytics.android.Crashlytics;
import com.gigamole.library.ArcProgressStackView;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
Expand Down Expand Up @@ -103,6 +106,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null) {
if (!mNotifStart && intent.getBooleanExtra(EXTRA_CLOSE, false) ||
intent.getBooleanExtra(EXTRA_NOTIF_CLOSE, false)) {
onStop();
stopSelf();
return super.onStartCommand(intent, flags, startId);
} else if (intent.getBooleanExtra(EXTRA_NOTIF_START, false)) {
Expand Down Expand Up @@ -170,7 +174,11 @@ public void onConnected(@Nullable Bundle bundle) {
@Override
public void onConnectionSuspended(int i) {
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener).await();
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
}
});
}
}
})
Expand Down Expand Up @@ -442,12 +450,6 @@ public void onGlobalLayout() {
});
}

@Override
public boolean stopService(Intent name) {
onStop();
return super.stopService(name);
}

@Override
public void onDestroy() {
onStop();
Expand All @@ -456,7 +458,15 @@ public void onDestroy() {

private void onStop() {
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener).await();
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, mLocationListener).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
});
} else if (mGoogleApiClient != null) {
mGoogleApiClient.disconnect();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public SpeedLimitApi(Context context) {
OkHttpClient osmClient = client.newBuilder()
.addInterceptor(mOsmApiSelectionInterceptor)
.build();
Retrofit osmRest = buildRetrofit(osmClient, OSM_OVERPASS_APIS[0]);
Retrofit osmRest = buildRetrofit(osmClient, mOsmOverpassApis.get(0).baseUrl);
mOsmService = osmRest.create(OsmService.class);
}

Expand Down

0 comments on commit bd8f8ba

Please sign in to comment.