commit 395b9c16be077b42b3f5621baa150df2d083dac5
parent 07976cadbdd7610f2f05572bf0bff023a9d9d9af
Author: Jan Dankert <devnull@localhost>
Date: Tue, 31 Jan 2012 23:24:11 +0100
Anzeige von persönlichen Nachrichten.
Diffstat:
6 files changed, 133 insertions(+), 136 deletions(-)
diff --git a/res/values/strings.xml b/res/values/strings.xml
@@ -44,6 +44,7 @@
<string name="waitingfornew">Erzeuge</string>
<string name="waitingforsave">Speichern</string>
<string name="waitingfor_loadmore">Lade weitere Einträge</string>
+ <string name="waitingfor_mailbox">Nachrichten werden geladen</string>
<string name="language">Sprache</string>
<string name="model">Variante</string>
<string name="new1">Neu</string>
diff --git a/src/de/mtbnews/android/MailActivity.java b/src/de/mtbnews/android/MailActivity.java
@@ -1,14 +1,8 @@
package de.mtbnews.android;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
-import org.mcsoxford.rss.RSSItem;
-import org.xmlrpc.android.XMLRPCException;
-
-import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
@@ -16,26 +10,72 @@ import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
-import de.mtbnews.android.adapter.MapContentAdapter;
+import de.mtbnews.android.adapter.ListEntryContentAdapter;
+import de.mtbnews.android.tapatalk.TapatalkClient;
+import de.mtbnews.android.tapatalk.TapatalkException;
+import de.mtbnews.android.tapatalk.wrapper.Mailbox;
+import de.mtbnews.android.tapatalk.wrapper.Message;
import de.mtbnews.android.util.ServerAsyncTask;
-public class MailActivity extends ListActivity
+public class MailActivity extends EndlessListActivity<Message>
{
+ private int totalMessageCount;
+ private String boxId;
+
@Override
protected void onCreate(Bundle savedInstanceState)
{
- setContentView(R.layout.listing);
+ if (((IBCApplication) getApplication()).ibcTheme)
+ setTheme(R.style.IBC);
- super.onCreate(savedInstanceState);
+ setContentView(R.layout.listing);
super.onCreate(savedInstanceState);
setContentView(R.layout.listing);
+ boxId = getIntent().getStringExtra("box_id");
+
+ ListAdapter adapter = new ListEntryContentAdapter(MailActivity.this,
+ super.entries);
+ setListAdapter(adapter);
+
+ initialLoad();
+
+ final ListView list2 = getListView();
+
+ list2.setOnItemClickListener(new OnItemClickListener()
+ {
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view,
+ int position, long id)
+ {
+ Intent i = new Intent(MailActivity.this, MessageActivity.class);
+ i.putExtra("box_id", boxId);
+ i.putExtra("message_id", MailActivity.super.entries.get(position).id);
+ startActivity(i);
+ }
+ });
+
+ }
+
+ @Override
+ protected int getTotalSize()
+ {
+ return totalMessageCount;
+ }
+
+ @Override
+ protected void loadEntries(
+ final OnListLoadedListener<Message> onListLoaded, final int from,
+ final int to, boolean firstLoad)
+ {
+
new ServerAsyncTask(this, R.string.waitingforcontent)
{
- private Object[] forumList;
+ private Mailbox mailbox;
@Override
protected void callServer() throws IOException
@@ -43,12 +83,14 @@ public class MailActivity extends ListActivity
try
{
- Object l = ((IBCApplication)getApplication()).client.getXMLRPCClient().call("get_box");
+ TapatalkClient client = ((IBCApplication) getApplication())
+ .getTapatalkClient();
+ mailbox = client.getBoxContent(boxId, from, to);
- this.forumList = (Object[]) ((Map) l).get("list");
+ totalMessageCount = mailbox.countAll;
}
- catch (XMLRPCException e)
+ catch (TapatalkException e)
{
throw new RuntimeException(e);
}
@@ -56,52 +98,11 @@ public class MailActivity extends ListActivity
protected void doOnSuccess()
{
- List<Map<String, Object>> list1 = new ArrayList<Map<String, Object>>();
- for (Object o : forumList)
- {
- list1.add((Map) o);
- }
- ListAdapter adapter = new MapContentAdapter(MailActivity.this,
- list1, null, "box_name", null);
- // IBCActivity.this.setTitle(feed.getTitle());
- setListAdapter(adapter);
-
+ // MailActivity.this.setTitle(mailbox.getName());
+ onListLoaded.listLoaded(mailbox.messages);
}
}.execute();
- final ListView list = getListView();
-
- list.setOnItemClickListener(new OnItemClickListener()
- {
-
- @Override
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id)
- {
-
- // final Intent intent = new Intent(ForumActivity.this,
- // NewsDetailActivity.class);
- // intent.putExtra("itemid", position);
- // startActivity(intent);
- }
- });
-
- final ListView list2 = getListView();
-
- list2.setOnItemClickListener(new OnItemClickListener()
- {
-
- @Override
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id)
- {
- RSSItem item = (RSSItem) getListAdapter().getItem(position);
-
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setData(item.getLink());
- startActivity(i);
- }
- });
}
}
diff --git a/src/de/mtbnews/android/MailboxActivity.java b/src/de/mtbnews/android/MailboxActivity.java
@@ -1,12 +1,7 @@
package de.mtbnews.android;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
-
-import org.mcsoxford.rss.RSSItem;
-import org.xmlrpc.android.XMLRPCException;
import android.app.ListActivity;
import android.content.Intent;
@@ -16,11 +11,16 @@ import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
-import de.mtbnews.android.adapter.MapContentAdapter;
+import de.mtbnews.android.adapter.ListEntryContentAdapter;
+import de.mtbnews.android.tapatalk.TapatalkClient;
+import de.mtbnews.android.tapatalk.TapatalkException;
+import de.mtbnews.android.tapatalk.wrapper.Mailbox;
import de.mtbnews.android.util.ServerAsyncTask;
public class MailboxActivity extends ListActivity
{
+ private List<Mailbox> mailboxList;
+
@Override
protected void onCreate(Bundle savedInstanceState)
{
@@ -36,21 +36,18 @@ public class MailboxActivity extends ListActivity
new ServerAsyncTask(this, R.string.waitingforcontent)
{
- private Object[] forumList;
-
@Override
protected void callServer() throws IOException
{
try
{
- Object l = ((IBCApplication) getApplication()).client
- .getXMLRPCClient().call("get_box_info");
-
- this.forumList = (Object[]) ((Map) l).get("list");
+ TapatalkClient client = ((IBCApplication) getApplication())
+ .getTapatalkClient();
+ mailboxList = client.getMailbox();
}
- catch (XMLRPCException e)
+ catch (TapatalkException e)
{
throw new RuntimeException(e);
}
@@ -58,35 +55,13 @@ public class MailboxActivity extends ListActivity
protected void doOnSuccess()
{
- List<Map<String, Object>> list1 = new ArrayList<Map<String, Object>>();
- for (Object o : forumList)
- {
- list1.add((Map) o);
- }
- ListAdapter adapter = new MapContentAdapter(
- MailboxActivity.this, list1, null, "box_name", null);
+ ListAdapter adapter = new ListEntryContentAdapter(
+ MailboxActivity.this, mailboxList);
// 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)
- {
-
- // final Intent intent = new Intent(ForumActivity.this,
- // NewsDetailActivity.class);
- // intent.putExtra("itemid", position);
- // startActivity(intent);
- }
- });
final ListView list2 = getListView();
@@ -97,10 +72,8 @@ public class MailboxActivity extends ListActivity
public void onItemClick(AdapterView<?> parent, View view,
int position, long id)
{
- RSSItem item = (RSSItem) getListAdapter().getItem(position);
-
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setData(item.getLink());
+ Intent i = new Intent(MailboxActivity.this, MailActivity.class);
+ i.putExtra("box_id", mailboxList.get(position).getId());
startActivity(i);
}
});
diff --git a/src/de/mtbnews/android/MessageActivity.java b/src/de/mtbnews/android/MessageActivity.java
@@ -5,15 +5,21 @@ import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
+import android.text.format.DateFormat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import de.mtbnews.android.tapatalk.TapatalkClient;
+import de.mtbnews.android.tapatalk.TapatalkException;
+import de.mtbnews.android.tapatalk.wrapper.Message;
import de.mtbnews.android.util.ServerAsyncTask;
public class MessageActivity extends Activity
{
+ private String boxId;
+ private String messageId;
+
@Override
protected void onCreate(Bundle savedInstanceState)
{
@@ -21,14 +27,27 @@ public class MessageActivity extends Activity
super.onCreate(savedInstanceState);
+ boxId = getIntent().getStringExtra("box_id");
+ messageId = getIntent().getStringExtra("message_id");
+
new ServerAsyncTask(this, R.string.waitingforcontent)
{
private TapatalkClient client;
+ private Message message;
@Override
protected void callServer() throws IOException
{
- client = ((IBCApplication)getApplication()).getTapatalkClient();
+ client = ((IBCApplication) getApplication())
+ .getTapatalkClient();
+ try
+ {
+ message = client.getMessage(boxId, messageId);
+ }
+ catch (TapatalkException e)
+ {
+ throw new RuntimeException(e);
+ }
}
protected void doOnSuccess()
@@ -36,7 +55,8 @@ public class MessageActivity extends Activity
// MessageActivity.this.setTitle(feed.getTitle());
TextView datum = (TextView) findViewById(R.id.item_date);
- // datum.setText(DateFormat.getTimeFormat(this).format(item.getPubDate()));
+ datum.setText(DateFormat.getTimeFormat(MessageActivity.this)
+ .format(message.getDate()));
// TextView name = (TextView) findViewById(R.id.item_title);
// name.setText(item.getTitle());
@@ -45,22 +65,22 @@ public class MessageActivity extends Activity
// if (e.getContent() != null)
// final String html = item.getContent();
- // desc.setText(Html.fromHtml(html, new ImageGetter(), null));
+ desc.setText(message.getContent());
// setTitle(item.getTitle());
- Button button = (Button) findViewById(R.id.item_button);
- button.setOnClickListener(new OnClickListener()
- {
-
- @Override
- public void onClick(View v)
-
- {
- Intent i = new Intent(Intent.ACTION_VIEW);
- // i.setData(item.getLink());
- startActivity(i);
- }
- });
+ // Button button = (Button) findViewById(R.id.item_button);
+ // button.setOnClickListener(new OnClickListener()
+ // {
+ //
+ // @Override
+ // public void onClick(View v)
+ //
+ // {
+ // Intent i = new Intent(Intent.ACTION_VIEW);
+ // // i.setData(item.getLink());
+ // startActivity(i);
+ // }
+ // });
}
}.execute();
diff --git a/src/de/mtbnews/android/tapatalk/TapatalkClient.java b/src/de/mtbnews/android/tapatalk/TapatalkClient.java
@@ -226,9 +226,10 @@ public class TapatalkClient
case SEARCHTYPE_PARTICIPATED:
method = "get_participated_topic";
if (searchId == null)
- params = new Object[] { username.getBytes(),start, end };
+ params = new Object[] { username.getBytes(), start, end };
else
- params = new Object[] { username.getBytes(), start, end, searchId };
+ params = new Object[] { username.getBytes(), start,
+ end, searchId };
break;
case SEARCHTYPE_UNREAD:
method = "get_unread_topic";
@@ -279,8 +280,7 @@ public class TapatalkClient
* @return
* @throws TapatalkException
*/
- public List<Mailbox> getMailbox(String boxId, int start, int end)
- throws TapatalkException
+ public List<Mailbox> getMailbox() throws TapatalkException
{
try
{
@@ -322,31 +322,32 @@ public class TapatalkClient
try
{
Object[] params = new Object[] { boxId, start, end };
- Map map = toMap(client.callEx("get_box_info", params));
+ Map map = toMap(client.callEx("get_box", params));
- Mailbox mailbox = new Mailbox(boxId, "", (Integer) map.get("size"),
- (Integer) map.get(""));
+ Mailbox mailbox = new Mailbox(boxId, "", (Integer) map
+ .get("total_message_count"), (Integer) map
+ .get("total_unread_count"));
final List<Message> messageList = new ArrayList<Message>();
mailbox.messages = messageList;
for (Object o1 : (Object[]) map.get("list"))
{
- Map mapMap = toMap(o1);
+ Map msgMap = toMap(o1);
- Object[] objects = (Object[]) mapMap.get("msg_to");
+ Object[] objects = (Object[]) msgMap.get("msg_to");
String[] msgTo = new String[objects.length];
for (int j = 0; j < objects.length; j++)
msgTo[j] = byteArrayToString((toMap(objects[j])
.get("username")));
- Message message = new Message((String) map.get("msg_id"),
- ((Integer) mapMap.get("msg_state")).equals(1), //
- (Date) mapMap.get("sent_date"),//
- byteArrayToString(mapMap.get("msg_from")),//
+ Message message = new Message((String) msgMap.get("msg_id"),
+ ((Integer) msgMap.get("msg_state")).equals(1), //
+ (Date) msgMap.get("sent_date"),//
+ byteArrayToString(msgMap.get("msg_from")),//
msgTo,//
- byteArrayToString(mapMap.get("msg_subject")), //
- byteArrayToString(mapMap.get("short_content")));
+ byteArrayToString(msgMap.get("msg_subject")), //
+ byteArrayToString(msgMap.get("short_content")));
messageList.add(message);
}
@@ -367,12 +368,12 @@ public class TapatalkClient
* @return
* @throws TapatalkException
*/
- public Message getMessage(String boxId, String messageId, boolean asHtml)
+ public Message getMessage(String boxId, String messageId)
throws TapatalkException
{
try
{
- final Object[] params = new Object[] { messageId, boxId, asHtml };
+ final Object[] params = new Object[] { messageId, boxId };
Map mapMap = toMap(client.callEx("get_message", params));
@@ -392,7 +393,8 @@ public class TapatalkClient
}
catch (XMLRPCException e)
{
- throw new TapatalkException("Could not search", e);
+ throw new TapatalkException("Could not read message " + boxId + ","
+ + messageId, e);
}
}
diff --git a/src/de/mtbnews/android/tapatalk/wrapper/Mailbox.java b/src/de/mtbnews/android/tapatalk/wrapper/Mailbox.java
@@ -8,8 +8,8 @@ public class Mailbox implements ListEntry
private String id;
private String name;
- private int countAll;
- private int countUnread;
+ public int countAll;
+ public int countUnread;
public List<Message> messages;
public Mailbox(String id, String name, Integer countAll, Integer countUnread)
@@ -40,13 +40,13 @@ public class Mailbox implements ListEntry
@Override
public String getName()
{
- return name;
+ return "" + countAll + " (" + countUnread + ")";
}
@Override
public String getTitle()
{
- return "" + countAll + " (" + countUnread + ")";
+ return name;
}
}