summaryrefslogtreecommitdiff
path: root/src/eu/deki/paste/PasteTask.java
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2012-12-28 03:31:03 +0100
committerReiner Herrmann <reiner@reiner-h.de>2012-12-28 03:31:03 +0100
commit58a3c87671c2b3af270d5db876a047e906c2b556 (patch)
tree40098fdd4cabe72247f60e811c20d99c798834c9 /src/eu/deki/paste/PasteTask.java
parent8a2d76c4903687b3f9199c125c2e945b9285d1a3 (diff)
get correct paste address; display error/success alert dialogs
Diffstat (limited to 'src/eu/deki/paste/PasteTask.java')
-rw-r--r--src/eu/deki/paste/PasteTask.java29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/eu/deki/paste/PasteTask.java b/src/eu/deki/paste/PasteTask.java
index 29b5c32..4a634e5 100644
--- a/src/eu/deki/paste/PasteTask.java
+++ b/src/eu/deki/paste/PasteTask.java
@@ -2,13 +2,14 @@ package eu.deki.paste;
import java.io.IOException;
import android.os.AsyncTask;
-import android.widget.Toast;
import android.content.Context;
+import android.app.AlertDialog;
+import android.app.AlertDialog.Builder;
import android.util.Log;
public abstract class PasteTask extends AsyncTask<String, Void, String>
{
- private String errorMessage = null;
+ private String errorMessage = "Fail";
protected Context parentActivity = null;
public PasteTask(Context parent)
@@ -29,9 +30,18 @@ public abstract class PasteTask extends AsyncTask<String, Void, String>
content = params[1];
expiration = params[2];
+ if(content.length() == 0)
+ {
+ errorMessage = parentActivity.getResources().getString(R.string.contentTooShort);
+ cancel(false);
+ return null;
+ }
+
try
{
result = paste(title, content, expiration);
+ if(result == null)
+ cancel(false);
}
catch(IOException ex)
{
@@ -47,14 +57,23 @@ public abstract class PasteTask extends AsyncTask<String, Void, String>
@Override
protected void onPostExecute(String result)
{
-
+ AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
+ String message = String.format(parentActivity.getResources().getString(R.string.pasteSuccessMessage), result);
+ builder.setMessage(message);
+ builder.setTitle(R.string.pasteSuccessTitle);
+ builder.setPositiveButton("OK", null);
+ builder.create().show();
}
@Override
protected void onCancelled()
{
- //Toast toast = Toast.makeText(parentActivity.getApplicationContext(), errorMessage, Toast.LENGTH_SHORT);
- //toast.show();
+ AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
+ String message = String.format(parentActivity.getResources().getString(R.string.pasteFailMessage), errorMessage);
+ builder.setMessage(message);
+ builder.setTitle(R.string.pasteFailTitle);
+ builder.setPositiveButton("OK", null);
+ builder.create().show();
}
protected abstract String paste(String title, String content, String delay) throws IOException;