// Path: lib/src/main/java/com/miguelbcr/io/rx_gps_service/lib/RxLocation.java
// public class RxLocation {
//   private static final String TAG = "RxLocation";
//   public static final int REQUEST_CHECK_LOCATION_SETTINGS = 65456;
//   private final GrantPermissions grantPermissions;
//   private GpsConfig gpsConfig;
// 
//   RxLocation(GpsConfig gpsConfig) {
//     this.gpsConfig = gpsConfig;
//     this.grantPermissions = new GrantPermissions(gpsConfig.getActivity());
//   }
// 
//   Observable<Location> getCurrentLocationForService() {
//     final ReactiveLocationProvider locationProvider =
//         new ReactiveLocationProvider(gpsConfig.getActivity());
// 
//     final LocationRequest locationRequest = LocationRequest.create()
//         .setPriority(gpsConfig.getPriority())
//         .setInterval(gpsConfig.getInterval())
//         .setFastestInterval(gpsConfig.getFastestInterval());
// 
//     final LocationSettingsRequest locationSettingsRequest =
//         new LocationSettingsRequest.Builder().addLocationRequest(locationRequest)
//             .setAlwaysShow(
//                 true)  //Reference: http://stackoverflow.com/questions/29824408/google-play-services-locationservices-api-new-option-never
//             .build();
// 
//     return Observable.zip(
//         grantPermissions.with(permissions()).builtObservable().subscribeOn(Schedulers.io()),
//         locationProvider.checkLocationSettings(locationSettingsRequest)
//             .subscribeOn(Schedulers.io()),
//         new Func2<Void, LocationSettingsResult, LocationSettingsResult>() {
//           @Override public LocationSettingsResult call(Void aVoid,
//               LocationSettingsResult locationSettingsResult) {
//             return locationSettingsResult;
//           }
//         }).doOnNext(new Action1<LocationSettingsResult>() {
//       @Override public void call(LocationSettingsResult locationSettingsResult) {
//         Status status = locationSettingsResult.getStatus();
//         if (status.getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) {
//           try {
//             status.startResolutionForResult(gpsConfig.getActivity(),
//                 REQUEST_CHECK_LOCATION_SETTINGS);
//           } catch (IntentSender.SendIntentException exception) {
//             Log.e(TAG, "Error opening settings activity.", exception);
//           }
//         }
//       }
//     }).flatMap(new Func1<LocationSettingsResult, Observable<Location>>() {
//       @Override public Observable<Location> call(LocationSettingsResult locationSettingsResult) {
//         return locationProvider.getUpdatedLocation(locationRequest);
//       }
//     });
//   }
// 
//   private String[] permissions() {
//     return new String[] {
//         Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION
//     };
//   }
// }


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import com.miguelbcr.io.rx_gps_service.lib.RxLocation;
import com.miguelbcr.rx_gpsservice.R;
package com.miguelbcr.rx_gpsservice.app;



public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

// Path: lib/src/main/java/com/miguelbcr/io/rx_gps_service/lib/RxLocation.java
// public class RxLocation {
//   private static final String TAG = "RxLocation";
//   public static final int REQUEST_CHECK_LOCATION_SETTINGS = 65456;
//   private final GrantPermissions grantPermissions;
//   private GpsConfig gpsConfig;
// 
//   RxLocation(GpsConfig gpsConfig) {
//     this.gpsConfig = gpsConfig;
//     this.grantPermissions = new GrantPermissions(gpsConfig.getActivity());
//   }
// 
//   Observable<Location> getCurrentLocationForService() {
//     final ReactiveLocationProvider locationProvider =
//         new ReactiveLocationProvider(gpsConfig.getActivity());
// 
//     final LocationRequest locationRequest = LocationRequest.create()
//         .setPriority(gpsConfig.getPriority())
//         .setInterval(gpsConfig.getInterval())
//         .setFastestInterval(gpsConfig.getFastestInterval());
// 
//     final LocationSettingsRequest locationSettingsRequest =
//         new LocationSettingsRequest.Builder().addLocationRequest(locationRequest)
//             .setAlwaysShow(
//                 true)  //Reference: http://stackoverflow.com/questions/29824408/google-play-services-locationservices-api-new-option-never
//             .build();
// 
//     return Observable.zip(
//         grantPermissions.with(permissions()).builtObservable().subscribeOn(Schedulers.io()),
//         locationProvider.checkLocationSettings(locationSettingsRequest)
//             .subscribeOn(Schedulers.io()),
//         new Func2<Void, LocationSettingsResult, LocationSettingsResult>() {
//           @Override public LocationSettingsResult call(Void aVoid,
//               LocationSettingsResult locationSettingsResult) {
//             return locationSettingsResult;
//           }
//         }).doOnNext(new Action1<LocationSettingsResult>() {
//       @Override public void call(LocationSettingsResult locationSettingsResult) {
//         Status status = locationSettingsResult.getStatus();
//         if (status.getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) {
//           try {
//             status.startResolutionForResult(gpsConfig.getActivity(),
//                 REQUEST_CHECK_LOCATION_SETTINGS);
//           } catch (IntentSender.SendIntentException exception) {
//             Log.e(TAG, "Error opening settings activity.", exception);
//           }
//         }
//       }
//     }).flatMap(new Func1<LocationSettingsResult, Observable<Location>>() {
//       @Override public Observable<Location> call(LocationSettingsResult locationSettingsResult) {
//         return locationProvider.getUpdatedLocation(locationRequest);
//       }
//     });
//   }
// 
//   private String[] permissions() {
//     return new String[] {
//         Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION
//     };
//   }
// }


// Path: app/src/main/java/com/miguelbcr/rx_gpsservice/app/MainActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import com.miguelbcr.io.rx_gps_service.lib.RxLocation;
import com.miguelbcr.rx_gpsservice.R;

package com.miguelbcr.rx_gpsservice.app;



public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == RxLocation.REQUEST_CHECK_LOCATION_SETTINGS) {