From 1fc6c53117831ca114cbc3b359d5d26222b51ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20P=C3=B3=C5=82grabia?= Date: Mon, 19 Sep 2016 23:18:32 +0200 Subject: [PATCH] Fixing issues when location is not available. --- .../pl/tpolgrabia/urbanexplorer/MainActivity.java | 6 ++++-- .../fragments/WikiLocationsFragment.java | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java index 6f2ec60..247a215 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java @@ -103,10 +103,9 @@ public class MainActivity extends ActionBarActivity { photoInfo = savedInstanceState != null ? (PanoramioImageInfo) savedInstanceState.getSerializable(AppConstants.PHOTO_INFO) : null; savedConfiguration = savedInstanceState != null ? savedInstanceState.getBoolean(AppConstants.SAVED_CONFIG_KEY) : false; - if (HelperUtils.checkForLocalicatonEnabled(this)) return; switchFragment(); updateSwipeHandler(); - HelperUtils.firstTimeNotification(this); + if (HelperUtils.checkForLocalicatonEnabled(this)) return; } @Override @@ -151,12 +150,14 @@ public class MainActivity extends ActionBarActivity { final String tag = fragTags.get(currFrag); if (tag == null) { lg.warn("Unknown fragment id"); + hideProgress(); return; } final Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag); if (fragment == null) { lg.warn("There is no fragment with the given tag"); + hideProgress(); return; } @@ -300,6 +301,7 @@ public class MainActivity extends ActionBarActivity { } savedConfiguration = false; + HelperUtils.firstTimeNotification(this); } @Override diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java index 7f7b354..7208f92 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java @@ -270,12 +270,13 @@ public class WikiLocationsFragment extends Fragment implements Refreshable { WikiCacheDto dto = new WikiCacheDto(); dto.setAppObject(appObjects); - LocationManager locationService = (LocationManager) getActivity().getSystemService(LOCATION_SERVICE); - Location location = locationService.getLastKnownLocation(LocationUtils.getDefaultLocation(getActivity())); - if (location != null) { - dto.setLongitude(location.getLongitude()); - dto.setLatitude(location.getLatitude()); - dto.setAltitude(location.getAltitude()); + if (getActivity() != null) { + Location location = NetUtils.getLastKnownLocation(getActivity()); + if (location != null) { + dto.setLongitude(location.getLongitude()); + dto.setLatitude(location.getLatitude()); + dto.setAltitude(location.getAltitude()); + } } dto.setFetchedAt(new GregorianCalendar().getTime());