Provider status enabling & disabling.

master
Tomasz Półgrabia 2016-09-19 15:18:48 +02:00
parent 2033a636ca
commit 6182d3b042
4 changed files with 52 additions and 2 deletions

View File

@ -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);
}

View File

@ -15,6 +15,8 @@ import java.util.List;
public class StandardLocationListener implements LocationListener {
private static final Logger lg = LoggerFactory.getLogger(StandardLocationListener.class);
private List<StandardLocationListenerCallback> locationChangedCallbacks = new ArrayList<>();
private List<ProviderStatusCallback>
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);
}
}

View File

@ -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");

View File

@ -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));