Jump to song in queue if picked just one (#624)
* Bump gradle versions needed for build Android Studio already refuses to build it as-is, so alter the versions required. * Rename mode -> action for better readability * Fix incorrect description on getByPos from timeline * Jump to song in queue if picked one. Implements #604
This commit is contained in:
parent
a50a9fd705
commit
117572eb7c
@ -4,7 +4,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.1.2'
|
||||
classpath 'com.android.tools.build:gradle:2.3.3'
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ android {
|
||||
}
|
||||
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion "25.0.2"
|
||||
buildToolsVersion "25.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "ch.blinkenlights.android.vanilla"
|
||||
|
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,7 +1,7 @@
|
||||
#Wed Jun 15 08:19:46 MSK 2016
|
||||
#Sun May 28 17:31:34 MSK 2017
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
|
||||
distributionSha256Sum=993b4f33b652c689e9721917d8e021cab6bbd3eae81b39ab2fd46fdb19a928d5
|
||||
|
@ -80,6 +80,7 @@ THE SOFTWARE.
|
||||
<string name="play_or_enqueue">Enqueue if playing; Play if paused</string>
|
||||
<string name="open">Open</string>
|
||||
<string name="go_home">Home directory</string>
|
||||
<string name="jumping_to_song">Song is already in queue, jumping…</string>
|
||||
|
||||
<plurals name="playing">
|
||||
<item quantity="one">1 track playing.</item>
|
||||
|
@ -52,6 +52,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@ -63,8 +64,8 @@ import junit.framework.Assert;
|
||||
public class LibraryActivity
|
||||
extends SlidingPlaybackActivity
|
||||
implements DialogInterface.OnClickListener
|
||||
, DialogInterface.OnDismissListener
|
||||
, SearchView.OnQueryTextListener
|
||||
, DialogInterface.OnDismissListener
|
||||
, SearchView.OnQueryTextListener
|
||||
{
|
||||
|
||||
|
||||
@ -360,25 +361,37 @@ public class LibraryActivity
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds songs matching the data from the given intent to the song timelime.
|
||||
* Adds songs matching the data from the given intent to the song timeline.
|
||||
*
|
||||
* @param intent An intent created with
|
||||
* {@link LibraryAdapter#createData(View)}.
|
||||
* @param action One of LibraryActivity.ACTION_*
|
||||
*/
|
||||
private void pickSongs(Intent intent, int action)
|
||||
private void pickSongs(Intent intent, final int action)
|
||||
{
|
||||
int effectiveAction = action; // mutable copy
|
||||
long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID);
|
||||
int type = mCurrentAdapter.getMediaType();
|
||||
|
||||
// special handling if we pick one song to be played that is already in queue
|
||||
boolean songPicked = (id >= 0 && type == MediaUtils.TYPE_SONG); // not invalid, not play all
|
||||
if (songPicked && effectiveAction == ACTION_PLAY) {
|
||||
int songPosInQueue = PlaybackService.get(this).getQueuePositionForSong(id);
|
||||
if (songPosInQueue > -1) {
|
||||
// we picked for play one song that is already present in the queue, just jump to it
|
||||
PlaybackService.get(this).jumpToQueuePosition(songPosInQueue);
|
||||
Toast.makeText(this, R.string.jumping_to_song, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean all = false;
|
||||
int mode = action;
|
||||
if (action == ACTION_PLAY_ALL || action == ACTION_ENQUEUE_ALL) {
|
||||
int type = mCurrentAdapter.getMediaType();
|
||||
boolean notPlayAllAdapter = type > MediaUtils.TYPE_SONG || id == LibraryAdapter.HEADER_ID;
|
||||
if (mode == ACTION_ENQUEUE_ALL && notPlayAllAdapter) {
|
||||
mode = ACTION_ENQUEUE;
|
||||
} else if (mode == ACTION_PLAY_ALL && notPlayAllAdapter) {
|
||||
mode = ACTION_PLAY;
|
||||
if (effectiveAction == ACTION_ENQUEUE_ALL && notPlayAllAdapter) {
|
||||
effectiveAction = ACTION_ENQUEUE;
|
||||
} else if (effectiveAction == ACTION_PLAY_ALL && notPlayAllAdapter) {
|
||||
effectiveAction = ACTION_PLAY;
|
||||
} else {
|
||||
all = true;
|
||||
}
|
||||
@ -388,7 +401,7 @@ public class LibraryActivity
|
||||
all = true; // page header was clicked -> force all mode
|
||||
|
||||
QueryTask query = buildQueryFromIntent(intent, false, (all ? mCurrentAdapter : null));
|
||||
query.mode = modeForAction[mode];
|
||||
query.mode = modeForAction[effectiveAction];
|
||||
PlaybackService.get(this).addSongs(query);
|
||||
|
||||
if (mDefaultAction == ACTION_LAST_USED && mLastAction != action) {
|
||||
|
@ -56,7 +56,6 @@ import android.os.PowerManager;
|
||||
import android.os.Process;
|
||||
import android.os.SystemClock;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
@ -1909,8 +1908,6 @@ public final class PlaybackService extends Service
|
||||
|
||||
/**
|
||||
* Add an Activity to the registered PlaybackActivities.
|
||||
*
|
||||
* @param activity The Activity to be added
|
||||
*/
|
||||
public static void addTimelineCallback(TimelineCallback consumer)
|
||||
{
|
||||
@ -1919,8 +1916,6 @@ public final class PlaybackService extends Service
|
||||
|
||||
/**
|
||||
* Remove an Activity from the registered PlaybackActivities
|
||||
*
|
||||
* @param activity The Activity to be removed
|
||||
*/
|
||||
public static void removeTimelineCallback(TimelineCallback consumer)
|
||||
{
|
||||
@ -2140,7 +2135,7 @@ public final class PlaybackService extends Service
|
||||
synchronized (mStateLock) {
|
||||
if((mState & FLAG_PLAYING) != 0) {
|
||||
mTransientAudioLoss = true;
|
||||
|
||||
|
||||
if(type == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
|
||||
setFlag(FLAG_DUCKING);
|
||||
} else {
|
||||
@ -2318,17 +2313,26 @@ public final class PlaybackService extends Service
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 'Song' with given id from timeline
|
||||
* Returns {@link Song} with given position from timeline or null if nothing found
|
||||
*/
|
||||
public Song getSongByQueuePosition(int id) {
|
||||
return mTimeline.getSongByQueuePosition(id);
|
||||
public Song getSongByQueuePosition(int pos) {
|
||||
return mTimeline.getSongByQueuePosition(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve song position in timeline
|
||||
* @param id song id as defined in {@link Song#id}
|
||||
* @return absolute position in song timeline or -1 if song currently not in timeline
|
||||
*/
|
||||
public int getQueuePositionForSong(long id) {
|
||||
return mTimeline.getQueuePositionForSong(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do a 'hard' jump to given queue position
|
||||
*/
|
||||
public void jumpToQueuePosition(int id) {
|
||||
mTimeline.setCurrentQueuePosition(id);
|
||||
public void jumpToQueuePosition(int pos) {
|
||||
mTimeline.setCurrentQueuePosition(pos);
|
||||
play();
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ public final class SongTimeline {
|
||||
|
||||
cursor.close();
|
||||
|
||||
// The query may have returned zero results or we might
|
||||
// The query may have returned zero results or we might
|
||||
// have failed to populate some songs: Get rid of all
|
||||
// uninitialized items
|
||||
Iterator<Song> it = songs.iterator();
|
||||
@ -631,7 +631,7 @@ public final class SongTimeline {
|
||||
|
||||
mCurrentPos = pos;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hard-Jump to given queue position
|
||||
*/
|
||||
@ -644,19 +644,33 @@ public final class SongTimeline {
|
||||
changed();
|
||||
return getSong(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns 'Song' at given position in queue
|
||||
*/
|
||||
public Song getSongByQueuePosition(int id) {
|
||||
public Song getSongByQueuePosition(int pos) {
|
||||
Song song = null;
|
||||
synchronized (this) {
|
||||
if (mSongs.size() > id)
|
||||
song = mSongs.get(id);
|
||||
if (mSongs.size() > pos)
|
||||
song = mSongs.get(pos);
|
||||
}
|
||||
return song;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns song position for given {@link Song}
|
||||
*/
|
||||
public int getQueuePositionForSong(long id) {
|
||||
synchronized (this) {
|
||||
for (int pos = 0; pos < mSongs.size(); pos++) {
|
||||
Song current = mSongs.get(pos);
|
||||
if (current.id == id)
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to the next or previous song or album.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user