Display chapter image directly
This commit is contained in:
parent
ddfb4de9cf
commit
9db5450243
|
@ -1,25 +1,25 @@
|
||||||
package de.danoeh.antennapod.fragment;
|
package de.danoeh.antennapod.fragment;
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.bumptech.glide.RequestBuilder;
|
||||||
import com.bumptech.glide.request.RequestOptions;
|
import com.bumptech.glide.request.RequestOptions;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
import de.danoeh.antennapod.core.event.PlaybackPositionEvent;
|
||||||
import de.danoeh.antennapod.core.glide.ApGlideSettings;
|
|
||||||
import de.danoeh.antennapod.core.feed.util.ImageResourceUtils;
|
import de.danoeh.antennapod.core.feed.util.ImageResourceUtils;
|
||||||
import de.danoeh.antennapod.core.util.EmbeddedChapterImage;
|
import de.danoeh.antennapod.core.glide.ApGlideSettings;
|
||||||
import de.danoeh.antennapod.core.util.ChapterUtils;
|
import de.danoeh.antennapod.core.util.ChapterUtils;
|
||||||
|
import de.danoeh.antennapod.core.util.EmbeddedChapterImage;
|
||||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||||
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
||||||
import io.reactivex.Maybe;
|
import io.reactivex.Maybe;
|
||||||
|
@ -43,7 +43,7 @@ public class CoverFragment extends Fragment {
|
||||||
private ImageView imgvCover;
|
private ImageView imgvCover;
|
||||||
private PlaybackController controller;
|
private PlaybackController controller;
|
||||||
private Disposable disposable;
|
private Disposable disposable;
|
||||||
private int displayedChapterIndex = -1;
|
private int displayedChapterIndex = -2;
|
||||||
private Playable media;
|
private Playable media;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -81,14 +81,7 @@ public class CoverFragment extends Fragment {
|
||||||
private void displayMediaInfo(@NonNull Playable media) {
|
private void displayMediaInfo(@NonNull Playable media) {
|
||||||
txtvPodcastTitle.setText(media.getFeedTitle());
|
txtvPodcastTitle.setText(media.getFeedTitle());
|
||||||
txtvEpisodeTitle.setText(media.getEpisodeTitle());
|
txtvEpisodeTitle.setText(media.getEpisodeTitle());
|
||||||
displayedChapterIndex = -1;
|
displayCoverImage(media.getPosition());
|
||||||
Glide.with(this)
|
|
||||||
.load(ImageResourceUtils.getImageLocation(media))
|
|
||||||
.apply(new RequestOptions()
|
|
||||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
|
||||||
.dontAnimate()
|
|
||||||
.fitCenter())
|
|
||||||
.into(imgvCover);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -127,12 +120,22 @@ public class CoverFragment extends Fragment {
|
||||||
if (controller == null) {
|
if (controller == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int chapter = ChapterUtils.getCurrentChapterIndex(media, event.getPosition());
|
displayCoverImage(event.getPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void displayCoverImage(int position) {
|
||||||
|
int chapter = ChapterUtils.getCurrentChapterIndex(media, position);
|
||||||
if (chapter != displayedChapterIndex) {
|
if (chapter != displayedChapterIndex) {
|
||||||
displayedChapterIndex = chapter;
|
displayedChapterIndex = chapter;
|
||||||
|
|
||||||
|
RequestBuilder<Drawable> cover = Glide.with(this)
|
||||||
|
.load(ImageResourceUtils.getImageLocation(media))
|
||||||
|
.apply(new RequestOptions()
|
||||||
|
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||||
|
.dontAnimate()
|
||||||
|
.fitCenter());
|
||||||
if (chapter == -1 || TextUtils.isEmpty(media.getChapters().get(chapter).getImageUrl())) {
|
if (chapter == -1 || TextUtils.isEmpty(media.getChapters().get(chapter).getImageUrl())) {
|
||||||
displayMediaInfo(media);
|
cover.into(imgvCover);
|
||||||
} else {
|
} else {
|
||||||
Glide.with(this)
|
Glide.with(this)
|
||||||
.load(EmbeddedChapterImage.getModelFor(media, chapter))
|
.load(EmbeddedChapterImage.getModelFor(media, chapter))
|
||||||
|
@ -140,6 +143,8 @@ public class CoverFragment extends Fragment {
|
||||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||||
.dontAnimate()
|
.dontAnimate()
|
||||||
.fitCenter())
|
.fitCenter())
|
||||||
|
.thumbnail(cover)
|
||||||
|
.error(cover)
|
||||||
.into(imgvCover);
|
.into(imgvCover);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue