diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/ProviderStatusCallback.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/ProviderStatusCallback.java new file mode 100644 index 0000000..bc852e8 --- /dev/null +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/ProviderStatusCallback.java @@ -0,0 +1,8 @@ +package pl.tpolgrabia.urbanexplorer.callbacks; + +/** + * Created by Tomasz Półgrabia (c310702) on 19.09.2016. + */ +public interface ProviderStatusCallback { + void callback(String provider, boolean enabled); +} diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/StandardLocationListener.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/StandardLocationListener.java index 87f05d2..bf247c0 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/StandardLocationListener.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/StandardLocationListener.java @@ -15,6 +15,8 @@ import java.util.List; public class StandardLocationListener implements LocationListener { private static final Logger lg = LoggerFactory.getLogger(StandardLocationListener.class); private List locationChangedCallbacks = new ArrayList<>(); + private List + providerStatusCallbacks = new ArrayList<>(); @Override public void onLocationChanged(Location location) { @@ -32,18 +34,38 @@ public class StandardLocationListener implements LocationListener { @Override public void onProviderEnabled(String provider) { lg.info("Provider {} enabled", provider); + + for (ProviderStatusCallback callback : providerStatusCallbacks){ + callback.callback(provider, true); + } } @Override public void onProviderDisabled(String provider) { lg.info("Provider {} disabled", provider); + + for (ProviderStatusCallback callback : providerStatusCallbacks){ + callback.callback(provider, false); + } } public void addCallback(StandardLocationListenerCallback callback) { + lg.trace("Location added callback"); locationChangedCallbacks.add(callback); } public boolean removeCallback(StandardLocationListenerCallback callback) { + lg.trace("Location removed callback"); return locationChangedCallbacks.remove(callback); } + + public void addProviderCallback(ProviderStatusCallback callback) { + lg.trace("Provider added callback"); + providerStatusCallbacks.add(callback); + } + + public void removeProviderCallback(ProviderStatusCallback callback) { + lg.trace("Provider removed calback"); + providerStatusCallbacks.remove(callback); + } } 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 1dcb283..52b3918 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java @@ -22,10 +22,10 @@ import pl.tpolgrabia.urbanexplorer.MainActivity; import pl.tpolgrabia.urbanexplorer.R; import pl.tpolgrabia.urbanexplorer.callbacks.PanoramioResponseCallback; import pl.tpolgrabia.urbanexplorer.callbacks.PanoramioResponseStatus; +import pl.tpolgrabia.urbanexplorer.callbacks.ProviderStatusCallback; import pl.tpolgrabia.urbanexplorer.callbacks.StandardLocationListenerCallback; import pl.tpolgrabia.urbanexplorer.dto.panoramio.PanoramioCacheDto; import pl.tpolgrabia.urbanexplorer.dto.panoramio.PanoramioImageInfo; -import pl.tpolgrabia.urbanexplorer.utils.LocationUtils; import pl.tpolgrabia.urbanexplorer.utils.NetUtils; import pl.tpolgrabia.urbanexplorer.utils.PanoramioUtils; @@ -101,6 +101,16 @@ public class HomeFragment extends Fragment { } } }); + mainActivity.getLocationCallback() + .addProviderCallback(new ProviderStatusCallback() { + @Override + public void callback(String provider, boolean enabled) { + if (enabled) { + lg.trace("Handling provider enabling - refreshing panoramio listing"); + fetchPanoramioPhotos(); + } + } + }); } @Override @@ -328,7 +338,6 @@ public class HomeFragment extends Fragment { MainActivity mainActivity = (MainActivity) getActivity(); - LocationManager locationService = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); final Location location = NetUtils.getLastKnownLocation(activity); if (location == null) { lg.info("Location is still not available"); 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 755a4ed..fa8e2e7 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/WikiLocationsFragment.java @@ -22,6 +22,7 @@ import pl.tpolgrabia.urbanexplorer.MainActivity; import pl.tpolgrabia.urbanexplorer.R; import pl.tpolgrabia.urbanexplorer.adapters.WikiLocationsAdapter; import pl.tpolgrabia.urbanexplorer.callbacks.FetchWikiLocationsCallback; +import pl.tpolgrabia.urbanexplorer.callbacks.ProviderStatusCallback; import pl.tpolgrabia.urbanexplorer.callbacks.StandardLocationListenerCallback; import pl.tpolgrabia.urbanexplorer.callbacks.WikiStatus; import pl.tpolgrabia.urbanexplorer.dto.wiki.WikiCacheDto; @@ -107,6 +108,16 @@ public class WikiLocationsFragment extends Fragment { } }); + mainActivity.getLocationCallback().addProviderCallback(new ProviderStatusCallback() { + @Override + public void callback(String provider, boolean enabled) { + if (enabled) { + lg.trace("Handling provider enabling - refreshing wiki listing"); + fetchWikiLocations(); + } + } + }); + ListView locations = (ListView) inflatedView.findViewById(R.id.wiki_places); locations.setOnItemLongClickListener(new FetchWikiLocationsCallback(WikiLocationsFragment.this, appObjects)); locations.setAdapter(new WikiLocationsAdapter(getActivity(), appObjects));