Show artistName in place of podcast url when it is available (#3762)

This commit is contained in:
Tony Tam 2020-03-17 16:11:52 -07:00 committed by GitHub
parent 05495d2110
commit 34fba016d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 71 additions and 25 deletions

View File

@ -165,7 +165,7 @@ dependencies {
implementation "com.github.shts:TriangleLabelView:$triangleLabelViewVersion" implementation "com.github.shts:TriangleLabelView:$triangleLabelViewVersion"
implementation 'com.leinardi.android:speed-dial:3.0.0' implementation 'com.leinardi.android:speed-dial:3.0.0'
implementation "com.github.AntennaPod:AntennaPod-AudioPlayer:$audioPlayerVersion" 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' implementation 'com.github.ByteHamster:SearchPreference:v2.0.0'
androidTestImplementation "org.awaitility:awaitility:$awaitilityVersion" androidTestImplementation "org.awaitility:awaitility:$awaitilityVersion"

View File

@ -44,7 +44,7 @@ public class PodcastListAdapter extends ArrayAdapter<GpodnetPodcast> {
holder.image = convertView.findViewById(R.id.imgvCover); holder.image = convertView.findViewById(R.id.imgvCover);
holder.title = convertView.findViewById(R.id.txtvTitle); holder.title = convertView.findViewById(R.id.txtvTitle);
holder.subscribers = convertView.findViewById(R.id.txtvSubscribers); holder.subscribers = convertView.findViewById(R.id.txtvSubscribers);
holder.url = convertView.findViewById(R.id.txtvUrl); holder.author = convertView.findViewById(R.id.txtvAuthor);
convertView.setTag(holder); convertView.setTag(holder);
} else { } else {
holder = (Holder) convertView.getTag(); holder = (Holder) convertView.getTag();
@ -64,7 +64,7 @@ public class PodcastListAdapter extends ArrayAdapter<GpodnetPodcast> {
holder.title.setText(podcast.getTitle()); holder.title.setText(podcast.getTitle());
holder.subscribers.setText(String.valueOf(podcast.getSubscribers())); holder.subscribers.setText(String.valueOf(podcast.getSubscribers()));
holder.url.setText(podcast.getUrl()); holder.author.setText(podcast.getAuthor());
return convertView; return convertView;
} }
@ -73,6 +73,6 @@ public class PodcastListAdapter extends ArrayAdapter<GpodnetPodcast> {
ImageView image; ImageView image;
TextView title; TextView title;
TextView subscribers; TextView subscribers;
TextView url; TextView author;
} }
} }

View File

@ -65,13 +65,16 @@ public class ItunesAdapter extends ArrayAdapter<PodcastSearchResult> {
viewHolder = (PodcastViewHolder) view.getTag(); viewHolder = (PodcastViewHolder) view.getTag();
} }
//Set the title // Set the title
viewHolder.titleView.setText(podcast.title); viewHolder.titleView.setText(podcast.title);
if(podcast.feedUrl != null && !podcast.feedUrl.contains("itunes.apple.com")) { if (podcast.author != null && ! podcast.author.trim().isEmpty()) {
viewHolder.urlView.setText(podcast.feedUrl); viewHolder.authorView.setText(podcast.author);
viewHolder.urlView.setVisibility(View.VISIBLE); 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 { } else {
viewHolder.urlView.setVisibility(View.GONE); viewHolder.authorView.setVisibility(View.GONE);
} }
//Update the empty imageView with the image from the feed //Update the empty imageView with the image from the feed
@ -103,7 +106,7 @@ public class ItunesAdapter extends ArrayAdapter<PodcastSearchResult> {
*/ */
final TextView titleView; final TextView titleView;
final TextView urlView; final TextView authorView;
/** /**
@ -113,7 +116,7 @@ public class ItunesAdapter extends ArrayAdapter<PodcastSearchResult> {
PodcastViewHolder(View view){ PodcastViewHolder(View view){
coverView = view.findViewById(R.id.imgvCover); coverView = view.findViewById(R.id.imgvCover);
titleView = view.findViewById(R.id.txtvTitle); titleView = view.findViewById(R.id.txtvTitle);
urlView = view.findViewById(R.id.txtvUrl); authorView = view.findViewById(R.id.txtvAuthor);
} }
} }
} }

View File

@ -25,15 +25,26 @@ public class PodcastSearchResult {
@Nullable @Nullable
public final String feedUrl; 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.title = title;
this.imageUrl = imageUrl; this.imageUrl = imageUrl;
this.feedUrl = feedUrl; this.feedUrl = feedUrl;
this.author = author;
}
private PodcastSearchResult(String title, @Nullable String imageUrl, @Nullable String feedUrl) {
this(title, imageUrl, feedUrl, "");
} }
public static PodcastSearchResult dummy() { public static PodcastSearchResult dummy() {
return new PodcastSearchResult("", "", ""); return new PodcastSearchResult("", "", "", "");
} }
/** /**
@ -46,7 +57,8 @@ public class PodcastSearchResult {
String title = json.optString("collectionName", ""); String title = json.optString("collectionName", "");
String imageUrl = json.optString("artworkUrl100", null); String imageUrl = json.optString("artworkUrl100", null);
String feedUrl = json.optString("feedUrl", 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=" + String feedUrl = "https://itunes.apple.com/lookup?id=" +
json.getJSONObject("id").getJSONObject("attributes").getString("im: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) { 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) { 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());
} }
} }

View File

@ -70,7 +70,7 @@
tools:background="@android:color/holo_green_dark" /> tools:background="@android:color/holo_green_dark" />
<TextView <TextView
android:id="@+id/txtvUrl" android:id="@+id/txtvAuthor"
style="android:style/TextAppearance.Small" style="android:style/TextAppearance.Small"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -81,7 +81,7 @@
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
android:ellipsize="middle" android:ellipsize="middle"
android:maxLines="2" android:maxLines="2"
tools:text="http://www.example.com/feed" tools:text="author"
tools:background="@android:color/holo_green_dark"/> tools:background="@android:color/holo_green_dark"/>
</RelativeLayout> </RelativeLayout>

View File

@ -45,7 +45,7 @@
tools:text="Podcast title" /> tools:text="Podcast title" />
<TextView <TextView
android:id="@+id/txtvUrl" android:id="@+id/txtvAuthor"
style="android:style/TextAppearance.Small" style="android:style/TextAppearance.Small"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -53,7 +53,7 @@
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
android:ellipsize="middle" android:ellipsize="middle"
android:maxLines="2" android:maxLines="2"
tools:text="http://www.example.com/feed" tools:text="author"
tools:background="@android:color/holo_green_dark"/> tools:background="@android:color/holo_green_dark"/>
</LinearLayout> </LinearLayout>

View File

@ -52,4 +52,4 @@
tools:background="@android:color/holo_blue_light"/> tools:background="@android:color/holo_blue_light"/>
</LinearLayout> </LinearLayout>
</RelativeLayout> </RelativeLayout>

View File

@ -688,8 +688,20 @@ public class GpodnetService {
website = (String) websiteObj; website = (String) websiteObj;
} }
String mygpoLink = object.getString("mygpo_link"); 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<GpodnetDevice> readDeviceListFromJSONArray(@NonNull JSONArray array) private List<GpodnetDevice> readDeviceListFromJSONArray(@NonNull JSONArray array)

View File

@ -10,6 +10,7 @@ public class GpodnetPodcast {
private final String logoUrl; private final String logoUrl;
private final String website; private final String website;
private final String mygpoLink; private final String mygpoLink;
private final String author;
public GpodnetPodcast(@NonNull String url, public GpodnetPodcast(@NonNull String url,
@NonNull String title, @NonNull String title,
@ -17,7 +18,9 @@ public class GpodnetPodcast {
int subscribers, int subscribers,
String logoUrl, String logoUrl,
String website, String website,
String mygpoLink) { String mygpoLink,
String author
) {
this.url = url; this.url = url;
this.title = title; this.title = title;
this.description = description; this.description = description;
@ -25,6 +28,7 @@ public class GpodnetPodcast {
this.logoUrl = logoUrl; this.logoUrl = logoUrl;
this.website = website; this.website = website;
this.mygpoLink = mygpoLink; this.mygpoLink = mygpoLink;
this.author = author;
} }
@Override @Override
@ -59,6 +63,8 @@ public class GpodnetPodcast {
return website; return website;
} }
public String getAuthor() { return author; }
public String getMygpoLink() { public String getMygpoLink() {
return mygpoLink; return mygpoLink;
} }