@@ -77,32 +77,56 @@ object Voice {
7777 @StringRes buttonEnable : Int? = null,
7878 @StringRes howEnable : Int? = null) {
7979 return showPermissionManualInstructions(anchor,
80- whyEnable?.let { anchor.context.getString (whyEnable) },
81- buttonEnable?.let { anchor.context.getString (buttonEnable) },
82- howEnable?.let { anchor.context.getString (howEnable) })
80+ whyEnable?.let { anchor.context.getText (whyEnable) },
81+ buttonEnable?.let { anchor.context.getText (buttonEnable) },
82+ howEnable?.let { anchor.context.getText (howEnable) })
8383 }
8484
8585 /* * Guides the user to manually enable recording permission in the app's settings.*/
8686 @JvmStatic
8787 fun showPermissionManualInstructions (anchor : View ,
88- whyEnable : String? = null,
89- buttonEnable : String? = null,
90- howEnable : String? = null) {
91- val snackbar = Snackbar .make(anchor, whyEnable
92- ? : anchor.context.getString(R .string.permission_enable_rationale), Snackbar .LENGTH_LONG )
93- .setAction(buttonEnable
94- ? : anchor.context.getString(R .string.permission_button_enable)) {
95- Snackbar .make(anchor, howEnable
96- ? : anchor.context.getString(R .string.permission_enable_instructions), Snackbar .LENGTH_SHORT )
97- .addCallback(object : BaseTransientBottomBar .BaseCallback <Snackbar >() {
98- override fun onDismissed (transientBottomBar : Snackbar ? , event : Int ) {
99- openAppSettings(anchor.context)
100- }
101- }).show()
102- }
88+ whyEnable : CharSequence? = null,
89+ buttonEnable : CharSequence? = null,
90+ howEnable : CharSequence? = null) {
91+ val c = anchor.context
92+ val whyText = (whyEnable ? : c.getText(R .string.permission_enable_rationale))
93+ val buttonText = (buttonEnable ? : c.getText(R .string.permission_button_enable))
94+ val howText = (howEnable ? : c.getText(R .string.permission_enable_instructions))
95+
96+ val snackbar = Snackbar .make(anchor, whyText, Snackbar .LENGTH_LONG ).setAction(buttonText) {
97+ Snackbar .make(anchor, howText, Snackbar .LENGTH_SHORT )
98+ .addCallback(object : BaseTransientBottomBar .BaseCallback <Snackbar >() {
99+ override fun onDismissed (transientBottomBar : Snackbar ? , event : Int ) = openAppSettings(c)
100+ }).show()
101+ }
103102 (snackbar.view.findViewById(android.support.design.R .id.snackbar_text) as TextView ).maxLines = 2
104103 snackbar.show()
105104 }
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+ }
106130}
107131
108132// TODO: Expose Activity extension methods instead?
0 commit comments