Browse Source

Release 0.6.1.2

Aidan Follestad 10 years ago
parent
commit
d9dbc91ca0

+ 6 - 3
README.md

@@ -23,7 +23,7 @@ Easily reference the library in your Android projects using this dependency in y
 
 
 ```Gradle
 ```Gradle
 dependencies {
 dependencies {
-    compile 'com.afollestad:material-dialogs:0.6.1.1'
+    compile 'com.afollestad:material-dialogs:0.6.1.2'
 }
 }
 ```
 ```
 
 
@@ -221,6 +221,8 @@ new MaterialDialog.Builder(this)
 ```
 ```
 
 
 If you want to preselect an item, pass an index 0 or greater in place of -1 in `itemsCallbackSingleChoice()`.
 If you want to preselect an item, pass an index 0 or greater in place of -1 in `itemsCallbackSingleChoice()`.
+Later, you can update the selected index using `setSelectedIndex(int)` on the `MaterialDialog` instance,
+if you're not using a custom adapter.
 
 
 If you do not set a positive action button using `positiveText()`, the dialog will automatically call
 If you do not set a positive action button using `positiveText()`, the dialog will automatically call
 the single choice callback when user presses the positive action button. The dialog will also dismiss itself,
 the single choice callback when user presses the positive action button. The dialog will also dismiss itself,
@@ -246,12 +248,13 @@ new MaterialDialog.Builder(this)
             public void onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
             public void onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
             }
             }
         })
         })
-        .positiveText("Choose")
+        .positiveText(R.string.choose)
         .show();
         .show();
 ```
 ```
 
 
 If you want to preselect any items, pass an array of indices (resource or literal) in place of null
 If you want to preselect any items, pass an array of indices (resource or literal) in place of null
-in `itemsCallbackMultiChoice()`.
+in `itemsCallbackMultiChoice()`. Later, you can update the selected indices using `setSelectedIndices(Integer[])`
+on the `MaterialDialog` instance, if you're not using a custom adapter.
 
 
 If you do not set a positive action button using `positiveText()`, the dialog will automatically call
 If you do not set a positive action button using `positiveText()`, the dialog will automatically call
 the multi choice callback when user presses the positive action button. The dialog will also dismiss itself,
 the multi choice callback when user presses the positive action button. The dialog will also dismiss itself,

+ 2 - 2
library/build.gradle

@@ -9,7 +9,7 @@ android {
         minSdkVersion 8
         minSdkVersion 8
         targetSdkVersion 21
         targetSdkVersion 21
         versionCode 1
         versionCode 1
-        versionName "0.6.1.1"
+        versionName "0.6.1.2"
     }
     }
     lintOptions {
     lintOptions {
         abortOnError false
         abortOnError false
@@ -27,7 +27,7 @@ publish {
     userOrg = 'drummer-aidan'
     userOrg = 'drummer-aidan'
     groupId = 'com.afollestad'
     groupId = 'com.afollestad'
     artifactId = 'material-dialogs'
     artifactId = 'material-dialogs'
-    version = '0.6.1.1'
+    version = '0.6.1.2'
     description = 'A library for implementing Material design styled dialogs across all versions of Android.'
     description = 'A library for implementing Material design styled dialogs across all versions of Android.'
     website = 'https://github.com/afollestad/material-dialogs'
     website = 'https://github.com/afollestad/material-dialogs'
     issueTracker = "${website}/issues"
     issueTracker = "${website}/issues"

+ 38 - 1
library/src/main/java/com/afollestad/materialdialogs/MaterialDialog.java

@@ -1561,7 +1561,7 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
     }
     }
 
 
     /**
     /**
-     * Convenience method for getting the currently selected index of a single choice list
+     * Convenience method for getting the currently selected index of a single choice list.
      *
      *
      * @return Currently selected index of a single choice list, or -1 if not showing a single choice list
      * @return Currently selected index of a single choice list, or -1 if not showing a single choice list
      */
      */
@@ -1587,6 +1587,43 @@ public class MaterialDialog extends DialogBase implements View.OnClickListener {
         }
         }
     }
     }
 
 
+    /**
+     * Convenience method for setting the currently selected index of a single choice list.
+     * This only works if you are not using a custom adapter; if you're using a custom adapter,
+     * an IllegalStateException is thrown.
+     * <p/>
+     * Note that this does not call the respective single choice callback.
+     *
+     * @param index The index of the list item to check.
+     */
+    public void setSelectedIndex(int index) {
+        mBuilder.selectedIndex = index;
+        if (mBuilder.adapter != null && mBuilder.adapter instanceof MaterialDialogAdapter) {
+            ((MaterialDialogAdapter) mBuilder.adapter).notifyDataSetChanged();
+        } else {
+            throw new IllegalStateException("You can only use setSelectedIndex() with the default adapter implementation.");
+        }
+    }
+
+    /**
+     * Convenience method for setting the currently selected indices of a multi choice list.
+     * This only works if you are not using a custom adapter; if you're using a custom adapter,
+     * an IllegalStateException is thrown.
+     * <p/>
+     * Note that this does not call the respective multi choice callback.
+     *
+     * @param indices The indices of the list items to check.
+     */
+    public void setSelectedIndices(Integer[] indices) {
+        mBuilder.selectedIndices = indices;
+        selectedIndicesList = new ArrayList<>(Arrays.asList(indices));
+        if (mBuilder.adapter != null && mBuilder.adapter instanceof MaterialDialogAdapter) {
+            ((MaterialDialogAdapter) mBuilder.adapter).notifyDataSetChanged();
+        } else {
+            throw new IllegalStateException("You can only use setSelectedIndices() with the default adapter implementation.");
+        }
+    }
+
     private class MaterialDialogAdapter extends ArrayAdapter<CharSequence> {
     private class MaterialDialogAdapter extends ArrayAdapter<CharSequence> {
 
 
         final int itemColor;
         final int itemColor;

+ 2 - 2
sample/build.gradle

@@ -8,8 +8,8 @@ android {
         applicationId "com.afollestad.materialdialogssample"
         applicationId "com.afollestad.materialdialogssample"
         minSdkVersion 14
         minSdkVersion 14
         targetSdkVersion 21
         targetSdkVersion 21
-        versionCode 66
-        versionName "0.6.1"
+        versionCode 67
+        versionName "0.6.1.2"
     }
     }
     lintOptions {
     lintOptions {
         abortOnError false
         abortOnError false

BIN
sample/sample.apk


+ 1 - 2
sample/src/main/java/com/afollestad/materialdialogssample/MainActivity.java

@@ -318,16 +318,15 @@ public class MainActivity extends ActionBarActivity implements FolderSelectorDia
                     public void onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
                     public void onSelection(MaterialDialog dialog, Integer[] which, CharSequence[] text) {
                         StringBuilder str = new StringBuilder();
                         StringBuilder str = new StringBuilder();
                         for (int i = 0; i < which.length; i++) {
                         for (int i = 0; i < which.length; i++) {
+                            if (i > 0) str.append('\n');
                             str.append(which[i]);
                             str.append(which[i]);
                             str.append(": ");
                             str.append(": ");
                             str.append(text[i]);
                             str.append(text[i]);
-                            str.append('\n');
                         }
                         }
                         Toast.makeText(getApplicationContext(), str.toString(), Toast.LENGTH_LONG).show();
                         Toast.makeText(getApplicationContext(), str.toString(), Toast.LENGTH_LONG).show();
                     }
                     }
                 })
                 })
                 .positiveText(R.string.choose)
                 .positiveText(R.string.choose)
-
                 .show();
                 .show();
     }
     }