aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-05-26 18:04:35 -0700
committerScott Jackson <daneren2005@gmail.com>2015-05-26 18:04:35 -0700
commit7606a374f95c079c2e88426c177515e05fda1e2b (patch)
tree6892e02bd7bbb0dcd0e4eee282c4ea5a31480984 /app
parent117c246d7e619ab9a3c0fb36fb152b8ad8bf9afe (diff)
downloaddsub-7606a374f95c079c2e88426c177515e05fda1e2b.tar.gz
dsub-7606a374f95c079c2e88426c177515e05fda1e2b.tar.bz2
dsub-7606a374f95c079c2e88426c177515e05fda1e2b.zip
#479 Separate personal from shared playlists
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/adapter/PlaylistAdapter.java88
-rw-r--r--app/src/main/java/github/daneren2005/dsub/domain/Playlist.java15
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java51
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/parser/PlaylistsParser.java3
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/PlaylistView.java5
5 files changed, 89 insertions, 73 deletions
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 d56a6b97..fa00c1dd 100644
--- a/app/src/main/java/github/daneren2005/dsub/adapter/PlaylistAdapter.java
+++ b/app/src/main/java/github/daneren2005/dsub/adapter/PlaylistAdapter.java
@@ -1,70 +1,54 @@
/*
- 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
- */
+ 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 github.daneren2005.dsub.R;
+
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
-import android.view.View;
import android.view.ViewGroup;
-import android.widget.ArrayAdapter;
import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.view.PlaylistView;
+import github.daneren2005.dsub.view.UpdateView;
-import java.util.Collections;
-import java.util.Comparator;
-
-/**
- * @author Sindre Mehus
- */
-public class PlaylistAdapter extends ArrayAdapter<Playlist> {
+public class PlaylistAdapter extends SectionAdapter<Playlist> {
+ public static int VIEW_TYPE_PLAYLIST = 1;
- private final Context activity;
-
- public PlaylistAdapter(Context activity, List<Playlist> Playlists) {
- super(activity, R.layout.basic_list_item, Playlists);
- this.activity = activity;
+ public PlaylistAdapter(Context context, List<Playlist> playlists, OnItemClickedListener listener) {
+ super(context, playlists);
+ this.onItemClickedListener = listener;
+ }
+ public PlaylistAdapter(Context context, List<String> headers, List<List<Playlist>> sections, OnItemClickedListener listener) {
+ super(context, headers, sections);
+ this.onItemClickedListener = listener;
}
@Override
- public View getView(int position, View convertView, ViewGroup parent) {
- Playlist entry = getItem(position);
- PlaylistView view;
- if (convertView != null && convertView instanceof PlaylistView) {
- view = (PlaylistView) convertView;
- } else {
- view = new PlaylistView(activity);
- }
- view.setObject(entry);
- return view;
+ public UpdateView.UpdateViewHolder onCreateSectionViewHolder(ViewGroup parent, int viewType) {
+ return new UpdateView.UpdateViewHolder(new PlaylistView(context));
}
- public static class PlaylistComparator implements Comparator<Playlist> {
- @Override
- public int compare(Playlist playlist1, Playlist playlist2) {
- return playlist1.getName().compareToIgnoreCase(playlist2.getName());
- }
-
- public static List<Playlist> sort(List<Playlist> playlists) {
- Collections.sort(playlists, new PlaylistComparator());
- return playlists;
- }
+ @Override
+ public void onBindViewHolder(UpdateView.UpdateViewHolder holder, Playlist playlist, int viewType) {
+ holder.getUpdateView().setObject(playlist);
+ holder.setItem(playlist);
+ }
+ @Override
+ public int getItemViewType(Playlist playlist) {
+ return VIEW_TYPE_PLAYLIST;
}
}
diff --git a/app/src/main/java/github/daneren2005/dsub/domain/Playlist.java b/app/src/main/java/github/daneren2005/dsub/domain/Playlist.java
index 7cd820c0..99b85ce9 100644
--- a/app/src/main/java/github/daneren2005/dsub/domain/Playlist.java
+++ b/app/src/main/java/github/daneren2005/dsub/domain/Playlist.java
@@ -19,6 +19,9 @@
package github.daneren2005.dsub.domain;
import java.io.Serializable;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
/**
* @author Sindre Mehus
@@ -125,4 +128,16 @@ public class Playlist implements Serializable {
Playlist playlist = (Playlist) o;
return playlist.id.equals(this.id);
}
+
+ public static class PlaylistComparator implements Comparator<Playlist> {
+ @Override
+ public int compare(Playlist playlist1, Playlist playlist2) {
+ return playlist1.getName().compareToIgnoreCase(playlist2.getName());
+ }
+
+ public static List<Playlist> sort(List<Playlist> playlists) {
+ Collections.sort(playlists, new PlaylistComparator());
+ return playlists;
+ }
+ }
}
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java
index 3d7e664f..8939360c 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectPlaylistFragment.java
@@ -2,18 +2,19 @@ package github.daneren2005.dsub.fragments;
import android.app.AlertDialog;
import android.content.DialogInterface;
+import android.content.res.Resources;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
+import android.support.v7.widget.RecyclerView;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.adapter.SectionAdapter;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.domain.ServerInfo;
@@ -31,9 +32,11 @@ import github.daneren2005.dsub.util.UserUtil;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.adapter.PlaylistAdapter;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
-public class SelectPlaylistFragment extends SelectListFragment<Playlist> {
+public class SelectPlaylistFragment extends SelectRecyclerFragment<Playlist> implements SectionAdapter.OnItemClickedListener<Playlist> {
private static final String TAG = SelectPlaylistFragment.class.getSimpleName();
@Override
@@ -47,8 +50,7 @@ public class SelectPlaylistFragment extends SelectListFragment<Playlist> {
else {
inflater.inflate(R.menu.select_playlist_context, menu);
- AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
- Playlist playlist = (Playlist) listView.getItemAtPosition(info.position);
+ Playlist playlist = adapter.getContextItem();
if(SyncUtil.isSyncedPlaylist(context, playlist.getId())) {
menu.removeItem(R.id.playlist_menu_sync);
} else {
@@ -71,9 +73,8 @@ public class SelectPlaylistFragment extends SelectListFragment<Playlist> {
if(menuItem.getGroupId() != getSupportTag()) {
return false;
}
-
- AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo();
- Playlist playlist = (Playlist) listView.getItemAtPosition(info.position);
+
+ Playlist playlist = adapter.getContextItem();
SubsonicFragment fragment;
Bundle args;
@@ -130,8 +131,31 @@ public class SelectPlaylistFragment extends SelectListFragment<Playlist> {
}
@Override
- public ArrayAdapter getAdapter(List<Playlist> playlists) {
- return new PlaylistAdapter(context, playlists);
+ public SectionAdapter<Playlist> getAdapter(List<Playlist> playlists) {
+ List<Playlist> mine = new ArrayList<>();
+ List<Playlist> shared = new ArrayList<>();
+
+ String currentUsername = UserUtil.getCurrentUsername(context);
+ for(Playlist playlist: playlists) {
+ if(playlist.getOwner() == null || playlist.getOwner().equals(currentUsername)) {
+ mine.add(playlist);
+ } else {
+ shared.add(playlist);
+ }
+ }
+
+ if(shared.isEmpty()) {
+ return new PlaylistAdapter(context, playlists, this);
+ } else {
+ Resources res = context.getResources();
+ List<String> headers = Arrays.asList(res.getString(R.string.playlist_mine), res.getString(R.string.playlist_shared));
+
+ List<List<Playlist>> sections = new ArrayList<>();
+ sections.add(mine);
+ sections.add(shared);
+
+ return new PlaylistAdapter(context, headers, sections, this);
+ }
}
@Override
@@ -149,9 +173,7 @@ public class SelectPlaylistFragment extends SelectListFragment<Playlist> {
}
@Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- Playlist playlist = (Playlist) parent.getItemAtPosition(position);
-
+ public void onItemClicked(Playlist playlist) {
SubsonicFragment fragment = new SelectDirectoryFragment();
Bundle args = new Bundle();
args.putString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId());
@@ -179,7 +201,8 @@ public class SelectPlaylistFragment extends SelectListFragment<Playlist> {
@Override
protected void done(Void result) {
- adapter.remove(playlist);
+ // TODO: Redo
+ // adapter.remove(playlist);
adapter.notifyDataSetChanged();
Util.toast(context, context.getResources().getString(R.string.menu_deleted_playlist, playlist.getName()));
}
diff --git a/app/src/main/java/github/daneren2005/dsub/service/parser/PlaylistsParser.java b/app/src/main/java/github/daneren2005/dsub/service/parser/PlaylistsParser.java
index 6f01d510..69e5af64 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/parser/PlaylistsParser.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/parser/PlaylistsParser.java
@@ -22,7 +22,6 @@ import android.content.Context;
import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.util.ProgressListener;
-import github.daneren2005.dsub.adapter.PlaylistAdapter;
import org.xmlpull.v1.XmlPullParser;
import java.io.Reader;
@@ -64,7 +63,7 @@ public class PlaylistsParser extends AbstractParser {
validate();
- return PlaylistAdapter.PlaylistComparator.sort(result);
+ return Playlist.PlaylistComparator.sort(result);
}
} \ No newline at end of file
diff --git a/app/src/main/java/github/daneren2005/dsub/view/PlaylistView.java b/app/src/main/java/github/daneren2005/dsub/view/PlaylistView.java
index 25613984..29d5cc1c 100644
--- a/app/src/main/java/github/daneren2005/dsub/view/PlaylistView.java
+++ b/app/src/main/java/github/daneren2005/dsub/view/PlaylistView.java
@@ -50,11 +50,6 @@ public class PlaylistView extends UpdateView {
starButton = (ImageButton) findViewById(R.id.item_star);
starButton.setFocusable(false);
moreButton = (ImageView) findViewById(R.id.item_more);
- moreButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- v.showContextMenu();
- }
- });
}
protected void setObjectImpl(Object obj) {