mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Add onSaveInstanceState()
This commit is contained in:
parent
9a8bbb4dd1
commit
2b4f29b625
2 changed files with 19 additions and 14 deletions
|
|
@ -30,6 +30,7 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
|
|||
|
||||
private NearbyAsyncTask nearbyAsyncTask;
|
||||
private NearbyAdapter mAdapter;
|
||||
private ListView listview;
|
||||
|
||||
private ProgressBar progressBar;
|
||||
private boolean isTaskRunning = false;
|
||||
|
|
@ -59,8 +60,18 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
listview = (ListView) getView().findViewById(R.id.listview);
|
||||
|
||||
if(savedInstanceState == null) {
|
||||
mLatestLocation = ((NearbyActivity) getActivity()).getmLatestLocation();
|
||||
|
||||
nearbyAsyncTask = new NearbyAsyncTask(this);
|
||||
nearbyAsyncTask.execute();
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
Log.d(TAG, "Saved instance state is null, populating ListView");
|
||||
}
|
||||
|
||||
// If we are returning here from a screen orientation
|
||||
// and the AsyncTask is still working, re-create and display the
|
||||
// progress dialog.
|
||||
|
|
@ -70,15 +81,8 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
mLatestLocation = ((NearbyActivity) getActivity()).getmLatestLocation();
|
||||
|
||||
nearbyAsyncTask = new NearbyAsyncTask(this);
|
||||
nearbyAsyncTask.execute();
|
||||
Log.d(TAG, "Adapter set to ListView");
|
||||
|
||||
public void onSaveInstanceState(Bundle outInstanceState) {
|
||||
outInstanceState.putInt("value", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -137,7 +141,7 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
|
|||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
mAdapter = new NearbyAdapter(getActivity(), places);
|
||||
ListView listview = (ListView) getView().findViewById(R.id.listview);
|
||||
|
||||
listview.setAdapter(mAdapter);
|
||||
|
||||
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
|
|
@ -256,7 +260,6 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
|
|||
for(int i = 0; i < 500; i++) {
|
||||
Place place = places.get(i);
|
||||
String distance = formatDistanceBetween(mLatestLocation, place.location);
|
||||
System.out.println("Sorted " + place.name + " at " + distance + " away.");
|
||||
place.setDistance(distance);
|
||||
}
|
||||
return places;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package fr.free.nrw.commons.nearby;
|
|||
|
||||
import android.net.Uri;
|
||||
import android.os.StrictMode;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
|
@ -12,6 +13,7 @@ import java.util.List;
|
|||
|
||||
public class NearbyPlaces {
|
||||
|
||||
private static final String TAG = "NearbyPlaces";
|
||||
static List<Place> places = null;
|
||||
|
||||
public static List<Place> get() {
|
||||
|
|
@ -30,6 +32,7 @@ public class NearbyPlaces {
|
|||
|
||||
boolean firstLine = true;
|
||||
String line;
|
||||
Log.d(TAG, "Reading from CSV file...");
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
|
||||
|
|
@ -39,7 +42,6 @@ public class NearbyPlaces {
|
|||
continue;
|
||||
}
|
||||
|
||||
System.out.println(line);
|
||||
String[] fields = line.split(",");
|
||||
String name = fields[0];
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue