diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2015-09-27 13:55:07 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2015-09-27 15:12:12 +0200 |
commit | d03c54d6fb6463a513aacd265dc3614806974cf9 (patch) | |
tree | 1bc8dc770b2d16c3d8c624649566afd23ce443c5 /app/src/main/java/de/danoeh/antennapod/dialog | |
parent | e74a549b1b4a2b3f3630914bf68c6e0bf731ec24 (diff) | |
download | AntennaPod-d03c54d6fb6463a513aacd265dc3614806974cf9.zip |
Variable Speed Dialog: Install Prestissimo or enable Sonic
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/dialog')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java | 126 |
1 files changed, 76 insertions, 50 deletions
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 b01b13492..5f6e3d0e2 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/VariableSpeedDialog.java @@ -3,22 +3,35 @@ package de.danoeh.antennapod.dialog; import android.app.AlertDialog; import android.content.ActivityNotFoundException; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; +import android.os.Build; +import android.util.Log; +import android.view.View; + +import com.afollestad.materialdialogs.DialogAction; +import com.afollestad.materialdialogs.MaterialDialog; import java.util.Arrays; import java.util.List; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.UserPreferences; +import de.danoeh.antennapod.core.util.IntentUtils; public class VariableSpeedDialog { + + private static final String TAG = VariableSpeedDialog.class.getSimpleName(); + + private static final Intent playStoreIntent = new Intent(Intent.ACTION_VIEW, + Uri.parse("market://details?id=com.falconware.prestissimo")); + private VariableSpeedDialog() { } public static void showDialog(final Context context) { - if (org.antennapod.audio.MediaPlayer.isPrestoLibraryInstalled(context)) { + if (org.antennapod.audio.MediaPlayer.isPrestoLibraryInstalled(context) + || UserPreferences.useSonic()) { showSpeedSelectorDialog(context); } else { showGetPluginDialog(context); @@ -26,26 +39,46 @@ public class VariableSpeedDialog { } private static void showGetPluginDialog(final Context context) { - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(R.string.no_playback_plugin_title); - builder.setMessage(R.string.no_playback_plugin_msg); - builder.setNegativeButton(R.string.close_label, null); - builder.setPositiveButton(R.string.download_plugin_label, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - try { - Intent playStoreIntent = new Intent( - Intent.ACTION_VIEW, - Uri.parse("market://details?id=com.falconware.prestissimo")); - context.startActivity(playStoreIntent); - } catch (ActivityNotFoundException e) { - // this is usually thrown on an emulator if the Android market is not installed - e.printStackTrace(); - } - } - }); - builder.create().show(); + 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); + builder.positiveText(R.string.download_plugin_label); + builder.negativeText(R.string.enable_sonic); + builder.neutralText(R.string.close_label); + builder.callback(new MaterialDialog.ButtonCallback() { + @Override + public void onPositive(MaterialDialog dialog) { + try { + context.startActivity(playStoreIntent); + } catch (ActivityNotFoundException e) { + // this is usually thrown on an emulator if the Android market is not installed + Log.e(TAG, Log.getStackTraceString(e)); + } + } + + @Override + public void onNegative(MaterialDialog dialog) { + if (Build.VERSION.SDK_INT >= 16) { // just to be safe + UserPreferences.enableSonic(true); + showSpeedSelectorDialog(context); + } + } + + @Override + public void onNeutral(MaterialDialog dialog) { + super.onNeutral(dialog); + } + }); + builder.forceStacking(true); + MaterialDialog dialog = builder.show(); + if(!IntentUtils.isCallable(context.getApplicationContext(), playStoreIntent)) { + View pos = dialog.getActionButton(DialogAction.POSITIVE); + pos.setEnabled(false); + } + if (Build.VERSION.SDK_INT < 16) { + View pos = dialog.getActionButton(DialogAction.NEGATIVE); + pos.setEnabled(false); + } } private static void showSpeedSelectorDialog(final Context context) { @@ -65,37 +98,30 @@ public class VariableSpeedDialog { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.set_playback_speed_label); builder.setMultiChoiceItems(R.array.playback_speed_values, - speedChecked, new DialogInterface.OnMultiChoiceClickListener() { - @Override - public void onClick(DialogInterface dialog, int which, - boolean isChecked) { - speedChecked[which] = isChecked; - } - - }); + speedChecked, (dialog, which, isChecked) -> { + speedChecked[which] = isChecked; + }); builder.setNegativeButton(android.R.string.cancel, null); builder.setPositiveButton(android.R.string.ok, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - int choiceCount = 0; - for (int i = 0; i < speedChecked.length; i++) { - if (speedChecked[i]) { - choiceCount++; - } - } - String[] newSpeedValues = new String[choiceCount]; - int newSpeedIndex = 0; - for (int i = 0; i < speedChecked.length; i++) { - if (speedChecked[i]) { - newSpeedValues[newSpeedIndex++] = speedValues[i]; - } - } - - UserPreferences.setPlaybackSpeedArray(newSpeedValues); - + (dialog, which) -> { + int choiceCount = 0; + for (int i = 0; i < speedChecked.length; i++) { + if (speedChecked[i]) { + choiceCount++; } - }); + } + String[] newSpeedValues = new String[choiceCount]; + int newSpeedIndex = 0; + for (int i = 0; i < speedChecked.length; i++) { + if (speedChecked[i]) { + newSpeedValues[newSpeedIndex++] = speedValues[i]; + } + } + + UserPreferences.setPlaybackSpeedArray(newSpeedValues); + + }); builder.create().show(); } + } |