Refresh event added and compile errors fixed.

master
Tomasz Półgrabia 2016-09-24 10:47:03 +02:00
parent e551aad598
commit 90c0a70b40
5 changed files with 64 additions and 10 deletions

View File

@ -1,7 +1,9 @@
package pl.tpolgrabia.urbanexplorer.callbacks;
import org.greenrobot.eventbus.EventBus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.tpolgrabia.urbanexplorer.events.RefreshEvent;
import pl.tpolgrabia.urbanexplorer.fragments.HomeFragment;
/**
@ -19,7 +21,7 @@ public class PanoramioProviderCallback implements ProviderStatusCallback {
public void callback(String provider, boolean enabled) {
if (enabled) {
lg.trace("Handling provider enabling - refreshing panoramio listing");
homeFragment.refresh();
EventBus.getDefault().post(new RefreshEvent(this));
}
}
}

View File

@ -0,0 +1,48 @@
package pl.tpolgrabia.urbanexplorer.events;
import java.sql.Ref;
/**
* Created by tpolgrabia on 24.09.16.
*/
public class RefreshEvent {
private Object source;
private Long time;
public RefreshEvent() {
this(null);
}
public RefreshEvent(Object source) {
this(source, System.currentTimeMillis());
}
public RefreshEvent(Object source, Long time) {
this.source = source;
this.time = time;
}
public Object getSource() {
return source;
}
public void setSource(Object source) {
this.source = source;
}
public Long getTime() {
return time;
}
public void setTime(Long time) {
this.time = time;
}
@Override
public String toString() {
return "RefreshEvent{" +
"source=" + source +
", time=" + time +
'}';
}
}

View File

@ -12,6 +12,7 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.tpolgrabia.urbanexplorer.MainActivity;
@ -19,6 +20,7 @@ import pl.tpolgrabia.urbanexplorer.R;
import pl.tpolgrabia.urbanexplorer.callbacks.*;
import pl.tpolgrabia.urbanexplorer.dto.panoramio.PanoramioImageInfo;
import pl.tpolgrabia.urbanexplorer.events.DataLoadingFinishEvent;
import pl.tpolgrabia.urbanexplorer.events.RefreshEvent;
import pl.tpolgrabia.urbanexplorer.handlers.PanoramioItemLongClickHandler;
import pl.tpolgrabia.urbanexplorer.handlers.PanoramioLocationsScrollListener;
import pl.tpolgrabia.urbanexplorer.utils.*;
@ -30,7 +32,7 @@ import java.util.concurrent.Semaphore;
/**
* A simple {@link Fragment} subclass.
*/
public class HomeFragment extends Fragment implements Refreshable {
public class HomeFragment extends Fragment {
private static final Logger lg = LoggerFactory.getLogger(HomeFragment.class);
@ -148,7 +150,7 @@ public class HomeFragment extends Fragment implements Refreshable {
return;
}
int offset = photos.size();
lg.debug("Fetching additional photos offset: {}, count: {}", offset, SettingsUtils.getPanoramioBulkDataSize(this));
lg.debug("Fetching additional photos offset: {}, count: {}", offset, SettingsUtils.getPanoramioBulkDataSize(getActivity()));
PanoramioUtils.fetchPanoramioImages(
activity,
location.getLatitude(),
@ -162,7 +164,7 @@ public class HomeFragment extends Fragment implements Refreshable {
}
private Long fetchLocationPageSize() {
return Long.valueOf(SettingsUtils.getPanoramioBulkDataSize(this));
return Long.valueOf(SettingsUtils.getPanoramioBulkDataSize(getActivity()));
}
@Override
@ -212,8 +214,8 @@ public class HomeFragment extends Fragment implements Refreshable {
lg.trace("Saved photos: {}", photos);
}
@Override
public void refresh() {
@Subscribe
public void refresh(RefreshEvent refreshEvent) {
lg.trace("Fetch panoramio photos");
final FragmentActivity activity = getActivity();
if (activity == null) {

View File

@ -16,6 +16,7 @@ import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.Gson;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.tpolgrabia.urbanexplorer.AppConstants;
@ -27,6 +28,7 @@ import pl.tpolgrabia.urbanexplorer.dto.wiki.WikiCacheDto;
import pl.tpolgrabia.urbanexplorer.dto.wiki.app.WikiAppObject;
import pl.tpolgrabia.urbanexplorer.events.DataLoadingFinishEvent;
import pl.tpolgrabia.urbanexplorer.events.DataLoadingStartEvent;
import pl.tpolgrabia.urbanexplorer.events.RefreshEvent;
import pl.tpolgrabia.urbanexplorer.utils.*;
import java.io.*;
@ -39,7 +41,7 @@ import static android.content.Context.LOCATION_SERVICE;
/**
* A simple {@link Fragment} subclass.
*/
public class WikiLocationsFragment extends Fragment implements Refreshable {
public class WikiLocationsFragment extends Fragment {
private static final Logger lg = LoggerFactory.getLogger(WikiLocationsFragment.class);
private static final String CLASS_TAG = WikiLocationsFragment.class.getSimpleName();
@ -314,8 +316,8 @@ public class WikiLocationsFragment extends Fragment implements Refreshable {
}
}
@Override
public void refresh() {
@Subscribe
public void refresh(RefreshEvent event) {
appObjects.clear();
fetchWikiLocations();
}

View File

@ -35,7 +35,7 @@ public class SettingsUtils {
}
public static int getPanoramioBulkDataSize(Context ctx) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx.getActivity());
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
final String sValue = sharedPrefs.getString(AppConstants.PANORAMIO_BULK_SIZE_KEY,
String.valueOf(AppConstants.PANORAMIO_BULK_SIZE_DEF_VALUE));
try {