aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github/daneren2005/dsub/adapter
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-08-20 17:53:00 -0700
committerScott Jackson <daneren2005@gmail.com>2015-08-20 17:53:00 -0700
commit36a9f62b10b97374355073e8317f49761bcbd5d8 (patch)
tree77814af34697d27233429ba4597b2cab1a1c9810 /app/src/main/java/github/daneren2005/dsub/adapter
parent305bf886c3776867943ba07da95fc4676adb848e (diff)
downloaddsub-36a9f62b10b97374355073e8317f49761bcbd5d8.tar.gz
dsub-36a9f62b10b97374355073e8317f49761bcbd5d8.tar.bz2
dsub-36a9f62b10b97374355073e8317f49761bcbd5d8.zip
Add fast scroller to more stuff as well as fixed some bugs with it
Diffstat (limited to 'app/src/main/java/github/daneren2005/dsub/adapter')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/AlbumListAdapter.java165
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/AlphabeticalAlbumAdapter.java44
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/ArtistAdapter.java8
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/GenreAdapter.java8
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/PlaylistAdapter.java8
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java8
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java36
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/TopRatedAlbumAdapter.java44
8 files changed, 134 insertions, 187 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/AlbumListAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/AlbumListAdapter.java
deleted file mode 100644
index 47f82259..00000000
--- a/app/src/main/java/github/daneren2005/dsub/adapter/AlbumListAdapter.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- 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 2010 (C) Sindre Mehus
- */
-package github.daneren2005.dsub.adapter;
-
-import android.content.Context;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
-import android.widget.SectionIndexer;
-
-import com.commonsware.cwac.endless.EndlessAdapter;
-import github.daneren2005.dsub.R;
-import github.daneren2005.dsub.domain.MusicDirectory;
-import github.daneren2005.dsub.domain.ServerInfo;
-import github.daneren2005.dsub.service.MusicService;
-import github.daneren2005.dsub.service.MusicServiceFactory;
-
-import java.util.ArrayList;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-public class AlbumListAdapter extends EndlessAdapter implements SectionIndexer {
- private static final String TAG = AlbumListAdapter.class.getSimpleName();
- Context context;
- ArrayAdapter<MusicDirectory.Entry> adapter;
- String type;
- String extra;
- int size;
- int offset;
- List<MusicDirectory.Entry> entries;
-
- private boolean shouldIndex = false;
- private Object[] sections;
- private Integer[] positions;
-
- public AlbumListAdapter(Context context, ArrayAdapter<MusicDirectory.Entry> adapter, String type, String extra, int size) {
- super(adapter);
- this.context = context;
- this.adapter = adapter;
- this.type = type;
- this.extra = extra;
- this.size = size;
- this.offset = size;
-
- if("alphabeticalByName".equals(this.type)) {
- shouldIndex = true;
- recreateIndexes();
- }
- }
-
- @Override
- protected boolean cacheInBackground() throws Exception {
- MusicService service = MusicServiceFactory.getMusicService(context);
- MusicDirectory result;
- if(("genres".equals(type) && ServerInfo.checkServerVersion(context, "1.10.0")) || "years".equals(type)) {
- result = service.getAlbumList(type, extra, size, offset, false, context, null);
- } else if("genres".equals(type) || "genres-songs".equals(type)) {
- result = service.getSongsByGenre(extra, size, offset, context, null);
- } else {
- result = service.getAlbumList(type, size, offset, shouldIndex, context, null);
- }
- entries = result.getChildren();
- return entries.size() > 0;
- }
-
- @Override
- protected void appendCachedData() {
- for(MusicDirectory.Entry entry: entries) {
- adapter.add(entry);
- }
- offset += entries.size();
- recreateIndexes();
- }
-
- @Override
- protected View getPendingView(ViewGroup parent) {
- View progress = LayoutInflater.from(context).inflate(R.layout.tab_progress, null);
- progress.setVisibility(View.VISIBLE);
- return progress;
- }
-
- private void recreateIndexes() {
- try {
- if (!shouldIndex) {
- return;
- }
-
- Set<String> sectionSet = new LinkedHashSet<String>(30);
- List<Integer> positionList = new ArrayList<Integer>(30);
- for (int i = 0; i < adapter.getCount(); i++) {
- MusicDirectory.Entry entry = adapter.getItem(i);
- String index;
- if (entry.getAlbum() != null) {
- index = entry.getAlbum().substring(0, 1);
- if (!Character.isLetter(index.charAt(0))) {
- index = "#";
- }
- } else {
- index = "*";
- }
-
- if (!sectionSet.contains(index)) {
- sectionSet.add(index);
- positionList.add(i);
- }
- }
- sections = sectionSet.toArray(new Object[sectionSet.size()]);
- positions = positionList.toArray(new Integer[positionList.size()]);
- } catch(Exception e) {
- Log.e(TAG, "Error while recreating indexes");
- }
- }
-
- @Override
- public Object[] getSections() {
- if(sections != null) {
- return sections;
- } else {
- return new Object[0];
- }
- }
-
- @Override
- public int getPositionForSection(int section) {
- if(sections != null) {
- section = Math.min(section, positions.length - 1);
- return positions[section];
- } else {
- return 0;
- }
- }
-
- @Override
- public int getSectionForPosition(int pos) {
- if(sections != null) {
- for (int i = 0; i < sections.length - 1; i++) {
- if (pos < positions[i + 1]) {
- return i;
- }
- }
- return sections.length - 1;
- } else {
- return 0;
- }
- }
-}
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/AlphabeticalAlbumAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/AlphabeticalAlbumAdapter.java
new file mode 100644
index 00000000..ccb3df4e
--- /dev/null
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/AlphabeticalAlbumAdapter.java
@@ -0,0 +1,44 @@
+/*
+ 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 java.util.List;
+
+import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.util.ImageLoader;
+import github.daneren2005.dsub.view.FastScroller;
+
+public class AlphabeticalAlbumAdapter extends EntryInfiniteGridAdapter implements FastScroller.BubbleTextGetter {
+ public AlphabeticalAlbumAdapter(Context context, List<MusicDirectory.Entry> entries, ImageLoader imageLoader, boolean largeCell) {
+ super(context, entries, imageLoader, largeCell);
+ }
+
+ @Override
+ public String getTextToShowInBubble(int position) {
+ // Make sure that we are not trying to get an item for the loading placeholder
+ if(position >= sections.get(0).size()) {
+ if(sections.get(0).size() > 0) {
+ return getTextToShowInBubble(position - 1);
+ } else {
+ return "*";
+ }
+ } else {
+ return getNameIndex(getItemForPosition(position).getAlbum());
+ }
+ }
+}
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/ArtistAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/ArtistAdapter.java
index 9116e587..2eea0e74 100644
--- a/app/src/main/java/github/daneren2005/dsub/adapter/ArtistAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/ArtistAdapter.java
@@ -125,13 +125,7 @@ public class ArtistAdapter extends SectionAdapter<Artist> implements FastScrolle
@Override
public String getTextToShowInBubble(int position) {
- Artist artist = getItemForPosition(position);
-
- if(artist == null) {
- return "";
- } else {
- return artist.getName().substring(0, 1);
- }
+ return getNameIndex(getItemForPosition(position).getName(), true);
}
public interface OnMusicFolderChanged {
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/GenreAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/GenreAdapter.java
index 7e6954f9..70aa5fe3 100644
--- a/app/src/main/java/github/daneren2005/dsub/adapter/GenreAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/GenreAdapter.java
@@ -18,12 +18,13 @@ package github.daneren2005.dsub.adapter;
import android.content.Context;
import android.view.ViewGroup;
import github.daneren2005.dsub.domain.Genre;
+import github.daneren2005.dsub.view.FastScroller;
import github.daneren2005.dsub.view.GenreView;
import github.daneren2005.dsub.view.UpdateView;
import java.util.List;
-public class GenreAdapter extends SectionAdapter<Genre>{
+public class GenreAdapter extends SectionAdapter<Genre> implements FastScroller.BubbleTextGetter{
public static int VIEW_TYPE_GENRE = 1;
public GenreAdapter(Context context, List<Genre> genres, OnItemClickedListener listener) {
@@ -45,4 +46,9 @@ public class GenreAdapter extends SectionAdapter<Genre>{
public int getItemViewType(Genre item) {
return VIEW_TYPE_GENRE;
}
+
+ @Override
+ public String getTextToShowInBubble(int position) {
+ return getNameIndex(getItemForPosition(position).getName());
+ }
}
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/PlaylistAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/PlaylistAdapter.java
index d7a9e8d7..7f7aacff 100644
--- a/app/src/main/java/github/daneren2005/dsub/adapter/PlaylistAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/PlaylistAdapter.java
@@ -62,12 +62,6 @@ public class PlaylistAdapter extends SectionAdapter<Playlist> implements FastScr
@Override
public String getTextToShowInBubble(int position) {
- Playlist playlist = getItemForPosition(position);
-
- if(playlist == null) {
- return "";
- } else {
- return playlist.getName().substring(0, 1);
- }
+ return getNameIndex(getItemForPosition(position).getName());
}
}
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 c1b132c7..f3eed393 100644
--- a/app/src/main/java/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/PodcastChannelAdapter.java
@@ -48,12 +48,6 @@ public class PodcastChannelAdapter extends SectionAdapter<PodcastChannel> implem
@Override
public String getTextToShowInBubble(int position) {
- PodcastChannel podcast = getItemForPosition(position);
-
- if(podcast == null) {
- return "";
- } else {
- return podcast.getName().substring(0, 1);
- }
+ return getNameIndex(getItemForPosition(position).getName());
}
}
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java
index eec1dedb..53cc5e99 100644
--- a/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/SectionAdapter.java
@@ -16,6 +16,7 @@
package github.daneren2005.dsub.adapter;
import android.content.Context;
+import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build;
import android.support.v7.widget.PopupMenu;
@@ -39,7 +40,9 @@ import java.util.List;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
+import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.MenuUtil;
+import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.BasicHeaderView;
import github.daneren2005.dsub.view.UpdateView;
import github.daneren2005.dsub.view.UpdateView.UpdateViewHolder;
@@ -47,6 +50,7 @@ import github.daneren2005.dsub.view.UpdateView.UpdateViewHolder;
public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewHolder<T>> {
private static String TAG = SectionAdapter.class.getSimpleName();
public static int VIEW_TYPE_HEADER = 0;
+ public static String[] ignoredArticles;
protected Context context;
protected List<String> headers;
@@ -461,6 +465,38 @@ public abstract class SectionAdapter<T> extends RecyclerView.Adapter<UpdateViewH
}
}
+ public String getNameIndex(String name) {
+ return getNameIndex(name, false);
+ }
+ public String getNameIndex(String name, boolean removeIgnoredArticles) {
+ if(name == null) {
+ return "*";
+ }
+
+ if(removeIgnoredArticles) {
+ if (ignoredArticles == null) {
+ SharedPreferences prefs = Util.getPreferences(context);
+ String ignoredArticlesString = prefs.getString(Constants.CACHE_KEY_IGNORE, "The El La Los Las Le Les");
+ ignoredArticles = ignoredArticlesString.split(" ");
+ }
+
+ name = name.toLowerCase();
+ for (String article : ignoredArticles) {
+ int index = name.indexOf(article.toLowerCase() + " ");
+ if (index == 0) {
+ name = name.substring(article.length() + 1);
+ }
+ }
+ }
+
+ String index = name.substring(0, 1).toUpperCase();
+ if (!Character.isLetter(index.charAt(0))) {
+ index = "#";
+ }
+
+ return index;
+ }
+
public interface OnItemClickedListener<T> {
void onItemClicked(T item);
void onCreateContextMenu(Menu menu, MenuInflater menuInflater, UpdateView<T> updateView, T item);
diff --git a/app/src/main/java/github/daneren2005/dsub/adapter/TopRatedAlbumAdapter.java b/app/src/main/java/github/daneren2005/dsub/adapter/TopRatedAlbumAdapter.java
new file mode 100644
index 00000000..876e5907
--- /dev/null
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/TopRatedAlbumAdapter.java
@@ -0,0 +1,44 @@
+/*
+ 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 java.util.List;
+
+import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.util.ImageLoader;
+import github.daneren2005.dsub.view.FastScroller;
+
+public class TopRatedAlbumAdapter extends EntryInfiniteGridAdapter implements FastScroller.BubbleTextGetter {
+ public TopRatedAlbumAdapter(Context context, List<MusicDirectory.Entry> entries, ImageLoader imageLoader, boolean largeCell) {
+ super(context, entries, imageLoader, largeCell);
+ }
+
+ @Override
+ public String getTextToShowInBubble(int position) {
+ // Make sure that we are not trying to get an item for the loading placeholder
+ if(position >= sections.get(0).size()) {
+ if(sections.get(0).size() > 0) {
+ return getTextToShowInBubble(position - 1);
+ } else {
+ return "*";
+ }
+ } else {
+ return Integer.toString(getItemForPosition(position).getRating());
+ }
+ }
+}