diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/panoramio/PanoramioLocationCallback.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/panoramio/PanoramioLocationCallback.java index b9870a0..3fd00d3 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/panoramio/PanoramioLocationCallback.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/panoramio/PanoramioLocationCallback.java @@ -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()); EventBus.getDefault().post(new RefreshEvent(this)); } + + @Subscribe + public void handleLocationChanged(LocationChangedEvent event) { + callback(event.getLocation()); + } } diff --git a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/panoramio/PanoramioProviderCallback.java b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/panoramio/PanoramioProviderCallback.java index 1d4d37e..e314131 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/panoramio/PanoramioProviderCallback.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/callbacks/panoramio/PanoramioProviderCallback.java @@ -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()); + } } 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 ee832ce..0af647c 100644 --- a/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java +++ b/app/src/main/java/pl/tpolgrabia/urbanexplorer/fragments/HomeFragment.java @@ -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