aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/ExpandableSectionAdapter.java144
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/SearchAdapter.java35
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java2
3 files changed, 168 insertions, 13 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
new file mode 100644
index 00000000..822c83f3
--- /dev/null
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/ExpandableSectionAdapter.java
@@ -0,0 +1,144 @@
+/*
+ This file is part of Subsonic.
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+ Copyright 2015 (C) Scott Jackson
+*/
+
+package github.daneren2005.dsub.adapter;
+
+import android.content.Context;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.util.DrawableTint;
+import github.daneren2005.dsub.view.BasicHeaderView;
+import github.daneren2005.dsub.view.UpdateView;
+
+public abstract class ExpandableSectionAdapter<T> extends SectionAdapter<T> {
+ private static final String TAG = ExpandableSectionAdapter.class.getSimpleName();
+ private static final int DEFAULT_VISIBLE = 4;
+ private static final int EXPAND_TOGGLE = R.attr.select_server;
+ private static final int COLLAPSE_TOGGLE = R.attr.select_tabs;
+
+ protected List<Integer> sectionsDefaultVisible;
+ protected List<List<T>> sectionsExtras;
+ protected int expandToggleRes;
+ protected int collapseToggleRes;
+
+ protected ExpandableSectionAdapter() {}
+ public ExpandableSectionAdapter(Context context, List<String> headers, List<List<T>> sections) {
+ init(context, headers, sections, null);
+ }
+ public ExpandableSectionAdapter(Context context, List<String> headers, List<List<T>> sections, List<Integer> sectionsDefaultVisible) {
+ init(context, headers, sections, sectionsDefaultVisible);
+ }
+ protected void init(Context context, List<String> headers, List<List<T>> fullSections, List<Integer> sectionsDefaultVisible) {
+ this.context = context;
+ this.headers = headers;
+ this.sectionsDefaultVisible = sectionsDefaultVisible;
+ if(sectionsDefaultVisible == null) {
+ sectionsDefaultVisible = new ArrayList<>(fullSections.size());
+ for(int i = 0; i < fullSections.size(); i++) {
+ sectionsDefaultVisible.add(DEFAULT_VISIBLE);
+ }
+ }
+
+ this.sections = new ArrayList<>();
+ this.sectionsExtras = new ArrayList<>();
+ int i = 0;
+ for(List<T> fullSection: fullSections) {
+ List<T> visibleSection = new ArrayList<>();
+
+ Integer defaultVisible = sectionsDefaultVisible.get(i);
+ if(defaultVisible == null || defaultVisible >= fullSection.size()) {
+ visibleSection.addAll(fullSection);
+ this.sectionsExtras.add(null);
+ } else {
+ visibleSection.addAll(fullSection.subList(0, defaultVisible));
+ this.sectionsExtras.add(fullSection.subList(defaultVisible, fullSection.size()));
+ Log.d(TAG, visibleSection.size() + " + " + this.sectionsExtras.get(i).size());
+ }
+ this.sections.add(visibleSection);
+
+ i++;
+ }
+
+ expandToggleRes = DrawableTint.getDrawableRes(context, EXPAND_TOGGLE);
+ collapseToggleRes = DrawableTint.getDrawableRes(context, COLLAPSE_TOGGLE);
+ }
+
+ @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, final int sectionIndex) {
+ UpdateView view = holder.getUpdateView();
+ ImageView toggleSelectionView = (ImageView) view.findViewById(R.id.item_select);
+
+ List<T> visibleSelection = sections.get(sectionIndex);
+ List<T> sectionExtras = sectionsExtras.get(sectionIndex);
+
+ if(sectionExtras != null && !sectionExtras.isEmpty()) {
+ toggleSelectionView.setVisibility(View.VISIBLE);
+ toggleSelectionView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ List<T> visibleSelection = sections.get(sectionIndex);
+ List<T> sectionExtras = sectionsExtras.get(sectionIndex);
+
+ // Update icon
+ int selectToggleAttr;
+ if (!visibleSelection.contains(sectionExtras.get(0))) {
+ selectToggleAttr = COLLAPSE_TOGGLE;
+
+ // Update how many are displayed
+ int lastIndex = getItemPosition(visibleSelection.get(visibleSelection.size() - 1));
+ visibleSelection.addAll(sectionExtras);
+ notifyItemRangeInserted(lastIndex, sectionExtras.size());
+ } else {
+ selectToggleAttr = EXPAND_TOGGLE;
+
+ // Update how many are displayed
+ visibleSelection.removeAll(sectionExtras);
+ int lastIndex = getItemPosition(visibleSelection.get(visibleSelection.size() - 1));
+ notifyItemRangeRemoved(lastIndex, sectionExtras.size());
+ }
+
+ ((ImageView) v).setImageResource(DrawableTint.getDrawableRes(context, selectToggleAttr));
+ }
+ });
+
+ int selectToggleAttr;
+ if (!visibleSelection.contains(sectionExtras.get(0))) {
+ selectToggleAttr = EXPAND_TOGGLE;
+ } else {
+ selectToggleAttr = COLLAPSE_TOGGLE;
+ }
+
+ toggleSelectionView.setImageResource(DrawableTint.getDrawableRes(context, selectToggleAttr));
+ } else {
+ toggleSelectionView.setVisibility(View.GONE);
+ }
+
+ if(view != null) {
+ view.setObject(header);
+ }
+ }
+}
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/SearchAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/SearchAdapter.java
index 66f2db21..69e5d56d 100644
--- a/app/src/main/java/github/daneren2005/dsub/adapter/SearchAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/SearchAdapter.java
@@ -19,7 +19,9 @@ import android.content.Context;
import android.content.res.Resources;
import android.view.Menu;
import android.view.MenuInflater;
+import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageView;
import java.io.Serializable;
import java.util.ArrayList;
@@ -28,10 +30,12 @@ import java.util.List;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory.Entry;
import github.daneren2005.dsub.domain.SearchResult;
+import github.daneren2005.dsub.util.DrawableTint;
import github.daneren2005.dsub.util.ImageLoader;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.AlbumView;
import github.daneren2005.dsub.view.ArtistView;
+import github.daneren2005.dsub.view.BasicHeaderView;
import github.daneren2005.dsub.view.SongView;
import github.daneren2005.dsub.view.UpdateView;
@@ -40,32 +44,39 @@ import static github.daneren2005.dsub.adapter.EntryGridAdapter.VIEW_TYPE_ALBUM_C
import static github.daneren2005.dsub.adapter.EntryGridAdapter.VIEW_TYPE_ALBUM_LINE;
import static github.daneren2005.dsub.adapter.EntryGridAdapter.VIEW_TYPE_SONG;
-public class SearchAdapter extends SectionAdapter<Serializable> {
- private SearchResult searchResult;
+public class SearchAdapter extends ExpandableSectionAdapter<Serializable> {
private ImageLoader imageLoader;
private boolean largeAlbums;
+ private static final int MAX_ARTISTS = 10;
+ private static final int MAX_ALBUMS = 4;
+ private static final int MAX_SONGS = 10;
+
public SearchAdapter(Context context, SearchResult searchResult, ImageLoader imageLoader, boolean largeAlbums, OnItemClickedListener listener) {
- this.context = context;
- this.searchResult = searchResult;
this.imageLoader = imageLoader;
this.largeAlbums = largeAlbums;
- this.sections = new ArrayList<>();
- this.headers = new ArrayList<>();
+ List<List<Serializable>> sections = new ArrayList<>();
+ List<String> headers = new ArrayList<>();
+ List<Integer> defaultVisible = new ArrayList<>();
Resources res = context.getResources();
if(!searchResult.getArtists().isEmpty()) {
- this.sections.add((List<Serializable>) (List<?>) searchResult.getArtists());
- this.headers.add(res.getString(R.string.search_artists));
+ sections.add((List<Serializable>) (List<?>) searchResult.getArtists());
+ headers.add(res.getString(R.string.search_artists));
+ defaultVisible.add(MAX_ARTISTS);
}
if(!searchResult.getAlbums().isEmpty()) {
- this.sections.add((List<Serializable>) (List<?>) searchResult.getAlbums());
- this.headers.add(res.getString(R.string.search_albums));
+ sections.add((List<Serializable>) (List<?>) searchResult.getAlbums());
+ headers.add(res.getString(R.string.search_albums));
+ defaultVisible.add(MAX_ALBUMS);
}
if(!searchResult.getSongs().isEmpty()) {
- this.sections.add((List<Serializable>) (List<?>) searchResult.getSongs());
- this.headers.add(res.getString(R.string.search_songs));
+ sections.add((List<Serializable>) (List<?>) searchResult.getSongs());
+ headers.add(res.getString(R.string.search_songs));
+ defaultVisible.add(MAX_SONGS);
}
+ init(context, headers, sections, defaultVisible);
+
this.onItemClickedListener = listener;
checkable = true;
}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java
index 1aef5982..6f7ac86e 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SearchFragment.java
@@ -39,7 +39,7 @@ import github.daneren2005.dsub.view.UpdateView;
public class SearchFragment extends SubsonicFragment implements SectionAdapter.OnItemClickedListener<Serializable> {
private static final String TAG = SearchFragment.class.getSimpleName();
- private static final int MAX_ARTISTS = 10;
+ private static final int MAX_ARTISTS = 20;
private static final int MAX_ALBUMS = 10;
private static final int MAX_SONGS = 25;
private static final int MIN_CLOSENESS = 1;