App can now be flattrd
This commit is contained in:
parent
bc9d13c0f4
commit
27f720b937
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue