From 34fba016d14f4df3ff35684cbd53fb0011fee7c0 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Tue, 17 Mar 2020 16:11:52 -0700 Subject: [PATCH] Show artistName in place of podcast url when it is available (#3762) --- app/build.gradle | 2 +- .../adapter/gpodnet/PodcastListAdapter.java | 6 +-- .../adapter/itunes/ItunesAdapter.java | 17 +++++---- .../discovery/PodcastSearchResult.java | 37 ++++++++++++++++--- .../res/layout/gpodnet_podcast_listitem.xml | 4 +- .../res/layout/itunes_podcast_listitem.xml | 4 +- app/src/main/res/layout/searchlist_item.xml | 2 +- .../core/gpoddernet/GpodnetService.java | 16 +++++++- .../core/gpoddernet/model/GpodnetPodcast.java | 8 +++- 9 files changed, 71 insertions(+), 25 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 516179a6e..34a2421b9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -165,7 +165,7 @@ dependencies { implementation "com.github.shts:TriangleLabelView:$triangleLabelViewVersion" implementation 'com.leinardi.android:speed-dial:3.0.0' implementation "com.github.AntennaPod:AntennaPod-AudioPlayer:$audioPlayerVersion" - implementation 'com.github.mfietz:fyydlin:v0.4.2' + implementation 'com.github.mfietz:fyydlin:v0.5.0' implementation 'com.github.ByteHamster:SearchPreference:v2.0.0' androidTestImplementation "org.awaitility:awaitility:$awaitilityVersion" diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/gpodnet/PodcastListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/gpodnet/PodcastListAdapter.java index 06c80e173..62b22879a 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/gpodnet/PodcastListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/gpodnet/PodcastListAdapter.java @@ -44,7 +44,7 @@ public class PodcastListAdapter extends ArrayAdapter { holder.image = convertView.findViewById(R.id.imgvCover); holder.title = convertView.findViewById(R.id.txtvTitle); holder.subscribers = convertView.findViewById(R.id.txtvSubscribers); - holder.url = convertView.findViewById(R.id.txtvUrl); + holder.author = convertView.findViewById(R.id.txtvAuthor); convertView.setTag(holder); } else { holder = (Holder) convertView.getTag(); @@ -64,7 +64,7 @@ public class PodcastListAdapter extends ArrayAdapter { holder.title.setText(podcast.getTitle()); holder.subscribers.setText(String.valueOf(podcast.getSubscribers())); - holder.url.setText(podcast.getUrl()); + holder.author.setText(podcast.getAuthor()); return convertView; } @@ -73,6 +73,6 @@ public class PodcastListAdapter extends ArrayAdapter { ImageView image; TextView title; TextView subscribers; - TextView url; + TextView author; } } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java index cc3b6fba0..7917c264f 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/itunes/ItunesAdapter.java @@ -65,13 +65,16 @@ public class ItunesAdapter extends ArrayAdapter { viewHolder = (PodcastViewHolder) view.getTag(); } - //Set the title + // Set the title viewHolder.titleView.setText(podcast.title); - if(podcast.feedUrl != null && !podcast.feedUrl.contains("itunes.apple.com")) { - viewHolder.urlView.setText(podcast.feedUrl); - viewHolder.urlView.setVisibility(View.VISIBLE); + if (podcast.author != null && ! podcast.author.trim().isEmpty()) { + viewHolder.authorView.setText(podcast.author); + viewHolder.authorView.setVisibility(View.VISIBLE); + } else if (podcast.feedUrl != null && !podcast.feedUrl.contains("itunes.apple.com")) { + viewHolder.authorView.setText(podcast.feedUrl); + viewHolder.authorView.setVisibility(View.VISIBLE); } else { - viewHolder.urlView.setVisibility(View.GONE); + viewHolder.authorView.setVisibility(View.GONE); } //Update the empty imageView with the image from the feed @@ -103,7 +106,7 @@ public class ItunesAdapter extends ArrayAdapter { */ final TextView titleView; - final TextView urlView; + final TextView authorView; /** @@ -113,7 +116,7 @@ public class ItunesAdapter extends ArrayAdapter { PodcastViewHolder(View view){ coverView = view.findViewById(R.id.imgvCover); titleView = view.findViewById(R.id.txtvTitle); - urlView = view.findViewById(R.id.txtvUrl); + authorView = view.findViewById(R.id.txtvAuthor); } } } diff --git a/app/src/main/java/de/danoeh/antennapod/discovery/PodcastSearchResult.java b/app/src/main/java/de/danoeh/antennapod/discovery/PodcastSearchResult.java index 6535df5ef..481c232c8 100644 --- a/app/src/main/java/de/danoeh/antennapod/discovery/PodcastSearchResult.java +++ b/app/src/main/java/de/danoeh/antennapod/discovery/PodcastSearchResult.java @@ -25,15 +25,26 @@ public class PodcastSearchResult { @Nullable public final String feedUrl; + /** + * artistName of the podcast feed + */ + @Nullable + public final String author; - private PodcastSearchResult(String title, @Nullable String imageUrl, @Nullable String feedUrl) { + + private PodcastSearchResult(String title, @Nullable String imageUrl, @Nullable String feedUrl, @Nullable String author) { this.title = title; this.imageUrl = imageUrl; this.feedUrl = feedUrl; + this.author = author; + } + + private PodcastSearchResult(String title, @Nullable String imageUrl, @Nullable String feedUrl) { + this(title, imageUrl, feedUrl, ""); } public static PodcastSearchResult dummy() { - return new PodcastSearchResult("", "", ""); + return new PodcastSearchResult("", "", "", ""); } /** @@ -46,7 +57,8 @@ public class PodcastSearchResult { String title = json.optString("collectionName", ""); String imageUrl = json.optString("artworkUrl100", null); String feedUrl = json.optString("feedUrl", null); - return new PodcastSearchResult(title, imageUrl, feedUrl); + String author = json.optString("artistName", null); + return new PodcastSearchResult(title, imageUrl, feedUrl, author); } /** @@ -68,14 +80,27 @@ public class PodcastSearchResult { } String feedUrl = "https://itunes.apple.com/lookup?id=" + json.getJSONObject("id").getJSONObject("attributes").getString("im:id"); - return new PodcastSearchResult(title, imageUrl, feedUrl); + + String author = null; + try { + author = json.getJSONObject("im:artist").getString("label"); + } catch (Exception e) { + // Some feeds have empty artist + } + return new PodcastSearchResult(title, imageUrl, feedUrl, author); } public static PodcastSearchResult fromFyyd(SearchHit searchHit) { - return new PodcastSearchResult(searchHit.getTitle(), searchHit.getThumbImageURL(), searchHit.getXmlUrl()); + return new PodcastSearchResult(searchHit.getTitle(), + searchHit.getThumbImageURL(), + searchHit.getXmlUrl(), + searchHit.getAuthor()); } public static PodcastSearchResult fromGpodder(GpodnetPodcast searchHit) { - return new PodcastSearchResult(searchHit.getTitle(), searchHit.getLogoUrl(), searchHit.getUrl()); + return new PodcastSearchResult(searchHit.getTitle(), + searchHit.getLogoUrl(), + searchHit.getUrl(), + searchHit.getAuthor()); } } diff --git a/app/src/main/res/layout/gpodnet_podcast_listitem.xml b/app/src/main/res/layout/gpodnet_podcast_listitem.xml index 6e02fa090..e5f44220f 100644 --- a/app/src/main/res/layout/gpodnet_podcast_listitem.xml +++ b/app/src/main/res/layout/gpodnet_podcast_listitem.xml @@ -70,7 +70,7 @@ tools:background="@android:color/holo_green_dark" /> diff --git a/app/src/main/res/layout/itunes_podcast_listitem.xml b/app/src/main/res/layout/itunes_podcast_listitem.xml index b2411c5df..d2472b0de 100644 --- a/app/src/main/res/layout/itunes_podcast_listitem.xml +++ b/app/src/main/res/layout/itunes_podcast_listitem.xml @@ -45,7 +45,7 @@ tools:text="Podcast title" /> diff --git a/app/src/main/res/layout/searchlist_item.xml b/app/src/main/res/layout/searchlist_item.xml index 4a055fea9..e8ff18c5f 100644 --- a/app/src/main/res/layout/searchlist_item.xml +++ b/app/src/main/res/layout/searchlist_item.xml @@ -52,4 +52,4 @@ tools:background="@android:color/holo_blue_light"/> - \ No newline at end of file + diff --git a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java index 97931237a..7cef4268f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/GpodnetService.java @@ -688,8 +688,20 @@ public class GpodnetService { website = (String) websiteObj; } String mygpoLink = object.getString("mygpo_link"); - return new GpodnetPodcast(url, title, description, subscribers, - logoUrl, website, mygpoLink); + + String author = null; + Object authorObj = object.opt("author"); + if (authorObj != null && authorObj instanceof String) { + author = (String) authorObj; + } + return new GpodnetPodcast(url, + title, + description, + subscribers, + logoUrl, + website, + mygpoLink, + author); } private List readDeviceListFromJSONArray(@NonNull JSONArray array) diff --git a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/model/GpodnetPodcast.java b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/model/GpodnetPodcast.java index 2c2d759c9..5433e3ee0 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/model/GpodnetPodcast.java +++ b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/model/GpodnetPodcast.java @@ -10,6 +10,7 @@ public class GpodnetPodcast { private final String logoUrl; private final String website; private final String mygpoLink; + private final String author; public GpodnetPodcast(@NonNull String url, @NonNull String title, @@ -17,7 +18,9 @@ public class GpodnetPodcast { int subscribers, String logoUrl, String website, - String mygpoLink) { + String mygpoLink, + String author + ) { this.url = url; this.title = title; this.description = description; @@ -25,6 +28,7 @@ public class GpodnetPodcast { this.logoUrl = logoUrl; this.website = website; this.mygpoLink = mygpoLink; + this.author = author; } @Override @@ -59,6 +63,8 @@ public class GpodnetPodcast { return website; } + public String getAuthor() { return author; } + public String getMygpoLink() { return mygpoLink; }