Archived
Added loading indicator.
This commit is contained in:
1 parent
4e10338d1f
commit
beec9498fb
3 files changed
+78
-28
No files matched your search
@@ -18,10 +18,22 @@
|
||||
android:layout_alignParentBottom="true" />
|
||||
|
||||
<!-- Program list -->
|
||||
<ListView android:id="@+id/event_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/header"
|
||||
android:layout_above="@id/footer" />
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/header"
|
||||
android:layout_above="@id/footer">
|
||||
|
||||
<ProgressBar android:id="@+id/event_list_progress_bar"
|
||||
android:layout_width="40px"
|
||||
android:layout_height="40px"
|
||||
android:layout_gravity="center"
|
||||
android:visibility="visible" />
|
||||
|
||||
<ListView android:id="@+id/event_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="invisible" />
|
||||
</FrameLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.studentersamfundet.app;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class DataHandler {
|
||||
public class DataHandler implements Serializable {
|
||||
private static final long serialVersionUID = 6697543939807512231L;
|
||||
private List<Event> events = new LinkedList<Event>();
|
||||
private Set<String> categories = new TreeSet<String>();
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.w3c.dom.NodeList;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -21,6 +22,7 @@ import android.view.View.OnLongClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -46,7 +48,8 @@ public class ProgramListActivity extends BaseDnsActivity {
|
||||
this.feed = new FeedFetcher(this, feedURL);
|
||||
this.parser = new XmlParser();
|
||||
|
||||
createList(Event.ALL, false);
|
||||
ListCreator lc = new ListCreator(Event.ALL, false);
|
||||
lc.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,7 +64,8 @@ public class ProgramListActivity extends BaseDnsActivity {
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_refresh:
|
||||
this.createList(Event.ALL, true);
|
||||
ListCreator lc = new ListCreator(Event.ALL, true);
|
||||
lc.execute();
|
||||
return true;
|
||||
|
||||
case R.id.menu_categories:
|
||||
@@ -73,25 +77,6 @@ public class ProgramListActivity extends BaseDnsActivity {
|
||||
}
|
||||
}
|
||||
|
||||
protected void createList(String category, boolean forcedUpdate) {
|
||||
// Do we have intarwebs?
|
||||
// YAY = Fetch the feed.
|
||||
// NAY = Inform about no connection.
|
||||
try {
|
||||
NodeList itemNodes = feed.fetch(forcedUpdate);
|
||||
dataHandler = parser.parse(itemNodes);
|
||||
|
||||
} catch (IOException e) {
|
||||
Toast toast = Toast.makeText(this, R.string.error_noconnection_noupdate, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
return;
|
||||
}
|
||||
|
||||
ListView list = (ListView)findViewById(R.id.event_list);
|
||||
|
||||
ListAdapter adapter = createAdapter(category);
|
||||
list.setAdapter(adapter);
|
||||
}
|
||||
|
||||
protected ListAdapter createAdapter(String category) {
|
||||
Event[] events = dataHandler.populateList(category);
|
||||
@@ -175,11 +160,62 @@ public class ProgramListActivity extends BaseDnsActivity {
|
||||
if (message.length < 1)
|
||||
message = new String[] { Event.ALL };
|
||||
|
||||
ProgramListActivity.this.createList(message[0], false);
|
||||
ListCreator lc = new ListCreator(message[0], false);
|
||||
lc.execute();
|
||||
}
|
||||
};
|
||||
|
||||
Dialog dialog = new ChooseCategoryDialog(this, callback, dataHandler.getCategories());
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
protected class ListCreator extends AsyncTask<Void, Void, Boolean> {
|
||||
protected String category;
|
||||
protected boolean forcedUpdate;
|
||||
|
||||
public ListCreator(String category, boolean forcedUpdate) {
|
||||
this.category = category;
|
||||
this.forcedUpdate = forcedUpdate;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
ListView list = (ListView)findViewById(R.id.event_list);
|
||||
list.setVisibility(View.GONE);
|
||||
|
||||
ProgressBar pb = (ProgressBar)findViewById(R.id.event_list_progress_bar);
|
||||
pb.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void ... v) {
|
||||
// Do we have intarwebs?
|
||||
// YAY = Fetch the feed.
|
||||
// NAY = Inform about no connection.
|
||||
try {
|
||||
NodeList itemNodes = feed.fetch(this.forcedUpdate);
|
||||
dataHandler = parser.parse(itemNodes);
|
||||
return true;
|
||||
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result) {
|
||||
if (result) {
|
||||
ListView list = (ListView)findViewById(R.id.event_list);
|
||||
ListAdapter adapter = createAdapter(this.category);
|
||||
list.setAdapter(adapter);
|
||||
list.setVisibility(View.VISIBLE);
|
||||
|
||||
ProgressBar pb = (ProgressBar)findViewById(R.id.event_list_progress_bar);
|
||||
pb.setVisibility(View.GONE);
|
||||
} else {
|
||||
Toast toast = Toast.makeText(ProgramListActivity.this, R.string.error_noconnection_noupdate, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user