Fixed auto-flattr when playback ends
This commit is contained in:
parent
421786e5c8
commit
df288f8f68
|
@ -408,8 +408,17 @@ public class UserPreferences implements
|
||||||
instance.updateInterval = newValue;
|
instance.updateInterval = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the auto-flattr settings
|
||||||
|
*
|
||||||
|
* @param context For accessing the shared preferences
|
||||||
|
* @param enabled Whether automatic flattring should be enabled at all
|
||||||
|
* @param autoFlattrThreshold The percentage of playback time after which an episode should be
|
||||||
|
* flattrd. Must be a value between 0 and 1 (inclusive)
|
||||||
|
* */
|
||||||
public static void setAutoFlattrSettings(Context context, boolean enabled, float autoFlattrThreshold) {
|
public static void setAutoFlattrSettings(Context context, boolean enabled, float autoFlattrThreshold) {
|
||||||
instanceAvailable();
|
instanceAvailable();
|
||||||
|
Validate.inclusiveBetween(0.0, 1.0, autoFlattrThreshold);
|
||||||
PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext())
|
PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext())
|
||||||
.edit()
|
.edit()
|
||||||
.putBoolean(PREF_AUTO_FLATTR, enabled)
|
.putBoolean(PREF_AUTO_FLATTR, enabled)
|
||||||
|
|
|
@ -43,6 +43,7 @@ import de.danoeh.antennapod.storage.DBTasks;
|
||||||
import de.danoeh.antennapod.storage.DBWriter;
|
import de.danoeh.antennapod.storage.DBWriter;
|
||||||
import de.danoeh.antennapod.util.BitmapDecoder;
|
import de.danoeh.antennapod.util.BitmapDecoder;
|
||||||
import de.danoeh.antennapod.util.QueueAccess;
|
import de.danoeh.antennapod.util.QueueAccess;
|
||||||
|
import de.danoeh.antennapod.util.flattr.FlattrThing;
|
||||||
import de.danoeh.antennapod.util.flattr.FlattrUtils;
|
import de.danoeh.antennapod.util.flattr.FlattrUtils;
|
||||||
import de.danoeh.antennapod.util.playback.Playable;
|
import de.danoeh.antennapod.util.playback.Playable;
|
||||||
|
|
||||||
|
@ -512,6 +513,11 @@ public class PlaybackService extends Service {
|
||||||
DBWriter.removeQueueItem(PlaybackService.this, item.getId(), true);
|
DBWriter.removeQueueItem(PlaybackService.this, item.getId(), true);
|
||||||
}
|
}
|
||||||
DBWriter.addItemToPlaybackHistory(PlaybackService.this, (FeedMedia) media);
|
DBWriter.addItemToPlaybackHistory(PlaybackService.this, (FeedMedia) media);
|
||||||
|
|
||||||
|
// auto-flattr if enabled
|
||||||
|
if (isAutoFlattrable(media) && UserPreferences.getAutoFlattrPlayedDurationThreshold() == 1.0f) {
|
||||||
|
DBTasks.flattrItemIfLoggedIn(PlaybackService.this, item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load next episode if previous episode was in the queue and if there
|
// Load next episode if previous episode was in the queue and if there
|
||||||
|
@ -762,7 +768,7 @@ public class PlaybackService extends Service {
|
||||||
FeedItem item = m.getItem();
|
FeedItem item = m.getItem();
|
||||||
m.setPlayedDuration(m.getPlayedDuration() + ((int)(deltaPlayedDuration * playbackSpeed)));
|
m.setPlayedDuration(m.getPlayedDuration() + ((int)(deltaPlayedDuration * playbackSpeed)));
|
||||||
// Auto flattr
|
// Auto flattr
|
||||||
if (FlattrUtils.hasToken() && UserPreferences.isAutoFlattr() && item.getPaymentLink() != null && item.getFlattrStatus().getUnflattred() &&
|
if (isAutoFlattrable(m) &&
|
||||||
(m.getPlayedDuration() > UserPreferences.getAutoFlattrPlayedDurationThreshold() * duration)) {
|
(m.getPlayedDuration() > UserPreferences.getAutoFlattrPlayedDurationThreshold() * duration)) {
|
||||||
|
|
||||||
if (BuildConfig.DEBUG)
|
if (BuildConfig.DEBUG)
|
||||||
|
@ -1051,4 +1057,13 @@ public class PlaybackService extends Service {
|
||||||
return mediaPlayer.getVideoSize();
|
return mediaPlayer.getVideoSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isAutoFlattrable(Playable p) {
|
||||||
|
if (p != null && p instanceof FeedMedia) {
|
||||||
|
FeedMedia media = (FeedMedia) p;
|
||||||
|
FeedItem item = ((FeedMedia) p).getItem();
|
||||||
|
return item != null && FlattrUtils.hasToken() && UserPreferences.isAutoFlattr() && item.getPaymentLink() != null && item.getFlattrStatus().getUnflattred();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue