OSDN Git Service

Eleven: Fix top tracks to play the track you select
authorlinus_lee <llee@cyngn.com>
Fri, 24 Oct 2014 00:05:58 +0000 (17:05 -0700)
committerlinus_lee <llee@cyngn.com>
Thu, 20 Nov 2014 20:51:35 +0000 (12:51 -0800)
There was a trade-off where we don't update the toptracks list while you are looking at it
because each song play could change the order, but the caveat was playing a song wouldn't
necessarily play the song you want.  The fix is to use the adapter's list and not re-query
the list

https://cyanogen.atlassian.net/browse/MUSIC-127

Change-Id: Iec882e156658c76986d365d6b2e5d16416aca9ac

src/com/cyngn/eleven/adapters/SongAdapter.java
src/com/cyngn/eleven/ui/fragments/SongFragment.java
src/com/cyngn/eleven/ui/fragments/profile/BasicSongFragment.java
src/com/cyngn/eleven/ui/fragments/profile/SmartPlaylistFragment.java

index 0293656..3d6ed83 100644 (file)
@@ -309,4 +309,16 @@ public class SongAdapter extends ArrayAdapter<Song>
 
         return false;
     }
+
+    /**
+     * @return Gets the list of song ids from the adapter
+     */
+    public long[] getSongIds() {
+        long[] ret = new long[getCount()];
+        for (int i = 0; i < getCount(); i++) {
+            ret[i] = getItem(i).mSongId;
+        }
+
+        return ret;
+    }
 }
index 4149716..2fc29bc 100644 (file)
@@ -40,11 +40,10 @@ public class SongFragment extends BasicSongFragment {
      */
     public void playAll(int position) {
         int internalPosition = mAdapter.getInternalPosition(position);
-        Cursor cursor = SongLoader.makeSongCursor(getActivity(), null);
-        final long[] list = MusicUtils.getSongListForCursor(cursor);
-        MusicUtils.playAll(getActivity(), list, internalPosition, -1, Config.IdType.NA, false);
-        cursor.close();
-        cursor = null;
+        final long[] list = mAdapter.getUnderlyingAdapter().getSongIds();
+        if (list != null) {
+            MusicUtils.playAll(getActivity(), list, internalPosition, -1, Config.IdType.NA, false);
+        }
     }
 
     /**
index 41e2baf..4a20618 100644 (file)
@@ -235,6 +235,20 @@ public abstract class BasicSongFragment extends Fragment implements
     }
 
     /**
+     * @return Gets the list of song ids from the adapter, or null if none
+     */
+    protected long[] getSongIdsFromAdapter() {
+        if (mAdapter != null) {
+            final SongAdapter adapter = mAdapter.getUnderlyingAdapter();
+            if (adapter != null) {
+                return adapter.getSongIds();
+            }
+        }
+
+        return null;
+    }
+
+    /**
      * Restarts the loader.
      */
     public void refresh() {
index eba930e..235244a 100644 (file)
@@ -11,6 +11,7 @@ import android.view.ViewGroup;
 import com.cyngn.eleven.Config.SmartPlaylistType;
 import com.cyngn.eleven.Config;
 import com.cyngn.eleven.R;
+import com.cyngn.eleven.adapters.SongAdapter;
 import com.cyngn.eleven.menu.ConfirmDialog;
 import com.cyngn.eleven.model.Playlist;
 import com.cyngn.eleven.utils.MusicUtils;
@@ -93,8 +94,18 @@ implements ConfirmDialog.ConfirmCallback {
     }
 
     public void playAll(int position, boolean shuffle) {
-        MusicUtils.playSmartPlaylist(getActivity(), position,
-                getSmartPlaylistType(), shuffle);
+        // we grab the song ids from the adapter instead of querying the cursor because the user
+        // expects what they see to be what they play.  The counter argument of updating the list
+        // could be made, but refreshing the smart playlists so often will be annoying and
+        // confusing for the user so this is an intermediate compromise.  An example is the top
+        // tracks list is based on the # of times you play a song, but near the beginning each
+        // song being played will change the list and the compromise is to update only when you
+        // enter the page.
+        long[] songIds = getSongIdsFromAdapter();
+        if (songIds != null) {
+            MusicUtils.playAll(getActivity(), songIds, position, getSmartPlaylistType().mId,
+                    Config.IdType.Playlist, shuffle);
+        }
     }
 
     protected abstract SmartPlaylistType getSmartPlaylistType();