diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-03-17 17:34:04 -0400 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-03-17 17:34:04 -0400 |
commit | c51a798b59b8ecaa380d694d00fb5d6c8866d7bf (patch) | |
tree | fd796fdf3b2bd9aafa294c136b91035719fa3658 /app/src/main/java/de/danoeh/antennapod | |
parent | ab2c75d4b1f1551f832008f0c63782e2fbc44c59 (diff) | |
parent | 75d683a6db785b9a01a90f3b3e5c3e00723603a3 (diff) | |
download | AntennaPod-c51a798b59b8ecaa380d694d00fb5d6c8866d7bf.zip |
Merge pull request #683 from mfietz/feature/gpodder-tags-layout
Gpodder tags show title and usage
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod')
3 files changed, 70 insertions, 15 deletions
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<GpodnetTag> { + + public TagListAdapter(Context context, int resource, List<GpodnetTag> 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,9 +66,9 @@ 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)); } }); @@ -77,6 +76,12 @@ public class TagListFragment extends ListFragment { } @Override + public void onResume() { + super.onResume(); + ((MainActivity) getActivity()).getMainActivtyActionBar().setTitle(R.string.add_feed_label); + } + + @Override public void onDestroyView() { super.onDestroyView(); cancelLoadTask(); @@ -121,11 +126,7 @@ public class TagListFragment extends ListFragment { final Context context = getActivity(); if (context != null) { if (gpodnetTags != null) { - List<String> tagNames = new ArrayList<String>(); - for (GpodnetTag tag : gpodnetTags) { - tagNames.add(tag.getName()); - } - setListAdapter(new ArrayAdapter<String>(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()); |