commit fc6d30776c00b07cfcab1f62752dca66f1058680
parent 49527a0a84046f92443f1ce016e90a2f3578f1b4
Author: dankert <devnull@localhost>
Date: Tue, 18 Oct 2011 00:18:19 +0200
PropertiesActivity läuft jetzt; Besser Code für AsyncTask mit Hilfsklasse.
Diffstat:
7 files changed, 280 insertions(+), 20 deletions(-)
diff --git a/res/layout/properties.xml b/res/layout/properties.xml
@@ -18,6 +18,12 @@
<EditText android:id="@+id/filename" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
+ <TableRow>
+ <TextView android:text="@string/filename"
+ android:layout_width="wrap_content" android:layout_height="wrap_content" />
+ <EditText android:id="@+id/description" android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+ </TableRow>
</TableLayout>
<Button android:id="@+id/button_save" android:text="@string/save"
diff --git a/src/de/openrat/android/blog/FolderActivity.java b/src/de/openrat/android/blog/FolderActivity.java
@@ -213,7 +213,7 @@ public class FolderActivity extends ListActivity
PropertiesActivity.class);
intent.putExtra(CLIENT, client);
intent.putExtra("objectid", entry.id);
- intent.putExtra(TYP, entry.type);
+ intent.putExtra(TYP, entry.type.name().toLowerCase());
startActivity(intent);
return true;
diff --git a/src/de/openrat/android/blog/NewActivity.java b/src/de/openrat/android/blog/NewActivity.java
@@ -2,9 +2,11 @@ package de.openrat.android.blog;
import android.app.Activity;
import android.os.Bundle;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
-import de.openrat.client.CMSRequest;
import de.openrat.client.OpenRatClient;
public class NewActivity extends Activity
@@ -28,10 +30,28 @@ public class NewActivity extends Activity
setContentView(R.layout.new1);
final RadioGroup radioGroupTemplates = (RadioGroup) findViewById(R.id.RadioGroupTemplates);
- radioGroupTemplates.setEnabled(menuid == R.id.menu_newpage);
+ if (menuid == R.id.menu_newpage)
+ {
+ radioGroupTemplates.setVisibility(View.VISIBLE);
- RadioButton radioButton = new RadioButton(this);
- radioButton.setText("test");
- radioGroupTemplates.addView(radioButton);
+ RadioButton radioButton = new RadioButton(this);
+ radioButton.setText("test");
+ radioGroupTemplates.addView(radioButton);
+
+ }
+ else
+ {
+ radioGroupTemplates.setVisibility(View.INVISIBLE);
+ }
+
+ final Button button = (Button) findViewById(R.id.button_save);
+ button.setOnClickListener(new OnClickListener()
+ {
+ @Override
+ public void onClick(View v)
+ {
+
+ }
+ });
}
}
diff --git a/src/de/openrat/android/blog/OpenRatBlog.java b/src/de/openrat/android/blog/OpenRatBlog.java
@@ -35,6 +35,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
+import de.openrat.android.blog.util.OpenRatClientAsyncTask;
import de.openrat.client.OpenRatClient;
/**
@@ -71,7 +72,7 @@ public class OpenRatBlog extends Activity
@Override
public void onClick(View v)
{
- AsyncTask<Void, Void, Void> loginTask = new AsyncTask<Void, Void, Void>()
+ AsyncTask<Void, Void, Void> oldloginTask = new AsyncTask<Void, Void, Void>()
{
ProgressDialog dialog = new ProgressDialog(OpenRatBlog.this);
@@ -98,7 +99,6 @@ public class OpenRatBlog extends Activity
client.login(prefs.getString("username", ""), prefs
.getString("password", ""));
-
// Verbindung und Login waren erfolgreich.
// Jetzt zur Projekt-Liste wechseln.
final Intent intent = new Intent(OpenRatBlog.this,
@@ -123,11 +123,45 @@ public class OpenRatBlog extends Activity
}
});
}
-
+
return null;
}
};
- loginTask.execute();
+ // oldloginTask.execute();
+
+ new OpenRatClientAsyncTask(OpenRatBlog.this, R.string.loading,
+ R.string.waitingforlogin)
+ {
+ @Override
+ protected void callServer() throws IOException
+ {
+ client.login(prefs.getString("username", ""), prefs
+ .getString("password", ""));
+
+ // Verbindung und Login waren erfolgreich.
+ // Jetzt zur Projekt-Liste wechseln.
+ final Intent intent = new Intent(OpenRatBlog.this,
+ ProjectActivity.class);
+ intent.putExtra(ProjectActivity.CLIENT, client);
+ startActivity(intent);
+ }
+
+ protected void doOnError(final IOException e)
+ {
+
+ runOnUiThread(new Runnable()
+ {
+
+ @Override
+ public void run()
+ {
+ Toast.makeText(OpenRatBlog.this,
+ e.getMessage(), Toast.LENGTH_LONG);
+ }
+ });
+ };
+
+ }.execute();
}
});
diff --git a/src/de/openrat/android/blog/PropertiesActivity.java b/src/de/openrat/android/blog/PropertiesActivity.java
@@ -1,9 +1,17 @@
package de.openrat.android.blog;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
import android.app.Activity;
import android.os.Bundle;
+import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
+import android.widget.EditText;
+import android.widget.Toast;
+import de.openrat.client.OpenRatClient;
public class PropertiesActivity extends Activity
{
@@ -15,15 +23,58 @@ public class PropertiesActivity extends Activity
setContentView(R.layout.properties);
- findViewById(R.id.button_save).setOnClickListener(new OnClickListener()
+ final OpenRatClient client = (OpenRatClient) getIntent()
+ .getSerializableExtra("client");
+ final String id = getIntent().getStringExtra("objectid");
+ final String type = getIntent().getStringExtra("type");
+
+ try
{
+ final Map<String, String> properties = client.getProperties(type,
+ id);
+
+ final EditText editTextName = (EditText) findViewById(R.id.name);
+ editTextName.setText(properties.get("name"));
- @Override
- public void onClick(View v)
- {
+ final EditText editTextFilename = (EditText) findViewById(R.id.filename);
+ editTextFilename.setText(properties.get("filename"));
- }
- });
+ final EditText editTextDesc = (EditText) findViewById(R.id.description);
+ editTextDesc.setText(properties.get("description"));
+
+ findViewById(R.id.button_save).setOnClickListener(
+ new OnClickListener()
+ {
+ @Override
+ public void onClick(View v)
+ {
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put("name", editTextName.getText()
+ .toString());
+ properties.put("filename", editTextFilename
+ .getText().toString());
+ properties.put("description", editTextDesc
+ .getText().toString());
+ try
+ {
+ client.setProperties(type, id, properties);
+ }
+ catch (IOException e)
+ {
+ Log.e(this.getClass().getSimpleName(), e
+ .getMessage(), e);
+ Toast.makeText(PropertiesActivity.this, e
+ .getMessage(), Toast.LENGTH_SHORT);
+ }
+ PropertiesActivity.this.finish();
+ }
+ });
+ }
+ catch (IOException e)
+ {
+ Log.e(this.getClass().getSimpleName(), e.getMessage(), e);
+ Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT);
+ }
}
}
diff --git a/src/de/openrat/android/blog/util/OpenRatClientAsyncTask.java b/src/de/openrat/android/blog/util/OpenRatClientAsyncTask.java
@@ -0,0 +1,101 @@
+/**
+ *
+ */
+package de.openrat.android.blog.util;
+
+import java.io.IOException;
+import java.util.List;
+
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.os.AsyncTask;
+import android.util.Log;
+import de.openrat.android.blog.FolderEntry;
+
+/**
+ * @author dankert
+ *
+ */
+public abstract class OpenRatClientAsyncTask extends
+ AsyncTask<Void, Void, Void>
+{
+ private ProgressDialog dialog;
+ private Context context;
+
+ public OpenRatClientAsyncTask(Context context, ProgressDialog dialog)
+ {
+ this.dialog = dialog;
+ this.context = context;
+ }
+
+ public OpenRatClientAsyncTask(Context context, int title, CharSequence message)
+ {
+ this.dialog = new ProgressDialog(context);
+ dialog.setTitle(title);
+ dialog.setMessage(message);
+ this.context = context;
+ }
+
+ public OpenRatClientAsyncTask(Context context, int title, int message)
+ {
+ this.dialog = new ProgressDialog(context);
+ dialog.setTitle(title);
+ dialog.setMessage(context.getResources().getString(message));
+ this.context = context;
+ }
+
+ @Override
+ protected void onPreExecute()
+ {
+ // dialog.setTitle(getResources().getString(R.string.loading));
+ // dialog.setMessage(getResources().getString(
+ // R.string.waitingforcontent));
+ dialog.show();
+ }
+
+ protected void onPostExecute(List<FolderEntry> result)
+ {
+ dialog.dismiss();
+
+ };
+
+ @Override
+ protected Void doInBackground(Void... params)
+ {
+ try
+ {
+ callServer();
+ }
+ catch (IOException e)
+ {
+ dialog.dismiss();
+ Log.e(this.getClass().getName(), e.getMessage(), e);
+
+ doOnError(e);
+
+ }
+
+ return null;
+ }
+
+ /**
+ * @param e
+ */
+ protected void doOnError(IOException e) {
+ dialog.setMessage( e.getMessage() );
+ dialog.show();
+ try
+ {
+ Thread.sleep(2000);
+ }
+ catch (InterruptedException e1)
+ {
+ }
+ dialog.dismiss();
+ }
+
+ /**
+ * @throws IOException
+ */
+ protected abstract void callServer() throws IOException;
+}
diff --git a/src/de/openrat/client/OpenRatClient.java b/src/de/openrat/client/OpenRatClient.java
@@ -4,14 +4,15 @@ import java.io.File;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
-
import de.openrat.android.blog.FolderEntry;
import de.openrat.android.blog.FolderEntry.FType;
import de.openrat.android.blog.util.FileUtils;
@@ -138,8 +139,7 @@ public class OpenRatClient extends CMSRequest
}
catch (SocketTimeoutException e)
{
- throw new OpenRatClientException(
- "Timeout exceeded", e);
+ throw new OpenRatClientException("Timeout exceeded", e);
}
catch (IOException e)
{
@@ -178,7 +178,8 @@ public class OpenRatClient extends CMSRequest
{
// throw new OpenRatClientException(
// "Server error: Response does not include a attribute 'notice_status'.\n"+response);
- return json; // Alles OK, kann passieren, wenn es keine Notices gibt.
+ return json; // Alles OK, kann passieren, wenn es keine Notices
+ // gibt.
}
}
@@ -382,4 +383,51 @@ public class OpenRatClient extends CMSRequest
readJSON();
}
+
+ public Map<String, String> getProperties(String type, String id)
+ throws IOException
+ {
+ super.clearParameters();
+ super.setAction(type);
+ super.setActionMethod("prop");
+ super.setId(id);
+
+ JSONObject json = readJSON();
+
+ final Map<String, String> properties = new HashMap<String, String>();
+
+ try
+ {
+ properties.put("name", json.getString("name"));
+ properties.put("filename", json.getString("filename"));
+ properties.put("description", json.getString("description"));
+ }
+ catch (JSONException e)
+ {
+ throw new OpenRatClientException("a property was not found", e);
+ }
+
+ return properties;
+
+ }
+
+ public void setProperties(String type, String id,
+ Map<String, String> properties) throws IOException
+ {
+ super.clearParameters();
+ super.setAction(type);
+ if ( type.equals("page") )
+ super.setActionMethod("prop");
+ else
+ super.setActionMethod("saveprop");
+ super.setMethod("POST");
+ super.setId(id);
+
+ for (String name : properties.keySet())
+ {
+ super.setParameter(name, properties.get(name));
+ }
+
+ readJSON();
+ }
}