Archived
Categories are now fully working.
This commit is contained in:
1 parent
104f780b3f
commit
911c2edd10
3 files changed
+17
-12
No files matched your search
@@ -1,10 +1,14 @@
|
||||
package com.studentersamfundet.app;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class DataHandler {
|
||||
private LinkedList<Event> events = new LinkedList<Event>();
|
||||
|
||||
private List<Event> events = new LinkedList<Event>();
|
||||
private Set<String> categories = new TreeSet<String>();
|
||||
|
||||
public void insert(String id, String title, String description, String date, String location, String text, String category) {
|
||||
int intId = Integer.parseInt(id);
|
||||
if (get(intId) != null)
|
||||
@@ -12,6 +16,7 @@ public class DataHandler {
|
||||
|
||||
Event e = new Event(intId, title, description, date, location, text, category);
|
||||
events.add(e);
|
||||
categories.add(category);
|
||||
}
|
||||
|
||||
public Event get(int id) {
|
||||
@@ -35,4 +40,8 @@ public class DataHandler {
|
||||
}
|
||||
return sorted.toArray(new Event[sorted.size()]);
|
||||
}
|
||||
|
||||
public String[] getCategories() {
|
||||
return categories.toArray(new String[categories.size()]);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public class ChooseCategoryDialog extends Dialog {
|
||||
}
|
||||
}
|
||||
|
||||
public ChooseCategoryDialog(Context context, Callback callback) {
|
||||
public ChooseCategoryDialog(Context context, Callback callback, String[] categories) {
|
||||
super(context);
|
||||
|
||||
if (callback == null)
|
||||
@@ -39,15 +39,10 @@ public class ChooseCategoryDialog extends Dialog {
|
||||
setContentView(R.layout.choose_category_dialog);
|
||||
setTitle("Choose category");
|
||||
setOnDismissListener(new OnDismiss());
|
||||
populateList(context);
|
||||
populateList(context, categories);
|
||||
}
|
||||
|
||||
private void populateList(Context context) {
|
||||
final String[] categories = new String[] {
|
||||
Event.ALL,
|
||||
"film"
|
||||
};
|
||||
|
||||
private void populateList(Context context, final String[] categories) {
|
||||
ListView list = (ListView)findViewById(R.id.choose_category_list);
|
||||
list.setAdapter(new ArrayAdapter<String>(context, R.layout.choose_category_list_row, R.id.choose_category_list_row_text, categories));
|
||||
list.setOnItemClickListener(new OnItemClickListener() {
|
||||
|
||||
@@ -143,15 +143,16 @@ public class ProgramListActivity extends BaseDnsActivity {
|
||||
}
|
||||
|
||||
protected void createCategoryDialog() {
|
||||
Dialog dialog = new ChooseCategoryDialog(this, new Callback() {
|
||||
Callback callback = new Callback() {
|
||||
public void run(String... message) {
|
||||
if (message.length < 1)
|
||||
message = new String[] { Event.ALL };
|
||||
|
||||
ProgramListActivity.this.createList(message[0], false);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Dialog dialog = new ChooseCategoryDialog(this, callback, dataHandler.getCategories());
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user