Skip to content

Commit 069a7cc

Browse files
committed
Proper indent and remove some helper methods
1 parent 473c84b commit 069a7cc

File tree

1 file changed

+17
-64
lines changed
  • ui/src/main/kotlin/com/algolia/instantsearch/voice/ui

1 file changed

+17
-64
lines changed

ui/src/main/kotlin/com/algolia/instantsearch/voice/ui/Voice.kt

Lines changed: 17 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import android.content.Intent
88
import android.content.pm.PackageManager
99
import android.net.Uri
1010
import android.provider.Settings
11-
import android.support.annotation.StringRes
1211
import android.support.design.widget.BaseTransientBottomBar
1312
import android.support.design.widget.Snackbar
1413
import android.support.v4.app.ActivityCompat
@@ -64,92 +63,46 @@ object Voice {
6463
.setData(Uri.fromParts("package", context.packageName, null)))
6564
}
6665

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-
9266
/** Displays the rationale behind requesting the recording permission via a [Snackbar].
9367
* @param anchor the view on which the SnackBar will be anchored.
9468
* @param activity the activity which would request the permission.
9569
* @param whyAllow a description of why the permission should be granted.
9670
* @param buttonAllow a call to action for granting the permission.
9771
* */
9872
@JvmStatic
99-
fun showPermissionRationale(anchor: View,
100-
activity: Activity,
101-
whyAllow: CharSequence? = null,
102-
buttonAllow: CharSequence? = null) {
73+
fun showPermissionRationale(
74+
anchor: View,
75+
activity: Activity,
76+
whyAllow: CharSequence? = null,
77+
buttonAllow: CharSequence? = null
78+
) {
10379
val whyText = whyAllow ?: activity.getString(R.string.permission_rationale)
10480
val buttonText = (buttonAllow ?: activity.getString(R.string.permission_button_again))
10581
Snackbar.make(anchor, whyText, Snackbar.LENGTH_LONG).setAction(buttonText) { requestPermission(activity) }.show()
10682
}
10783

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-
* */
111-
@JvmStatic
112-
fun showPermissionManualInstructions(anchor: View) {
113-
return showPermissionManualInstructions(anchor, null as Int?, null, null)
114-
}
115-
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-
* */
122-
@JvmStatic
123-
fun showPermissionManualInstructions(anchor: View,
124-
@StringRes whyEnable: Int? = null,
125-
@StringRes buttonEnable: Int? = null,
126-
@StringRes howEnable: Int? = null) {
127-
return showPermissionManualInstructions(anchor,
128-
whyEnable?.let { anchor.context.getText(whyEnable) },
129-
buttonEnable?.let { anchor.context.getText(buttonEnable) },
130-
howEnable?.let { anchor.context.getText(howEnable) })
131-
}
132-
13384
/** Guides the user to manually enable recording permission in the app's settings.
13485
* @param anchor the view on which the SnackBar will be anchored.
13586
* @param whyEnable a description of why the permission should be enabled.
13687
* @param buttonEnable a call to action for enabling the permission.
13788
* @param howEnable instructions to manually enable the permission in settings.
13889
* */
13990
@JvmStatic
140-
fun showPermissionManualInstructions(anchor: View,
141-
whyEnable: CharSequence? = null,
142-
buttonEnable: CharSequence? = null,
143-
howEnable: CharSequence? = null) {
144-
val c = anchor.context
145-
val whyText = (whyEnable ?: c.getText(R.string.permission_enable_rationale))
146-
val buttonText = (buttonEnable ?: c.getText(R.string.permission_button_enable))
147-
val howText = (howEnable ?: c.getText(R.string.permission_enable_instructions))
91+
fun showPermissionManualInstructions(
92+
anchor: View,
93+
whyEnable: CharSequence? = null,
94+
buttonEnable: CharSequence? = null,
95+
howEnable: CharSequence? = null
96+
) {
97+
val context = anchor.context
98+
val whyText = (whyEnable ?: context.getText(R.string.permission_enable_rationale))
99+
val buttonText = (buttonEnable ?: context.getText(R.string.permission_button_enable))
100+
val howText = (howEnable ?: context.getText(R.string.permission_enable_instructions))
148101

149102
val snackbar = Snackbar.make(anchor, whyText, Snackbar.LENGTH_LONG).setAction(buttonText) {
150103
Snackbar.make(anchor, howText, Snackbar.LENGTH_SHORT)
151104
.addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() {
152-
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) = openAppSettings(c)
105+
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) = openAppSettings(context)
153106
}).show()
154107
}
155108
(snackbar.view.findViewById(android.support.design.R.id.snackbar_text) as TextView).maxLines = 2

0 commit comments

Comments
 (0)