From 8aa1911bcb3799afa05cbf2b93af2c8833b42e6b Mon Sep 17 00:00:00 2001 From: Robert Kolner Date: Wed, 19 Oct 2011 21:33:35 +0200 Subject: [PATCH] Added date formatting --- src/com/studentersamfundet/app/Event.java | 22 ++++++----- .../studentersamfundet/app/FeedFetcher.java | 2 +- .../app/ui/EventViewActivity.java | 6 ++- .../app/ui/ProgramListActivity.java | 37 ++++++++++--------- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/com/studentersamfundet/app/Event.java b/src/com/studentersamfundet/app/Event.java index 2b4562d..d5edc4d 100644 --- a/src/com/studentersamfundet/app/Event.java +++ b/src/com/studentersamfundet/app/Event.java @@ -1,15 +1,20 @@ package com.studentersamfundet.app; import java.io.Serializable; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; public class Event implements Serializable { private static final long serialVersionUID = 1L; public static final String ALL = "Alle"; + private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + public int id; public String title; public String description; - public String date; + public Date date; public String location; public String text; public String category; @@ -25,21 +30,18 @@ public class Event implements Serializable { this.id = id; this.title = title.trim(); this.description = (description == null) ? "" : description.trim(); - this.date = (date == null) ? "" : date.trim(); this.location = (location == null) ? "" : location.trim(); this.text = (text == null) ? "" : text.trim(); this.category = (category == null) ? "" : category.trim(); + + try { + this.date = (date == null) ? null : dateFormat.parse(date.trim()); + } catch (ParseException e) { + this.date = null; + } } public String toString() { return this.title; } - - public String getDateString() { - String date = this.date; - - String month = date.substring(5, 7); - String day = date.substring(8, 10); - return Utils.stripNullFromDay(day) + ". " + Utils.intToMonthStr(Integer.parseInt(month)); - } } diff --git a/src/com/studentersamfundet/app/FeedFetcher.java b/src/com/studentersamfundet/app/FeedFetcher.java index 985d36e..e83b84c 100644 --- a/src/com/studentersamfundet/app/FeedFetcher.java +++ b/src/com/studentersamfundet/app/FeedFetcher.java @@ -110,7 +110,7 @@ public class FeedFetcher { private boolean doesFileNeedUpdate(Context c) throws IOException { /** Maximum amount of time before the file needs updating, in ms: */ - final long maxInterval = 1000 * 60 * 60 * 24 * 7; // one week + final long maxInterval = 1000 * 60 * 60; // one hour File file = c.getFileStreamPath(LOCAL_FILENAME); if (! file.exists()) return true; diff --git a/src/com/studentersamfundet/app/ui/EventViewActivity.java b/src/com/studentersamfundet/app/ui/EventViewActivity.java index faf178c..93365b5 100644 --- a/src/com/studentersamfundet/app/ui/EventViewActivity.java +++ b/src/com/studentersamfundet/app/ui/EventViewActivity.java @@ -1,5 +1,7 @@ package com.studentersamfundet.app.ui; +import java.text.SimpleDateFormat; + import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -34,7 +36,9 @@ public class EventViewActivity extends BaseDnsActivity { title.setText(Html.fromHtml(e.title)); location.setText(Html.fromHtml(e.location)); - datetime.setText(Html.fromHtml(e.date)); + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + datetime.setText(e.date != null ? dateFormat.format(e.date) : ""); StringBuilder sb = new StringBuilder(); diff --git a/src/com/studentersamfundet/app/ui/ProgramListActivity.java b/src/com/studentersamfundet/app/ui/ProgramListActivity.java index 06cff21..0e647a3 100644 --- a/src/com/studentersamfundet/app/ui/ProgramListActivity.java +++ b/src/com/studentersamfundet/app/ui/ProgramListActivity.java @@ -1,12 +1,12 @@ package com.studentersamfundet.app.ui; import java.io.IOException; -import java.text.ParseException; import java.text.SimpleDateFormat; import org.w3c.dom.NodeList; import android.app.Dialog; +import android.content.ActivityNotFoundException; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; @@ -98,8 +98,9 @@ public class ProgramListActivity extends BaseDnsActivity { TextView titleView = (TextView) row.findViewById(R.id.event_list_row_text); titleView.setText(Html.fromHtml(e.title)); + SimpleDateFormat dateFormat = new SimpleDateFormat("d. MMMM"); TextView dateView = (TextView) row.findViewById(R.id.event_list_row_date); - dateView.setText(Html.fromHtml(e.getDateString())); + dateView.setText(dateFormat.format(e.date)); row.setOnClickListener(new OnClickListener() { @@ -114,24 +115,26 @@ public class ProgramListActivity extends BaseDnsActivity { row.setOnLongClickListener(new OnLongClickListener() { public boolean onLongClick(View v) { - long startDate = 0; + if (e.date == null) + return false; + + long startDate = e.date.getTime(); + try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - startDate = sdf.parse(e.date).getTime(); - } catch (ParseException e) { + Intent intent = new Intent(Intent.ACTION_EDIT); + intent.setType("vnd.android.cursor.item/event"); + intent.putExtra("title", e.title); + intent.putExtra("beginTime", startDate); + intent.putExtra("endTime", startDate + (2*60*60*1000)); // Two hours + intent.putExtra("allDay", false); + intent.putExtra("eventLocation", e.location); + intent.putExtra("reminder", false); + + startActivity(intent); + return true; + } catch (ActivityNotFoundException e) { return false; } - - Intent intent = new Intent(Intent.ACTION_EDIT); - intent.setType("vnd.android.cursor.item/event"); - intent.putExtra("title", e.title); - intent.putExtra("beginTime", startDate); - intent.putExtra("endTime", startDate + (2*60*60*1000)); // Two hours - intent.putExtra("allDay", false); - intent.putExtra("eventLocation", e.location); - intent.putExtra("reminder", false); - startActivity(intent); - return true; } });