Reduce dependencies of model to UserPreferences

This commit is contained in:
ByteHamster 2021-04-22 21:17:52 +02:00
parent daf6226483
commit 0d49f39ea0
6 changed files with 20 additions and 22 deletions

View File

@ -249,7 +249,7 @@ public class FeedItemMenuHandler {
final Handler h = new Handler(fragment.requireContext().getMainLooper());
final Runnable r = () -> {
FeedMedia media = item.getMedia();
if (media != null && media.hasAlmostEnded() && UserPreferences.isAutoDelete()) {
if (media != null && FeedItemUtil.hasAlmostEnded(media) && UserPreferences.isAutoDelete()) {
DBWriter.deleteFeedMediaOfItem(fragment.requireContext(), media.getId());
}
};

View File

@ -17,7 +17,6 @@ import java.util.List;
import de.danoeh.antennapod.core.preferences.GpodnetPreferences;
import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.PodDBAdapter;
@ -228,11 +227,6 @@ public class FeedMedia extends FeedFile implements Playable {
((PlaybackPreferences.getCurrentPlayerStatus() == PlaybackPreferences.PLAYER_STATUS_PLAYING));
}
public boolean hasAlmostEnded() {
int smartMarkAsPlayedSecs = UserPreferences.getSmartMarkAsPlayedSecs();
return this.duration > 0 && this.position >= this.duration - smartMarkAsPlayedSecs * 1000;
}
@Override
public int getTypeAsInt() {
return FEEDFILETYPE_FEEDMEDIA;

View File

@ -4,7 +4,6 @@ import android.database.Cursor;
import androidx.annotation.NonNull;
import android.text.TextUtils;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.PodDBAdapter;
import java.io.Serializable;
@ -203,16 +202,8 @@ public class FeedPreferences implements Serializable {
this.volumeAdaptionSetting = volumeAdaptionSetting;
}
public boolean getCurrentAutoDelete() {
switch (autoDeleteAction) {
case GLOBAL:
return UserPreferences.isAutoDelete();
case YES:
return true;
case NO:
default: // fall-through
return false;
}
public AutoDeleteAction getCurrentAutoDelete() {
return autoDeleteAction;
}
public String getUsername() {

View File

@ -73,6 +73,7 @@ import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.FeedSearcher;
import de.danoeh.antennapod.core.feed.util.ImageResourceUtils;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.IntentUtils;
import de.danoeh.antennapod.core.util.NetworkUtils;
import de.danoeh.antennapod.core.util.gui.NotificationUtils;
@ -1095,7 +1096,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
FeedMedia media = (FeedMedia) playable;
FeedItem item = media.getItem();
boolean smartMarkAsPlayed = media.hasAlmostEnded();
boolean smartMarkAsPlayed = FeedItemUtil.hasAlmostEnded(media);
if (!ended && smartMarkAsPlayed) {
Log.d(TAG, "smart mark as played");
}
@ -1121,8 +1122,12 @@ public class PlaybackService extends MediaBrowserServiceCompat {
// don't know if it actually matters to not autodownload when smart mark as played is triggered
DBWriter.removeQueueItem(PlaybackService.this, ended, item);
// Delete episode if enabled
if (item.getFeed().getPreferences().getCurrentAutoDelete()
&& (!item.isTagged(FeedItem.TAG_FAVORITE) || !UserPreferences.shouldFavoriteKeepEpisode())) {
FeedPreferences.AutoDeleteAction action =
item.getFeed().getPreferences().getCurrentAutoDelete();
boolean shouldAutoDelete = action == FeedPreferences.AutoDeleteAction.YES
|| (action == FeedPreferences.AutoDeleteAction.GLOBAL && UserPreferences.isAutoDelete());
if (shouldAutoDelete && (!item.isTagged(FeedItem.TAG_FAVORITE)
|| !UserPreferences.shouldFavoriteKeepEpisode())) {
DBWriter.deleteFeedMediaOfItem(PlaybackService.this, media.getId());
Log.d(TAG, "Episode Deleted");
}

View File

@ -39,6 +39,7 @@ import de.danoeh.antennapod.core.sync.model.ISyncService;
import de.danoeh.antennapod.core.sync.model.SubscriptionChanges;
import de.danoeh.antennapod.core.sync.model.SyncServiceException;
import de.danoeh.antennapod.core.sync.model.UploadChangesResponse;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.LongList;
import de.danoeh.antennapod.core.util.URLChecker;
import de.danoeh.antennapod.core.util.gui.NotificationUtils;
@ -465,7 +466,7 @@ public class SyncService extends Worker {
if (playItem != null) {
FeedMedia media = playItem.getMedia();
media.setPosition(action.getPosition() * 1000);
if (playItem.getMedia().hasAlmostEnded()) {
if (FeedItemUtil.hasAlmostEnded(playItem.getMedia())) {
Log.d(TAG, "Marking as played");
playItem.setPlayed(true);
queueToBeRemoved.add(playItem.getId());

View File

@ -2,6 +2,8 @@ package de.danoeh.antennapod.core.util;
import androidx.annotation.NonNull;
import de.danoeh.antennapod.core.feed.FeedMedia;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
@ -66,4 +68,9 @@ public class FeedItemUtil {
}
return null;
}
public static boolean hasAlmostEnded(FeedMedia media) {
int smartMarkAsPlayedSecs = UserPreferences.getSmartMarkAsPlayedSecs();
return media.getDuration() > 0 && media.getPosition() >= media.getDuration() - smartMarkAsPlayedSecs * 1000;
}
}