3030import android .widget .TextView ;
3131import android .widget .Toast ;
3232
33+ import butterknife .BindView ;
34+ import butterknife .ButterKnife ;
3335import io .pslab .R ;
3436import io .pslab .fragment .LuxMeterFragmentConfig ;
3537import io .pslab .fragment .LuxMeterFragmentData ;
38+ import io .pslab .fragment .SettingsFragment ;
3639import io .pslab .others .CSVLogger ;
3740import io .pslab .others .CustomSnackBar ;
3841import io .pslab .others .GPSLogger ;
3942import io .pslab .others .MathUtils ;
40- import io .pslab .fragment .SettingsFragment ;
4143import io .pslab .others .SwipeGestureDetector ;
42- import butterknife .BindView ;
43- import butterknife .ButterKnife ;
4444
4545public class LuxMeterActivity extends AppCompatActivity {
4646
@@ -221,7 +221,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
221221 ((LuxMeterFragmentData ) selectedFragment ).stopSensorFetching ();
222222 invalidateOptionsMenu ();
223223 Long uniqueRef = realmPreferences .getLong ("uniqueCount" , 0 );
224- selectedFragment .saveDataInRealm (uniqueRef );
224+ selectedFragment .saveDataInRealm (uniqueRef , locationPref , gpsLogger );
225225 CustomSnackBar .showSnackBar (coordinatorLayout , getString (R .string .exp_data_saved ), null , null );
226226 SharedPreferences .Editor editor = realmPreferences .edit ();
227227 editor .putLong ("uniqueCount" , uniqueRef + 1 );
@@ -243,6 +243,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
243243 ((LuxMeterFragmentData ) selectedFragment ).startSensorFetching ();
244244 invalidateOptionsMenu ();
245245 }
246+ String snackText = getString (R .string .data_recording_start )+"\n " +(locationPref ?getString (R .string .location_enabled ):getString (R .string .location_disabled ));
247+ CustomSnackBar .showSnackBar (coordinatorLayout , snackText , null , null );
246248 }
247249 break ;
248250 case R .id .show_map :
@@ -255,14 +257,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
255257 }
256258 Intent MAP = new Intent (getApplicationContext (), MapsActivity .class );
257259 startActivity (MAP );
258- startActivity (new Intent (this , ShowLoggedData .class ));
259260 break ;
260261 case R .id .settings :
261262 startActivity (new Intent (this , SettingsActivity .class ));
262263 break ;
263264 case R .id .show_logged_data :
264- Intent intent = new Intent (this ,DataLoggerActivity .class );
265- intent .putExtra (DataLoggerActivity .CALLER_ACTIVITY ,"Lux Meter" );
265+ Intent intent = new Intent (this , DataLoggerActivity .class );
266+ intent .putExtra (DataLoggerActivity .CALLER_ACTIVITY , "Lux Meter" );
266267 startActivity (intent );
267268
268269 break ;
@@ -280,37 +281,25 @@ protected void onResume() {
280281 recordData = true ;
281282 ((LuxMeterFragmentData ) selectedFragment ).startSensorFetching ();
282283 invalidateOptionsMenu ();
284+ gpsLogger .startFetchingLocation ();
285+ CustomSnackBar .showSnackBar (coordinatorLayout ,getString (R .string .data_recording_start )+getString (R .string .location_enabled ) , null , null );
283286 } else {
284287 recordData = false ;
285288 Toast .makeText (getApplicationContext (), getString (R .string .gps_not_enabled ),
286289 Toast .LENGTH_SHORT ).show ();
290+ gpsLogger .removeUpdate ();
287291 }
292+ checkGpsOnResume = false ;
288293 }
289294 locationPref = PreferenceManager .getDefaultSharedPreferences (getBaseContext ()).getBoolean (SettingsFragment .KEY_INCLUDE_LOCATION , false );
295+ if (!locationPref && gpsLogger !=null ){
296+ gpsLogger = null ;
297+ }
290298 }
291299
292300 @ Override
293301 public void onRequestPermissionsResult (int requestCode , @ NonNull String [] permissions , @ NonNull int [] grantResults ) {
294- if (requestCode == MY_PERMISSIONS_REQUEST_STORAGE_FOR_DATA ) {
295- if (grantResults .length > 0
296- && grantResults [0 ] == PackageManager .PERMISSION_GRANTED ) {
297- if (locationPref ) {
298- gpsLogger = new GPSLogger (this , (LocationManager ) getSystemService (Context .LOCATION_SERVICE ));
299- if (gpsLogger .isGPSEnabled ()) {
300- recordData = true ;
301- CustomSnackBar .showSnackBar (coordinatorLayout , getString (R .string .data_recording_start ) + "\n " + getString (R .string .location_enabled ), null , null );
302- } else {
303- checkGpsOnResume = true ;
304- }
305- gpsLogger .startFetchingLocation ();
306- } else {
307- recordData = true ;
308- CustomSnackBar .showSnackBar (coordinatorLayout , getString (R .string .data_recording_start ) + "\n " + getString (R .string .location_disabled ), null , null );
309- }
310- } else {
311- Toast .makeText (this , R .string .prmsn_denied_storage , Toast .LENGTH_SHORT ).show ();
312- }
313- } else if (requestCode == MY_PERMISSIONS_REQUEST_STORAGE_FOR_MAPS
302+ if (requestCode == MY_PERMISSIONS_REQUEST_STORAGE_FOR_MAPS
314303 && grantResults [0 ] == PackageManager .PERMISSION_GRANTED ) {
315304 Intent MAP = new Intent (getApplicationContext (), MapsActivity .class );
316305 startActivity (MAP );
0 commit comments