[Android] Show different choices in extension activation dialog

David Papazian git at videolan.org
Mon Aug 28 09:43:00 CEST 2017


vlc-android | branch: master | David Papazian <david.papazian at metz.supelec.fr> | Fri Aug 25 17:11:26 2017 +0200| [b402c802039247248ca356d549aa063b33ab8ad8] | committer: Geoffrey Métais

Show different choices in extension activation dialog

Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>

> https://code.videolan.org/videolan/vlc-android/commit/b402c802039247248ca356d549aa063b33ab8ad8
---

 vlc-android/res/values/strings.xml                 |  6 ++---
 .../videolan/vlc/extensions/ExtensionsManager.java | 30 +++++++++++++++++++---
 2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 71cff6388..07b6a0a6e 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -367,10 +367,10 @@
     <string name="extensions_prefs_category">Extensions</string>
     <string name="extensions_enable_category">Chose extensions to enable</string>
     <string name="extensions_empty">No extension detected</string>
-    <string name="extension_permission_title">New extension \"%1$s\" detected</string>
-    <string name="extension_permission_subtitle">Activate extension\?</string>
+    <string name="extension_permission_title">Activate new extension \"%1$s\"\?</string>
+    <string name="extension_permission_checkbox_title">Show in %1$s</string>
     <string name="extension_prefs_activation_title">Activate</string>
-    <string name="android_auto">Android-auto</string>
+    <string name="android_auto">Android auto</string>
 
     <string name="controls_prefs_category">Controls</string>
 
diff --git a/vlc-android/src/org/videolan/vlc/extensions/ExtensionsManager.java b/vlc-android/src/org/videolan/vlc/extensions/ExtensionsManager.java
index 7ef9f6f8b..d274d8f68 100644
--- a/vlc-android/src/org/videolan/vlc/extensions/ExtensionsManager.java
+++ b/vlc-android/src/org/videolan/vlc/extensions/ExtensionsManager.java
@@ -21,6 +21,7 @@ import org.videolan.vlc.R;
 import org.videolan.vlc.gui.MainActivity;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -159,13 +160,32 @@ public class ExtensionsManager {
     }
 
     public void showExtensionPermissionDialog(final Activity activity, final int id, final ExtensionListing extension, final String key) {
-        PreferenceManager.getDefaultSharedPreferences(activity.getApplication()).edit().putBoolean(key + "_" + ANDROID_AUTO_SUFFIX, true).apply();
+        final List<CharSequence> extraTitles = new ArrayList<>();
+        final List<String> extraKeys = new ArrayList<>();
+
+        //Add necessary checkboxes
+        if (androidAutoInstalled && extension.androidAutoEnabled()) {
+            extraTitles.add(activity.getString(R.string.extension_permission_checkbox_title, activity.getString(R.string.android_auto)));
+            extraKeys.add(key + "_" + ANDROID_AUTO_SUFFIX);
+        }
+
+        final boolean[] extraCheckedStates = new boolean[extraTitles.size()];
+        Arrays.fill(extraCheckedStates, Boolean.TRUE);
         new AlertDialog.Builder(activity).setTitle(activity.getString(R.string.extension_permission_title, extension.title()))
-                .setMessage(R.string.extension_permission_subtitle)
+                .setMultiChoiceItems(extraTitles.toArray(new CharSequence[extraTitles.size()]),
+                        extraCheckedStates,
+                        new DialogInterface.OnMultiChoiceClickListener() {
+                            @Override
+                            public void onClick(DialogInterface dialogInterface, int pos, boolean b) {
+                                extraCheckedStates[pos] = b;
+                            }
+                        })
                 .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                     @Override
-                    public void onClick(DialogInterface dialogInterface, int i) {
+                    public void onClick(DialogInterface dialogInterface, int _) {
                         PreferenceManager.getDefaultSharedPreferences(activity.getApplication()).edit().putBoolean(key, true).apply();
+                        for (int i=0; i<extraTitles.size(); i++)
+                            PreferenceManager.getDefaultSharedPreferences(activity.getApplication()).edit().putBoolean(extraKeys.get(i), extraCheckedStates[i]).apply();
                         displayPlugin(activity, id, extension, true);
                         activity.findViewById(R.id.navigation).postInvalidate();
                     }
@@ -173,13 +193,15 @@ public class ExtensionsManager {
                 .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                     @Override
                     public void onClick(DialogInterface dialogInterface, int i) {
-                        PreferenceManager.getDefaultSharedPreferences(activity.getApplication()).edit().putBoolean(key, false).apply();
+                        dialogInterface.cancel();
                     }
                 })
                 .setOnCancelListener(new DialogInterface.OnCancelListener() {
                     @Override
                     public void onCancel(DialogInterface dialogInterface) {
                         PreferenceManager.getDefaultSharedPreferences(activity.getApplication()).edit().putBoolean(key, false).apply();
+                        for (int i=0; i<extraTitles.size(); i++)
+                            PreferenceManager.getDefaultSharedPreferences(activity.getApplication()).edit().putBoolean(extraKeys.get(i), false).apply();
                     }
                 })
                 .show();



More information about the Android mailing list