Removed chapter loader from model
This commit is contained in:
parent
ddd6a12354
commit
b7d34e0514
|
@ -118,7 +118,7 @@ public class ChaptersFragment extends Fragment {
|
|||
disposable = Maybe.create(emitter -> {
|
||||
Playable media = controller.getMedia();
|
||||
if (media != null) {
|
||||
media.loadChapterMarks(getContext());
|
||||
ChapterUtils.loadChapters(media, getContext());
|
||||
emitter.onSuccess(media);
|
||||
} else {
|
||||
emitter.onComplete();
|
||||
|
|
|
@ -12,7 +12,6 @@ import androidx.annotation.Nullable;
|
|||
import android.support.v4.media.MediaBrowserCompat;
|
||||
import android.support.v4.media.MediaDescriptionCompat;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -24,7 +23,6 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService;
|
|||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||
import de.danoeh.antennapod.core.util.ChapterUtils;
|
||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||
import de.danoeh.antennapod.core.sync.SyncService;
|
||||
import de.danoeh.antennapod.core.sync.model.EpisodeAction;
|
||||
|
@ -385,33 +383,6 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadChapterMarks(Context context) {
|
||||
if (item == null && itemID != 0) {
|
||||
item = DBReader.getFeedItem(itemID);
|
||||
}
|
||||
if (item == null || item.getChapters() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Chapter> chapters = loadChapters(context);
|
||||
if (chapters == null) {
|
||||
// Do not try loading again. There are no chapters.
|
||||
item.setChapters(Collections.emptyList());
|
||||
} else {
|
||||
item.setChapters(chapters);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Chapter> loadChapters(Context context) {
|
||||
List<Chapter> chaptersFromDatabase = null;
|
||||
if (item.hasChapters()) {
|
||||
chaptersFromDatabase = DBReader.loadChaptersOfFeedItem(item);
|
||||
}
|
||||
List<Chapter> chaptersFromMediaFile = ChapterUtils.loadChaptersFromMediaFile(this, context);
|
||||
return ChapterMerger.merge(chaptersFromDatabase, chaptersFromMediaFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEpisodeTitle() {
|
||||
if (item == null) {
|
||||
|
@ -493,6 +464,10 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||
return download_url != null;
|
||||
}
|
||||
|
||||
public long getItemId() {
|
||||
return itemID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveCurrentPosition(SharedPreferences pref, int newPosition, long timeStamp) {
|
||||
if(item != null && item.isNew()) {
|
||||
|
@ -549,7 +524,7 @@ public class FeedMedia extends FeedFile implements Playable {
|
|||
|
||||
@Override
|
||||
public void setChapters(List<Chapter> chapters) {
|
||||
if(item != null) {
|
||||
if (item != null) {
|
||||
item.setChapters(chapters);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import androidx.annotation.NonNull;
|
|||
import android.util.Log;
|
||||
|
||||
import de.danoeh.antennapod.core.preferences.SleepTimerPreferences;
|
||||
import de.danoeh.antennapod.core.util.ChapterUtils;
|
||||
import de.danoeh.antennapod.core.widget.WidgetUpdater;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
@ -315,7 +316,7 @@ public class PlaybackServiceTaskManager {
|
|||
|
||||
if (media.getChapters() == null) {
|
||||
chapterLoaderFuture = Completable.create(emitter -> {
|
||||
media.loadChapterMarks(context);
|
||||
ChapterUtils.loadChapters(media, context);
|
||||
emitter.onComplete();
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
|
|
@ -6,7 +6,10 @@ import android.net.Uri;
|
|||
import android.util.Log;
|
||||
import androidx.annotation.NonNull;
|
||||
import de.danoeh.antennapod.core.feed.Chapter;
|
||||
import de.danoeh.antennapod.core.feed.ChapterMerger;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.service.download.AntennapodHttpClient;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.core.util.comparator.ChapterStartTimeComparator;
|
||||
import de.danoeh.antennapod.core.util.id3reader.ChapterReader;
|
||||
import de.danoeh.antennapod.core.util.id3reader.ID3ReaderException;
|
||||
|
@ -47,6 +50,33 @@ public class ChapterUtils {
|
|||
return chapters.size() - 1;
|
||||
}
|
||||
|
||||
public static void loadChapters(Playable playable, Context context) {
|
||||
if (playable.getChapters() != null) {
|
||||
// Already loaded
|
||||
return;
|
||||
}
|
||||
|
||||
List<Chapter> chaptersFromDatabase = null;
|
||||
if (playable instanceof FeedMedia) {
|
||||
FeedMedia feedMedia = (FeedMedia) playable;
|
||||
if (feedMedia.getItem() == null) {
|
||||
feedMedia.setItem(DBReader.getFeedItem(feedMedia.getItemId()));
|
||||
}
|
||||
if (feedMedia.getItem().hasChapters()) {
|
||||
chaptersFromDatabase = DBReader.loadChaptersOfFeedItem(feedMedia.getItem());
|
||||
}
|
||||
}
|
||||
|
||||
List<Chapter> chaptersFromMediaFile = ChapterUtils.loadChaptersFromMediaFile(playable, context);
|
||||
List<Chapter> chapters = ChapterMerger.merge(chaptersFromDatabase, chaptersFromMediaFile);
|
||||
if (chapters == null) {
|
||||
// Do not try loading again. There are no chapters.
|
||||
playable.setChapters(Collections.emptyList());
|
||||
} else {
|
||||
playable.setChapters(chapters);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Chapter> loadChaptersFromMediaFile(Playable playable, Context context) {
|
||||
try (CountingInputStream in = openStream(playable, context)) {
|
||||
List<Chapter> chapters = readId3ChaptersFrom(in);
|
||||
|
|
|
@ -9,7 +9,6 @@ import android.os.Parcelable;
|
|||
import android.text.TextUtils;
|
||||
import de.danoeh.antennapod.core.feed.Chapter;
|
||||
import de.danoeh.antennapod.core.feed.MediaType;
|
||||
import de.danoeh.antennapod.core.util.ChapterUtils;
|
||||
import de.danoeh.antennapod.core.util.DateUtils;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -120,11 +119,6 @@ public class ExternalMedia implements Playable {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadChapterMarks(Context context) {
|
||||
setChapters(ChapterUtils.loadChaptersFromMediaFile(this, context));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEpisodeTitle() {
|
||||
return episodeTitle;
|
||||
|
|
|
@ -33,13 +33,6 @@ public interface Playable extends Parcelable, ShownotesProvider {
|
|||
*/
|
||||
void loadMetadata() throws PlayableException;
|
||||
|
||||
/**
|
||||
* This method is called from a separate thread by the PlaybackService.
|
||||
* Playable objects should load their chapter marks in this method if no
|
||||
* local file was available when loadMetadata() was called.
|
||||
*/
|
||||
void loadChapterMarks(Context context);
|
||||
|
||||
/**
|
||||
* Returns the title of the episode that this playable represents
|
||||
*/
|
||||
|
|
|
@ -11,7 +11,6 @@ import de.danoeh.antennapod.core.feed.Feed;
|
|||
import de.danoeh.antennapod.core.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.feed.MediaType;
|
||||
import de.danoeh.antennapod.core.util.ChapterUtils;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -128,11 +127,6 @@ public class RemoteMedia implements Playable {
|
|||
//Already loaded
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadChapterMarks(Context context) {
|
||||
setChapters(ChapterUtils.loadChaptersFromMediaFile(this, context));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEpisodeTitle() {
|
||||
return episodeTitle;
|
||||
|
|
Loading…
Reference in New Issue