From c8c5267bdab2a12138c20e74781855d16b13fb99 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 28 Aug 2014 22:27:33 -0700 Subject: #251 Add layout for displaying when songs are already in playlist --- res/layout/basic_count_item.xml | 35 ++++++++++++++++++++++ .../dsub/fragments/SubsonicFragment.java | 30 +++++++++++-------- 2 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 res/layout/basic_count_item.xml diff --git a/res/layout/basic_count_item.xml b/res/layout/basic_count_item.xml new file mode 100644 index 00000000..36a0e75d --- /dev/null +++ b/res/layout/basic_count_item.xml @@ -0,0 +1,35 @@ + + + + + + + \ No newline at end of file diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 0655e461..14e941f1 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -34,15 +34,18 @@ import android.support.v4.widget.SwipeRefreshLayout; import android.util.Log; import android.view.ContextMenu; import android.view.GestureDetector; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; +import android.widget.LinearLayout; import android.widget.TextView; import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.DownloadActivity; @@ -929,7 +932,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR // Create new if not getting a convert view to use LinearLayout view; if(convertView == null) { - view = LayoutInflater.from(context).inflate(R.layout.basic_count_item, parent, false); + view = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.basic_count_item, parent, false); } else { view = (LinearLayout) convertView; } @@ -943,12 +946,11 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR int count = 0; // Don't try to lookup playlist for Create New if(!"-1".equals(playlist.getId())) { - String cacheName = "playlist" + (Util.getRestUrl(context, null, false) + playlist.getId()).hashCode() + ".ser"; - MusicDirectory playlist = FileUtil.deserialize(context, cacheName, MusicDirectory.class); - if(playlist != null) { + MusicDirectory cache = FileUtil.deserialize(context, Util.getCacheName(context, "playlist", playlist.getId()), MusicDirectory.class); + if(cache != null) { // Try to find song instances in the given playlists - for(MusicDirectory song: songs) { - if(playlist.getChildren().contains(song)) { + for(MusicDirectory.Entry song: songs) { + if(cache.getChildren().contains(song)) { count++; } } @@ -969,20 +971,22 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR countView.setText(displayName); countView.setVisibility(View.VISIBLE); } + + return view; } }; AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.playlist_add_to) .setAdapter(playlistAdapter, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - if(which > 0) { - addToPlaylist(playlists.get(which - 1), songs); - } else { - createNewPlaylist(songs, false); + public void onClick(DialogInterface dialog, int which) { + if (which > 0) { + addToPlaylist(playlists.get(which - 1), songs); + } else { + createNewPlaylist(songs, false); + } } - } - }); + }); AlertDialog dialog = builder.create(); dialog.show(); } -- cgit v1.2.3