Replaced old callbacks with eventbus for Panoramio.
parent
b89125b1ac
commit
a84b1d08ca
|
@ -2,9 +2,11 @@ package pl.tpolgrabia.urbanexplorer.callbacks.panoramio;
|
|||
|
||||
import android.location.Location;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pl.tpolgrabia.panoramiobindings.dto.PanoramioImageInfo;
|
||||
import pl.tpolgrabia.urbanexplorer.events.LocationChangedEvent;
|
||||
import pl.tpolgrabia.urbanexplorerutils.callbacks.StandardLocationListenerCallback;
|
||||
import pl.tpolgrabia.urbanexplorer.fragments.HomeFragment;
|
||||
import pl.tpolgrabia.urbanexplorerutils.events.RefreshEvent;
|
||||
|
@ -28,4 +30,9 @@ public class PanoramioLocationCallback implements StandardLocationListenerCallba
|
|||
homeFragment.setPhotos(new ArrayList<PanoramioImageInfo>());
|
||||
EventBus.getDefault().post(new RefreshEvent(this));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void handleLocationChanged(LocationChangedEvent event) {
|
||||
callback(event.getLocation());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package pl.tpolgrabia.urbanexplorer.callbacks.panoramio;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import pl.tpolgrabia.panoramiobindings.callback.ProviderStatusCallback;
|
||||
import pl.tpolgrabia.urbanexplorer.events.ProviderStatusChangedEvent;
|
||||
import pl.tpolgrabia.urbanexplorerutils.events.RefreshEvent;
|
||||
import pl.tpolgrabia.urbanexplorer.fragments.HomeFragment;
|
||||
|
||||
|
@ -25,4 +27,9 @@ public class PanoramioProviderCallback implements ProviderStatusCallback {
|
|||
EventBus.getDefault().post(new RefreshEvent(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void handleProviderStatusChanged(ProviderStatusChangedEvent event) {
|
||||
callback(event.getProvider(), event.isEnabled());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ public class HomeFragment extends Fragment {
|
|||
private boolean noMorePhotos;
|
||||
private String currentGeocodedLocation;
|
||||
private GeocoderUtils geocoderUtils;
|
||||
private PanoramioLocationCallback locationChangedHandler;
|
||||
private PanoramioProviderCallback providerChangedHandler;
|
||||
|
||||
public HomeFragment() {
|
||||
// Required empty public constructor
|
||||
|
@ -74,10 +76,13 @@ public class HomeFragment extends Fragment {
|
|||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
MainActivity mainActivity = ((MainActivity) getActivity());
|
||||
final StandardLocationListener locationCallback = mainActivity.getLocationCallback();
|
||||
locationCallback.addCallback(new PanoramioLocationCallback(this));
|
||||
locationCallback.addProviderCallback(new PanoramioProviderCallback(this));
|
||||
|
||||
locationChangedHandler = new PanoramioLocationCallback(this);
|
||||
providerChangedHandler = new PanoramioProviderCallback(this);
|
||||
|
||||
EventBus.getDefault().register(locationChangedHandler);
|
||||
EventBus.getDefault().register(providerChangedHandler);
|
||||
|
||||
geocoderUtils = new GeocoderUtils(getActivity(), AppConstants.GOOGLE_API_KEY);
|
||||
}
|
||||
|
||||
|
@ -217,6 +222,9 @@ public class HomeFragment extends Fragment {
|
|||
lg.trace("onDestroy");
|
||||
EventBus.getDefault().unregister(this);
|
||||
PanoramioCacheUtils.savePhotosToCache(getActivity(), photos);
|
||||
|
||||
EventBus.getDefault().unregister(locationChangedHandler);
|
||||
EventBus.getDefault().unregister(providerChangedHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue