Archived
Added news.
This commit is contained in:
1 parent
542a8e891e
commit
e13c92ecf7
8 files changed
+116
-18
No files matched your search
+3
-2
@@ -19,8 +19,9 @@
|
||||
</activity>
|
||||
<activity android:name=".ui.EventViewActivity"></activity>
|
||||
<activity android:name=".ui.JoinUsActivity"></activity>
|
||||
<activity android:name=".ui.EventListActivity"></activity>
|
||||
<activity android:name=".ui.EventListTicketsActivity"></activity>
|
||||
<activity android:name=".ui.lists.EventListActivity"></activity>
|
||||
<activity android:name=".ui.lists.EventListTicketsActivity"></activity>
|
||||
<activity android:name=".ui.lists.NewsListActivity"></activity>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="3dp"
|
||||
android:paddingBottom="3dp">
|
||||
|
||||
<TextView android:id="@+id/news_list_row_title"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true" />
|
||||
|
||||
<TextView android:id="@+id/news_list_row_desc"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@id/news_list_row_title" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.studentersamfundet.app.ui;
|
||||
|
||||
import com.studentersamfundet.app.R;
|
||||
import com.studentersamfundet.app.ui.lists.EventListActivity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
|
||||
@@ -10,10 +10,12 @@ import android.view.View.OnTouchListener;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.Animation;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.studentersamfundet.app.FeedFetcher;
|
||||
import com.studentersamfundet.app.R;
|
||||
import com.studentersamfundet.app.ui.lists.EventListActivity;
|
||||
import com.studentersamfundet.app.ui.lists.EventListTicketsActivity;
|
||||
import com.studentersamfundet.app.ui.lists.NewsListActivity;
|
||||
|
||||
public class DnsActivity extends BaseDnsActivity {
|
||||
public static final String feedURL = "http://studentersamfundet.no/rss/lars_program_feed.php";
|
||||
@@ -156,7 +158,8 @@ public class DnsActivity extends BaseDnsActivity {
|
||||
}
|
||||
|
||||
public void newsButton(View v) {
|
||||
Toast.makeText(this, "Not implemented (yet!)", Toast.LENGTH_SHORT).show();
|
||||
Intent intent = setupNewIntent(NewsListActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public void joinButton(View v) {
|
||||
|
||||
+20
-10
@@ -1,4 +1,4 @@
|
||||
package com.studentersamfundet.app.ui;
|
||||
package com.studentersamfundet.app.ui.lists;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -10,11 +10,13 @@ import com.studentersamfundet.app.FeedFetcher;
|
||||
import com.studentersamfundet.app.IRSSParser;
|
||||
import com.studentersamfundet.app.R;
|
||||
import com.studentersamfundet.app.RSSParserProgram;
|
||||
import com.studentersamfundet.app.ui.BaseDnsActivity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
@@ -22,7 +24,7 @@ import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
public abstract class BaseListActivity extends BaseDnsActivity {
|
||||
private DataHandler dataHandler;
|
||||
private DataHandler datahandler;
|
||||
private FeedFetcher feed;
|
||||
private IRSSParser parser;
|
||||
|
||||
@@ -45,14 +47,18 @@ public abstract class BaseListActivity extends BaseDnsActivity {
|
||||
}
|
||||
|
||||
protected final DataHandler getDataHandler() {
|
||||
if (!isUpdated && dataHandler == null)
|
||||
if (!isUpdated && datahandler == null)
|
||||
throw new RuntimeException("You have to create and run list creator first!");
|
||||
|
||||
return this.dataHandler;
|
||||
return this.datahandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list adapter used by listview.
|
||||
* @param objects
|
||||
* @return
|
||||
*/
|
||||
protected abstract <T> ListAdapter createAdapter(T[] objects);
|
||||
protected abstract <T> ListCreator<?> getListCreator(Context c, int idList, int idProgressBar);
|
||||
|
||||
protected abstract class ListCreator<T> extends AsyncTask<Void, Void, Boolean> {
|
||||
private String category = Event.ALL;
|
||||
@@ -87,14 +93,15 @@ public abstract class BaseListActivity extends BaseDnsActivity {
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
if (forcedUpdate) {
|
||||
dataHandler = null;
|
||||
datahandler = null;
|
||||
}
|
||||
|
||||
ListView list = (ListView)findViewById(idList);
|
||||
list.setVisibility(View.GONE);
|
||||
|
||||
ProgressBar pb = (ProgressBar)findViewById(idProgressBar);
|
||||
pb.setVisibility(View.VISIBLE);
|
||||
if (pb != null)
|
||||
pb.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,9 +110,9 @@ public abstract class BaseListActivity extends BaseDnsActivity {
|
||||
// YAY = Fetch the feed.
|
||||
// NAY = Inform about no connection.
|
||||
try {
|
||||
if (dataHandler == null) {
|
||||
if (datahandler == null) {
|
||||
NodeList itemNodes = feed.fetch(BaseListActivity.this, this.forcedUpdate);
|
||||
dataHandler = parser.parse(itemNodes);
|
||||
datahandler = parser.parse(itemNodes);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -121,12 +128,15 @@ public abstract class BaseListActivity extends BaseDnsActivity {
|
||||
if (result) {
|
||||
ListView list = (ListView)findViewById(idList);
|
||||
T[] objects = getObjects();
|
||||
|
||||
Log.i("DNSapp", "Showing " +objects.length +" objects.");
|
||||
ListAdapter adapter = createAdapter(objects);
|
||||
list.setAdapter(adapter);
|
||||
list.setVisibility(View.VISIBLE);
|
||||
|
||||
ProgressBar pb = (ProgressBar)findViewById(idProgressBar);
|
||||
pb.setVisibility(View.GONE);
|
||||
if (pb != null)
|
||||
pb.setVisibility(View.GONE);
|
||||
} else {
|
||||
Toast toast = Toast.makeText(context, R.string.error_noconnection_noupdate, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
+4
-2
@@ -1,4 +1,4 @@
|
||||
package com.studentersamfundet.app.ui;
|
||||
package com.studentersamfundet.app.ui.lists;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -29,6 +29,8 @@ import android.widget.Toast;
|
||||
|
||||
import com.studentersamfundet.app.Event;
|
||||
import com.studentersamfundet.app.R;
|
||||
import com.studentersamfundet.app.ui.ChooseCategoryDialog;
|
||||
import com.studentersamfundet.app.ui.EventViewActivity;
|
||||
import com.studentersamfundet.app.ui.ChooseCategoryDialog.Callback;
|
||||
|
||||
public class EventListActivity extends BaseListActivity {
|
||||
@@ -169,7 +171,7 @@ public class EventListActivity extends BaseListActivity {
|
||||
|
||||
|
||||
|
||||
protected <T> ListCreator<?> getListCreator(Context context, int idList, int idProgressBar) {
|
||||
protected ListCreator<Event> getListCreator(Context context, int idList, int idProgressBar) {
|
||||
return new ListCreator<Event>(context, idList, idProgressBar) {
|
||||
|
||||
@Override
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package com.studentersamfundet.app.ui;
|
||||
package com.studentersamfundet.app.ui.lists;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -10,7 +10,7 @@ import com.studentersamfundet.app.Event;
|
||||
|
||||
public class EventListTicketsActivity extends EventListActivity {
|
||||
@Override
|
||||
protected ListCreator<?> getListCreator(Context context, int idList, int idProgressBar) {
|
||||
protected ListCreator<Event> getListCreator(Context context, int idList, int idProgressBar) {
|
||||
return new ListCreator<Event>(context, idList, idProgressBar) {
|
||||
@Override
|
||||
protected Event[] getObjects() {
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.studentersamfundet.app.ui.lists;
|
||||
|
||||
import com.studentersamfundet.app.News;
|
||||
import com.studentersamfundet.app.R;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class NewsListActivity extends BaseListActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.event_list);
|
||||
|
||||
ListCreator<?> lc = new ListCreator<News>(this, R.id.event_list, R.id.event_list_progress_bar) {
|
||||
|
||||
@Override
|
||||
protected News[] getObjects() {
|
||||
return getDataHandler().getNews();
|
||||
}
|
||||
};
|
||||
lc.execute();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected <T> ListAdapter createAdapter(T[] objects) {
|
||||
final News[] news = (News[])objects;
|
||||
ListAdapter adapter = new ArrayAdapter<News>(this, 0, 0, news) {
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewGroup row;
|
||||
|
||||
if (null == convertView) {
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
row = (ViewGroup)inflater.inflate(0, null);
|
||||
} else {
|
||||
row = (ViewGroup)convertView;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
title.setText(article.title);
|
||||
description.setText(article.description);
|
||||
|
||||
return row;
|
||||
}
|
||||
};
|
||||
|
||||
return adapter;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user