Restored flattr integration

This commit is contained in:
daniel oeh 2012-07-26 12:09:20 +02:00
parent 20397a06e6
commit 0cce685cc9
9 changed files with 73 additions and 38 deletions

View File

@ -31,9 +31,28 @@
android:summary="@string/pref_mobileUpdate_sum"
android:title="@string/pref_mobileUpdate_title" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/other_pref" ><Preference android:summary="@string/pref_flattr_this_app_sum" android:title="@string/pref_flattr_this_app_title" android:key="prefFlattrThisApp">
<PreferenceCategory android:title="@string/flattr_settings_label" >
<PreferenceScreen
android:key="pref_flattr_authenticate"
android:summary="@string/pref_flattr_auth_sum"
android:title="@string/pref_flattr_auth_title" >
<intent android:action=".activities.FlattrAuthActivity" />
</PreferenceScreen>
<Preference
android:key="prefRevokeAccess"
android:summary="@string/pref_revokeAccess_sum"
android:title="@string/pref_revokeAccess_title" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/other_pref" >
<Preference
android:key="prefFlattrThisApp"
android:summary="@string/pref_flattr_this_app_sum"
android:title="@string/pref_flattr_this_app_title" >
</Preference>
<Preference android:title="@string/about_pref" android:key="prefAbout"/>
<Preference
android:key="prefAbout"
android:title="@string/about_pref" />
</PreferenceCategory>
</PreferenceScreen>

View File

@ -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 {
}
}*/
}

View File

@ -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

View File

@ -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<Void, Void, Void> {
protected static final String TAG = "FlattrClickWorker";
protected Context context;
@ -110,4 +112,4 @@ public class FlattrClickWorker extends AsyncTask<Void, Void, Void> {
}
}
}*/
}

View File

@ -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<Void, Void, AccessToken> {
private static final String TAG = "FlattrTokenFetcher";
Context context;
@ -89,4 +94,3 @@ public class FlattrTokenFetcher extends AsyncTask<Void, Void, AccessToken> {
}
}
*/

View File

@ -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 {
}
}
*/

View File

@ -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();
}
*/
}

View File

@ -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);

View File

@ -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);