From 596462b7a2805748dcae4e80c4ff83200f915d09 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Tue, 17 Mar 2015 12:36:04 +0100 Subject: [PATCH 1/3] Gpodder categories shows title instead of tag and additionally the usage --- .../adapter/gpodnet/TagListAdapter.java | 54 ++++++++++++++++++ .../fragment/gpodnet/TagFragment.java | 12 ++-- .../fragment/gpodnet/TagListFragment.java | 19 ++++--- .../main/res/layout/gpodnet_tag_listitem.xml | 33 +++++++++++ .../core/gpoddernet/GpodnetService.java | 7 ++- .../core/gpoddernet/model/GpodnetTag.java | 56 ++++++++++++------- 6 files changed, 142 insertions(+), 39 deletions(-) create mode 100644 app/src/main/java/de/danoeh/antennapod/adapter/gpodnet/TagListAdapter.java create mode 100644 app/src/main/res/layout/gpodnet_tag_listitem.xml diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/gpodnet/TagListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/gpodnet/TagListAdapter.java new file mode 100644 index 000000000..b4eadefb5 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/adapter/gpodnet/TagListAdapter.java @@ -0,0 +1,54 @@ +package de.danoeh.antennapod.adapter.gpodnet; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import java.util.List; + +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.core.gpoddernet.model.GpodnetTag; + +/** + * Adapter for displaying a list of GPodnetPodcast-Objects. + */ +public class TagListAdapter extends ArrayAdapter { + + public TagListAdapter(Context context, int resource, List objects) { + super(context, resource, objects); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Holder holder; + + GpodnetTag tag = getItem(position); + + // Inflate Layout + if (convertView == null) { + holder = new Holder(); + LayoutInflater inflater = (LayoutInflater) getContext() + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + convertView = inflater.inflate(R.layout.gpodnet_tag_listitem, parent, false); + holder.title = (TextView) convertView.findViewById(R.id.txtvTitle); + holder.usage = (TextView) convertView.findViewById(R.id.txtvUsage); + convertView.setTag(holder); + } else { + holder = (Holder) convertView.getTag(); + } + + holder.title.setText(tag.getTitle()); + holder.usage.setText(String.valueOf(tag.getUsage())); + + return convertView; + } + + static class Holder { + TextView title; + TextView usage; + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagFragment.java index c8cdbcfed..e2450f03d 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagFragment.java @@ -24,11 +24,11 @@ public class TagFragment extends PodcastListFragment { private GpodnetTag tag; - public static TagFragment newInstance(String tagName) { - Validate.notNull(tagName); + public static TagFragment newInstance(GpodnetTag tag) { + Validate.notNull(tag); TagFragment fragment = new TagFragment(); Bundle args = new Bundle(); - args.putString("tag", tagName); + args.putParcelable("tag", tag); fragment.setArguments(args); return fragment; } @@ -38,14 +38,14 @@ public class TagFragment extends PodcastListFragment { super.onCreate(savedInstanceState); Bundle args = getArguments(); - Validate.isTrue(args != null && args.getString("tag") != null, "args invalid"); - tag = new GpodnetTag(args.getString("tag")); + Validate.isTrue(args != null && args.getParcelable("tag") != null, "args invalid"); + tag = args.getParcelable("tag"); } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - ((MainActivity) getActivity()).getMainActivtyActionBar().setTitle(tag.getName()); + ((MainActivity) getActivity()).getMainActivtyActionBar().setTitle(tag.getTitle()); } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java index 24e0e4caa..cc87407b4 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/gpodnet/TagListFragment.java @@ -10,14 +10,13 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.View; import android.widget.AdapterView; -import android.widget.ArrayAdapter; import android.widget.TextView; -import java.util.ArrayList; import java.util.List; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.adapter.gpodnet.TagListAdapter; import de.danoeh.antennapod.core.gpoddernet.GpodnetService; import de.danoeh.antennapod.core.gpoddernet.GpodnetServiceException; import de.danoeh.antennapod.core.gpoddernet.model.GpodnetTag; @@ -67,15 +66,21 @@ public class TagListFragment extends ListFragment { getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { - String selectedTag = (String) getListAdapter().getItem(position); + GpodnetTag tag = (GpodnetTag) getListAdapter().getItem(position); MainActivity activity = (MainActivity) getActivity(); - activity.loadChildFragment(TagFragment.newInstance(selectedTag)); + activity.loadChildFragment(TagFragment.newInstance(tag)); } }); startLoadTask(); } + @Override + public void onResume() { + super.onResume(); + ((MainActivity) getActivity()).getMainActivtyActionBar().setTitle(R.string.add_feed_label); + } + @Override public void onDestroyView() { super.onDestroyView(); @@ -121,11 +126,7 @@ public class TagListFragment extends ListFragment { final Context context = getActivity(); if (context != null) { if (gpodnetTags != null) { - List tagNames = new ArrayList(); - for (GpodnetTag tag : gpodnetTags) { - tagNames.add(tag.getName()); - } - setListAdapter(new ArrayAdapter(context, android.R.layout.simple_list_item_1, tagNames)); + setListAdapter(new TagListAdapter(context, android.R.layout.simple_list_item_1, gpodnetTags)); } else if (exception != null) { TextView txtvError = new TextView(getActivity()); txtvError.setText(exception.getMessage()); diff --git a/app/src/main/res/layout/gpodnet_tag_listitem.xml b/app/src/main/res/layout/gpodnet_tag_listitem.xml new file mode 100644 index 000000000..8a4167c34 --- /dev/null +++ b/app/src/main/res/layout/gpodnet_tag_listitem.xml @@ -0,0 +1,33 @@ + + + + + + + + + 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 791ccd5ec..a353c984a 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 @@ -172,9 +172,10 @@ public class GpodnetService { jsonTagList.length()); for (int i = 0; i < jsonTagList.length(); i++) { JSONObject jObj = jsonTagList.getJSONObject(i); - String name = jObj.getString("tag"); + String title = jObj.getString("title"); + String tag = jObj.getString("tag"); int usage = jObj.getInt("usage"); - tagList.add(new GpodnetTag(name, usage)); + tagList.add(new GpodnetTag(title, tag, usage)); } return tagList; } catch (JSONException e) { @@ -194,7 +195,7 @@ public class GpodnetService { try { URL url = new URI(BASE_SCHEME, BASE_HOST, String.format( - "/api/2/tag/%s/%d.json", tag.getName(), count), null).toURL(); + "/api/2/tag/%s/%d.json", tag.getTag(), count), null).toURL(); Request.Builder request = new Request.Builder().url(url); String response = executeRequest(request); diff --git a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/model/GpodnetTag.java b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/model/GpodnetTag.java index 7178f4be5..cd865731b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/model/GpodnetTag.java +++ b/core/src/main/java/de/danoeh/antennapod/core/gpoddernet/model/GpodnetTag.java @@ -1,46 +1,60 @@ package de.danoeh.antennapod.core.gpoddernet.model; +import android.os.Parcel; +import android.os.Parcelable; + import org.apache.commons.lang3.Validate; -import java.util.Comparator; +public class GpodnetTag implements Parcelable { -public class GpodnetTag { + private final String title; + private final String tag; + private final int usage; - private String name; - private int usage; + public GpodnetTag(String title, String tag, int usage) { + Validate.notNull(title); + Validate.notNull(tag); - public GpodnetTag(String name, int usage) { - Validate.notNull(name); - - this.name = name; + this.title = title; + this.tag = tag; this.usage = usage; } - public GpodnetTag(String name) { - super(); - this.name = name; + public static GpodnetTag createFromParcel(Parcel in) { + final String title = in.readString(); + final String tag = in.readString(); + final int usage = in.readInt(); + return new GpodnetTag(title, tag, usage); } @Override public String toString() { - return "GpodnetTag [name=" + name + ", usage=" + usage + "]"; + return "GpodnetTag [title="+title+", tag=" + tag + ", usage=" + usage + "]"; } - public String getName() { - return name; + public String getTitle() { + return title; + } + + public String getTag() { + return tag; } public int getUsage() { return usage; } - public static class UsageComparator implements Comparator { - - @Override - public int compare(GpodnetTag o1, GpodnetTag o2) { - return o1.usage - o2.usage; - } - + @Override + public int describeContents() { + return 0; } + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(title); + dest.writeString(tag); + dest.writeInt(usage); + } + + } From 61dbe18a90f164011e43e23d349a5c1400cb76e8 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Tue, 17 Mar 2015 12:53:04 +0100 Subject: [PATCH 2/3] Removed unintended layout element to make list items clickable again --- app/src/main/res/layout/gpodnet_podcast_listitem.xml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/src/main/res/layout/gpodnet_podcast_listitem.xml b/app/src/main/res/layout/gpodnet_podcast_listitem.xml index 8890f1b77..84c6c280e 100644 --- a/app/src/main/res/layout/gpodnet_podcast_listitem.xml +++ b/app/src/main/res/layout/gpodnet_podcast_listitem.xml @@ -79,15 +79,4 @@ tools:text="http://www.example.com/feed" tools:background="@android:color/holo_green_dark"/> - From 75d683a6db785b9a01a90f3b3e5c3e00723603a3 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Tue, 17 Mar 2015 13:26:30 +0100 Subject: [PATCH 3/3] Gpodder tags alignment --- app/src/main/res/layout/gpodnet_tag_listitem.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/gpodnet_tag_listitem.xml b/app/src/main/res/layout/gpodnet_tag_listitem.xml index 8a4167c34..9e545e59d 100644 --- a/app/src/main/res/layout/gpodnet_tag_listitem.xml +++ b/app/src/main/res/layout/gpodnet_tag_listitem.xml @@ -4,6 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + android:gravity="center_vertical" tools:background="@android:color/darker_gray">