Re-enable support for the "Flattr this app" item in Settings
This commit is contained in:
parent
4b998019ef
commit
375aefb2bf
@ -30,6 +30,7 @@ import de.danoeh.antennapod.preferences.GpodnetPreferences;
|
||||
import de.danoeh.antennapod.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.util.flattr.FlattrStatus;
|
||||
import de.danoeh.antennapod.util.flattr.FlattrUtils;
|
||||
import de.danoeh.antennapod.util.flattr.SimpleFlattrThing;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -80,7 +81,11 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
new FlattrClickWorker(PreferenceActivity.this,
|
||||
FlattrUtils.APP_URL).executeAsync();
|
||||
new SimpleFlattrThing(PreferenceActivity.this.getString(R.string.app_name),
|
||||
FlattrUtils.APP_URL,
|
||||
new FlattrStatus(FlattrStatus.STATUS_QUEUE)
|
||||
)
|
||||
).executeAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ public class FlattrClickWorker extends AsyncTask<Void, String, Void> {
|
||||
protected final static int NO_THINGS = 3;
|
||||
|
||||
private boolean enqueue_only = false;
|
||||
private FlattrThing extra_flattr_thing; // additional urls to flattr that do *not* originate from the queue
|
||||
|
||||
public FlattrClickWorker(Context context, boolean enqueue_only) {
|
||||
this(context);
|
||||
@ -77,11 +78,13 @@ public class FlattrClickWorker extends AsyncTask<Void, String, Void> {
|
||||
/* only used in PreferencesActivity for flattring antennapod itself,
|
||||
* can't really enqueue this thing
|
||||
*/
|
||||
public FlattrClickWorker(Context context, String url) {
|
||||
Log.e(TAG, "Not implemented yet");
|
||||
public FlattrClickWorker(Context context, FlattrThing thing) {
|
||||
this(context);
|
||||
extra_flattr_thing = thing;
|
||||
Log.d(TAG, "Going to flattr special thing that is not in the queue: " + thing.getTitle());
|
||||
}
|
||||
|
||||
protected void onNoAccessToken() {
|
||||
protected void onNoAccessToken() {
|
||||
Log.w(TAG, "No access token was available");
|
||||
FlattrUtils.showNoTokenDialog(context, "");
|
||||
}
|
||||
@ -196,7 +199,7 @@ public class FlattrClickWorker extends AsyncTask<Void, String, Void> {
|
||||
if (!FlattrUtils.hasToken()) {
|
||||
exitCode = NO_TOKEN;
|
||||
}
|
||||
else if (DBReader.getFlattrQueueEmpty(context)) {
|
||||
else if (DBReader.getFlattrQueueEmpty(context) && extra_flattr_thing == null) {
|
||||
exitCode = NO_THINGS;
|
||||
}
|
||||
else if (!haveInternetAccess(context) || enqueue_only) {
|
||||
@ -206,6 +209,9 @@ public class FlattrClickWorker extends AsyncTask<Void, String, Void> {
|
||||
List<FlattrThing> flattrList = DBReader.getFlattrQueue(context);
|
||||
Log.d(TAG, "flattrQueue processing list with " + flattrList.size() + " items.");
|
||||
|
||||
if (extra_flattr_thing != null)
|
||||
flattrList.add(extra_flattr_thing);
|
||||
|
||||
flattrd.ensureCapacity(flattrList.size());
|
||||
|
||||
for (FlattrThing thing: flattrList) {
|
||||
|
@ -853,8 +853,10 @@ public class DBWriter {
|
||||
DBWriter.setFeedItem(context, (FeedItem) thing);
|
||||
else if (thing instanceof Feed)
|
||||
DBWriter.setCompleteFeed(context, (Feed) thing);
|
||||
else if (thing instanceof SimpleFlattrThing)
|
||||
{} // SimpleFlattrThings are generated on the fly and do not have DB backing
|
||||
else
|
||||
Log.e(TAG, "flattrQueue processing - thing is neither FeedItem nor Feed");
|
||||
Log.e(TAG, "flattrQueue processing - thing is neither FeedItem nor Feed nor SimpleFlattrThing");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3,9 +3,9 @@ package de.danoeh.antennapod.util.flattr;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class FlattrStatus {
|
||||
private static final int STATUS_UNFLATTERED = 0;
|
||||
private static final int STATUS_QUEUE = 1;
|
||||
private static final int STATUS_FLATTRED = 2;
|
||||
public static final int STATUS_UNFLATTERED = 0;
|
||||
public static final int STATUS_QUEUE = 1;
|
||||
public static final int STATUS_FLATTRED = 2;
|
||||
|
||||
private int status = STATUS_UNFLATTERED;
|
||||
private Calendar lastFlattred;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.danoeh.antennapod.util.flattr;
|
||||
|
||||
import de.danoeh.antennapod.util.flattr.FlattrStatus;
|
||||
|
||||
public interface FlattrThing {
|
||||
public String getTitle();
|
||||
public String getPaymentLink();
|
||||
|
30
src/de/danoeh/antennapod/util/flattr/SimpleFlattrThing.java
Normal file
30
src/de/danoeh/antennapod/util/flattr/SimpleFlattrThing.java
Normal file
@ -0,0 +1,30 @@
|
||||
package de.danoeh.antennapod.util.flattr;
|
||||
|
||||
/* SimpleFlattrThing is a trivial implementation of the FlattrThing interface */
|
||||
public class SimpleFlattrThing implements FlattrThing {
|
||||
public SimpleFlattrThing(String title, String url, FlattrStatus status)
|
||||
{
|
||||
this.title = title;
|
||||
this.url = url;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public String getPaymentLink()
|
||||
{
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public FlattrStatus getFlattrStatus()
|
||||
{
|
||||
return this.status;
|
||||
}
|
||||
|
||||
private String title;
|
||||
private String url;
|
||||
private FlattrStatus status;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user