From f3bf708e260822645a65963ff402794cb0cca66e Mon Sep 17 00:00:00 2001 From: Tony Tam <149837+tonytamsf@users.noreply.github.com> Date: Mon, 25 Jan 2021 05:17:30 -0800 Subject: [PATCH] Show publish date for podcasts and file creation date for local feeds (#4862) --- .../antennapod/fragment/CoverFragment.java | 12 ++++++--- .../antennapod/core/feed/FeedMedia.java | 12 +++++++++ .../core/util/playback/ExternalMedia.java | 25 +++++++++++++++++++ .../core/util/playback/Playable.java | 7 +++++- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java index d77c3c4f3..7538b42d0 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java @@ -13,11 +13,9 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; - import com.bumptech.glide.Glide; import com.bumptech.glide.load.resource.bitmap.FitCenter; import com.bumptech.glide.load.resource.bitmap.RoundedCorners; @@ -25,9 +23,11 @@ import com.bumptech.glide.RequestBuilder; import com.bumptech.glide.request.RequestOptions; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.event.PlaybackPositionEvent; +import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.util.ImageResourceUtils; import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.util.ChapterUtils; +import de.danoeh.antennapod.core.util.DateUtils; import de.danoeh.antennapod.core.util.EmbeddedChapterImage; import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.PlaybackController; @@ -35,6 +35,7 @@ import io.reactivex.Maybe; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; +import org.apache.commons.lang3.StringUtils; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; @@ -93,7 +94,12 @@ public class CoverFragment extends Fragment { } private void displayMediaInfo(@NonNull Playable media) { - txtvPodcastTitle.setText(media.getFeedTitle()); + String pubDateStr = DateUtils.formatAbbrev(getActivity(), ((FeedMedia) media).getPubDate()); + txtvPodcastTitle.setText(StringUtils.stripToEmpty(media.getFeedTitle()) + + "\u00A0" + + "・" + + "\u00A0" + + StringUtils.replace(StringUtils.stripToEmpty(pubDateStr), " ", "\u00A0")); txtvEpisodeTitle.setText(media.getEpisodeTitle()); displayedChapterIndex = -2; // Force refresh displayCoverImage(media.getPosition()); diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java index 4857e899d..b3b3d5c7a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedMedia.java @@ -477,6 +477,18 @@ public class FeedMedia extends FeedFile implements Playable { return item.getPaymentLink(); } + @Override + public Date getPubDate() { + if (item == null) { + return null; + } + if (item.getPubDate() != null) { + return item.getPubDate(); + } else { + return null; + } + } + @Override public boolean localFileAvailable() { return isDownloaded() && file_url != null; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/ExternalMedia.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/ExternalMedia.java index 6c107996f..39fceb27c 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/ExternalMedia.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/ExternalMedia.java @@ -6,10 +6,16 @@ import android.content.SharedPreferences.Editor; import android.media.MediaMetadataRetriever; import android.os.Parcel; 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; +import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.concurrent.Callable; import org.apache.commons.io.FilenameUtils; @@ -25,6 +31,7 @@ public class ExternalMedia implements Playable { private String episodeTitle; private String feedTitle; private MediaType mediaType; + private Date pubDate; private List chapters; private int duration; private int position; @@ -99,6 +106,19 @@ public class ExternalMedia implements Playable { e.printStackTrace(); throw new PlayableException("NumberFormatException when reading duration of media file"); } + + String dateStr = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE); + if (!TextUtils.isEmpty(dateStr)) { + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.getDefault()); + pubDate = simpleDateFormat.parse(dateStr); + } catch (ParseException parseException) { + pubDate = DateUtils.parse(dateStr); + } + } else { + pubDate = null; + } + setChapters(ChapterUtils.loadChaptersFromFileUrl(this)); } @@ -147,6 +167,11 @@ public class ExternalMedia implements Playable { return duration; } + @Override + public Date getPubDate() { + return pubDate; + } + @Override public int getPosition() { return position; diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java index 5b15913c8..59abdd10a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/Playable.java @@ -13,7 +13,7 @@ import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.util.ShownotesProvider; - +import java.util.Date; import java.util.List; /** @@ -67,6 +67,11 @@ public interface Playable extends Parcelable, */ String getFeedTitle(); + /** + * Returns the published date + */ + Date getPubDate(); + /** * Returns a unique identifier, for example a file url or an ID from a * database.