Provider status enabling & disabling.
parent
2033a636ca
commit
6182d3b042
|
@ -0,0 +1,8 @@
|
||||||
|
package pl.tpolgrabia.urbanexplorer.callbacks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Tomasz Półgrabia <tomasz.polgrabia@unicredit.eu> (c310702) on 19.09.2016.
|
||||||
|
*/
|
||||||
|
public interface ProviderStatusCallback {
|
||||||
|
void callback(String provider, boolean enabled);
|
||||||
|
}
|
|
@ -15,6 +15,8 @@ import java.util.List;
|
||||||
public class StandardLocationListener implements LocationListener {
|
public class StandardLocationListener implements LocationListener {
|
||||||
private static final Logger lg = LoggerFactory.getLogger(StandardLocationListener.class);
|
private static final Logger lg = LoggerFactory.getLogger(StandardLocationListener.class);
|
||||||
private List<StandardLocationListenerCallback> locationChangedCallbacks = new ArrayList<>();
|
private List<StandardLocationListenerCallback> locationChangedCallbacks = new ArrayList<>();
|
||||||
|
private List<ProviderStatusCallback>
|
||||||
|
providerStatusCallbacks = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
|
@ -32,18 +34,38 @@ public class StandardLocationListener implements LocationListener {
|
||||||
@Override
|
@Override
|
||||||
public void onProviderEnabled(String provider) {
|
public void onProviderEnabled(String provider) {
|
||||||
lg.info("Provider {} enabled", provider);
|
lg.info("Provider {} enabled", provider);
|
||||||
|
|
||||||
|
for (ProviderStatusCallback callback : providerStatusCallbacks){
|
||||||
|
callback.callback(provider, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProviderDisabled(String provider) {
|
public void onProviderDisabled(String provider) {
|
||||||
lg.info("Provider {} disabled", provider);
|
lg.info("Provider {} disabled", provider);
|
||||||
|
|
||||||
|
for (ProviderStatusCallback callback : providerStatusCallbacks){
|
||||||
|
callback.callback(provider, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCallback(StandardLocationListenerCallback callback) {
|
public void addCallback(StandardLocationListenerCallback callback) {
|
||||||
|
lg.trace("Location added callback");
|
||||||
locationChangedCallbacks.add(callback);
|
locationChangedCallbacks.add(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeCallback(StandardLocationListenerCallback callback) {
|
public boolean removeCallback(StandardLocationListenerCallback callback) {
|
||||||
|
lg.trace("Location removed callback");
|
||||||
return locationChangedCallbacks.remove(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,10 @@ import pl.tpolgrabia.urbanexplorer.MainActivity;
|
||||||
import pl.tpolgrabia.urbanexplorer.R;
|
import pl.tpolgrabia.urbanexplorer.R;
|
||||||
import pl.tpolgrabia.urbanexplorer.callbacks.PanoramioResponseCallback;
|
import pl.tpolgrabia.urbanexplorer.callbacks.PanoramioResponseCallback;
|
||||||
import pl.tpolgrabia.urbanexplorer.callbacks.PanoramioResponseStatus;
|
import pl.tpolgrabia.urbanexplorer.callbacks.PanoramioResponseStatus;
|
||||||
|
import pl.tpolgrabia.urbanexplorer.callbacks.ProviderStatusCallback;
|
||||||
import pl.tpolgrabia.urbanexplorer.callbacks.StandardLocationListenerCallback;
|
import pl.tpolgrabia.urbanexplorer.callbacks.StandardLocationListenerCallback;
|
||||||
import pl.tpolgrabia.urbanexplorer.dto.panoramio.PanoramioCacheDto;
|
import pl.tpolgrabia.urbanexplorer.dto.panoramio.PanoramioCacheDto;
|
||||||
import pl.tpolgrabia.urbanexplorer.dto.panoramio.PanoramioImageInfo;
|
import pl.tpolgrabia.urbanexplorer.dto.panoramio.PanoramioImageInfo;
|
||||||
import pl.tpolgrabia.urbanexplorer.utils.LocationUtils;
|
|
||||||
import pl.tpolgrabia.urbanexplorer.utils.NetUtils;
|
import pl.tpolgrabia.urbanexplorer.utils.NetUtils;
|
||||||
import pl.tpolgrabia.urbanexplorer.utils.PanoramioUtils;
|
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
|
@Override
|
||||||
|
@ -328,7 +338,6 @@ public class HomeFragment extends Fragment {
|
||||||
|
|
||||||
MainActivity mainActivity = (MainActivity) getActivity();
|
MainActivity mainActivity = (MainActivity) getActivity();
|
||||||
|
|
||||||
LocationManager locationService = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
|
|
||||||
final Location location = NetUtils.getLastKnownLocation(activity);
|
final Location location = NetUtils.getLastKnownLocation(activity);
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
lg.info("Location is still not available");
|
lg.info("Location is still not available");
|
||||||
|
|
|
@ -22,6 +22,7 @@ import pl.tpolgrabia.urbanexplorer.MainActivity;
|
||||||
import pl.tpolgrabia.urbanexplorer.R;
|
import pl.tpolgrabia.urbanexplorer.R;
|
||||||
import pl.tpolgrabia.urbanexplorer.adapters.WikiLocationsAdapter;
|
import pl.tpolgrabia.urbanexplorer.adapters.WikiLocationsAdapter;
|
||||||
import pl.tpolgrabia.urbanexplorer.callbacks.FetchWikiLocationsCallback;
|
import pl.tpolgrabia.urbanexplorer.callbacks.FetchWikiLocationsCallback;
|
||||||
|
import pl.tpolgrabia.urbanexplorer.callbacks.ProviderStatusCallback;
|
||||||
import pl.tpolgrabia.urbanexplorer.callbacks.StandardLocationListenerCallback;
|
import pl.tpolgrabia.urbanexplorer.callbacks.StandardLocationListenerCallback;
|
||||||
import pl.tpolgrabia.urbanexplorer.callbacks.WikiStatus;
|
import pl.tpolgrabia.urbanexplorer.callbacks.WikiStatus;
|
||||||
import pl.tpolgrabia.urbanexplorer.dto.wiki.WikiCacheDto;
|
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);
|
ListView locations = (ListView) inflatedView.findViewById(R.id.wiki_places);
|
||||||
locations.setOnItemLongClickListener(new FetchWikiLocationsCallback(WikiLocationsFragment.this, appObjects));
|
locations.setOnItemLongClickListener(new FetchWikiLocationsCallback(WikiLocationsFragment.this, appObjects));
|
||||||
locations.setAdapter(new WikiLocationsAdapter(getActivity(), appObjects));
|
locations.setAdapter(new WikiLocationsAdapter(getActivity(), appObjects));
|
||||||
|
|
Loading…
Reference in New Issue