aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/github')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java80
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Constants.java1
2 files changed, 73 insertions, 8 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
index 7c20dc28..9eddbc89 100644
--- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
+++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java
@@ -400,11 +400,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
- DownloadService downloadService = getDownloadService();
- if (downloadService == null) {
- return false;
- }
-
float playbackSpeed = 1.0f;
switch (menuItem.getItemId()) {
case R.id.playback_speed_half:
@@ -419,10 +414,12 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
case R.id.playback_speed_tripple:
playbackSpeed = 3.0f;
break;
+ case R.id.playback_speed_custom:
+ setPlaybackSpeed();
+ return true;
}
- downloadService.setPlaybackSpeed(playbackSpeed);
- updateTitle();
+ setPlaybackSpeed(playbackSpeed);
return true;
}
});
@@ -1485,8 +1482,15 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
stringRes = R.string.download_playback_speed_tripple;
}
+ String playbackSpeedText = null;
if(stringRes != -1) {
- title += " (" + context.getResources().getString(stringRes) + ")";
+ playbackSpeedText = context.getResources().getString(stringRes);
+ } else if(Math.abs(playbackSpeed - 1.0) > 0.01) {
+ playbackSpeedText = Float.toString(playbackSpeed) + "x";
+ }
+
+ if(playbackSpeedText != null) {
+ title += " (" + playbackSpeedText + ")";
}
setTitle(title);
}
@@ -1504,4 +1508,64 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
return entries;
}
+
+ private void setPlaybackSpeed() {
+ View dialogView = context.getLayoutInflater().inflate(R.layout.set_playback_speed, null);
+
+ // Setup playbackSpeed label
+ final TextView playbackSpeedBox = (TextView) dialogView.findViewById(R.id.playback_speed_label);
+ final SharedPreferences prefs = Util.getPreferences(context);
+ String playbackSpeedString = prefs.getString(Constants.PREFERENCES_KEY_CUSTOM_PLAYBACK_SPEED, "17");
+ int playbackSpeed = Integer.parseInt(playbackSpeedString);
+ playbackSpeedBox.setText(new Float(playbackSpeed / 10.0).toString());
+
+ // Setup playbackSpeed slider
+ final SeekBar playbackSpeedBar = (SeekBar) dialogView.findViewById(R.id.playback_speed_bar);
+ playbackSpeedBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ if (fromUser) {
+ playbackSpeedBox.setText(new Float((progress + 5) / 10.0).toString());
+ seekBar.setProgress(progress);
+ }
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ }
+ });
+ playbackSpeedBar.setProgress(playbackSpeed - 5);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle(R.string.download_playback_speed_custom)
+ .setView(dialogView)
+ .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ int playbackSpeed = playbackSpeedBar.getProgress() + 5;
+
+ SharedPreferences.Editor editor = prefs.edit();
+ editor.putString(Constants.PREFERENCES_KEY_CUSTOM_PLAYBACK_SPEED, Integer.toString(playbackSpeed));
+ editor.commit();
+
+ setPlaybackSpeed(new Float(playbackSpeed / 10.0));
+ }
+ })
+ .setNegativeButton(R.string.common_cancel, null);
+ AlertDialog dialog = builder.create();
+ dialog.show();
+ }
+ private void setPlaybackSpeed(float playbackSpeed) {
+ DownloadService downloadService = getDownloadService();
+ if (downloadService == null) {
+ return;
+ }
+
+ downloadService.setPlaybackSpeed(playbackSpeed);
+ updateTitle();
+ }
}
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Constants.java b/app/src/main/java/github/daneren2005/dsub/util/Constants.java
index 4109ea67..b7a68962 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Constants.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Constants.java
@@ -176,6 +176,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_HEADS_UP_NOTIFICATION = "headsUpNotification";
public static final String PREFERENCES_KEY_CAST_CACHE = "castCache";
public static final String PREFERENCES_KEY_PLAYBACK_SPEED = "playbackSpeed";
+ public static final String PREFERENCES_KEY_CUSTOM_PLAYBACK_SPEED = "customPlaybackSpeed";
public static final String OFFLINE_SCROBBLE_COUNT = "scrobbleCount";
public static final String OFFLINE_SCROBBLE_ID = "scrobbleID";