This repository has been archived on 2026-10-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
android-app/src/com/studentersamfundet/app/DataHandler.java
T

76 lines
1.8 KiB
Java

package com.studentersamfundet.app;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
public class DataHandler {
private List<Event> events = new LinkedList<Event>();
private List<News> news = new LinkedList<News>();
private Set<String> eventCategories = new TreeSet<String>();
public void insertEvent(String id,
String title,
String description,
String date,
String location,
String text,
String category,
String imageUri,
String priceReg,
String priceMem,
String ticketUri) {
int intId = Integer.parseInt(id);
if (getEvent(intId) != null)
return;
Event e = new Event(intId, title, description, date, location, text, category, imageUri);
events.add(e);
eventCategories.add(category);
}
public void insertNews(String title, String description, String content, String link, String pubDate) {
News n = new News(title, description, content, link, pubDate);
this.news.add(n);
}
public Event getEvent(int id) {
for (Event e : events) {
if (e.id == id)
return e;
}
return null;
}
public Event[] populateEventList(String category) {
LinkedList<Event> sorted = new LinkedList<Event>();
if (category.equals(Event.ALL)) {
return events.toArray(new Event[events.size()]);
}
for (Event event : events) {
if (category.equals(event.getCategory()))
sorted.add(event);
}
return sorted.toArray(new Event[sorted.size()]);
}
public News[] populateNewsList() {
return this.news.toArray(new News[this.news.size()]);
}
public String[] getEventCategories() {
String[] result = new String[eventCategories.size() + 1];
result[0] = Event.ALL;
int counter = 1;
for (String c : eventCategories) {
result[counter++] = c;
}
return result;
}
}