package com.camilstaps.taize; import com.camilstaps.common.Date; import com.camilstaps.common.DatedString; import org.json.JSONException; import org.json.JSONObject; /** * A Podcast is linked to a Date and has a title and a URL * The title and the URL are held together in a JSON-encoded string, so that this class can extend DatedString * @author Camil Staps */ public class Podcast extends DatedString implements Comparable { public Podcast(Date date, String title, String url) throws JSONException { super(date, (new JSONObject()).put("title", title).put("url", url).toString()); } /** * Get the JSON object from the string * @return */ private JSONObject getJSONObject() { try { return new JSONObject(getString()); } catch (JSONException e) { return null; } } /** * Get the title of the podcast * @return */ public String getTitle() { try { return getJSONObject().getString("title"); } catch (JSONException e) { return ""; } } /** * Get the URL of the podcast * @return */ public String getUrl() { try { return getJSONObject().getString("url"); } catch (JSONException e) { return ""; } } /** * Compare with another podcast by date * @param another * @return */ @Override public int compareTo(Podcast another) { return getDate().compareTo(another.getDate()); } }