import android.net.http.AndroidHttpClient;
import android.os.AsyncTask;
import android.os.Bundle;
-import android.os.Parcelable;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
public class OverviewFragment extends ListFragment {
private static final String TAG = "OverviewFragment";
- private Parcelable mListState;
@Override
public void onCreate(final Bundle savedInstanceState) {
(WeatherInformationApplication) getActivity().getApplication();
application.setForecast(forecast);
}
-
- this.mListState = savedInstanceState.getParcelable("ListState");
}
this.setHasOptionsMenu(false);
- final OverviewAdapter adapter = new OverviewAdapter(
- this.getActivity(), R.layout.weather_main_entry_list);
-
// TODO: string static resource
this.setEmptyText("No data available");
-
- this.setListAdapter(adapter);
- this.setListShown(true);
- this.setListShownNoAnimation(true);
+ this.setListShownNoAnimation(false);
}
@Override
task.execute(weatherLocation.getLatitude(), weatherLocation.getLongitude());
// TODO: make sure thread UI keeps running in parallel after that. I guess.
}
-
- // TODO: could mListState be an old value? It is just updated in onActivityCreated method... :/
- // What is this for? And be careful, it runs at the same time as updateUI!!! :(
- if (this.mListState != null) {
- this.getListView().onRestoreInstanceState(this.mListState);
- }
}
@Override
savedInstanceState.putSerializable("Forecast", forecast);
}
- this.mListState = this.getListView().onSaveInstanceState();
- savedInstanceState.putParcelable("ListState", this.mListState);
-
super.onSaveInstanceState(savedInstanceState);
}
// 5. Update UI.
- this.setListAdapter(null);
adapter.addAll(entries);
this.setListAdapter(adapter);
}
// have two progress dialogs... How may I solve this problem? I HATE ANDROID.
private class OverviewTask extends AsyncTask<Object, Void, Forecast> {
private final Fragment localFragment;
- final CustomHTTPClient weatherHTTPClient;
- final ServiceParser weatherService;
+ private final CustomHTTPClient weatherHTTPClient;
+ private final ServiceParser weatherService;
public OverviewTask(final Fragment fragment, final CustomHTTPClient weatherHTTPClient,
final ServiceParser weatherService) {
}
@Override
+ protected void onPreExecute() {
+ final OverviewFragment overview = (OverviewFragment) this.localFragment;
+ overview.setListAdapter(null);
+ // TODO: string static resource
+ overview.setEmptyText("No data available");
+ overview.setListShownNoAnimation(false);
+ }
+
+ @Override
protected Forecast doInBackground(final Object... params) {
Log.i(TAG, "OverviewFragment doInBackground");
final double latitude = (Double) params[0];
protected void onPostExecute(final Forecast forecast) {
// TODO: Is AsyncTask calling this method even when RunTimeException in doInBackground method?
// I hope so, otherwise I must catch(Throwable) in doInBackground method :(
+ final OverviewFragment overview = (OverviewFragment) this.localFragment;
+ // TODO: string static resource
+ overview.setEmptyText("Error trying to download remote data");
+ overview.setListShownNoAnimation(true);
+
if (forecast == null) {
// Nothing to do
// TODO: Should I show some error message? I am not doing it on WP8 Should I do it on WP8?