aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-03-21 17:47:09 -0700
committerScott Jackson <daneren2005@gmail.com>2016-03-21 17:47:09 -0700
commitd8ffc1970920bb20467bedfc968acbc76486a18e (patch)
treeb9b951533edc8fe2836d19c117b4e4e8d83ec32d /app/src/main
parenta55812c8876d9e17a61bc9c49a7a6f0712eeae0b (diff)
downloaddsub-d8ffc1970920bb20467bedfc968acbc76486a18e.tar.gz
dsub-d8ffc1970920bb20467bedfc968acbc76486a18e.tar.bz2
dsub-d8ffc1970920bb20467bedfc968acbc76486a18e.zip
Refactor PodcastChannelAdapter to use ExpandableSectionAdapter
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/ExpandableSectionAdapter.java7
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java64
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SelectPodcastsFragment.java17
3 files changed, 16 insertions, 72 deletions
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<T> extends SectionAdapter<T> {
protected int collapseToggleRes;
protected ExpandableSectionAdapter() {}
+ public ExpandableSectionAdapter(Context context, List<T> section) {
+ List<List<T>> sections = new ArrayList<>();
+ sections.add(section);
+
+ init(context, Arrays.asList("Section"), sections, Arrays.asList((Integer) null));
+ }
public ExpandableSectionAdapter(Context context, List<String> headers, List<List<T>> 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<Serializable> implements FastScroller.BubbleTextGetter {
+public class PodcastChannelAdapter extends ExpandableSectionAdapter<Serializable> 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<Serializable> extraEpisodes;
public PodcastChannelAdapter(Context context, List<Serializable> podcasts, ImageLoader imageLoader, OnItemClickedListener listener, boolean largeCell) {
super(context, podcasts);
@@ -56,9 +52,8 @@ public class PodcastChannelAdapter extends SectionAdapter<Serializable> implemen
this.onItemClickedListener = listener;
this.largeCell = largeCell;
}
- public PodcastChannelAdapter(Context context, List<String> headers, List<List<Serializable>> sections, List<Serializable> extraEpisodes, ImageLoader imageLoader, OnItemClickedListener listener, boolean largeCell) {
- super(context, headers, sections);
- this.extraEpisodes = extraEpisodes;
+ public PodcastChannelAdapter(Context context, List<String> headers, List<List<Serializable>> 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<Serializable> 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<Serializable>
@Override
public SectionAdapter getAdapter(List<Serializable> 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<String> headers = Arrays.asList(PodcastChannelAdapter.EPISODE_HEADER, PodcastChannelAdapter.CHANNEL_HEADER);
+ Resources res = context.getResources();
+ List<String> headers = Arrays.asList(res.getString(R.string.main_albums_newest), res.getString(R.string.select_podcasts_channels));
List<MusicDirectory.Entry> episodes = newestEpisodes.getChildren(false, true);
List<Serializable> 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<Serializable> extraEpisodes = new ArrayList<>();
- extraEpisodes.addAll(episodes);
+ serializableEpisodes.addAll(episodes);
List<List<Serializable>> 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);
}
}