commit 9ea009d9ef12a28cba3620ee32531117f710ad21
parent 3fa789d03a097e2f370844bacb908623a34a461f
Author: Jan Dankert <devnull@localhost>
Date: Sun, 22 Jan 2012 23:52:01 +0100
Forum-Liste...
Diffstat:
10 files changed, 414 insertions(+), 96 deletions(-)
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
@@ -16,6 +16,7 @@
<activity android:name="NewsDetailActivity" android:label="@string/news"></activity>
<activity android:name="PhotoActivity" android:label="@string/photos"></activity>
+ <activity android:name="ForumOverviewActivity" android:label="@string/forum"></activity>
<activity android:name="ForumActivity" android:label="@string/forum"></activity>
<activity android:name="TopicActivity" android:label="@string/forum"></activity>
<activity android:name="PostActivity" android:label="@string/forum"></activity>
diff --git a/res/menu/forum.xml b/res/menu/forum.xml
@@ -0,0 +1,13 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/menu_mailbox" android:title="@string/mailbox"
+ android:icon="@android:drawable/ic_menu_send"></item>
+ <item android:id="@+id/menu_participated_topics" android:title="@string/participated_topics"
+ android:icon="@android:drawable/ic_menu_view"></item>
+ <item android:id="@+id/menu_latest_topics" android:title="@string/latest_topics"
+ android:icon="@android:drawable/ic_menu_today"></item>
+ <item android:id="@+id/menu_unread_topics" android:title="@string/unread_topics"
+ android:icon="@android:drawable/ic_menu_info_details"></item>
+ <item android:id="@+id/menu_logout" android:title="@string/logout"
+ android:icon="@android:drawable/ic_lock_lock"></item>
+</menu>
+ +
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
@@ -84,6 +84,19 @@
<string name="release">Freigeben</string>
<string name="noserver">Es ist noch kein Server konfiguriert. Über die Menütaste können Sie einen neuen Server anlegen.</string>
<string name="www">Zur Webseite</string>
+ <string name="scroll_down">Immer an das Ende scrollen</string>
+ <string name="use_ibc_theme">Das IBC-Theme benutzen</string>
+ <string name="auto_login">Automatisch anmelden</string>
+ <string name="num_load">Anzahl Posts laden</string>
+ <string name="login">Anmelden</string>
+ <string name="logout">Abmelden</string>
+ <string-array name="num_load_list">
+ <item>5</item>
+ <item>10</item>
+ <item>20</item>
+ <item>50</item>
+ </string-array>
+
<string name="forum">Forum</string>
<string name="news">News</string>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
@@ -1,18 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/preferences">
-
- <!--
- <EditTextPreference android:key="timeout"
+
+ <CheckBoxPreference android:defaultValue="true"
+ android:key="ibc_theme" android:title="@string/use_ibc_theme" />
+
+ <!--
+ <EditTextPreference android:key="timeout"
android:title="@string/timeout" android:summary="@string/timeout_desc"
android:defaultValue="30"></EditTextPreference>
- -->
+ -->
<!--
<EditTextPreference android:key="server"
android:title="@string/server"></EditTextPreference>
-->
- <EditTextPreference android:key="username"
- android:title="@string/username"></EditTextPreference>
- <EditTextPreference android:key="password"
- android:password="true" android:title="@string/password"></EditTextPreference>
+ <PreferenceCategory android:title="@string/username">
+
+ <EditTextPreference android:key="username"
+ android:title="@string/username"></EditTextPreference>
+ <EditTextPreference android:key="password"
+ android:password="true" android:title="@string/password"></EditTextPreference>
+ </PreferenceCategory>
+
+ <PreferenceCategory android:title="@string/forum">
+
+ <ListPreference android:defaultValue="10"
+ android:entries="@array/num_load_list" android:entryValues="@array/num_load_list"
+ android:key="num_load" android:title="@string/num_load" />
+
+ <CheckBoxPreference android:defaultValue="false"
+ android:key="scroll_down" android:title="@string/scroll_down" />
+
+ <CheckBoxPreference android:defaultValue="true"
+ android:key="auto_login" android:title="@string/auto_login" />
+ </PreferenceCategory>
</PreferenceScreen>
diff --git a/src/de/mtbnews/android/ForumActivity.java b/src/de/mtbnews/android/ForumActivity.java
@@ -16,6 +16,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -25,6 +26,8 @@ import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import de.mtbnews.android.adapter.MapContentAdapter;
+import de.mtbnews.android.tapatalk.TapatalkClient;
+import de.mtbnews.android.tapatalk.TapatalkException;
import de.mtbnews.android.util.AppData;
import de.mtbnews.android.util.IBC;
import de.mtbnews.android.util.ServerAsyncTask;
@@ -36,17 +39,25 @@ import de.mtbnews.android.util.ServerAsyncTask;
public class ForumActivity extends ListActivity
{
private Object[] forumList;
-
+ private SharedPreferences prefs;
+
@Override
protected void onCreate(Bundle savedInstanceState)
{
if (AppData.client == null)
- AppData.client = new XMLRPCClient(IBC.IBC_FORUM_CONNECTOR_URL);
+ AppData.client = new TapatalkClient(IBC.IBC_FORUM_CONNECTOR_URL);
super.onCreate(savedInstanceState);
setContentView(R.layout.listing);
+ prefs = PreferenceManager.getDefaultSharedPreferences(this);
+
+ if (prefs.getBoolean("auto_login", false))
+ {
+ login();
+ }
+
if (getIntent().getBooleanExtra("latest", false))
{
loadLatest();
@@ -61,20 +72,47 @@ public class ForumActivity extends ListActivity
}
else
{
- loadForum();
+ String forumId = getIntent().getStringExtra("forum_id");
+
+ loadForum(forumId);
}
}
+ private void login()
+ {
+ final TapatalkClient client = AppData.client;
+ new ServerAsyncTask(this, R.string.waitingforlogin)
+ {
+
+ @Override
+ protected void callServer() throws IOException
+ {
+
+ try
+ {
+ Map<String, Object> map = client.login(prefs.getString(
+ "username", ""), prefs.getString("password", ""));
+
+ }
+ catch (TapatalkException e)
+ {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ }.execute();
+ }
+
private void loadUnread()
{
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
- final XMLRPCClient client = AppData.client;
+ final XMLRPCClient client = AppData.client.getXMLRPCClient();
new ServerAsyncTask(this, R.string.waitingforcontent)
{
-
-
@Override
protected void callServer() throws IOException
{
@@ -117,7 +155,7 @@ public class ForumActivity extends ListActivity
list.add((Map) o);
}
ListAdapter adapter = new MapContentAdapter(ForumActivity.this,
- list, null, "topic_title", "short_content");
+ list, "post_time", "topic_title", "short_content");
// IBCActivity.this.setTitle(feed.getTitle());
setListAdapter(adapter);
@@ -134,10 +172,11 @@ public class ForumActivity extends ListActivity
int position, long id)
{
- final Intent intent = new Intent(ForumActivity.this,
- TopicActivity.class);
- intent.putExtra("topic_id", (String) ((Map)forumList[position]).get("topic_id"));
- startActivity(intent);
+ final Intent intent = new Intent(ForumActivity.this,
+ TopicActivity.class);
+ intent.putExtra("topic_id",
+ (String) ((Map) forumList[position]).get("topic_id"));
+ startActivity(intent);
}
});
}
@@ -146,25 +185,17 @@ public class ForumActivity extends ListActivity
{
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
- final XMLRPCClient client = AppData.client;
+ final XMLRPCClient client = AppData.client.getXMLRPCClient();
new ServerAsyncTask(this, R.string.waitingforcontent)
{
-
@Override
protected void callServer() throws IOException
{
- // add 2 to 4
- Object[] params = new Object[] {
- prefs.getString("username", "").getBytes(),
- prefs.getString("password", "").getBytes() };
-
try
{
- Object sum = client.callEx("login", params);
-
// Object l = client.call("get_inbox_stat");
// System.out.println(l.toString() );
Object l = client.call("get_latest_topic");
@@ -193,7 +224,7 @@ public class ForumActivity extends ListActivity
list.add((Map) o);
}
ListAdapter adapter = new MapContentAdapter(ForumActivity.this,
- list, null, "topic_title", "short_content");
+ list, "post_time", "topic_title", "short_content");
// IBCActivity.this.setTitle(feed.getTitle());
setListAdapter(adapter);
@@ -222,7 +253,7 @@ public class ForumActivity extends ListActivity
{
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
- final XMLRPCClient client = AppData.client;
+ final XMLRPCClient client = AppData.client.getXMLRPCClient();
new ServerAsyncTask(this, R.string.waitingforcontent)
{
@@ -233,26 +264,14 @@ public class ForumActivity extends ListActivity
protected void callServer() throws IOException
{
- // add 2 to 4
- Object[] params = new Object[] {
- prefs.getString("username", "").getBytes(),
- prefs.getString("password", "").getBytes() };
+ Object[] params = new Object[] { prefs
+ .getString("username", "").getBytes() };
try
{
- Object sum = client.callEx("login", params);
-
- // Object l = client.call("get_inbox_stat");
- // System.out.println(l.toString() );
- Object l = client.call("get_participated_topic");
-
- this.forumList = (Object[]) ((Map) l).get("topics");
-
- System.out.println(l.toString());
-
- // Object i = client.call("get_box_info");
- // System.out.println(i.toString() );
+ Map map = (Map) client.call("get_participated_topic");
+ this.forumList = (Object[]) map.get("topics");
}
catch (XMLRPCException e)
{
@@ -295,11 +314,10 @@ public class ForumActivity extends ListActivity
});
}
- private void loadForum()
+ private void loadForum(final String forumId)
{
- final SharedPreferences prefs = PreferenceManager
- .getDefaultSharedPreferences(this);
- final XMLRPCClient client = AppData.client;
+
+ final XMLRPCClient client = AppData.client.getXMLRPCClient();
new ServerAsyncTask(this, R.string.waitingforcontent)
{
@@ -310,25 +328,11 @@ public class ForumActivity extends ListActivity
protected void callServer() throws IOException
{
- // add 2 to 4
- Object[] params = new Object[] {
- prefs.getString("username", "").getBytes(),
- prefs.getString("password", "").getBytes() };
-
try
{
- Object sum = client.callEx("login", params);
-
- // Object l = client.call("get_inbox_stat");
- // System.out.println(l.toString() );
- Object l = client.call("get_forum");
-
- this.forumList = (Object[]) l;
- System.out.println(l.toString());
-
- // Object i = client.call("get_box_info");
- // System.out.println(i.toString() );
+ Map map = (Map) client.call("get_topic", forumId);
+ this.forumList = (Object[]) map.get("topics");
}
catch (XMLRPCException e)
{
@@ -346,7 +350,7 @@ public class ForumActivity extends ListActivity
list.add((Map) o);
}
ListAdapter adapter = new MapContentAdapter(ForumActivity.this,
- list, null, "forum_name", "description");
+ list, "last_reply_time", "topic_title", "short_content");
// IBCActivity.this.setTitle(feed.getTitle());
setListAdapter(adapter);
@@ -405,8 +409,29 @@ public class ForumActivity extends ListActivity
intent3.putExtra("unread", true);
startActivity(intent3);
return true;
+
+ case R.id.menu_logout:
+ return false;
+
+ case R.id.menu_login:
+
+ if (TextUtils.isEmpty(prefs.getString("username", "")))
+ {
+ Intent intent4 = new Intent(this, Configuration.class);
+ startActivity(intent4);
+ }
+ // Evtl. gibt es jetzt einen Benutzernamen ...
+
+ if (!TextUtils.isEmpty(prefs.getString("username", "")))
+ {
+ Intent intent4 = new Intent(this, Configuration.class);
+ startActivity(intent4);
+ }
+
+ login();
+
+ return true;
}
return false;
}
-
}
diff --git a/src/de/mtbnews/android/ForumOverviewActivity.java b/src/de/mtbnews/android/ForumOverviewActivity.java
@@ -0,0 +1,241 @@
+/**
+ *
+ */
+package de.mtbnews.android;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.xmlrpc.android.XMLRPCClient;
+import org.xmlrpc.android.XMLRPCException;
+
+import android.app.ExpandableListActivity;
+import android.app.ListActivity;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.text.TextUtils;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ExpandableListView;
+import android.widget.ListAdapter;
+import android.widget.ListView;
+import android.widget.AdapterView.OnItemClickListener;
+import de.mtbnews.android.adapter.MapContentAdapter;
+import de.mtbnews.android.tapatalk.TapatalkClient;
+import de.mtbnews.android.tapatalk.TapatalkException;
+import de.mtbnews.android.util.AppData;
+import de.mtbnews.android.util.IBC;
+import de.mtbnews.android.util.ServerAsyncTask;
+
+/**
+ * @author dankert
+ *
+ */
+public class ForumOverviewActivity extends ListActivity
+{
+ private SharedPreferences prefs;
+
+ private List<Map<String, Object>> list;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState)
+ {
+ if (AppData.client == null)
+ AppData.client = new TapatalkClient(IBC.IBC_FORUM_CONNECTOR_URL);
+
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.listing);
+
+ prefs = PreferenceManager.getDefaultSharedPreferences(this);
+
+ if (prefs.getBoolean("auto_login", false))
+ {
+ login();
+ }
+
+ loadForum();
+ }
+
+ private void login()
+ {
+ final TapatalkClient client = AppData.client;
+ new ServerAsyncTask(this, R.string.waitingforlogin)
+ {
+
+ @Override
+ protected void callServer() throws IOException
+ {
+
+ // add 2 to 4
+
+ try
+ {
+ Map<String, Object> map = client.login(prefs.getString(
+ "username", ""), prefs.getString("password", ""));
+
+ }
+ catch (TapatalkException e)
+ {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ }.execute();
+ }
+
+ private void loadForum()
+ {
+ final XMLRPCClient client = AppData.client.getXMLRPCClient();
+
+ new ServerAsyncTask(this, R.string.waitingforcontent)
+ {
+
+ private Object[] forumList;
+
+ @Override
+ protected void callServer() throws IOException
+ {
+
+ try
+ {
+ Object l = client.call("get_forum");
+
+ this.forumList = (Object[]) l;
+ }
+ catch (XMLRPCException e)
+ {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ protected void doOnSuccess()
+ {
+ list = flattenArrayMap(this.forumList, "child");
+
+ ListAdapter adapter = new MapContentAdapter(
+ ForumOverviewActivity.this, list, null, "forum_name",
+ "description");
+ // IBCActivity.this.setTitle(feed.getTitle());
+ setListAdapter(adapter);
+
+ }
+
+ }.execute();
+ final ListView list = getListView();
+
+ list.setOnItemClickListener(new OnItemClickListener()
+ {
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view,
+ int position, long id)
+ {
+
+ Map<String, Object> map = ForumOverviewActivity.this.list
+ .get(position);
+
+ boolean subOnly = (Boolean) map.get("sub_only");
+ if (!subOnly)
+ {
+ final Intent intent = new Intent(
+ ForumOverviewActivity.this, ForumActivity.class);
+ intent.putExtra("forum_id", (String) map.get("forum_id"));
+ startActivity(intent);
+ }
+ }
+ });
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu)
+ {
+ super.onCreateOptionsMenu(menu);
+ MenuInflater mi = new MenuInflater(getApplication());
+ mi.inflate(R.menu.forum, menu);
+
+ return true;
+ }
+
+ public boolean onOptionsItemSelected(MenuItem item)
+ {
+ switch (item.getItemId())
+ {
+ case R.id.menu_mailbox:
+ startActivity(new Intent(this, MailboxActivity.class));
+ return true;
+
+ case R.id.menu_participated_topics:
+ Intent intent = new Intent(this, ForumActivity.class);
+ intent.putExtra("participated", true);
+ startActivity(intent);
+ return true;
+
+ case R.id.menu_latest_topics:
+ Intent intent2 = new Intent(this, ForumActivity.class);
+ intent2.putExtra("latest", true);
+ startActivity(intent2);
+ return true;
+ case R.id.menu_unread_topics:
+ Intent intent3 = new Intent(this, ForumActivity.class);
+ intent3.putExtra("unread", true);
+ startActivity(intent3);
+ return true;
+
+ case R.id.menu_logout:
+ return false;
+
+ case R.id.menu_login:
+
+ if (TextUtils.isEmpty(prefs.getString("username", "")))
+ {
+ Intent intent4 = new Intent(this, Configuration.class);
+ startActivity(intent4);
+ }
+ // Evtl. gibt es jetzt einen Benutzernamen ...
+
+ if (!TextUtils.isEmpty(prefs.getString("username", "")))
+ {
+ Intent intent4 = new Intent(this, Configuration.class);
+ startActivity(intent4);
+ }
+
+ login();
+
+ return true;
+ }
+ return false;
+ }
+
+ private List<Map<String, Object>> flattenArrayMap(Object[] objects,
+ String childName)
+ {
+
+ List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
+
+ for (Object object : objects)
+ {
+ Map map = (Map) object;
+ list.add(map);
+
+ if (map.containsKey(childName))
+ {
+ list.addAll(flattenArrayMap((Object[]) map.get(childName),
+ childName));
+ }
+ }
+ return list;
+
+ }
+}
diff --git a/src/de/mtbnews/android/IBCActivity.java b/src/de/mtbnews/android/IBCActivity.java
@@ -61,31 +61,31 @@ public class IBCActivity extends ListActivity
SharedPreferences globalPrefs = PreferenceManager
.getDefaultSharedPreferences(this);
- if (globalPrefs.getString("username", "").equals("") )
- {
- // Noch kein Benutzer konfiguriert. Hinweis anzeigen!
- final AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setMessage(getResources().getString(R.string.noserver));
- AlertDialog alert = builder.create();
- alert.show();
- }
-
+ // Gast-Zugang ist ok, daher keine Meldung anzeigen...
+ // if (globalPrefs.getString("username", "").equals("") )
+ // {
+ // // Noch kein Benutzer konfiguriert. Hinweis anzeigen!
+ // final AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ // builder.setMessage(getResources().getString(R.string.noserver));
+ // AlertDialog alert = builder.create();
+ // alert.show();
+ // }
+
Button forumButton = (Button) findViewById(R.id.forum);
- forumButton.setOnClickListener( new OnClickListener()
+ forumButton.setOnClickListener(new OnClickListener()
{
-
+
@Override
public void onClick(View v)
{
- startActivity(new Intent(IBCActivity.this, ForumActivity.class));
+ startActivity(new Intent(IBCActivity.this, ForumOverviewActivity.class));
}
});
-
-
+
Button photoButton = (Button) findViewById(R.id.photo);
- photoButton.setOnClickListener( new OnClickListener()
+ photoButton.setOnClickListener(new OnClickListener()
{
-
+
@Override
public void onClick(View v)
{
@@ -96,18 +96,18 @@ public class IBCActivity extends ListActivity
reloadFeed();
}
-
/**
*
*/
private void reloadFeed()
{
- if ( AppData.newsFeed != null ) {
+ if (AppData.newsFeed != null)
+ {
// Nicht nochmal laden.
// TODO: Reload-Funktion.
return;
}
-
+
new ServerAsyncTask(this, R.string.waitingforcontent)
{
@@ -154,8 +154,6 @@ public class IBCActivity extends ListActivity
});
}
-
-
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
@@ -173,7 +171,7 @@ public class IBCActivity extends ListActivity
case R.id.menu_preferences:
startActivity(new Intent(this, Configuration.class));
return true;
-
+
}
return false;
}
diff --git a/src/de/mtbnews/android/TopicActivity.java b/src/de/mtbnews/android/TopicActivity.java
@@ -22,6 +22,7 @@ import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import de.mtbnews.android.adapter.MapContentAdapter;
+import de.mtbnews.android.tapatalk.TapatalkClient;
import de.mtbnews.android.util.AppData;
import de.mtbnews.android.util.ServerAsyncTask;
@@ -54,11 +55,10 @@ public class TopicActivity extends ListActivity
protected void callServer() throws IOException
{
- XMLRPCClient client = AppData.client;
+ XMLRPCClient client = AppData.client.getXMLRPCClient();
// add 2 to 4
try
{
-
// add 2 to 4
Object[] params = new Object[] { TopicActivity.this
.getIntent().getStringExtra("topic_id") };
diff --git a/src/de/mtbnews/android/adapter/MapContentAdapter.java b/src/de/mtbnews/android/adapter/MapContentAdapter.java
@@ -6,14 +6,13 @@ package de.mtbnews.android.adapter;
import java.util.List;
import java.util.Map;
-import org.mcsoxford.rss.RSSItem;
-
import android.content.Context;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
+import android.widget.LinearLayout;
import android.widget.TextView;
import de.mtbnews.android.R;
@@ -80,6 +79,13 @@ public class MapContentAdapter extends BaseAdapter
final View view = inflator.inflate(R.layout.rss_item, null);
+ // Linken Rand ggf. erhöhen.
+ // LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(
+ // LinearLayout.LayoutParams.FILL_PARENT,
+ // LinearLayout.LayoutParams.WRAP_CONTENT);
+ // params2.setMargins(20,0,0,0);
+ // view.setLayoutParams(params2);
+
if (dateKey != null)
{
TextView datum = (TextView) view.findViewById(R.id.item_date);
@@ -92,7 +98,6 @@ public class MapContentAdapter extends BaseAdapter
if (titleKey != null)
{
-
TextView name = (TextView) view.findViewById(R.id.item_title);
name.setText(new String((byte[]) e.get(titleKey)));
}
diff --git a/src/de/mtbnews/android/util/AppData.java b/src/de/mtbnews/android/util/AppData.java
@@ -3,6 +3,8 @@ package de.mtbnews.android.util;
import org.mcsoxford.rss.RSSFeed;
import org.xmlrpc.android.XMLRPCClient;
+import de.mtbnews.android.tapatalk.TapatalkClient;
+
/**
* Speichert Anwendungsdaten.
*
@@ -15,5 +17,5 @@ public class AppData
public static RSSFeed photoFeed;
- public static XMLRPCClient client;
+ public static TapatalkClient client;
}