@@ -39,46 +39,45 @@ object Voice {
3939 * Gets whether your application was granted the [recording permission][RECORD_AUDIO].
4040 */
4141 @JvmStatic
42- fun isRecordAudioPermissionGranted (context : Context ) =
43- ContextCompat .checkSelfPermission(context , RECORD_AUDIO ) == PackageManager .PERMISSION_GRANTED
42+ fun Context. isRecordAudioPermissionGranted () =
43+ ContextCompat .checkSelfPermission(this , RECORD_AUDIO ) == PackageManager .PERMISSION_GRANTED
4444
4545 /* *
46- * Gets whether your [ activity] should show UI with rationale for requesting the [recording permission][RECORD_AUDIO].
46+ * Gets whether your activity should show UI with rationale for requesting the [recording permission][RECORD_AUDIO].
4747 */
4848 @JvmStatic
49- fun shouldExplainPermission (activity : Activity ) =
50- ActivityCompat .shouldShowRequestPermissionRationale(activity , Manifest .permission.RECORD_AUDIO )
49+ fun Activity. shouldExplainPermission () =
50+ ActivityCompat .shouldShowRequestPermissionRationale(this , Manifest .permission.RECORD_AUDIO )
5151
5252 /* *
53- * Requests the [recording permission][RECORD_AUDIO] from your [ activity] .*/
53+ * Requests the [recording permission][RECORD_AUDIO] from your activity.*/
5454 @JvmStatic
55- fun requestPermission ( activity : Activity ) {
56- ActivityCompat .requestPermissions(activity , arrayOf(RECORD_AUDIO ), PermissionRequestRecordAudio )
55+ fun Activity. requestRecordingPermission ( ) {
56+ ActivityCompat .requestPermissions(this , arrayOf(RECORD_AUDIO ), PermissionRequestRecordAudio )
5757 }
5858
59- /* * Opens the application's settings from a given [ context] , so the user can enable recording permission.*/
59+ /* * Opens the application's settings from a given context, so the user can enable the recording permission.*/
6060 @JvmStatic
61- fun openAppSettings (context : Context ) {
62- context. startActivity(Intent (Settings .ACTION_APPLICATION_DETAILS_SETTINGS )
63- .setData(Uri .fromParts(" package" , context. packageName, null )))
61+ fun Context. openAppSettings () {
62+ startActivity(Intent (Settings .ACTION_APPLICATION_DETAILS_SETTINGS )
63+ .setData(Uri .fromParts(" package" , packageName, null )))
6464 }
6565
6666 /* * Displays the rationale behind requesting the recording permission via a [Snackbar].
6767 * @param anchor the view on which the SnackBar will be anchored.
68- * @param activity the activity which would request the permission.
6968 * @param whyAllow a description of why the permission should be granted.
7069 * @param buttonAllow a call to action for granting the permission.
7170 * */
7271 @JvmStatic
73- fun showPermissionRationale (
72+ @JvmOverloads
73+ fun Activity.showPermissionRationale (
7474 anchor : View ,
75- activity : Activity ,
7675 whyAllow : CharSequence? = null,
7776 buttonAllow : CharSequence? = null
7877 ) {
79- val whyText = whyAllow ? : activity. getString(R .string.permission_rationale)
80- val buttonText = (buttonAllow ? : activity. getString(R .string.permission_button_again))
81- Snackbar .make(anchor, whyText, Snackbar .LENGTH_LONG ).setAction(buttonText) { requestPermission(activity ) }.show()
78+ val whyText = whyAllow ? : getString(R .string.permission_rationale)
79+ val buttonText = (buttonAllow ? : getString(R .string.permission_button_again))
80+ Snackbar .make(anchor, whyText, Snackbar .LENGTH_LONG ).setAction(buttonText) { requestRecordingPermission( ) }.show()
8281 }
8382
8483 /* * Guides the user to manually enable recording permission in the app's settings.
@@ -88,6 +87,7 @@ object Voice {
8887 * @param howEnable instructions to manually enable the permission in settings.
8988 * */
9089 @JvmStatic
90+ @JvmOverloads
9191 fun showPermissionManualInstructions (
9292 anchor : View ,
9393 whyEnable : CharSequence? = null,
@@ -102,12 +102,10 @@ object Voice {
102102 val snackbar = Snackbar .make(anchor, whyText, Snackbar .LENGTH_LONG ).setAction(buttonText) {
103103 Snackbar .make(anchor, howText, Snackbar .LENGTH_SHORT )
104104 .addCallback(object : BaseTransientBottomBar .BaseCallback <Snackbar >() {
105- override fun onDismissed (transientBottomBar : Snackbar ? , event : Int ) = openAppSettings(context )
105+ override fun onDismissed (transientBottomBar : Snackbar ? , event : Int ) = context. openAppSettings()
106106 }).show()
107107 }
108108 (snackbar.view.findViewById(android.support.design.R .id.snackbar_text) as TextView ).maxLines = 2
109109 snackbar.show()
110110 }
111- }
112-
113- // TODO: Expose Activity extension methods
111+ }
0 commit comments