Added an activity for showing news.

This commit is contained in:
Robert Kolner committed 2012-03-26 14:15:32 +02:00
1 parent 7526b27d18
commit 3e0bbb2d97
5 files changed
+132 -9

No files matched your search

+1
View File
@@ -18,6 +18,7 @@
</intent-filter>
</activity>
<activity android:name=".ui.EventViewActivity"></activity>
<activity android:name=".ui.NewsViewActivity"></activity>
<activity android:name=".ui.JoinUsActivity"></activity>
<activity android:name=".ui.lists.EventListActivity"></activity>
<activity android:name=".ui.lists.EventListTicketsActivity"></activity>
+37
View File
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Header -->
<include layout="@layout/header"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentTop="true"/>
<!-- The event -->
<TextView android:id="@+id/news_view_title"
style="@style/BigHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/header" />
<TextView android:id="@+id/news_view_datetime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/news_view_title"
android:paddingLeft="5dp"
android:paddingRight="5dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/news_view_datetime">
<TextView android:id="@+id/news_view_description"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
</RelativeLayout>
+25 -5
View File
@@ -8,11 +8,11 @@ import java.util.Date;
public class News implements Serializable {
private static final long serialVersionUID = 4015441794784305793L;
public String title;
public String description;
public String content;
public String link;
public Date pubDate;
private String title;
private String description;
private String content;
private String link;
private Date pubDate;
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -28,4 +28,24 @@ public class News implements Serializable {
this.pubDate = null;
}
}
public String getTitle() {
return this.title;
}
public String getDescription() {
return this.description;
}
public String getContent() {
return this.content;
}
public String getLink() {
return this.link;
}
public Date getPubDate() {
return this.pubDate;
}
}
@@ -0,0 +1,53 @@
package com.studentersamfundet.app.ui;
import java.text.SimpleDateFormat;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.util.Linkify;
import android.widget.TextView;
import com.studentersamfundet.app.News;
import com.studentersamfundet.app.R;
public class NewsViewActivity extends BaseDnsActivity {
News article;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.news_view);
Intent intent = getIntent();
this.article = (News)intent.getSerializableExtra("news");
final News a = this.article;
if (a == null) {
throw new Error("This should NEVER happen");
}
TextView title = (TextView) findViewById(R.id.news_view_title);
TextView description = (TextView) findViewById(R.id.news_view_description);
TextView datetime = (TextView) findViewById(R.id.news_view_datetime);
title.setText(Html.fromHtml(a.getTitle()));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
datetime.setText(a.getPubDate() != null ? dateFormat.format(a.getPubDate()) : "");
StringBuilder sb = new StringBuilder();
if (a.getDescription().length() > 0) {
sb.append("<b>");
sb.append(a.getDescription());
sb.append("</b><br/><br/>");
}
if (a.getContent().length() > 0) {
sb.append(a.getContent());
}
description.setText(Html.fromHtml(sb.toString()));
Linkify.addLinks(description, Linkify.ALL);
}
}
@@ -4,10 +4,13 @@ import java.text.SimpleDateFormat;
import com.studentersamfundet.app.News;
import com.studentersamfundet.app.R;
import com.studentersamfundet.app.ui.NewsViewActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
@@ -45,17 +48,26 @@ public class NewsListActivity extends BaseListActivity {
row = (ViewGroup)convertView;
}
News article = news[position];
final News article = news[position];
TextView title = (TextView)row.findViewById(R.id.news_list_row_title);
TextView description = (TextView)row.findViewById(R.id.news_list_row_desc);
TextView footer = (TextView)row.findViewById(R.id.news_list_row_byline);
title.setText(article.title);
description.setText(article.description);
title.setText(article.getTitle());
description.setText(article.getDescription());
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm, d. MMMM y");
footer.setText(sdf.format(article.pubDate));
footer.setText(sdf.format(article.getPubDate()));
row.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(NewsListActivity.this, NewsViewActivity.class);
intent.putExtra("news", article);
startActivity(intent);
}
});
return row;
}