Show publish date for podcasts and file creation date for local feeds (#4862)

This commit is contained in:
Tony Tam 2021-01-25 05:17:30 -08:00 committed by GitHub
parent cd23eccf95
commit f3bf708e26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 4 deletions

View File

@ -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());

View File

@ -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;

View File

@ -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<Chapter> 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;

View File

@ -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.