Skip to content

Commit

Permalink
Add setting to use skip steps instead of seeking (#152)
Browse files Browse the repository at this point in the history
closes #147
  • Loading branch information
ThiefMaster authored and SyncedSynapse committed Apr 15, 2018
1 parent 93d4d37 commit 7c18df2
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/org/xbmc/kore/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public class Settings {
public static final String KEY_PREF_SHOW_NOW_PLAYING_PANEL = "pref_show_nowplayingpanel";
public static final boolean DEFAULT_PREF_SHOW_NOW_PLAYING_PANEL = true;

// Seek mode
public static final String KEY_PREF_NOTIFICATION_SEEK_JUMP = "pref_notification_seek_jump";
public static final boolean DEFAULT_PREF_NOTIFICATION_SEEK_JUMP = false;

// Pause during calls
public static final String KEY_PREF_PAUSE_DURING_CALLS = "pref_pause_during_calls";
public static final boolean DEFAULT_PREF_PAUSE_DURING_CALLS = false;
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/org/xbmc/kore/jsonrpc/method/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ public String resultFromJson(ObjectNode jsonObject) throws ApiException {
public static final class Seek extends ApiMethod<PlayerType.SeekReturnType> {
public final static String METHOD_NAME = "Player.Seek";

/**
* Seek constants
*/
public static final String BACKWARD = "smallbackward";
public static final String FORWARD = "smallforward";

/**
* Seek through the playing item (by time)
* @param playerId Player id for which to stop playback
Expand All @@ -263,6 +269,17 @@ public Seek(int playerId, int value) {
addParameterToRequest("value", value);
}

/**
* Seek through the playing item (by step)
* @param playerId Player id for which to stop playback
* @param value step (smallbackward/smallforward)
*/
public Seek(int playerId, String value) {
super();
addParameterToRequest("playerid", playerId);
addParameterToRequest("value", value);
}

@Override
public String getMethodName() { return METHOD_NAME; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public class IntentActionsService extends Service {
ACTION_REWIND = "rewind",
ACTION_FAST_FORWARD = "fast_forward",
ACTION_PREVIOUS = "previous",
ACTION_NEXT = "next";
ACTION_NEXT = "next",
ACTION_JUMP_BACKWARD = "jump_backward",
ACTION_JUMP_FORWARD = "jump_forward";

@Override
public void onCreate() { }
Expand Down Expand Up @@ -79,6 +81,16 @@ public int onStartCommand(Intent intent, int flags, int startId) {
new Player.GoTo(playerId, Player.GoTo.NEXT),
null, null);
break;
case ACTION_JUMP_BACKWARD:
hostConnection.execute(
new Player.Seek(playerId, Player.Seek.BACKWARD),
null, null);
break;
case ACTION_JUMP_FORWARD:
hostConnection.execute(
new Player.Seek(playerId, Player.Seek.FORWARD),
null, null);
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.view.View;
Expand All @@ -35,6 +36,7 @@
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
import org.xbmc.kore.R;
import org.xbmc.kore.Settings;
import org.xbmc.kore.host.HostConnectionObserver;
import org.xbmc.kore.host.HostManager;
import org.xbmc.kore.jsonrpc.notification.Player;
Expand Down Expand Up @@ -227,14 +229,22 @@ private void notifyPlaying(PlayerType.GetActivePlayersReturnType getActivePlayer
break;
}

// Create the actions, depending on the type of media
// Create the actions, depending on the type of media and the user's preference
PendingIntent rewindPendingIntent, ffPendingIntent, playPausePendingIntent;
playPausePendingIntent = buildActionPendingIntent(getActivePlayerResult.playerid, IntentActionsService.ACTION_PLAY_PAUSE);
boolean useSeekJump = PreferenceManager
.getDefaultSharedPreferences(this.mService)
.getBoolean(Settings.KEY_PREF_NOTIFICATION_SEEK_JUMP, Settings.DEFAULT_PREF_NOTIFICATION_SEEK_JUMP);
if (getItemResult.type.equals(ListType.ItemsAll.TYPE_SONG)) {
rewindPendingIntent = buildActionPendingIntent(getActivePlayerResult.playerid, IntentActionsService.ACTION_PREVIOUS);
rewindIcon = R.drawable.ic_skip_previous_white_24dp;
ffPendingIntent = buildActionPendingIntent(getActivePlayerResult.playerid, IntentActionsService.ACTION_NEXT);
ffIcon = R.drawable.ic_skip_next_white_24dp;
} else if (useSeekJump) {
rewindPendingIntent = buildActionPendingIntent(getActivePlayerResult.playerid, IntentActionsService.ACTION_JUMP_BACKWARD);
rewindIcon = R.drawable.ic_chevron_left_white_24dp;
ffPendingIntent = buildActionPendingIntent(getActivePlayerResult.playerid, IntentActionsService.ACTION_JUMP_FORWARD);
ffIcon = R.drawable.ic_chevron_right_white_24dp;
} else {
rewindPendingIntent = buildActionPendingIntent(getActivePlayerResult.playerid, IntentActionsService.ACTION_REWIND);
rewindIcon = R.drawable.ic_fast_rewind_white_24dp;
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@
<string name="show_notification">Show notification while playing</string>
<string name="show_now_playing_panel">Show now playing panel while playing</string>
<string name="show_now_playing_panel_summary">Displays an expandable panel at the bottom of the screen when media is playing</string>
<string name="notification_seek_jump">Use steps for seeking</string>
<string name="notification_seek_jump_speed">Change playback speed when seeking from notification</string>
<string name="notification_seek_jump_step">Use skip steps when seeking from notification</string>
<string name="pause_during_calls">Pause during phone call</string>
<string name="use_hardware_volume_keys">Use device volume keys</string>
<string name="vibrate_on_remote">Vibrate on touch</string>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
android:title="@string/show_notification"
android:defaultValue="false"/>

<SwitchPreference
android:key="pref_notification_seek_jump"
android:dependency="pref_show_notification"
android:title="@string/notification_seek_jump"
android:summaryOff="@string/notification_seek_jump_speed"
android:summaryOn="@string/notification_seek_jump_step"
android:defaultValue="false"/>

<SwitchPreferenceCompat
android:key="pref_pause_during_calls"
android:title="@string/pause_during_calls"
Expand Down

0 comments on commit 7c18df2

Please sign in to comment.