diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-08-28 22:40:48 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-08-28 22:40:48 -0700 |
commit | 4d88a0cff594c4d615bd77c855ce7d32066cf4cf (patch) | |
tree | 727f0aa29084a6d6df024c7dddbc5ef11203f035 | |
parent | c8c5267bdab2a12138c20e74781855d16b13fb99 (diff) | |
download | dsub-4d88a0cff594c4d615bd77c855ce7d32066cf4cf.tar.gz dsub-4d88a0cff594c4d615bd77c855ce7d32066cf4cf.tar.bz2 dsub-4d88a0cff594c4d615bd77c855ce7d32066cf4cf.zip |
#251 Move to it's own UpdateView so doesn't slow everything down
-rw-r--r-- | src/github/daneren2005/dsub/fragments/SubsonicFragment.java | 46 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/view/PlaylistSongView.java | 99 |
2 files changed, 106 insertions, 39 deletions
diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index 14e941f1..9c76ba3c 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -73,6 +73,7 @@ import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.LoadingTask;
import github.daneren2005.dsub.util.UserUtil;
import github.daneren2005.dsub.util.Util;
+import github.daneren2005.dsub.view.PlaylistSongView;
import github.daneren2005.dsub.view.UpdateView;
import java.io.File;
@@ -930,48 +931,15 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR Playlist playlist = getItem(position);
// Create new if not getting a convert view to use
- LinearLayout view;
+ PlaylistSongView view;
if(convertView == null) {
- view = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.basic_count_item, parent, false);
+ view = (PlaylistSongView) new PlaylistSongView(context);
} else {
- view = (LinearLayout) convertView;
- }
-
- TextView nameView = (TextView) view.findViewById(R.id.basic_count_name);
- nameView.setText(playlist.getName());
-
- TextView countView = (TextView) view.findViewById(R.id.basic_count_count);
-
- // Count up song duplicates in playlist
- int count = 0;
- // Don't try to lookup playlist for Create New
- if(!"-1".equals(playlist.getId())) {
- 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.Entry song: songs) {
- if(cache.getChildren().contains(song)) {
- count++;
- }
- }
- }
- }
-
- // Update count display with appropriate information
- if(count <= 0) {
- countView.setVisibility(View.GONE);
- } else {
- String displayName;
- if(count < 10) {
- displayName = "0" + count;
- } else {
- displayName = "" + count;
- }
-
- countView.setText(displayName);
- countView.setVisibility(View.VISIBLE);
+ view = (PlaylistSongView) convertView;
}
+ view.setObject(playlist, songs);
+
return view;
}
};
@@ -981,7 +949,7 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR .setAdapter(playlistAdapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which > 0) {
- addToPlaylist(playlists.get(which - 1), songs);
+ addToPlaylist(playlists.get(which), songs);
} else {
createNewPlaylist(songs, false);
}
diff --git a/src/github/daneren2005/dsub/view/PlaylistSongView.java b/src/github/daneren2005/dsub/view/PlaylistSongView.java new file mode 100644 index 00000000..873470bc --- /dev/null +++ b/src/github/daneren2005/dsub/view/PlaylistSongView.java @@ -0,0 +1,99 @@ +/*
+ 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 2009 (C) Sindre Mehus
+ */
+package github.daneren2005.dsub.view;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import java.util.List;
+
+import github.daneren2005.dsub.R;
+import github.daneren2005.dsub.domain.MusicDirectory;
+import github.daneren2005.dsub.domain.Playlist;
+import github.daneren2005.dsub.util.FileUtil;
+import github.daneren2005.dsub.util.SyncUtil;
+import github.daneren2005.dsub.util.Util;
+
+public class PlaylistSongView extends UpdateView {
+ private static final String TAG = PlaylistSongView.class.getSimpleName();
+
+ private Context context;
+ private Playlist playlist;
+
+ private TextView titleView;
+ private TextView countView;
+ private int count = 0;
+ private List<MusicDirectory.Entry> songs;
+
+ public PlaylistSongView(Context context) {
+ super(context, false);
+ this.context = context;
+ LayoutInflater.from(context).inflate(R.layout.basic_count_item, this, true);
+
+ titleView = (TextView) findViewById(R.id.basic_count_name);
+ countView = (TextView) findViewById(R.id.basic_count_count);
+ }
+
+ protected void setObjectImpl(Object obj1, Object obj2) {
+ this.playlist = (Playlist) obj1;
+ this.songs = (List<MusicDirectory.Entry>) obj2;
+ count = 0;
+ titleView.setText(playlist.getName());
+ // Make sure to hide initially so it's not present briefly before update
+ countView.setVisibility(View.GONE);
+ }
+
+ @Override
+ protected void updateBackground() {
+ // Don't try to lookup playlist for Create New
+ if(!"-1".equals(playlist.getId())) {
+ 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.Entry song: songs) {
+ if(cache.getChildren().contains(song)) {
+ count++;
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void update() {
+ // Update count display with appropriate information
+ if(count <= 0) {
+ countView.setVisibility(View.GONE);
+ } else {
+ String displayName;
+ if(count < 10) {
+ displayName = "0" + count;
+ } else {
+ displayName = "" + count;
+ }
+
+ countView.setText(displayName);
+ countView.setVisibility(View.VISIBLE);
+ }
+ }
+}
|