Many minor changes.

This commit is contained in:
Robert Kolner committed 2013-02-09 01:21:35 +01:00
1 parent ddaf0a40c9
commit 7932de4e76
5 files changed
+43 -22

No files matched your search

@@ -11,6 +11,7 @@ import android.util.Log;
public class DataHandler implements Serializable {
private static final long serialVersionUID = 6787541405689146002L;
private static final String TAG = DataHandler.class.getName();
private Collection<Event> events = new LinkedHashSet<Event>();
private Collection<News> news = new LinkedList<News>();
@@ -24,13 +25,14 @@ public class DataHandler implements Serializable {
String text,
String category,
String imageUri,
String thumbUri,
String priceReg,
String priceMem,
String ticketUriStr,
String fbUriStr) {
int intId = Integer.parseInt(id);
Event event = new Event(intId, title, description, date, location, text, category, imageUri);
Event event = new Event(intId, title, description, date, location, text, category);
int regularPrice = 0;
int memberPrice = 0;
@@ -39,12 +41,11 @@ public class DataHandler implements Serializable {
memberPrice = Integer.parseInt(priceMem);
} catch (NumberFormatException e1) {
/* Do nothing. */
Log.w("TAG", e1.toString());
Log.w(TAG, e1.toString());
}
event.setFbUriStr(fbUriStr);
event.setTicketsInfo(regularPrice, memberPrice, ticketUriStr);
event.setImage(imageUri, thumbUri);
events.add(event);
eventCategories.add(category);
+14 -5
View File
@@ -17,7 +17,9 @@ public class Event implements Serializable {
private String location;
private String text;
private String category;
private String image;
private String thumb;
private int regularPrice;
private int memberPrice;
@@ -31,15 +33,13 @@ public class Event implements Serializable {
String date,
String location,
String text,
String category,
String image) {
String category) {
this.id = id;
this.title = title.trim();
this.description = (description == null) ? "" : description.trim();
this.location = (location == null) ? "" : location.trim();
this.text = (text == null) ? "" : text.trim();
this.category = (category == null) ? "" : category.trim();
this.image = image;
try {
this.date = (date == null) ? null : new Date(1000 * Long.parseLong(date.trim()));
@@ -79,11 +79,15 @@ public class Event implements Serializable {
return Uri.parse("http://studentersamfundet.no/vis.php?ID=" + this.id);
}
public Uri getImageUri(int size) {
public Uri getImageUri() {
if (this.id <= 0) {
return null;
}
return Uri.parse(image);
return Uri.parse(this.image);
}
public Uri getThumbnail() {
return Uri.parse(this.thumb);
}
public String getPriceString() {
@@ -106,6 +110,11 @@ public class Event implements Serializable {
return ticketUri;
}
public void setImage(String imageUri, String thumbUri) {
this.image = imageUri;
this.thumb = thumbUri;
}
public void setTicketsInfo(int regularPrice, int memberPrice, String ticketUri) {
this.regularPrice = regularPrice;
this.memberPrice = memberPrice;
@@ -31,6 +31,7 @@ public class JSONParserProgram implements IParser {
String description = "";
String text = "";
String image = "";
String thumb = "";
String date = "";
String location = "";
@@ -57,16 +58,21 @@ public class JSONParserProgram implements IParser {
description = tempJSON.getString("excerpt");
date = tempJSON.getString("date");
text = tempJSON.getString("content");
image = tempJSON.getString("thumbnail");
category = tempJSON.getString("event");
tempJSON = tempJSON.getJSONObject("custom_fields");
ticketUrl = tempJSON.getJSONArray("_neuf_events_bs_url").getString(0);
fbUrl = tempJSON.getJSONArray("_neuf_events_fb_url").getString(0);
location = tempJSON.getJSONArray("_neuf_events_venue").getString(0);
priceReg = tempJSON.getJSONArray("_neuf_events_price_regular").getString(0);
priceMem = tempJSON.getJSONArray("_neuf_events_price_member").getString(0);
date = tempJSON.getJSONArray("_neuf_events_starttime").getString(0);
JSONObject custom = tempJSON.getJSONObject("custom_fields");
ticketUrl = custom.getJSONArray("_neuf_events_bs_url").getString(0);
fbUrl = custom.getJSONArray("_neuf_events_fb_url").getString(0);
location = custom.getJSONArray("_neuf_events_venue").getString(0);
priceReg = custom.getJSONArray("_neuf_events_price_regular").getString(0);
priceMem = custom.getJSONArray("_neuf_events_price_member").getString(0);
date = custom.getJSONArray("_neuf_events_starttime").getString(0);
JSONArray attachments = tempJSON.getJSONArray("attachments");
JSONObject images = attachments.getJSONObject(0).getJSONObject("images");
image = images.getJSONObject("full").getString("url");
thumb = images.getJSONObject("thumbnail").getString("url");
// This is as ugly as it gets. Refactor?
dh.insertEvent(id,
@@ -77,6 +83,7 @@ public class JSONParserProgram implements IParser {
text,
category,
image,
thumb,
priceReg,
priceMem,
ticketUrl,
@@ -3,6 +3,7 @@ package com.studentersamfundet.app.network;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.security.InvalidParameterException;
import java.util.concurrent.ConcurrentHashMap;
@@ -27,7 +28,7 @@ public class ImageLoader extends AsyncTask<String, Void, Drawable> {
this.position = position;
this.imageId = imageViewId;
}
@Override
protected Drawable doInBackground(String... params) {
if (params.length > 1)
@@ -37,21 +38,23 @@ public class ImageLoader extends AsyncTask<String, Void, Drawable> {
if (d != null)
return d;
try {
HttpURLConnection con = (HttpURLConnection)new URL(params[0]).openConnection();
String url = URI.create(params[0]).toASCIIString();
HttpURLConnection con = (HttpURLConnection)new URL(url).openConnection();
InputStream is = con.getInputStream();
//
if (is == null)
return null;
d = Drawable.createFromStream(is, params[0].toString());
d = Drawable.createFromStream(is, url);
if (d == null)
return null;
cache.put(params[0], d);
} catch (IOException e) {
Log.e("DNSapp", "An exception has occured while downloading images!");
Log.e("DNSapp", "An exception has occured while downloading images: " +e.getLocalizedMessage());
}
return d;
}
@@ -96,9 +96,10 @@ public class EventListActivity extends BaseListActivity {
final Event e = getItem(position);
/* Set images: */
String thumbnailUri = e.getThumbnail().toString();
ImageLoader loader = new ImageLoader(parent, position, R.id.event_list_row_image);
loader.setProgressbar(R.id.event_list_row_image_pb);
loader.execute(e.getImageUri(imageSize).toString());
loader.execute(thumbnailUri);
/* Set text: */