commit d5cca85f841ebb868deb29640ab82b896fac0548
parent 7dd73c9c072c9cc6a9c11a4c5253792f822d9d2e
Author: dankert <devnull@localhost>
Date: Thu, 20 Oct 2011 23:55:50 +0200
Lesen von Seitenelementen.
Diffstat:
6 files changed, 147 insertions(+), 24 deletions(-)
diff --git a/src/de/openrat/android/blog/FolderActivity.java b/src/de/openrat/android/blog/FolderActivity.java
@@ -69,19 +69,10 @@ public class FolderActivity extends ListActivity
protected void callServer() throws IOException
{
folderid = getIntent().getStringExtra("folderid");
- try
- {
if (folderid == null)
folderid = client.getRootFolder();
- data = client.getFolderEntries(folderid);
- }
- catch (IOException e)
- {
- Log.e(this.getClass().getName(), e.getMessage(), e);
- Toast.makeText(FolderActivity.this, e.getMessage(),
- Toast.LENGTH_SHORT);
- }
+ data = client.getFolderEntries(folderid);
}
protected void doOnSuccess()
@@ -119,7 +110,7 @@ public class FolderActivity extends ListActivity
intent = new Intent(FolderActivity.this,
PageElementsActivity.class);
intent.putExtra(CLIENT, client);
- intent.putExtra("pageid", entry.id);
+ intent.putExtra(PageElementsActivity.ID, entry.id);
startActivity(intent);
default:
}
diff --git a/src/de/openrat/android/blog/PageElementsActivity.java b/src/de/openrat/android/blog/PageElementsActivity.java
@@ -3,13 +3,22 @@
*/
package de.openrat.android.blog;
+import java.io.IOException;
import java.util.ArrayList;
-import java.util.List;
+import java.util.Arrays;
import java.util.Map;
import android.app.ListActivity;
import android.os.Bundle;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ListView;
import android.widget.SimpleAdapter;
+import android.widget.Toast;
+import android.widget.AdapterView.OnItemClickListener;
+import de.openrat.android.blog.adapter.SimpleNameAdapter;
+import de.openrat.android.blog.util.OpenRatClientAsyncTask;
+import de.openrat.client.OpenRatClient;
/**
* @author dankert
@@ -17,21 +26,57 @@ import android.widget.SimpleAdapter;
*/
public class PageElementsActivity extends ListActivity
{
- private static final String NAME = "name";
+ public static final String ID = "id";
+ public static final String CLIENT = "client";
+ private String objectid;
+ private OpenRatClient client;
+
+ Map<String, String> data;
@Override
protected void onCreate(Bundle savedInstanceState)
{
- // TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.listing);
- int[] to = new int[] { R.id.name };
- String[] from = new String[] { NAME };
-
- ArrayList<Map<String,?>> list = new ArrayList<Map<String,?>>();
- new SimpleAdapter(this,list,R.layout.listing_pageelement, from, to);
+ client = (OpenRatClient) getIntent().getSerializableExtra(CLIENT);
+
+ new OpenRatClientAsyncTask(this, R.string.waitingforcontent)
+ {
+
+ @Override
+ protected void callServer() throws IOException
+ {
+ objectid = getIntent().getStringExtra(ID);
+ data = client.getPageElements(objectid);
+ }
+
+ protected void doOnSuccess()
+ {
+ SimpleNameAdapter adapter = new SimpleNameAdapter(PageElementsActivity.this,
+ new ArrayList<String>(data.values()));
+ setListAdapter(adapter);
+ };
+
+ }.execute();
+
+
+ ListView list = getListView();
+ list.setOnItemClickListener(new OnItemClickListener()
+ {
+
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view,
+ int position, long id)
+ {
+ String elementid = Arrays.asList(
+ data.keySet().toArray(new String[] {})).get(position);
+ Toast.makeText(PageElementsActivity.this, elementid+": "+data.get(elementid),
+ Toast.LENGTH_SHORT);
+
+ }
+ });
}
diff --git a/src/de/openrat/android/blog/ProjectActivity.java b/src/de/openrat/android/blog/ProjectActivity.java
@@ -95,6 +95,9 @@ public class ProjectActivity extends ListActivity
startActivity(i);
}
+ protected void doOnError(IOException error) {
+ super.doOnError(error);
+ };
}.execute();
}
diff --git a/src/de/openrat/android/blog/util/OpenRatClientAsyncTask.java b/src/de/openrat/android/blog/util/OpenRatClientAsyncTask.java
@@ -51,7 +51,7 @@ public abstract class OpenRatClientAsyncTask extends
this.context = context;
this.progressDialog = new ProgressDialog(context);
- progressDialog.setTitle(R.string.loading);
+ // progressDialog.setTitle(R.string.loading);
progressDialog.setMessage(context.getResources().getString(message));
}
@@ -121,6 +121,7 @@ public abstract class OpenRatClientAsyncTask extends
/**
* Startet die Serveranfrage und fängt auftretene Fehler.
+ *
* @see android.os.AsyncTask#doInBackground(Params[])
*/
@Override
@@ -143,7 +144,8 @@ public abstract class OpenRatClientAsyncTask extends
* Ausführen der Serveranfrage. Auftretene {@link IOException} sollte
* weitergeworfen werden, da daraus ein {@link AlertDialog} erzeugt wird.
*
- * @throws IOException Vom Server erzeugte Fehler
+ * @throws IOException
+ * Vom Server erzeugte Fehler
*/
protected abstract void callServer() throws IOException;
}
diff --git a/src/de/openrat/client/HTTPRequest.java b/src/de/openrat/client/HTTPRequest.java
@@ -486,8 +486,8 @@ public class HTTPRequest implements Serializable
{
// non-200-status seems to be an error.
- throw new IOException("No HTTP 200: Status=" + httpRetCode
- + " (" + httpResponse + ")");
+ //throw new IOException("No HTTP 200: Status=" + httpRetCode
+ // + " (" + httpResponse + ")");
}
while (true)
diff --git a/src/de/openrat/client/OpenRatClient.java b/src/de/openrat/client/OpenRatClient.java
@@ -93,6 +93,52 @@ public class OpenRatClient extends CMSRequest
}
/**
+ * Liest den Inhalt für ein Seitenelement.
+ *
+ * @return
+ */
+ public String getValue(String pageid, String elementid) throws IOException
+ {
+ clearParameters();
+ setAction("pageelement");
+ setActionMethod("edit");
+ setId(pageid);
+ setParameter("elementid", elementid);
+
+ JSONObject json = readJSON();
+
+ try
+ {
+ String value = json.getString("value");
+ return value;
+ }
+ catch (JSONException e)
+ {
+ throw new OpenRatClientException(
+ "JSON-Error while resolving root folder", e);
+ }
+ }
+
+ /**
+ * Setzt einen neuen Inhalt für ein Seitenelement.
+ *
+ * @return
+ */
+ public void setValue(String pageid, String elementid, String value)
+ throws IOException
+ {
+ clearParameters();
+ setAction("pageelement");
+ setActionMethod("save");
+ setId(pageid);
+ setParameter("elementid", elementid);
+ setParameter("value", value);
+ setMethod("POST");
+
+ readJSON();
+ }
+
+ /**
* Ermittelt den Inhalt eines Ordners.
*
* @param folderid
@@ -149,6 +195,7 @@ public class OpenRatClient extends CMSRequest
try
{
response = super.performRequest();
+ Log.d("client", "Server-Response:\n" + response);
}
catch (SocketTimeoutException e)
{
@@ -395,11 +442,46 @@ public class OpenRatClient extends CMSRequest
super.setAction("index");
super.setActionMethod("project");
super.setParameter("id", projectid);
- super.setMethod("POST");
+ //super.setMethod("POST");
readJSON();
}
+ public Map<String, String> getPageElements(String id) throws IOException
+ {
+
+ Map<String, String> el = new HashMap<String, String>();
+ super.clearParameters();
+ super.setAction("page");
+ super.setActionMethod("el");
+ super.setId(id);
+
+ JSONObject json = readJSON();
+
+ final Map<String, String> elementMap = new LinkedHashMap<String, String>();
+
+ try
+ {
+ JSONObject elements = json.getJSONObject("el");
+
+ for (Iterator ti = elements.keys(); ti.hasNext();)
+ {
+ String elementId = (String) ti.next();
+ String pageelementName = elements.getJSONObject(elementId)
+ .getString("name");
+ elementMap.put(elementId, pageelementName);
+ }
+ }
+ catch (JSONException e)
+ {
+ Log.w(this.getClass().getSimpleName(), "\n\n" + json);
+ throw new OpenRatClientException("a property was not found", e);
+ }
+
+ return elementMap;
+
+ }
+
public Map<String, String> getProperties(String type, String id)
throws IOException
{