From 5a077774fcfeb89fc3eac6993c4320d81c5ed157 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Wed, 20 Jan 2016 19:10:51 +0100 Subject: iTunes Search: SearchView in Action Bar, error/result message, retry, feed url --- .../antennapod/adapter/itunes/ItunesAdapter.java | 51 +++++++++++++++++++--- 1 file changed, 46 insertions(+), 5 deletions(-) (limited to 'app/src/main/java/de/danoeh/antennapod/adapter/itunes') 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 08ffdd197..47ac4c757 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 @@ -10,6 +10,7 @@ import android.widget.TextView; import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -65,6 +66,12 @@ public class ItunesAdapter extends ArrayAdapter { //Set the title viewHolder.titleView.setText(podcast.title); + if(!podcast.feedUrl.contains("itunes.apple.com")) { + viewHolder.urlView.setText(podcast.feedUrl); + viewHolder.urlView.setVisibility(View.VISIBLE); + } else { + viewHolder.urlView.setVisibility(View.GONE); + } //Update the empty imageView with the image from the feed Glide.with(context) @@ -94,6 +101,8 @@ public class ItunesAdapter extends ArrayAdapter { */ public final TextView titleView; + public final TextView urlView; + /** * Constructor @@ -102,6 +111,7 @@ public class ItunesAdapter extends ArrayAdapter { PodcastViewHolder(View view){ coverView = (ImageView) view.findViewById(R.id.imgvCover); titleView = (TextView) view.findViewById(R.id.txtvTitle); + urlView = (TextView) view.findViewById(R.id.txtvUrl); } } @@ -124,16 +134,47 @@ public class ItunesAdapter extends ArrayAdapter { */ public final String feedUrl; + + private Podcast(String title, String imageUrl, String feedUrl) { + this.title = title; + this.imageUrl = imageUrl; + this.feedUrl = feedUrl; + } + + /** + * Constructs a Podcast instance from a iTunes search result + * + * @param json object holding the podcast information + * @throws JSONException + */ + public static Podcast fromSearch(JSONObject json) throws JSONException { + String title = json.getString("collectionName"); + String imageUrl = json.getString("artworkUrl100"); + String feedUrl = json.getString("feedUrl"); + return new Podcast(title, imageUrl, feedUrl); + } + /** - * Constructor. + * Constructs a Podcast instance from iTunes toplist entry * * @param json object holding the podcast information * @throws JSONException */ - public Podcast(JSONObject json) throws JSONException { - title = json.getString("collectionName"); - imageUrl = json.getString("artworkUrl100"); - feedUrl = json.getString("feedUrl"); + public static Podcast fromToplist(JSONObject json) throws JSONException { + String title = json.getJSONObject("title").getString("label"); + String imageUrl = null; + JSONArray images = json.getJSONArray("im:image"); + for(int i=0; imageUrl == null && i < images.length(); i++) { + JSONObject image = images.getJSONObject(i); + String height = image.getJSONObject("attributes").getString("height"); + if(Integer.valueOf(height) >= 100) { + imageUrl = image.getString("label"); + } + } + String feedUrl = "https://itunes.apple.com/lookup?id=" + + json.getJSONObject("id").getJSONObject("attributes").getString("im:id"); + return new Podcast(title, imageUrl, feedUrl); } + } } -- cgit v1.2.3