Added date formatting

This commit is contained in:
Robert Kolner committed 2011-10-19 21:33:35 +02:00
1 parent da89841001
commit 8aa1911bcb
4 files changed
+38 -29

No files matched your search

+12 -10
View File
@@ -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));
}
}
@@ -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;
@@ -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();
@@ -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;
}
});