From 7932de4e76b613f9d7cbb38244ef22cc89f45a97 Mon Sep 17 00:00:00 2001 From: Robert Kolner Date: Sat, 9 Feb 2013 01:21:35 +0100 Subject: [PATCH] Many minor changes. --- .../studentersamfundet/app/DataHandler.java | 9 ++++---- src/com/studentersamfundet/app/Event.java | 19 +++++++++++---- .../app/JSONParserProgram.java | 23 ++++++++++++------- .../app/network/ImageLoader.java | 11 +++++---- .../app/ui/lists/EventListActivity.java | 3 ++- 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/com/studentersamfundet/app/DataHandler.java b/src/com/studentersamfundet/app/DataHandler.java index 3432985..885ad32 100644 --- a/src/com/studentersamfundet/app/DataHandler.java +++ b/src/com/studentersamfundet/app/DataHandler.java @@ -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 events = new LinkedHashSet(); private Collection news = new LinkedList(); @@ -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); diff --git a/src/com/studentersamfundet/app/Event.java b/src/com/studentersamfundet/app/Event.java index bece380..8d74fe1 100644 --- a/src/com/studentersamfundet/app/Event.java +++ b/src/com/studentersamfundet/app/Event.java @@ -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; diff --git a/src/com/studentersamfundet/app/JSONParserProgram.java b/src/com/studentersamfundet/app/JSONParserProgram.java index 05ea03a..bffa502 100644 --- a/src/com/studentersamfundet/app/JSONParserProgram.java +++ b/src/com/studentersamfundet/app/JSONParserProgram.java @@ -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, diff --git a/src/com/studentersamfundet/app/network/ImageLoader.java b/src/com/studentersamfundet/app/network/ImageLoader.java index 653e212..5bfb055 100644 --- a/src/com/studentersamfundet/app/network/ImageLoader.java +++ b/src/com/studentersamfundet/app/network/ImageLoader.java @@ -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 { 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 { 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; } diff --git a/src/com/studentersamfundet/app/ui/lists/EventListActivity.java b/src/com/studentersamfundet/app/ui/lists/EventListActivity.java index 943bfa3..05256d6 100644 --- a/src/com/studentersamfundet/app/ui/lists/EventListActivity.java +++ b/src/com/studentersamfundet/app/ui/lists/EventListActivity.java @@ -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: */