parent
cb109107ad
commit
983b39efdf
|
@ -133,10 +133,12 @@ public class MainActivity extends ActionBarActivity {
|
|||
switch (currentFragmentId) {
|
||||
case HOME_FRAGMENT_ID:
|
||||
// switch to home fragment
|
||||
setTitle("Panoramio search");
|
||||
Log.d(CLASS_TAG, "Switching to home fragment");
|
||||
switchFragment(new HomeFragment());
|
||||
break;
|
||||
case WIKI_FRAGMENT_ID:
|
||||
setTitle("Wiki search");
|
||||
// switch to wiki fragment
|
||||
Log.d(CLASS_TAG, "Switching to wiki fragment");
|
||||
switchFragment(new WikiLocationsFragment());
|
||||
|
|
|
@ -55,22 +55,22 @@ public class WikiLocationsFragment extends Fragment {
|
|||
// Inflate the layout for this fragment
|
||||
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);
|
||||
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
|
||||
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()));
|
||||
|
||||
if (location == null) {
|
||||
|
@ -79,8 +79,13 @@ public class WikiLocationsFragment extends Fragment {
|
|||
return;
|
||||
}
|
||||
|
||||
Editable search_limit = ((EditText) inflatedView.findViewById(R.id.wiki_search_limit)).getText();
|
||||
Editable radius_limit = ((EditText) inflatedView.findViewById(R.id.wiki_search_radius)).getText();
|
||||
if (getView() == null) {
|
||||
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(),
|
||||
|
@ -101,7 +106,7 @@ public class WikiLocationsFragment extends Fragment {
|
|||
|
||||
// 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() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
|
||||
|
@ -131,7 +136,7 @@ public class WikiLocationsFragment extends Fragment {
|
|||
.getJSONObject("pages")
|
||||
.getJSONObject(item.getPageId().toString())
|
||||
.getString("fullurl");
|
||||
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW,
|
||||
Uri.parse(wikiUrl));
|
||||
startActivity(intent);
|
||||
} 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
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateLocationInfo();
|
||||
fetchWikiLocations();
|
||||
}
|
||||
|
||||
public void updateLocationInfo() {
|
||||
|
|
|
@ -36,9 +36,4 @@
|
|||
|
||||
</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>
|
||||
|
|
Loading…
Reference in New Issue