From 27f720b9377a57db9601eb1380f895e33dd11908 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Fri, 20 Jul 2012 12:51:26 +0200 Subject: [PATCH] App can now be flattrd --- .../activity/PreferenceActivity.java | 13 +++++++++++-- src/de/danoeh/antennapod/util/FlattrUtils.java | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/de/danoeh/antennapod/activity/PreferenceActivity.java b/src/de/danoeh/antennapod/activity/PreferenceActivity.java index f737aa28b..8cca57c77 100644 --- a/src/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/src/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -1,5 +1,7 @@ package de.danoeh.antennapod.activity; +import org.shredzone.flattr4j.model.Thing; + import android.content.Intent; import android.os.Bundle; import android.preference.Preference; @@ -10,6 +12,7 @@ import com.actionbarsherlock.app.SherlockPreferenceActivity; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; +import de.danoeh.antennapod.asynctask.FlattrClickWorker; import de.danoeh.antennapod.util.FlattrUtils; import de.danoeh.antennapod.R; @@ -32,7 +35,12 @@ public class PreferenceActivity extends SherlockPreferenceActivity { @Override public boolean onPreferenceClick(Preference preference) { - Log.d(TAG, "Flattring this app"); // TODO implement + Thing appThing = FlattrUtils + .getAppThing(PreferenceActivity.this); + if (appThing != null) { + new FlattrClickWorker(PreferenceActivity.this, + appThing.getUrl()).execute(); + } return true; } }); @@ -84,7 +92,8 @@ public class PreferenceActivity extends SherlockPreferenceActivity { public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: - startActivity(new Intent(PreferenceActivity.this, MainActivity.class)); + startActivity(new Intent(PreferenceActivity.this, + MainActivity.class)); break; default: return false; diff --git a/src/de/danoeh/antennapod/util/FlattrUtils.java b/src/de/danoeh/antennapod/util/FlattrUtils.java index eb1a5ca6e..6f009698a 100644 --- a/src/de/danoeh/antennapod/util/FlattrUtils.java +++ b/src/de/danoeh/antennapod/util/FlattrUtils.java @@ -5,6 +5,7 @@ import java.util.EnumSet; import org.shredzone.flattr4j.FlattrFactory; import org.shredzone.flattr4j.FlattrService; import org.shredzone.flattr4j.exception.FlattrException; +import org.shredzone.flattr4j.model.Thing; import org.shredzone.flattr4j.oauth.AccessToken; import org.shredzone.flattr4j.oauth.AndroidAuthenticator; import org.shredzone.flattr4j.oauth.Scope; @@ -37,6 +38,10 @@ public class FlattrUtils { private static final String PREF_ACCESS_TOKEN = "de.danoeh.antennapod.preference.flattrAccessToken"; + /** Flattr URL for this app. */ + public static final String APP_URL = "http://flattr.com/thing/745609"; + public static final String APP_THING_ID = "745609"; + private static AndroidAuthenticator createAuthenticator() { return new AndroidAuthenticator(HOST_NAME, APP_KEY, APP_SECRET); } @@ -87,6 +92,19 @@ public class FlattrUtils { Log.d(TAG, "Deleting flattr token"); storeToken(null); } + + /** Get the thing that represents this app */ + public static Thing getAppThing(Context context) { + FlattrFactory factory = FlattrFactory.getInstance(); + FlattrService fs = factory.createFlattrService(retrieveToken()); + try { + return fs.getThing(Thing.withId(APP_THING_ID)); + } catch (FlattrException e) { + e.printStackTrace(); + showErrorDialog(context, e.getMessage()); + return null; + } + } public static void clickUrl(AccessToken token, Context context, String url) throws FlattrException {