Added error handling on refresh. Fixed a bug which made callback to CategoryChooser be always called on dismiss, not only when a category was actually chosen.

This commit is contained in:
Robert Kolner committed 2011-10-19 21:54:12 +02:00
1 parent 8aa1911bcb
commit 8d589b088d
5 files changed
+28 -15

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent">
android:layout_height="wrap_content">
<ListView android:id="@+id/choose_category_list"
android:layout_width="wrap_content"
+6 -6
View File
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20px"
android:paddingRight="20px"
android:paddingTop="3px"
android:paddingBottom="3px">
<TextView android:id="@+id/choose_category_list_row_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingLeft="20px"
android:paddingRight="20px"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:textSize="20sp" />
</FrameLayout>
+1
View File
@@ -10,4 +10,5 @@
<string name="menu_refresh">Oppdater</string>
<string name="menu_categories">Kategorier</string>
<string name="choose_category">Velg kategori</string>
<string name="error_loading">Vent til oppdateringen fullfører</string>
</resources>
@@ -16,7 +16,7 @@ import android.widget.AdapterView.OnItemClickListener;
public class ChooseCategoryDialog extends Dialog {
private final Callback callback;
private String chosenCategory = Event.ALL;
private String chosenCategory = null;
public interface Callback {
public void run(String ... message);
@@ -24,7 +24,9 @@ public class ChooseCategoryDialog extends Dialog {
private class OnDismiss implements OnDismissListener {
public void onDismiss(DialogInterface dialog) {
callback.run(chosenCategory);
if (chosenCategory != null) {
callback.run(chosenCategory);
}
}
}
@@ -167,9 +167,13 @@ public class ProgramListActivity extends BaseDnsActivity {
lc.execute();
}
};
Dialog dialog = new ChooseCategoryDialog(this, callback, dataHandler.getCategories());
dialog.show();
if (dataHandler != null) {
Dialog dialog = new ChooseCategoryDialog(this, callback, dataHandler.getCategories());
dialog.show();
} else {
Toast.makeText(this, R.string.error_loading, Toast.LENGTH_SHORT);
}
}
protected class ListCreator extends AsyncTask<Void, Void, Boolean> {
@@ -183,6 +187,10 @@ public class ProgramListActivity extends BaseDnsActivity {
@Override
protected void onPreExecute() {
if (forcedUpdate) {
dataHandler = null;
}
ListView list = (ListView)findViewById(R.id.event_list);
list.setVisibility(View.GONE);
@@ -196,9 +204,11 @@ public class ProgramListActivity extends BaseDnsActivity {
// YAY = Fetch the feed.
// NAY = Inform about no connection.
try {
NodeList itemNodes = feed.fetch(this.forcedUpdate);
dataHandler = parser.parse(itemNodes);
return true;
if (dataHandler == null) {
NodeList itemNodes = feed.fetch(this.forcedUpdate);
dataHandler = parser.parse(itemNodes);
}
return true;
} catch (IOException e) {
return false;