From 0cce685cc9cfcd54d87674c88e6173b9b6aa1c2d Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Thu, 26 Jul 2012 12:09:20 +0200 Subject: [PATCH] Restored flattr integration --- res/xml/preferences.xml | 23 ++++++++++- .../activity/FlattrAuthActivity.java | 6 ++- .../activity/PreferenceActivity.java | 40 ++++++++++--------- .../asynctask/FlattrClickWorker.java | 6 ++- .../asynctask/FlattrTokenFetcher.java | 8 +++- .../util/flattr/FlattrServiceCreator.java | 7 +--- .../antennapod/util/flattr/FlattrUtils.java | 13 +++++- .../util/menuhandler/FeedItemMenuHandler.java | 4 +- .../util/menuhandler/FeedMenuHandler.java | 4 +- 9 files changed, 73 insertions(+), 38 deletions(-) diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index e13da035d..d6c9ff1aa 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -31,9 +31,28 @@ android:summary="@string/pref_mobileUpdate_sum" android:title="@string/pref_mobileUpdate_title" /> - + + + + + + + + + - + \ No newline at end of file diff --git a/src/de/danoeh/antennapod/activity/FlattrAuthActivity.java b/src/de/danoeh/antennapod/activity/FlattrAuthActivity.java index 81f002aca..d60662cf5 100644 --- a/src/de/danoeh/antennapod/activity/FlattrAuthActivity.java +++ b/src/de/danoeh/antennapod/activity/FlattrAuthActivity.java @@ -1,6 +1,8 @@ package de.danoeh.antennapod.activity; +import org.shredzone.flattr4j.exception.FlattrException; + import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -19,7 +21,7 @@ import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; /** Guides the user through the authentication process */ -/* + public class FlattrAuthActivity extends SherlockActivity { private static final String TAG = "FlattrAuthActivity"; @@ -116,4 +118,4 @@ public class FlattrAuthActivity extends SherlockActivity { } -}*/ +} diff --git a/src/de/danoeh/antennapod/activity/PreferenceActivity.java b/src/de/danoeh/antennapod/activity/PreferenceActivity.java index af1b1dbae..8c0d1eb91 100644 --- a/src/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/src/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -11,6 +11,7 @@ import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuItem; import de.danoeh.antennapod.R; +import de.danoeh.antennapod.asynctask.FlattrClickWorker; import de.danoeh.antennapod.util.flattr.FlattrUtils; public class PreferenceActivity extends SherlockPreferenceActivity { @@ -32,24 +33,25 @@ public class PreferenceActivity extends SherlockPreferenceActivity { @Override public boolean onPreferenceClick(Preference preference) { - Uri supportUri = Uri.parse(FlattrUtils.APP_LINK); - startActivity(new Intent(Intent.ACTION_VIEW, supportUri)); + new FlattrClickWorker(PreferenceActivity.this, + FlattrUtils.APP_URL).executeAsync(); return true; } }); - /* - * Disabled until it works - * findPreference(PREF_FLATTR_REVOKE).setOnPreferenceClickListener( new - * OnPreferenceClickListener() { - * - * @Override public boolean onPreferenceClick(Preference preference) { - * FlattrUtils.revokeAccessToken(PreferenceActivity.this); - * checkItemVisibility(); return true; } - * - * }); - */ + findPreference(PREF_FLATTR_REVOKE).setOnPreferenceClickListener( + new OnPreferenceClickListener() { + + @Override + public boolean onPreferenceClick(Preference preference) { + FlattrUtils.revokeAccessToken(PreferenceActivity.this); + checkItemVisibility(); + return true; + } + + }); + findPreference(PREF_ABOUT).setOnPreferenceClickListener( new OnPreferenceClickListener() { @@ -72,12 +74,12 @@ public class PreferenceActivity extends SherlockPreferenceActivity { @SuppressWarnings("deprecation") private void checkItemVisibility() { - /* - * boolean hasFlattrToken = FlattrUtils.hasToken(); - * - * findPreference(PREF_FLATTR_AUTH).setEnabled(!hasFlattrToken); - * findPreference(PREF_FLATTR_REVOKE).setEnabled(hasFlattrToken); - */ + + boolean hasFlattrToken = FlattrUtils.hasToken(); + + findPreference(PREF_FLATTR_AUTH).setEnabled(!hasFlattrToken); + findPreference(PREF_FLATTR_REVOKE).setEnabled(hasFlattrToken); + } @Override diff --git a/src/de/danoeh/antennapod/asynctask/FlattrClickWorker.java b/src/de/danoeh/antennapod/asynctask/FlattrClickWorker.java index c0d0b10bc..975aa5efe 100644 --- a/src/de/danoeh/antennapod/asynctask/FlattrClickWorker.java +++ b/src/de/danoeh/antennapod/asynctask/FlattrClickWorker.java @@ -1,5 +1,7 @@ package de.danoeh.antennapod.asynctask; +import org.shredzone.flattr4j.exception.FlattrException; + import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.Context; @@ -11,7 +13,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.util.flattr.FlattrUtils; /** Performs a click action in a background thread. */ -/* + public class FlattrClickWorker extends AsyncTask { protected static final String TAG = "FlattrClickWorker"; protected Context context; @@ -110,4 +112,4 @@ public class FlattrClickWorker extends AsyncTask { } } -}*/ +} diff --git a/src/de/danoeh/antennapod/asynctask/FlattrTokenFetcher.java b/src/de/danoeh/antennapod/asynctask/FlattrTokenFetcher.java index b61f88a50..b56e83d25 100644 --- a/src/de/danoeh/antennapod/asynctask/FlattrTokenFetcher.java +++ b/src/de/danoeh/antennapod/asynctask/FlattrTokenFetcher.java @@ -1,6 +1,10 @@ package de.danoeh.antennapod.asynctask; +import org.shredzone.flattr4j.exception.FlattrException; +import org.shredzone.flattr4j.oauth.AccessToken; +import org.shredzone.flattr4j.oauth.AndroidAuthenticator; + import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.Context; @@ -9,10 +13,11 @@ import android.os.AsyncTask; import android.util.Log; import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; +import de.danoeh.antennapod.activity.FlattrAuthActivity; import de.danoeh.antennapod.util.flattr.FlattrUtils; /** Fetches the access token in the background in order to avoid networkOnMainThread exception. */ -/* + public class FlattrTokenFetcher extends AsyncTask { private static final String TAG = "FlattrTokenFetcher"; Context context; @@ -89,4 +94,3 @@ public class FlattrTokenFetcher extends AsyncTask { } } -*/ \ No newline at end of file diff --git a/src/de/danoeh/antennapod/util/flattr/FlattrServiceCreator.java b/src/de/danoeh/antennapod/util/flattr/FlattrServiceCreator.java index 97c4c6c6b..6e42fcde2 100644 --- a/src/de/danoeh/antennapod/util/flattr/FlattrServiceCreator.java +++ b/src/de/danoeh/antennapod/util/flattr/FlattrServiceCreator.java @@ -1,6 +1,4 @@ package de.danoeh.antennapod.util.flattr; -/* -package de.danoeh.antennapod.util; import org.shredzone.flattr4j.FlattrFactory; import org.shredzone.flattr4j.FlattrService; @@ -9,9 +7,9 @@ import org.shredzone.flattr4j.oauth.AccessToken; import de.danoeh.antennapod.AppConfig; import android.util.Log; -*/ + /** Ensures that only one instance of the FlattrService class exists at a time */ -/* + public class FlattrServiceCreator { public static final String TAG = "FlattrServiceCreator"; @@ -27,4 +25,3 @@ public class FlattrServiceCreator { } } -*/ \ No newline at end of file diff --git a/src/de/danoeh/antennapod/util/flattr/FlattrUtils.java b/src/de/danoeh/antennapod/util/flattr/FlattrUtils.java index eff0dc49b..b1ae64b06 100644 --- a/src/de/danoeh/antennapod/util/flattr/FlattrUtils.java +++ b/src/de/danoeh/antennapod/util/flattr/FlattrUtils.java @@ -2,6 +2,13 @@ package de.danoeh.antennapod.util.flattr; import java.util.EnumSet; +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; + import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.ProgressDialog; @@ -19,6 +26,8 @@ import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.PodcastApp; import de.danoeh.antennapod.R; +import de.danoeh.antennapod.activity.FlattrAuthActivity; +import de.danoeh.antennapod.asynctask.FlattrTokenFetcher; /** Utility methods for doing something with flattr. */ @@ -36,7 +45,7 @@ public class FlattrUtils { // Human-readable flattr-page. public static final String APP_LINK = "https://flattr.com/thing/745609/"; public static final String APP_THING_ID = "745609"; -/* + private static volatile AccessToken cachedToken; private static AndroidAuthenticator createAuthenticator() { @@ -211,7 +220,7 @@ public class FlattrUtils { }); builder.create().show(); } - */ + } \ No newline at end of file diff --git a/src/de/danoeh/antennapod/util/menuhandler/FeedItemMenuHandler.java b/src/de/danoeh/antennapod/util/menuhandler/FeedItemMenuHandler.java index 9cdb7d519..a5e697140 100644 --- a/src/de/danoeh/antennapod/util/menuhandler/FeedItemMenuHandler.java +++ b/src/de/danoeh/antennapod/util/menuhandler/FeedItemMenuHandler.java @@ -9,6 +9,7 @@ import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import de.danoeh.antennapod.R; +import de.danoeh.antennapod.asynctask.FlattrClickWorker; import de.danoeh.antennapod.feed.FeedItem; import de.danoeh.antennapod.feed.FeedManager; import de.danoeh.antennapod.storage.DownloadRequester; @@ -103,8 +104,7 @@ public class FeedItemMenuHandler { context.startActivity(new Intent(Intent.ACTION_VIEW, uri)); break; case R.id.support_item: - Uri supportUri = Uri.parse(selectedItem.getPaymentLink()); - context.startActivity(new Intent(Intent.ACTION_VIEW, supportUri)); + new FlattrClickWorker(context, selectedItem.getPaymentLink()).executeAsync(); break; case R.id.share_link_item: ShareUtils.shareFeedItemLink(context, selectedItem); diff --git a/src/de/danoeh/antennapod/util/menuhandler/FeedMenuHandler.java b/src/de/danoeh/antennapod/util/menuhandler/FeedMenuHandler.java index 35e22ebee..38adc0b50 100644 --- a/src/de/danoeh/antennapod/util/menuhandler/FeedMenuHandler.java +++ b/src/de/danoeh/antennapod/util/menuhandler/FeedMenuHandler.java @@ -11,6 +11,7 @@ import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; import de.danoeh.antennapod.activity.FeedInfoActivity; +import de.danoeh.antennapod.asynctask.FlattrClickWorker; import de.danoeh.antennapod.feed.Feed; import de.danoeh.antennapod.feed.FeedItem; import de.danoeh.antennapod.feed.FeedManager; @@ -72,8 +73,7 @@ public class FeedMenuHandler { context.startActivity(new Intent(Intent.ACTION_VIEW, uri)); break; case R.id.support_item: - Uri supportUri = Uri.parse(selectedFeed.getPaymentLink()); - context.startActivity(new Intent(Intent.ACTION_VIEW, supportUri)); + new FlattrClickWorker(context, selectedFeed.getPaymentLink()).executeAsync(); break; case R.id.share_link_item: ShareUtils.shareFeedlink(context, selectedFeed);