From 0e8909807d5a4c7e74c4c2ab877b68e172f17a6f Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Thu, 12 Jul 2012 15:41:56 +0200 Subject: [PATCH] Flattring things now works --- AndroidManifest.xml | 49 ++++++++++++++++++------- res/values/strings.xml | 1 + src/de/podfetcher/util/FlattrUtils.java | 36 ++++++++++++------ 3 files changed, 62 insertions(+), 24 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 1c591b410..c2a0240f0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -52,9 +52,13 @@ android:enabled="true" > - + - + @@ -62,7 +66,7 @@ - + @@ -74,25 +78,44 @@ android:enabled="true" android:exported="false" > - + + - + - + - + + - + - + - - + + + + - - + + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 9cea3f619..5d83dc80d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -113,5 +113,6 @@ Authenticate Action forbidden Antennapod has no permission for this action. The reason for this could be that the access token of Antennapod to your account has been revoked. You can either re-reauthenticate or visit the website of the thing instead. + Successfully flattred this thing! \ No newline at end of file diff --git a/src/de/podfetcher/util/FlattrUtils.java b/src/de/podfetcher/util/FlattrUtils.java index 7a46bae8a..d4eb1aa64 100644 --- a/src/de/podfetcher/util/FlattrUtils.java +++ b/src/de/podfetcher/util/FlattrUtils.java @@ -5,15 +5,10 @@ import java.util.EnumSet; import org.shredzone.flattr4j.FlattrFactory; import org.shredzone.flattr4j.FlattrService; import org.shredzone.flattr4j.exception.FlattrException; -import org.shredzone.flattr4j.exception.ForbiddenException; import org.shredzone.flattr4j.oauth.AccessToken; import org.shredzone.flattr4j.oauth.AndroidAuthenticator; import org.shredzone.flattr4j.oauth.Scope; -import de.podfetcher.PodcastApp; -import de.podfetcher.R; -import de.podfetcher.activity.FlattrAuthActivity; - import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; @@ -23,14 +18,18 @@ import android.content.SharedPreferences; import android.net.Uri; import android.preference.PreferenceManager; import android.util.Log; +import android.widget.Toast; +import de.podfetcher.PodcastApp; +import de.podfetcher.R; +import de.podfetcher.activity.FlattrAuthActivity; /** Utility methods for doing something with flattr. */ public class FlattrUtils { private static final String TAG = "FlattrUtils"; - private static final String HOST_NAME = ""; - private static final String APP_KEY = ""; - private static final String APP_SECRET = ""; + private static final String HOST_NAME = "de.danoeh.antennapod"; + private static final String APP_KEY = "qBoVa9rhUOSPCrBwYPjzyNytHRbkPul5VzRWz93jNMZf4rCS7LhwpGPWnR73biZW"; + private static final String APP_SECRET = "IGJ8FDiif7n9pPSmr0JHwotK5rD7AsU8Yt7uWfC2cQ2svKFNAekXtExpV1mlk7k8"; private static final String PREF_ACCESS_TOKEN = "de.danoeh.antennapod.preference.flattrAccessToken"; @@ -92,11 +91,12 @@ public class FlattrUtils { FlattrService fs = factory.createFlattrService(retrieveToken()); try { fs.click(url); - } catch (ForbiddenException fe) { - deleteToken(); - showForbiddenDialog(context, url); + Toast toast = Toast.makeText(context.getApplicationContext(), + R.string.flattr_click_success, Toast.LENGTH_LONG); + toast.show(); } catch (FlattrException e) { e.printStackTrace(); + showErrorDialog(context, e.getMessage()); } } else { showNoTokenDialog(context, url); @@ -174,4 +174,18 @@ public class FlattrUtils { }); builder.create().show(); } + + private static void showErrorDialog(final Context context, final String msg) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.error_label); + builder.setMessage(msg); + builder.setNeutralButton(android.R.string.ok, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.cancel(); + } + }); + builder.create().show(); + } }