android-ibc-forum

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit b3332564a8c7cc26ca0601713de835c1eb89c005
parent 8a51af01b13fb60d7dcf4489f08d3a9dcceee597
Author: Jan Dankert <devnull@localhost>
Date:   Sun,  5 Feb 2012 21:14:50 +0100

Foren/Themen als gelesen markieren.

Diffstat:
res/menu/forum.xml | 6++++++
res/values/strings.xml | 2+-
src/de/mtbnews/android/ForumActivity.java | 68+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
src/de/mtbnews/android/TopicActivity.java | 42++++++++++++++++++++++++++++++++++++------
src/de/mtbnews/android/tapatalk/TapatalkClient.java | 48++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 156 insertions(+), 10 deletions(-)

diff --git a/res/menu/forum.xml b/res/menu/forum.xml @@ -8,6 +8,12 @@ <item android:id="@+id/menu_subscribe" android:title="@string/subscribe_forum" android:icon="@android:drawable/ic_input_get"></item> + + <item android:id="@+id/menu_mark_all_read" android:title="@string/mark_all_forum_read" + android:icon="@android:drawable/ic_menu_agenda"></item> + + <item android:id="@+id/menu_mark_read" android:title="@string/mark_forum_read" + android:icon="@android:drawable/ic_menu_agenda"></item> <!-- <item android:id="@+id/menu_mailbox" android:title="@string/mailbox" android:icon="@android:drawable/ic_menu_send"></item> diff --git a/res/values/strings.xml b/res/values/strings.xml @@ -134,7 +134,7 @@ </string> <string name="subscription_service">Abo-Dienst</string> <string name="subscription_service_started">Abo-Dienst gestartet</string> - <string name="subscription_saved">Abonnement wurdeaktualisiert</string> + <string name="subscription_saved">Abonnement wurde aktualisiert</string> <string name="subscription_service_stopped">Abo-Dienst gestoppt</string> <string name="subscription_service_desc">Informiert bei neuen Nachrichten und ungelesenen Beitr├Ągen in abonnierten Foren und Themen</string> diff --git a/src/de/mtbnews/android/ForumActivity.java b/src/de/mtbnews/android/ForumActivity.java @@ -270,10 +270,12 @@ public class ForumActivity extends EndlessListActivity<Topic> builder.setItems(R.array.subscription_modes, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, final int item) + public void onClick(DialogInterface dialog, + final int item) { - new ServerAsyncTask(ForumActivity.this,R.string.waitingfor_subscription_forums) + new ServerAsyncTask(ForumActivity.this, + R.string.waitingfor_subscription_forums) { @Override @@ -300,11 +302,71 @@ public class ForumActivity extends EndlessListActivity<Topic> R.string.subscription_saved, Toast.LENGTH_SHORT).show(); } - }; + }.execute(); } }); builder.create().show(); return true; + case R.id.menu_mark_read: + + new ServerAsyncTask(ForumActivity.this, + R.string.mark_forum_read) + { + + @Override + protected void callServer() throws IOException + { + TapatalkClient client = ((IBCApplication) getApplication()) + .getTapatalkClient(); + try + { + client.markForumAsRead(forumId); + } + catch (TapatalkException e) + { + throw new RuntimeException(e); + } + } + + @Override + protected void doOnSuccess() + { + Toast + .makeText(getApplicationContext(), + R.string.subscription_saved, + Toast.LENGTH_SHORT).show(); + } + }.execute(); + + return true; + + case R.id.menu_mark_all_read: + + new ServerAsyncTask(ForumActivity.this, + R.string.mark_forum_read) + { + @Override + protected void callServer() throws IOException + { + TapatalkClient client = ((IBCApplication) getApplication()) + .getTapatalkClient(); + try + { + client.markForumAsRead(null); + } + catch (TapatalkException e) + { + throw new RuntimeException(e); + } + } + + @Override + protected void doOnSuccess() + { + } + }.execute(); + + return true; } return false; } diff --git a/src/de/mtbnews/android/TopicActivity.java b/src/de/mtbnews/android/TopicActivity.java @@ -41,7 +41,7 @@ public class TopicActivity extends EndlessListActivity<Post> private String topicTitle; private int totalSize; - + @Override protected void onCreate(Bundle savedInstanceState) { @@ -51,7 +51,7 @@ public class TopicActivity extends EndlessListActivity<Post> super.onCreate(savedInstanceState); topicId = TopicActivity.this.getIntent().getStringExtra(TOPIC_ID); - //forumId = TopicActivity.this.getIntent().getStringExtra("forum_id"); + // forumId = TopicActivity.this.getIntent().getStringExtra("forum_id"); setContentView(R.layout.listing); @@ -154,7 +154,7 @@ public class TopicActivity extends EndlessListActivity<Post> intent.putExtra("subject", topicTitle); startActivity(intent); return true; - + case R.id.menu_subscribe: AlertDialog.Builder builder = new AlertDialog.Builder(this); @@ -162,9 +162,11 @@ public class TopicActivity extends EndlessListActivity<Post> builder.setItems(R.array.subscription_modes, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, final int item) + public void onClick(DialogInterface dialog, + final int item) { - new ServerAsyncTask(TopicActivity.this,R.string.waitingfor_subscription_forums) + new ServerAsyncTask(TopicActivity.this, + R.string.mark_topic_read) { @Override @@ -191,12 +193,40 @@ public class TopicActivity extends EndlessListActivity<Post> R.string.subscription_saved, Toast.LENGTH_SHORT).show(); } - }; + }.execute(); } }); builder.create().show(); return true; + case R.id.menu_mark_read: + + new ServerAsyncTask(TopicActivity.this, + R.string.mark_topic_read) + { + + @Override + protected void callServer() throws IOException + { + TapatalkClient client = ((IBCApplication) getApplication()) + .getTapatalkClient(); + try + { + client.markTopicAsRead(topicId); + } + catch (TapatalkException e) + { + throw new RuntimeException(e); + } + } + + @Override + protected void doOnSuccess() + { + } + }.execute(); + return true; + } return false; } diff --git a/src/de/mtbnews/android/tapatalk/TapatalkClient.java b/src/de/mtbnews/android/tapatalk/TapatalkClient.java @@ -275,6 +275,54 @@ public class TapatalkClient } } + /** + * Mark a forum as read + * + * @param forumId + * if <code>null</code>, all forums are marked read + * @throws TapatalkException + */ + public void markForumAsRead(String forumId) throws TapatalkException + { + try + { + if (forumId == null) + { + toMap(client.call("mark_all_as_read")); + } + else + { + Object[] params = new Object[] { forumId }; + toMap(client.callEx("mark_all_as_read", params)); + } + + } + catch (XMLRPCException e) + { + throw new TapatalkException("XMLRPC-Error: " + e.getMessage(), e); + } + } + + /** + * Mark a forum as read + * + * @param topicId + * @throws TapatalkException + */ + public void markTopicAsRead(String topicId) throws TapatalkException + { + try + { + Object param = new String[] { topicId }; + toMap(client.call("mark_topic_read", param)); + + } + catch (XMLRPCException e) + { + throw new TapatalkException("XMLRPC-Error: " + e.getMessage(), e); + } + } + public final static int SUBSCRIBE_NONE = -1; public final static int SUBSCRIBE_WITHOUT_EMAIL = 0; public final static int SUBSCRIBE_INSTANT_EMAIL = 1;