mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-01-31 19:04:52 +01:00
* make FlattrClickWorker drop toast when launched interactively
as part of a flattr action (by explicitely flattring a thing) * make it report a notification when it was launched implicitly (when refreshing feeds) or when flattring failed followup on #331
This commit is contained in:
parent
7ebdef2c54
commit
33b1f10744
@ -58,13 +58,22 @@ public class FlattrClickWorker extends AsyncTask<Void, String, Void> {
|
||||
protected final static int NO_TOKEN = 1;
|
||||
protected final static int ENQUEUED = 2;
|
||||
protected final static int NO_THINGS = 3;
|
||||
|
||||
private boolean enqueue_only = false;
|
||||
|
||||
public final static int ENQUEUE_ONLY = 1;
|
||||
public final static int FLATTR_TOAST = 2;
|
||||
public static final int FLATTR_NOTIFICATION = 3;
|
||||
|
||||
private int run_mode = FLATTR_NOTIFICATION;
|
||||
|
||||
private FlattrThing extra_flattr_thing; // additional urls to flattr that do *not* originate from the queue
|
||||
|
||||
public FlattrClickWorker(Context context, boolean enqueue_only) {
|
||||
/**
|
||||
* @param context
|
||||
* @param run_mode can be one of ENQUEUE_ONLY, FLATTR_TOAST and FLATTR_NOTIFICATION
|
||||
*/
|
||||
public FlattrClickWorker(Context context, int run_mode) {
|
||||
this(context);
|
||||
this.enqueue_only = enqueue_only;
|
||||
this.run_mode = run_mode;
|
||||
}
|
||||
|
||||
public FlattrClickWorker(Context context) {
|
||||
@ -84,6 +93,7 @@ public class FlattrClickWorker extends AsyncTask<Void, String, Void> {
|
||||
public FlattrClickWorker(Context context, FlattrThing thing) {
|
||||
this(context);
|
||||
extra_flattr_thing = thing;
|
||||
run_mode = FLATTR_TOAST;
|
||||
Log.d(TAG, "Going to flattr special thing that is not in the queue: " + thing.getTitle());
|
||||
}
|
||||
|
||||
@ -134,29 +144,39 @@ public class FlattrClickWorker extends AsyncTask<Void, String, Void> {
|
||||
|
||||
Log.d(TAG, "Going to post notification: " + notificationBigText);
|
||||
|
||||
if (android.os.Build.VERSION.SDK_INT >= 16) {
|
||||
notificationBuilder = new Notification.BigTextStyle(
|
||||
new Notification.Builder(context)
|
||||
.setOngoing(false)
|
||||
.setContentTitle(notificationTitle)
|
||||
.setContentText(notificationText)
|
||||
.setSubText(notificationSubText)
|
||||
.setSmallIcon(R.drawable.stat_notify_sync))
|
||||
.bigText(notificationText + "\n" + notificationBigText);
|
||||
notificationManager.cancel(NOTIFICATION_ID);
|
||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
||||
}
|
||||
else
|
||||
notificationManager.cancel(NOTIFICATION_ID);
|
||||
|
||||
if (run_mode == FLATTR_NOTIFICATION || flattr_failed.size() > 0)
|
||||
{
|
||||
notificationCompatBuilder = new NotificationCompat.Builder(context) // need new notificationBuilder and cancel/renotify to get rid of progress bar
|
||||
.setContentTitle(notificationTitle)
|
||||
.setContentText(notificationText)
|
||||
.setSubText(notificationBigText)
|
||||
.setTicker(notificationTitle)
|
||||
.setSmallIcon(R.drawable.stat_notify_sync)
|
||||
.setOngoing(false);
|
||||
notificationManager.cancel(NOTIFICATION_ID);
|
||||
notificationManager.notify(NOTIFICATION_ID, notificationCompatBuilder.build());
|
||||
if (android.os.Build.VERSION.SDK_INT >= 16) {
|
||||
notificationBuilder = new Notification.BigTextStyle(
|
||||
new Notification.Builder(context)
|
||||
.setOngoing(false)
|
||||
.setContentTitle(notificationTitle)
|
||||
.setContentText(notificationText)
|
||||
.setSubText(notificationSubText)
|
||||
.setSmallIcon(R.drawable.stat_notify_sync))
|
||||
.bigText(notificationText + "\n" + notificationBigText);
|
||||
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
|
||||
}
|
||||
else
|
||||
{
|
||||
notificationCompatBuilder = new NotificationCompat.Builder(context) // need new notificationBuilder and cancel/renotify to get rid of progress bar
|
||||
.setContentTitle(notificationTitle)
|
||||
.setContentText(notificationText)
|
||||
.setSubText(notificationBigText)
|
||||
.setTicker(notificationTitle)
|
||||
.setSmallIcon(R.drawable.stat_notify_sync)
|
||||
.setOngoing(false);
|
||||
notificationManager.notify(NOTIFICATION_ID, notificationCompatBuilder.build());
|
||||
}
|
||||
}
|
||||
else if (run_mode == FLATTR_TOAST)
|
||||
{
|
||||
Toast.makeText(context.getApplicationContext(),
|
||||
notificationTitle + " " + notificationText,
|
||||
Toast.LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,7 +255,7 @@ public class FlattrClickWorker extends AsyncTask<Void, String, Void> {
|
||||
else if (DBReader.getFlattrQueueEmpty(context) && extra_flattr_thing == null) {
|
||||
exitCode = NO_THINGS;
|
||||
}
|
||||
else if (!haveInternetAccess(context) || enqueue_only) {
|
||||
else if (!haveInternetAccess(context) || run_mode == ENQUEUE_ONLY) {
|
||||
exitCode = ENQUEUED;
|
||||
}
|
||||
else {
|
||||
|
@ -335,9 +335,7 @@ public class FeedMedia extends FeedFile implements Playable {
|
||||
if (UserPreferences.isAutoFlattr() && item.getPaymentLink() != null && item.getFlattrStatus().getUnflattred() && (played_duration > 0.8*duration)) {
|
||||
Log.d(TAG, "saveCurrentPosition: performing auto flattr since played duration " + Integer.toString(played_duration) + " is 80% of file duration " + Integer.toString(duration));
|
||||
item.getFlattrStatus().setFlattrQueue();
|
||||
|
||||
DBWriter.setFeedItem(PodcastApp.getInstance(), item);
|
||||
new FlattrClickWorker(PodcastApp.getInstance(), true).executeAsync();
|
||||
DBWriter.setFeedItemFlattrStatus(PodcastApp.getInstance(), item, false);
|
||||
}
|
||||
|
||||
DBWriter.setFeedMediaPlaybackInformation(PodcastApp.getInstance(), this);
|
||||
|
@ -154,7 +154,7 @@ public final class DBTasks {
|
||||
isRefreshing.set(false);
|
||||
|
||||
if (AppConfig.DEBUG) Log.d(TAG, "Flattring all pending things.");
|
||||
new FlattrClickWorker(context).executeSync(); // flattr pending things
|
||||
new FlattrClickWorker(context, FlattrClickWorker.FLATTR_NOTIFICATION).executeSync(); // flattr pending things
|
||||
|
||||
if (AppConfig.DEBUG) Log.d(TAG, "Fetching flattr status.");
|
||||
new FlattrStatusFetcher(context).executeAsync();
|
||||
|
@ -229,7 +229,7 @@ public class DBWriter {
|
||||
adapter.setFeedFlattrStatus(feed);
|
||||
adapter.close();
|
||||
if (startFlattrClickWorker) {
|
||||
new FlattrClickWorker(context).executeAsync();
|
||||
new FlattrClickWorker(context, FlattrClickWorker.FLATTR_TOAST).executeAsync();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -803,7 +803,7 @@ public class DBWriter {
|
||||
adapter.setFeedItemFlattrStatus(item);
|
||||
adapter.close();
|
||||
if (startFlattrClickWorker) {
|
||||
new FlattrClickWorker(context).executeAsync();
|
||||
new FlattrClickWorker(context, FlattrClickWorker.FLATTR_TOAST).executeAsync();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user