@@ -51,26 +51,74 @@ object Voice {
5151 ActivityCompat .shouldShowRequestPermissionRationale(activity, Manifest .permission.RECORD_AUDIO )
5252
5353 /* *
54- * Requests the [recording permission][RECORD_AUDIO].*/
54+ * Requests the [recording permission][RECORD_AUDIO] from your [activity] .*/
5555 @JvmStatic
5656 fun requestPermission (activity : Activity ) {
5757 ActivityCompat .requestPermissions(activity, arrayOf(RECORD_AUDIO ), PermissionRequestRecordAudio )
5858 }
5959
60- /* * Opens the application's settings, so the user can enable recording permission.*/
60+ /* * Opens the application's settings from a given [context] , so the user can enable recording permission.*/
6161 @JvmStatic
6262 fun openAppSettings (context : Context ) {
6363 context.startActivity(Intent (Settings .ACTION_APPLICATION_DETAILS_SETTINGS )
6464 .setData(Uri .fromParts(" package" , context.packageName, null )))
6565 }
6666
67- /* * Guides the user to manually enable recording permission in the app's settings.*/
67+ /* * Displays the rationale behind requesting the recording permission via a [Snackbar].
68+ * @param anchor the view on which the SnackBar will be anchored.
69+ * @param activity the activity which would request the permission.
70+ * */
71+ @JvmStatic
72+ fun showPermissionRationale (anchor : View ,
73+ activity : Activity ) {
74+ showPermissionRationale(anchor, activity, null as String? )
75+ }
76+
77+ /* * Displays the rationale behind requesting the recording permission via a [Snackbar].
78+ * @param anchor the view on which the SnackBar will be anchored.
79+ * @param activity the activity which would request the permission.
80+ * @param whyAllow a description of why the permission should be granted.
81+ * @param buttonAllow a call to action for granting the permission.
82+ * */
83+ @Suppress(" unused" ) // For library users
84+ @JvmStatic
85+ fun showPermissionRationale (anchor : View , activity : Activity ,
86+ @StringRes whyAllow : Int? = null, @StringRes buttonAllow : Int? = null) {
87+ @StringRes val whyRes = whyAllow ? : R .string.permission_rationale
88+ @StringRes val buttonRes = (buttonAllow ? : R .string.permission_button_again)
89+ Snackbar .make(anchor, whyRes, Snackbar .LENGTH_LONG ).setAction(buttonRes) { requestPermission(activity) }.show()
90+ }
91+
92+ /* * Displays the rationale behind requesting the recording permission via a [Snackbar].
93+ * @param anchor the view on which the SnackBar will be anchored.
94+ * @param activity the activity which would request the permission.
95+ * @param whyAllow a description of why the permission should be granted.
96+ * @param buttonAllow a call to action for granting the permission.
97+ * */
98+ @JvmStatic
99+ fun showPermissionRationale (anchor : View ,
100+ activity : Activity ,
101+ whyAllow : CharSequence? = null,
102+ buttonAllow : CharSequence? = null) {
103+ val whyText = whyAllow ? : activity.getString(R .string.permission_rationale)
104+ val buttonText = (buttonAllow ? : activity.getString(R .string.permission_button_again))
105+ Snackbar .make(anchor, whyText, Snackbar .LENGTH_LONG ).setAction(buttonText) { requestPermission(activity) }.show()
106+ }
107+
108+ /* * Guides the user to manually enable recording permission in the app's settings via [Snackbars][Snackbar].
109+ * @param anchor the view on which the SnackBar will be anchored.
110+ * */
68111 @JvmStatic
69112 fun showPermissionManualInstructions (anchor : View ) {
70113 return showPermissionManualInstructions(anchor, null as Int? , null , null )
71114 }
72115
73- /* * Guides the user to manually enable recording permission in the app's settings.*/
116+ /* * Guides the user to manually enable recording permission in the app's settings.
117+ * @param anchor the view on which the SnackBar will be anchored.
118+ * @param whyEnable a description of why the permission should be enabled.
119+ * @param buttonEnable a call to action for enabling the permission.
120+ * @param howEnable instructions to manually enable the permission in settings.
121+ * */
74122 @JvmStatic
75123 fun showPermissionManualInstructions (anchor : View ,
76124 @StringRes whyEnable : Int? = null,
@@ -82,7 +130,12 @@ object Voice {
82130 howEnable?.let { anchor.context.getText(howEnable) })
83131 }
84132
85- /* * Guides the user to manually enable recording permission in the app's settings.*/
133+ /* * Guides the user to manually enable recording permission in the app's settings.
134+ * @param anchor the view on which the SnackBar will be anchored.
135+ * @param whyEnable a description of why the permission should be enabled.
136+ * @param buttonEnable a call to action for enabling the permission.
137+ * @param howEnable instructions to manually enable the permission in settings.
138+ * */
86139 @JvmStatic
87140 fun showPermissionManualInstructions (anchor : View ,
88141 whyEnable : CharSequence? = null,
@@ -102,31 +155,6 @@ object Voice {
102155 (snackbar.view.findViewById(android.support.design.R .id.snackbar_text) as TextView ).maxLines = 2
103156 snackbar.show()
104157 }
105-
106- @JvmStatic
107- fun showPermissionRationale (anchor : View ,
108- activity : Activity ) {
109- showPermissionRationale(anchor, activity, null as String? )
110- }
111-
112- @Suppress(" unused" ) // For library users
113- @JvmStatic
114- fun showPermissionRationale (anchor : View , activity : Activity ,
115- @StringRes whyAllow : Int? = null, @StringRes buttonAllow : Int? = null) {
116- @StringRes val whyRes = whyAllow ? : R .string.permission_rationale
117- @StringRes val buttonRes = (buttonAllow ? : R .string.permission_button_again)
118- Snackbar .make(anchor, whyRes, Snackbar .LENGTH_LONG ).setAction(buttonRes) { requestPermission(activity) }.show()
119- }
120-
121- @JvmStatic
122- fun showPermissionRationale (anchor : View ,
123- activity : Activity ,
124- whyAllow : CharSequence? = null,
125- buttonAllow : CharSequence? = null) {
126- val whyText = whyAllow ? : activity.getString(R .string.permission_rationale)
127- val buttonText = (buttonAllow ? : activity.getString(R .string.permission_button_again))
128- Snackbar .make(anchor, whyText, Snackbar .LENGTH_LONG ).setAction(buttonText) { requestPermission(activity) }.show()
129- }
130158}
131159
132160// TODO: Expose Activity extension methods instead?
0 commit comments