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()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
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
|
compileSdkVersion 25
|
||||||
buildToolsVersion "25.0.2"
|
buildToolsVersion "25.0.3"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "ch.blinkenlights.android.vanilla"
|
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
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
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
|
distributionSha256Sum=993b4f33b652c689e9721917d8e021cab6bbd3eae81b39ab2fd46fdb19a928d5
|
||||||
|
@ -80,6 +80,7 @@ THE SOFTWARE.
|
|||||||
<string name="play_or_enqueue">Enqueue if playing; Play if paused</string>
|
<string name="play_or_enqueue">Enqueue if playing; Play if paused</string>
|
||||||
<string name="open">Open</string>
|
<string name="open">Open</string>
|
||||||
<string name="go_home">Home directory</string>
|
<string name="go_home">Home directory</string>
|
||||||
|
<string name="jumping_to_song">Song is already in queue, jumping…</string>
|
||||||
|
|
||||||
<plurals name="playing">
|
<plurals name="playing">
|
||||||
<item quantity="one">1 track playing.</item>
|
<item quantity="one">1 track playing.</item>
|
||||||
|
@ -52,6 +52,7 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@ -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
|
* @param intent An intent created with
|
||||||
* {@link LibraryAdapter#createData(View)}.
|
* {@link LibraryAdapter#createData(View)}.
|
||||||
* @param action One of LibraryActivity.ACTION_*
|
* @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);
|
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;
|
boolean all = false;
|
||||||
int mode = action;
|
|
||||||
if (action == ACTION_PLAY_ALL || action == ACTION_ENQUEUE_ALL) {
|
if (action == ACTION_PLAY_ALL || action == ACTION_ENQUEUE_ALL) {
|
||||||
int type = mCurrentAdapter.getMediaType();
|
|
||||||
boolean notPlayAllAdapter = type > MediaUtils.TYPE_SONG || id == LibraryAdapter.HEADER_ID;
|
boolean notPlayAllAdapter = type > MediaUtils.TYPE_SONG || id == LibraryAdapter.HEADER_ID;
|
||||||
if (mode == ACTION_ENQUEUE_ALL && notPlayAllAdapter) {
|
if (effectiveAction == ACTION_ENQUEUE_ALL && notPlayAllAdapter) {
|
||||||
mode = ACTION_ENQUEUE;
|
effectiveAction = ACTION_ENQUEUE;
|
||||||
} else if (mode == ACTION_PLAY_ALL && notPlayAllAdapter) {
|
} else if (effectiveAction == ACTION_PLAY_ALL && notPlayAllAdapter) {
|
||||||
mode = ACTION_PLAY;
|
effectiveAction = ACTION_PLAY;
|
||||||
} else {
|
} else {
|
||||||
all = true;
|
all = true;
|
||||||
}
|
}
|
||||||
@ -388,7 +401,7 @@ public class LibraryActivity
|
|||||||
all = true; // page header was clicked -> force all mode
|
all = true; // page header was clicked -> force all mode
|
||||||
|
|
||||||
QueryTask query = buildQueryFromIntent(intent, false, (all ? mCurrentAdapter : null));
|
QueryTask query = buildQueryFromIntent(intent, false, (all ? mCurrentAdapter : null));
|
||||||
query.mode = modeForAction[mode];
|
query.mode = modeForAction[effectiveAction];
|
||||||
PlaybackService.get(this).addSongs(query);
|
PlaybackService.get(this).addSongs(query);
|
||||||
|
|
||||||
if (mDefaultAction == ACTION_LAST_USED && mLastAction != action) {
|
if (mDefaultAction == ACTION_LAST_USED && mLastAction != action) {
|
||||||
|
@ -56,7 +56,6 @@ import android.os.PowerManager;
|
|||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.provider.MediaStore;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
@ -1909,8 +1908,6 @@ public final class PlaybackService extends Service
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an Activity to the registered PlaybackActivities.
|
* Add an Activity to the registered PlaybackActivities.
|
||||||
*
|
|
||||||
* @param activity The Activity to be added
|
|
||||||
*/
|
*/
|
||||||
public static void addTimelineCallback(TimelineCallback consumer)
|
public static void addTimelineCallback(TimelineCallback consumer)
|
||||||
{
|
{
|
||||||
@ -1919,8 +1916,6 @@ public final class PlaybackService extends Service
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove an Activity from the registered PlaybackActivities
|
* Remove an Activity from the registered PlaybackActivities
|
||||||
*
|
|
||||||
* @param activity The Activity to be removed
|
|
||||||
*/
|
*/
|
||||||
public static void removeTimelineCallback(TimelineCallback consumer)
|
public static void removeTimelineCallback(TimelineCallback consumer)
|
||||||
{
|
{
|
||||||
@ -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) {
|
public Song getSongByQueuePosition(int pos) {
|
||||||
return mTimeline.getSongByQueuePosition(id);
|
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
|
* Do a 'hard' jump to given queue position
|
||||||
*/
|
*/
|
||||||
public void jumpToQueuePosition(int id) {
|
public void jumpToQueuePosition(int pos) {
|
||||||
mTimeline.setCurrentQueuePosition(id);
|
mTimeline.setCurrentQueuePosition(pos);
|
||||||
play();
|
play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -648,15 +648,29 @@ public final class SongTimeline {
|
|||||||
/**
|
/**
|
||||||
* Returns 'Song' at given position in queue
|
* Returns 'Song' at given position in queue
|
||||||
*/
|
*/
|
||||||
public Song getSongByQueuePosition(int id) {
|
public Song getSongByQueuePosition(int pos) {
|
||||||
Song song = null;
|
Song song = null;
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (mSongs.size() > id)
|
if (mSongs.size() > pos)
|
||||||
song = mSongs.get(id);
|
song = mSongs.get(pos);
|
||||||
}
|
}
|
||||||
return song;
|
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.
|
* Move to the next or previous song or album.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user