Further cleaning wiki fragment.

master
Tomasz Półgrabia 2016-09-24 11:28:41 +02:00
parent 92638eab02
commit 6374d983ba
3 changed files with 55 additions and 36 deletions

View File

@ -0,0 +1,26 @@
package pl.tpolgrabia.urbanexplorer.callbacks;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.tpolgrabia.urbanexplorer.fragments.WikiLocationsFragment;
/**
* Created by tpolgrabia on 24.09.16.
*/
public class WikiLocationGeoCoderCallback implements LocationGeoCoderCallback {
private static final Logger lg = LoggerFactory.getLogger(WikiLocationGeoCoderCallback.class);
private WikiLocationsFragment wikiLocationsFragment;
public WikiLocationGeoCoderCallback(WikiLocationsFragment wikiLocationsFragment) {
this.wikiLocationsFragment = wikiLocationsFragment;
}
@Override
public void callback(int code, String message, String googleStatus, String geocodedLocation) {
lg.debug("Geocoded result code {}, message {}, status: {}, value {}",
code, message, googleStatus, geocodedLocation);
wikiLocationsFragment.setCurrentGeocodedLocation(geocodedLocation);
wikiLocationsFragment.updateLocationInfo();
}
}

View File

@ -108,8 +108,6 @@ public class WikiLocationsFragment extends Fragment {
return;
}
MainActivity mainActivity = (MainActivity) getActivity();
if (lastFetchSize == 0) {
lg.trace("There is no results");
EventBus.getDefault().post(new DataLoadingFinishEvent(this));
@ -131,12 +129,6 @@ public class WikiLocationsFragment extends Fragment {
return;
}
if (getView() == null) {
lg.info("Wiki view is not yet initialized");
EventBus.getDefault().post(new DataLoadingFinishEvent(this));
return;
}
WikiUtils.fetchAppData(activity,
location.getLatitude(),
location.getLongitude(),
@ -160,37 +152,10 @@ public class WikiLocationsFragment extends Fragment {
}
private void updateGeocodedLocation() {
if (getActivity() == null) {
lg.debug("Activity is not attached");
return;
}
Location location = LocationUtils.getLastKnownLocation(getActivity());
if (location == null) {
lg.debug("Location is still not available");
return;
}
LocationUtils.getGeoCodedLocation(getActivity(), location.getLatitude(), location.getLongitude(), new LocationGeoCoderCallback() {
@Override
public void callback(int code, String message, String googleStatus, String geocodedLocation) {
lg.debug("Geocoded result code {}, message {}, status: {}, value {}",
code, message, googleStatus, geocodedLocation);
currentGeocodedLocation = geocodedLocation;
updateLocationInfo();
}
});
WikiUtils.getGeoCodedLocation(getActivity(), new WikiLocationGeoCoderCallback(this));
}
public void updateLocationInfo() {
final FragmentActivity activity = getActivity();
if (activity == null) {
lg.warn("Activity shouldn't be null. No headless fragment");
return;
}
currentLocation.setText(currentGeocodedLocation);
}
@ -231,4 +196,7 @@ public class WikiLocationsFragment extends Fragment {
this.appObjects = appObjects;
}
public void setCurrentGeocodedLocation(String currentGeocodedLocation) {
this.currentGeocodedLocation = currentGeocodedLocation;
}
}

View File

@ -1,6 +1,8 @@
package pl.tpolgrabia.urbanexplorer.utils;
import android.content.Context;
import android.location.Location;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;
import com.androidquery.AQuery;
import com.androidquery.callback.AjaxCallback;
@ -11,6 +13,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pl.tpolgrabia.urbanexplorer.callbacks.WikiLocationGeoCoderCallback;
import pl.tpolgrabia.urbanexplorer.callbacks.WikiResponseCallback;
import pl.tpolgrabia.urbanexplorer.callbacks.WikiStatus;
import pl.tpolgrabia.urbanexplorer.dto.wiki.app.WikiAppObject;
@ -21,6 +24,7 @@ import pl.tpolgrabia.urbanexplorer.dto.wiki.generator.WikiThumbnail;
import pl.tpolgrabia.urbanexplorer.dto.wiki.geosearch.WikiGeoObject;
import pl.tpolgrabia.urbanexplorer.dto.wiki.geosearch.WikiGeoResponse;
import pl.tpolgrabia.urbanexplorer.dto.wiki.geosearch.WikiGeoResponseCallback;
import pl.tpolgrabia.urbanexplorer.fragments.WikiLocationsFragment;
import java.util.*;
@ -350,4 +354,25 @@ public class WikiUtils {
callback
);
}
public static void getGeoCodedLocation(Context ctx, WikiLocationGeoCoderCallback clbk) {
if (ctx == null) {
lg.warn("Context is null - not available");
clbk.callback(-1, "ERROR", "ERROR", "Not available");
return;
}
Location location = LocationUtils.getLastKnownLocation(ctx);
if (location == null) {
lg.debug("Location is still not available");
return;
}
LocationUtils.getGeoCodedLocation(ctx,
location.getLatitude(),
location.getLongitude(),
clbk);
}
}