parent
cb109107ad
commit
983b39efdf
|
@ -133,10 +133,12 @@ public class MainActivity extends ActionBarActivity {
|
||||||
switch (currentFragmentId) {
|
switch (currentFragmentId) {
|
||||||
case HOME_FRAGMENT_ID:
|
case HOME_FRAGMENT_ID:
|
||||||
// switch to home fragment
|
// switch to home fragment
|
||||||
|
setTitle("Panoramio search");
|
||||||
Log.d(CLASS_TAG, "Switching to home fragment");
|
Log.d(CLASS_TAG, "Switching to home fragment");
|
||||||
switchFragment(new HomeFragment());
|
switchFragment(new HomeFragment());
|
||||||
break;
|
break;
|
||||||
case WIKI_FRAGMENT_ID:
|
case WIKI_FRAGMENT_ID:
|
||||||
|
setTitle("Wiki search");
|
||||||
// switch to wiki fragment
|
// switch to wiki fragment
|
||||||
Log.d(CLASS_TAG, "Switching to wiki fragment");
|
Log.d(CLASS_TAG, "Switching to wiki fragment");
|
||||||
switchFragment(new WikiLocationsFragment());
|
switchFragment(new WikiLocationsFragment());
|
||||||
|
|
|
@ -55,22 +55,22 @@ public class WikiLocationsFragment extends Fragment {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
final View inflatedView = inflater.inflate(R.layout.fragment_wiki_locations, container, false);
|
final View inflatedView = inflater.inflate(R.layout.fragment_wiki_locations, container, false);
|
||||||
|
|
||||||
inflatedView.findViewById(R.id.wiki_fetch_places).setOnClickListener(
|
|
||||||
new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
// TODO replace this
|
|
||||||
Toast.makeText(getActivity(), "Fetch wiki objects", Toast.LENGTH_SHORT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
locationService = (LocationManager) getActivity().getSystemService(LOCATION_SERVICE);
|
locationService = (LocationManager) getActivity().getSystemService(LOCATION_SERVICE);
|
||||||
currentLocation = (TextView) inflatedView.findViewById(R.id.wiki_current_location);
|
currentLocation = (TextView) inflatedView.findViewById(R.id.wiki_current_location);
|
||||||
fetchPlaces = (Button)inflatedView.findViewById(R.id.wiki_fetch_places);
|
|
||||||
fetchPlaces.setOnClickListener(new View.OnClickListener() {
|
MainActivity mainActivity = (MainActivity) getActivity();
|
||||||
|
mainActivity.getLocationCallback().addCallback(new StandardLocationListenerCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void callback(Location location) {
|
||||||
|
updateLocationInfo();
|
||||||
|
fetchWikiLocations();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return inflatedView;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fetchWikiLocations() {
|
||||||
final Location location = locationService.getLastKnownLocation(LocationUtils.getDefaultLocation(getActivity()));
|
final Location location = locationService.getLastKnownLocation(LocationUtils.getDefaultLocation(getActivity()));
|
||||||
|
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
|
@ -79,8 +79,13 @@ public class WikiLocationsFragment extends Fragment {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Editable search_limit = ((EditText) inflatedView.findViewById(R.id.wiki_search_limit)).getText();
|
if (getView() == null) {
|
||||||
Editable radius_limit = ((EditText) inflatedView.findViewById(R.id.wiki_search_radius)).getText();
|
Log.i(CLASS_TAG, "Wiki view is not yet initialized");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Editable search_limit = ((EditText) getView().findViewById(R.id.wiki_search_limit)).getText();
|
||||||
|
Editable radius_limit = ((EditText) getView().findViewById(R.id.wiki_search_radius)).getText();
|
||||||
|
|
||||||
|
|
||||||
WikiUtils.fetchAppData(getActivity(),
|
WikiUtils.fetchAppData(getActivity(),
|
||||||
|
@ -101,7 +106,7 @@ public class WikiLocationsFragment extends Fragment {
|
||||||
|
|
||||||
// TODO on success
|
// TODO on success
|
||||||
|
|
||||||
ListView locations = (ListView) inflatedView.findViewById(R.id.wiki_places);
|
ListView locations = (ListView) getView().findViewById(R.id.wiki_places);
|
||||||
locations.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
locations.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
|
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
|
||||||
|
@ -131,7 +136,7 @@ public class WikiLocationsFragment extends Fragment {
|
||||||
.getJSONObject("pages")
|
.getJSONObject("pages")
|
||||||
.getJSONObject(item.getPageId().toString())
|
.getJSONObject(item.getPageId().toString())
|
||||||
.getString("fullurl");
|
.getString("fullurl");
|
||||||
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
|
Intent intent = new Intent(Intent.ACTION_VIEW,
|
||||||
Uri.parse(wikiUrl));
|
Uri.parse(wikiUrl));
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
@ -147,25 +152,13 @@ public class WikiLocationsFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
MainActivity mainActivity = (MainActivity) getActivity();
|
|
||||||
mainActivity.getLocationCallback().addCallback(new StandardLocationListenerCallback() {
|
|
||||||
@Override
|
|
||||||
public void callback(Location location) {
|
|
||||||
updateLocationInfo();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return inflatedView;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
updateLocationInfo();
|
updateLocationInfo();
|
||||||
|
fetchWikiLocations();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateLocationInfo() {
|
public void updateLocationInfo() {
|
||||||
|
|
|
@ -36,9 +36,4 @@
|
||||||
|
|
||||||
</ListView>
|
</ListView>
|
||||||
|
|
||||||
<Button android:id="@+id/wiki_fetch_places"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Fetch wiki places in the neighbourhood"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
Loading…
Reference in New Issue