commit 3fa789d03a097e2f370844bacb908623a34a461f
parent 5d3dfff98cfc02be40a8c31a31b9ec2482b04032
Author: Jan Dankert <devnull@localhost>
Date: Sat, 21 Jan 2012 22:57:44 +0100
Fehlende Dateien ergänzt...
Diffstat:
3 files changed, 353 insertions(+), 0 deletions(-)
diff --git a/src/de/mtbnews/android/PostActivity.java b/src/de/mtbnews/android/PostActivity.java
@@ -0,0 +1,84 @@
+/**
+ *
+ */
+package de.mtbnews.android;
+
+import java.io.IOException;
+import java.lang.reflect.ReflectPermission;
+import java.util.Map;
+
+import org.xmlrpc.android.XMLRPCClient;
+import org.xmlrpc.android.XMLRPCException;
+
+import android.app.Activity;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import de.mtbnews.android.util.IBC;
+import de.mtbnews.android.util.ServerAsyncTask;
+
+/**
+ * @author dankert
+ *
+ */
+public class PostActivity extends Activity
+{
+ public static final String ID = "id";
+ public static final String CLIENT = "client";
+ private String objectid;
+
+ Map<String, String> data;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState)
+ {
+ final SharedPreferences prefs = PreferenceManager
+ .getDefaultSharedPreferences(this);
+
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.listing);
+
+ new ServerAsyncTask(this, R.string.waitingforcontent)
+ {
+
+ @Override
+ protected void callServer() throws IOException
+ {
+
+ XMLRPCClient client = new XMLRPCClient(IBC.IBC_FORUM_CONNECTOR_URL);
+ // add 2 to 4
+ Object[] params = new Object[] {
+ prefs.getString("username", "").getBytes(),
+ prefs.getString("password", "").getBytes() };
+
+ try
+ {
+ Object sum = client.callEx("login", params);
+ System.out.println(sum.getClass());
+ System.out.println(sum);
+
+ Object l = client.call("get_inbox_stat");
+ System.out.println(l.toString() );
+
+ Object i = client.call("get_box_info");
+ System.out.println(i.toString() );
+
+ }
+ catch (XMLRPCException e)
+ {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ protected void doOnSuccess()
+ {
+ }
+
+ }.execute();
+
+ }
+
+}
diff --git a/src/de/mtbnews/android/TopicActivity.java b/src/de/mtbnews/android/TopicActivity.java
@@ -0,0 +1,111 @@
+/**
+ *
+ */
+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.ListActivity;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.view.View;
+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.util.AppData;
+import de.mtbnews.android.util.ServerAsyncTask;
+
+/**
+ * @author dankert
+ *
+ */
+public class TopicActivity extends ListActivity
+{
+ public static final String ID = "id";
+ public static final String CLIENT = "client";
+
+ private Object[] forumList;
+
+ Map<String, String> data;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState)
+ {
+ final SharedPreferences prefs = PreferenceManager
+ .getDefaultSharedPreferences(this);
+
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.listing);
+
+ new ServerAsyncTask(this, R.string.waitingforcontent)
+ {
+ @Override
+ protected void callServer() throws IOException
+ {
+
+ XMLRPCClient client = AppData.client;
+ // add 2 to 4
+ try
+ {
+
+ // add 2 to 4
+ Object[] params = new Object[] { TopicActivity.this
+ .getIntent().getStringExtra("topic_id") };
+ Object l = client.call("get_thread",params[0]);
+
+ forumList = (Object[]) ((Map) l).get("posts");
+
+// TopicActivity.this.setTitle(((Map) l).get("topic_title")
+// .toString());
+
+ }
+ catch (XMLRPCException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ 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(TopicActivity.this,
+ list1, null, "post_title", "post_content");
+ // 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(TopicActivity.this,
+ PostActivity.class);
+ intent.putExtra("itemid", position);
+ startActivity(intent);
+ }
+ });
+
+ }
+}
diff --git a/src/de/mtbnews/android/util/ServerAsyncTask.java b/src/de/mtbnews/android/util/ServerAsyncTask.java
@@ -0,0 +1,158 @@
+/**
+ *
+ */
+package de.mtbnews.android.util;
+
+import java.io.IOException;
+
+import android.app.AlertDialog;
+import android.app.ProgressDialog;
+import android.app.AlertDialog.Builder;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.os.AsyncTask;
+import android.util.Log;
+
+/**
+ * Ein asynchroner Task für den Zugriff auf den OpenRat-CMS-Server. Der Aufruf
+ * des Servers muss in der zu überschreibenden Methode {@link #callServer()}
+ * durchgeführt werden.<br>
+ * <br>
+ * <br>
+ * Während der Serverabfrage wird ein {@link ProgressDialog} angezeigt. Falls
+ * die Abfrage nicht erfolgreich ist, wird automatisch ein {@link AlertDialog}
+ * mit einer Fehlermeldung angezeigt.<br>
+ * <br>
+ * <br>
+ * Durch überschreiben von {@link #doOnError(IOException)} kann selber auf einen
+ * Fehler reagiert werden. Durch Überschreiben von {@link #doOnSuccess()} kann
+ * eine Aktion nach erfolgreicher Serveranfrage ausgeführt werden. <br>
+ *
+ * @author dankert
+ *
+ */
+public abstract class ServerAsyncTask extends
+ AsyncTask<Void, Void, Void>
+{
+ private ProgressDialog progressDialog;
+ private Context context;
+ private AlertDialog alertDialog;
+ private IOException error;
+
+ /**
+ * @param context
+ * Context des Aufrufers
+ * @param message
+ * Resource-Id für den Text im {@link ProgressDialog}.
+ */
+ public ServerAsyncTask(Context context, int message)
+ {
+ this.context = context;
+
+ this.progressDialog = new ProgressDialog(context);
+ // progressDialog.setTitle(R.string.loading);
+ progressDialog.setMessage(context.getResources().getString(message));
+ }
+
+ @Override
+ final protected void onPreExecute()
+ {
+ progressDialog.setCancelable(true);
+ progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener(){
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ ServerAsyncTask.this.cancel(true);
+ }
+ });
+
+ progressDialog.show();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
+ */
+ @Override
+ final protected void onPostExecute(Void result)
+ {
+ progressDialog.dismiss();
+
+ if (error != null)
+ {
+ doOnError(error);
+ }
+ else
+ {
+ doOnSuccess();
+ }
+ }
+
+ /**
+ * Wird aufgerufen, falls die Serveranfrage nicht durchgeführt werden
+ * konnte. Läuft im UI-Thread.
+ *
+ * @param error
+ * Exception, die aufgetreten ist.
+ */
+ protected void doOnError(IOException error)
+ {
+ final Builder builder = new AlertDialog.Builder(this.context);
+ alertDialog = builder.setCancelable(true).create();
+ final int causeRId = ExceptionUtils.getResourceStringId(error);
+ String msg = // this.context.getResources().getString(R.string.reason)
+ // + ":\n\n" +
+ error.getMessage();
+
+ Throwable t = error;
+ while (t.getCause() != null)
+ {
+ t = t.getCause();
+ msg += ": " + t.getMessage();
+ }
+
+ alertDialog.setTitle(causeRId);
+ alertDialog.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
+ alertDialog.setMessage(msg);
+ alertDialog.show();
+
+ }
+
+ /**
+ * Wird aufgerufen, falls die Serveranfrage erfolgreich durchgeführt werden
+ * konnte. Läuft im UI-Thread.
+ */
+ protected void doOnSuccess()
+ {
+ }
+
+ /**
+ * Startet die Serveranfrage und fängt auftretene Fehler.
+ *
+ * @see android.os.AsyncTask#doInBackground(Params[])
+ */
+ @Override
+ final protected Void doInBackground(Void... params)
+ {
+ try
+ {
+ callServer();
+ }
+ catch (IOException e)
+ {
+ Log.e(this.getClass().getName(), e.getMessage(), e);
+ error = e;
+ }
+
+ return null;
+ }
+
+ /**
+ * Ausführen der Serveranfrage. Auftretene {@link IOException} sollte
+ * weitergeworfen werden, da daraus ein {@link AlertDialog} erzeugt wird.
+ *
+ * @throws IOException
+ * Vom Server erzeugte Fehler
+ */
+ protected abstract void callServer() throws IOException;
+}