diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2016-01-24 18:44:22 -0500 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2016-01-24 18:44:22 -0500 |
commit | f5f3477ac01356e17fb48768420d104a5d9919f2 (patch) | |
tree | ca2fb9afb09a5547e4e8cc4203b02840422aa85d | |
parent | 0eefa8c5412bf15c00fd83f318629377b4805c20 (diff) | |
parent | 6392f7abd4c778e2058c7a37bea2c6cfdde26496 (diff) | |
download | AntennaPod-f5f3477ac01356e17fb48768420d104a5d9919f2.zip |
Merge pull request #1605 from mfietz/issue/1603-change-speed-confusion
Eliminate confusion from UI elements that change playback speed
3 files changed, 43 insertions, 12 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index cf168305a..bdc210651 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -421,15 +421,23 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O }) .show(); final SeekBar barPlaybackSpeed = (SeekBar) dialog.findViewById(R.id.playback_speed); - final Button butDecSpeed = (Button) dialog.findViewById(R.id.butDecSpeed); butDecSpeed.setOnClickListener(v -> { - barPlaybackSpeed.setProgress(barPlaybackSpeed.getProgress() - 2); + if(controller != null && controller.canSetPlaybackSpeed()) { + barPlaybackSpeed.setProgress(barPlaybackSpeed.getProgress() - 2); + } else { + VariableSpeedDialog.showGetPluginDialog(this); + } }); final Button butIncSpeed = (Button) dialog.findViewById(R.id.butIncSpeed); butIncSpeed.setOnClickListener(v -> { - barPlaybackSpeed.setProgress(barPlaybackSpeed.getProgress() + 2); + if(controller != null && controller.canSetPlaybackSpeed()) { + barPlaybackSpeed.setProgress(barPlaybackSpeed.getProgress() + 2); + } else { + VariableSpeedDialog.showGetPluginDialog(this); + } }); + final TextView txtvPlaybackSpeed = (TextView) dialog.findViewById(R.id.txtvPlaybackSpeed); float currentSpeed = 1.0f; try { @@ -443,15 +451,25 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O barPlaybackSpeed.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - float playbackSpeed = (progress + 10) / 20.0f; - controller.setPlaybackSpeed(playbackSpeed); - String speed = String.format("%.2f", playbackSpeed); - UserPreferences.setPlaybackSpeed(speed); - txtvPlaybackSpeed.setText(speed + "x"); + if(controller != null && controller.canSetPlaybackSpeed()) { + float playbackSpeed = (progress + 10) / 20.0f; + controller.setPlaybackSpeed(playbackSpeed); + String speed = String.format("%.2f", playbackSpeed); + UserPreferences.setPlaybackSpeed(speed); + txtvPlaybackSpeed.setText(speed + "x"); + } else if(fromUser) { + float speed = Float.valueOf(UserPreferences.getPlaybackSpeed()); + barPlaybackSpeed.post(() -> { + barPlaybackSpeed.setProgress((int) (20 * speed) - 10); + }); + } } @Override public void onStartTrackingTouch(SeekBar seekBar) { + if(controller != null && !controller.canSetPlaybackSpeed()) { + VariableSpeedDialog.showGetPluginDialog(MediaplayerActivity.this); + } } @Override @@ -734,7 +752,7 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O UserPreferences.setPlaybackSpeed(newSpeed); controller.setPlaybackSpeed(Float.parseFloat(newSpeed)); } else { - VariableSpeedDialog.showDialog(this); + VariableSpeedDialog.showGetPluginDialog(this); } }); butPlaybackSpeed.setOnLongClickListener(v -> { diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java index 6d19b0612..3ed82b9bd 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java @@ -35,11 +35,15 @@ public class VariableSpeedDialog { || Build.VERSION.SDK_INT >= 23) { showSpeedSelectorDialog(context); } else { - showGetPluginDialog(context); + showGetPluginDialog(context, true); } } - private static void showGetPluginDialog(final Context context) { + public static void showGetPluginDialog(final Context context) { + showGetPluginDialog(context, false); + } + + private static void showGetPluginDialog(final Context context, boolean showSpeedSelector) { MaterialDialog.Builder builder = new MaterialDialog.Builder(context); builder.title(R.string.no_playback_plugin_title); builder.content(R.string.no_playback_plugin_or_sonic_msg); @@ -49,7 +53,9 @@ public class VariableSpeedDialog { builder.onPositive((dialog, which) -> { if (Build.VERSION.SDK_INT >= 16) { // just to be safe UserPreferences.enableSonic(true); - showSpeedSelectorDialog(context); + if(showSpeedSelector) { + showSpeedSelectorDialog(context); + } } }); builder.onNegative((dialog, which) -> { diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java index 31cb25d40..27935978c 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java @@ -11,6 +11,7 @@ import android.content.SharedPreferences; import android.content.res.TypedArray; import android.media.MediaPlayer; import android.os.AsyncTask; +import android.os.Build; import android.os.IBinder; import android.preference.PreferenceManager; import android.support.annotation.NonNull; @@ -34,6 +35,7 @@ import de.danoeh.antennapod.core.feed.Chapter; import de.danoeh.antennapod.core.feed.FeedMedia; import de.danoeh.antennapod.core.feed.MediaType; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; +import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; import de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer; import de.danoeh.antennapod.core.service.playback.PlayerStatus; @@ -677,6 +679,11 @@ public abstract class PlaybackController { } public boolean canSetPlaybackSpeed() { + if (org.antennapod.audio.MediaPlayer.isPrestoLibraryInstalled(activity.getApplicationContext()) + || UserPreferences.useSonic() + || Build.VERSION.SDK_INT >= 23) { + return true; + } return playbackService != null && playbackService.canSetSpeed(); } |