diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java index 247a215..8dbe728 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/MainActivity.java @@ -101,7 +101,7 @@ public class MainActivity extends ActionBarActivity { currFrag = fragId == null ? MainActivityState.PANORAMIO : fragId; lg.trace("Set final frag id: {}", fragId); photoInfo = savedInstanceState != null ? (PanoramioImageInfo) savedInstanceState.getSerializable(AppConstants.PHOTO_INFO) : null; - savedConfiguration = savedInstanceState != null ? savedInstanceState.getBoolean(AppConstants.SAVED_CONFIG_KEY) : false; + savedConfiguration = savedInstanceState != null && savedInstanceState.getBoolean(AppConstants.SAVED_CONFIG_KEY); switchFragment(); updateSwipeHandler(); @@ -147,7 +147,7 @@ public class MainActivity extends ActionBarActivity { } private void refreshFragment() { - final String tag = fragTags.get(currFrag); + final String tag = fragTags.get(currFrag.getOrder()); if (tag == null) { lg.warn("Unknown fragment id"); hideProgress(); diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/wiki/app/WikiAppObject.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/wiki/app/WikiAppObject.java index 6dbb1b8..47c9923 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/wiki/app/WikiAppObject.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/dto/wiki/app/WikiAppObject.java @@ -6,6 +6,7 @@ import java.io.Serializable; * Created by tpolgrabia on 05.09.16. */ public class WikiAppObject implements Serializable { + private static final long serialVersionUID = 4012661137123526703L; private String url; private String thumbnail; private String title; diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/exceptions/PanoramioResponseNotExpected.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/exceptions/PanoramioResponseNotExpected.java index 941effd..f684da1 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/exceptions/PanoramioResponseNotExpected.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/exceptions/PanoramioResponseNotExpected.java @@ -4,6 +4,8 @@ package pl.tpolgrabia.urbanexplorer.exceptions; * Created by tpolgrabia on 27.08.16. */ public class PanoramioResponseNotExpected extends RuntimeException { + private static final long serialVersionUID = 4518500758010368539L; + public PanoramioResponseNotExpected(String errorCause) { super(errorCause); } diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java index 1e6238c..75c9608 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java @@ -120,6 +120,12 @@ public class HomeFragment extends Fragment implements Refreshable { } Location currLocation = NetUtils.getLastKnownLocation(getActivity()); + lg.debug("Current location is {}", currLocation); + if (currLocation == null) { + lg.debug("Current location is not available"); + return; + } + LocationUtils.getGeoCodedLocation(getActivity(), currLocation.getLatitude(), currLocation.getLongitude(), new LocationGeoCoderCallback() { @Override public void callback(int code, String message, String googleStatus, String geocodedLocation) { @@ -177,7 +183,7 @@ public class HomeFragment extends Fragment implements Refreshable { } } - if (photos == null || photos.isEmpty()) { + if (photos.isEmpty()) { // maybe we find something in our cache file try (Reader br = new InputStreamReader( @@ -243,7 +249,6 @@ public class HomeFragment extends Fragment implements Refreshable { } }); - ; return inflatedView; } @@ -278,7 +283,6 @@ public class HomeFragment extends Fragment implements Refreshable { } - LocationManager locationService = (LocationManager)getActivity().getSystemService(Context.LOCATION_SERVICE); final Location location = NetUtils.getLastKnownLocation(activity); if (location == null) { @@ -384,7 +388,6 @@ public class HomeFragment extends Fragment implements Refreshable { new PanoramioResponseCallback() { @Override public void callback(PanoramioResponseStatus status, List images, Long imagesCount) { - Long pageSize = fetchLocationPageSize(); ArrayAdapter adapter = new PanoramioAdapter(activity, R.layout.location_item, @@ -393,7 +396,12 @@ public class HomeFragment extends Fragment implements Refreshable { if (images.isEmpty()) { Toast.makeText(getActivity(), "No results", Toast.LENGTH_SHORT).show(); } - ListView locations = (ListView)getView().findViewById(R.id.locations); + final View view = getView(); + if (view == null) { + lg.trace("Fragment's view is not initialized"); + return; + } + ListView locations = (ListView) view.findViewById(R.id.locations); locations.setAdapter(adapter); MainActivity mainActivity = (MainActivity) getActivity(); if (mainActivity == null) { @@ -407,7 +415,7 @@ public class HomeFragment extends Fragment implements Refreshable { } private Long fetchLocationPageSize() { - return new Long(getPanoramioBulkDataSize()); + return Long.valueOf(getPanoramioBulkDataSize()); } private Double fetchRadiusX() { 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 4ee9292..50483bf 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java @@ -255,7 +255,7 @@ public class WikiLocationsFragment extends Fragment implements Refreshable { lg.warn("Activity shouldn't be null. No headless fragment"); return; } - final Location location = NetUtils.getLastKnownLocation(activity); + currentLocation.setText(currentGeocodedLocation); } diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/LocationUtils.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/LocationUtils.java index 0186afa..229abc7 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/LocationUtils.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/utils/LocationUtils.java @@ -85,6 +85,11 @@ public class LocationUtils { } JSONArray results = object.optJSONArray("results"); + if (results == null) { + clbk.callback(status.getCode(), status.getMessage(), googleStatus, null); + return; + } + int n = results.length(); for (int i = 0; i < n; i++) { result = results.optJSONObject(i); diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/workers/FetchingPhotosWorker.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/workers/FetchingPhotosWorker.java deleted file mode 100644 index a4d85e8..0000000 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/workers/FetchingPhotosWorker.java +++ /dev/null @@ -1,25 +0,0 @@ -package pl.tpolgrabia.urbanexplorer.workers; - -import android.os.AsyncTask; -import pl.tpolgrabia.urbanexplorer.fragments.HomeFragment; - -/** - * Created by tpolgrabia on 11.09.16. - */ -public class FetchingPhotosWorker extends AsyncTask { - - private HomeFragment homeFragment; - - public FetchingPhotosWorker(HomeFragment homeFragment) { - this.homeFragment = homeFragment; - } - - @Override - protected Boolean doInBackground(Boolean... params) { - for (Boolean arg : params) { - - } - - return null; - } -}