From d8ffc1970920bb20467bedfc968acbc76486a18e Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 21 Mar 2016 17:47:09 -0700 Subject: Refactor PodcastChannelAdapter to use ExpandableSectionAdapter --- .../dsub/adapter/ExpandableSectionAdapter.java | 7 +++ .../dsub/adapter/PodcastChannelAdapter.java | 64 ++-------------------- .../dsub/fragments/SelectPodcastsFragment.java | 17 ++---- 3 files changed, 16 insertions(+), 72 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/ExpandableSectionAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/ExpandableSectionAdapter.java index 822c83f3..b1a692d5 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/ExpandableSectionAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/ExpandableSectionAdapter.java @@ -22,6 +22,7 @@ import android.view.ViewGroup; import android.widget.ImageView; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import github.daneren2005.dsub.R; @@ -41,6 +42,12 @@ public abstract class ExpandableSectionAdapter extends SectionAdapter { protected int collapseToggleRes; protected ExpandableSectionAdapter() {} + public ExpandableSectionAdapter(Context context, List section) { + List> sections = new ArrayList<>(); + sections.add(section); + + init(context, Arrays.asList("Section"), sections, Arrays.asList((Integer) null)); + } public ExpandableSectionAdapter(Context context, List headers, List> sections) { init(context, headers, sections, null); } diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java index 97d29407..f843a722 100644 --- a/app/src/main/java/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java +++ b/app/src/main/java/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java @@ -34,21 +34,17 @@ import github.daneren2005.dsub.view.SongView; import github.daneren2005.dsub.view.UpdateView; import java.io.Serializable; +import java.util.Arrays; import java.util.List; -public class PodcastChannelAdapter extends SectionAdapter implements FastScroller.BubbleTextGetter { +public class PodcastChannelAdapter extends ExpandableSectionAdapter implements FastScroller.BubbleTextGetter { public static final int VIEW_TYPE_PODCAST_LEGACY = 1; public static final int VIEW_TYPE_PODCAST_LINE = 2; public static final int VIEW_TYPE_PODCAST_CELL = 3; public static final int VIEW_TYPE_PODCAST_EPISODE = 4; - public static final String EPISODE_HEADER = "episodes"; - public static final String CHANNEL_HEADER = "channels"; - private ImageLoader imageLoader; private boolean largeCell; - private int selectToggleAttr = R.attr.select_server; - private List extraEpisodes; public PodcastChannelAdapter(Context context, List podcasts, ImageLoader imageLoader, OnItemClickedListener listener, boolean largeCell) { super(context, podcasts); @@ -56,9 +52,8 @@ public class PodcastChannelAdapter extends SectionAdapter implemen this.onItemClickedListener = listener; this.largeCell = largeCell; } - public PodcastChannelAdapter(Context context, List headers, List> sections, List extraEpisodes, ImageLoader imageLoader, OnItemClickedListener listener, boolean largeCell) { - super(context, headers, sections); - this.extraEpisodes = extraEpisodes; + public PodcastChannelAdapter(Context context, List headers, List> sections, ImageLoader imageLoader, OnItemClickedListener listener, boolean largeCell) { + super(context, headers, sections, Arrays.asList(3, null)); this.imageLoader = imageLoader; this.onItemClickedListener = listener; this.largeCell = largeCell; @@ -128,55 +123,4 @@ public class PodcastChannelAdapter extends SectionAdapter implemen menu.removeItem(R.id.menu_remove_playlist); menu.removeItem(R.id.menu_star); } - - @Override - public UpdateView.UpdateViewHolder onCreateHeaderHolder(ViewGroup parent) { - return new UpdateView.UpdateViewHolder(new BasicHeaderView(context, R.layout.expandable_header)); - } - - @Override - public void onBindHeaderHolder(UpdateView.UpdateViewHolder holder, String header, int sectionIndex) { - UpdateView view = holder.getUpdateView(); - ImageView toggleSelectionView = (ImageView) view.findViewById(R.id.item_select); - - String display; - if(EPISODE_HEADER.equals(header)) { - display = context.getResources().getString(R.string.main_albums_newest); - - if(extraEpisodes != null && !extraEpisodes.isEmpty()) { - toggleSelectionView.setVisibility(View.VISIBLE); - toggleSelectionView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - // Update icon - if (selectToggleAttr == R.attr.select_server) { - selectToggleAttr = R.attr.select_tabs; - - // Update how many are displayed - sections.get(0).addAll(extraEpisodes); - notifyItemRangeInserted(4, extraEpisodes.size()); - } else { - selectToggleAttr = R.attr.select_server; - - // Update how many are displayed - sections.get(0).removeAll(extraEpisodes); - notifyItemRangeRemoved(4, extraEpisodes.size()); - } - - ((ImageView) v).setImageResource(DrawableTint.getDrawableRes(context, selectToggleAttr)); - } - }); - toggleSelectionView.setImageResource(DrawableTint.getDrawableRes(context, selectToggleAttr)); - } else { - toggleSelectionView.setVisibility(View.GONE); - } - } else { - display = context.getResources().getString(R.string.select_podcasts_channels); - toggleSelectionView.setVisibility(View.GONE); - } - - if(view != null) { - view.setObject(display); - } - } } diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java index 37fc21cc..3505a32b 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java @@ -151,28 +151,21 @@ public class SelectPodcastsFragment extends SelectRecyclerFragment @Override public SectionAdapter getAdapter(List channels) { - if(newestEpisodes == null || newestEpisodes.getChildrenSize() == 0) { + if(newestEpisodes == null || newestEpisodes.getChildrenSize() == 0 || true) { return new PodcastChannelAdapter(context, channels, hasCoverArt ? getImageLoader() : null, this, largeAlbums); } else { - List headers = Arrays.asList(PodcastChannelAdapter.EPISODE_HEADER, PodcastChannelAdapter.CHANNEL_HEADER); + Resources res = context.getResources(); + List headers = Arrays.asList(res.getString(R.string.main_albums_newest), res.getString(R.string.select_podcasts_channels)); List episodes = newestEpisodes.getChildren(false, true); List serializableEpisodes = new ArrayList<>(); - - // Put 3 in current list - while(serializableEpisodes.size() < 3 && !episodes.isEmpty()) { - serializableEpisodes.add(episodes.remove(0)); - } - - // Put rest in extra set - List extraEpisodes = new ArrayList<>(); - extraEpisodes.addAll(episodes); + serializableEpisodes.addAll(episodes); List> sections = new ArrayList<>(); sections.add(serializableEpisodes); sections.add(channels); - return new PodcastChannelAdapter(context, headers, sections, extraEpisodes, ServerInfo.checkServerVersion(context, "1.13") ? getImageLoader() : null, this, largeAlbums); + return new PodcastChannelAdapter(context, headers, sections, ServerInfo.checkServerVersion(context, "1.13") ? getImageLoader() : null, this, largeAlbums); } } -- cgit v1.2.3