mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-28 01:18:31 +00:00
t/android_common: Fix lint errors for !! usages
The lint doesn't recommend us to use someVariable!!, and we can use built-in Kotlin's requireNotNull and with scope function to use variables without errors. Signed-off-by: utzcoz <utzcoz@outlook.com> Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2382>
This commit is contained in:
parent
ab48d41724
commit
4f3c9bb2fe
|
@ -43,28 +43,32 @@ class DisplayOverOtherAppsStatusFragment : Fragment() {
|
||||||
|
|
||||||
private fun updateStatus(view: View?) {
|
private fun updateStatus(view: View?) {
|
||||||
displayOverOtherAppsEnabled = Settings.canDrawOverlays(requireContext())
|
displayOverOtherAppsEnabled = Settings.canDrawOverlays(requireContext())
|
||||||
val tv = view!!.findViewById<TextView>(R.id.textDisplayOverOtherAppsStatus)
|
with(requireNotNull(view)) {
|
||||||
// Combining format with html style tag might have problem. See
|
val tv = this.findViewById<TextView>(R.id.textDisplayOverOtherAppsStatus)
|
||||||
// https://developer.android.com/guide/topics/resources/string-resource.html#StylingWithHTML
|
// Combining format with html style tag might have problem. See
|
||||||
val msg =
|
// https://developer.android.com/guide/topics/resources/string-resource.html#StylingWithHTML
|
||||||
getString(
|
val msg =
|
||||||
R.string.msg_display_over_other_apps,
|
getString(
|
||||||
if (displayOverOtherAppsEnabled) getString(R.string.enabled)
|
R.string.msg_display_over_other_apps,
|
||||||
else getString(R.string.disabled),
|
if (displayOverOtherAppsEnabled) getString(R.string.enabled)
|
||||||
)
|
else getString(R.string.disabled),
|
||||||
tv.text = Html.fromHtml(msg, Html.FROM_HTML_MODE_LEGACY)
|
)
|
||||||
|
tv.text = Html.fromHtml(msg, Html.FROM_HTML_MODE_LEGACY)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun launchDisplayOverOtherAppsSettings() {
|
private fun launchDisplayOverOtherAppsSettings() {
|
||||||
// Since Android 11, framework ignores the uri and takes user to the top-level settings.
|
// Since Android 11, framework ignores the uri and takes user to the top-level settings.
|
||||||
// See https://developer.android.com/about/versions/11/privacy/permissions#system-alert
|
// See https://developer.android.com/about/versions/11/privacy/permissions#system-alert
|
||||||
// for detail.
|
// for detail.
|
||||||
val intent =
|
with(requireNotNull(context)) {
|
||||||
Intent(
|
val intent =
|
||||||
Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
Intent(
|
||||||
Uri.parse("package:" + context!!.packageName),
|
Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||||
)
|
Uri.parse("package:" + this.packageName),
|
||||||
startActivityForResult(intent, REQUEST_CODE_DISPLAY_OVER_OTHER_APPS)
|
)
|
||||||
|
startActivityForResult(intent, REQUEST_CODE_DISPLAY_OVER_OTHER_APPS)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
|
|
|
@ -22,17 +22,19 @@ import androidx.fragment.app.DialogFragment
|
||||||
class RestartRuntimeDialogFragment : DialogFragment() {
|
class RestartRuntimeDialogFragment : DialogFragment() {
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val message = arguments!!.getString(ARGS_KEY_MESSAGE)
|
with(requireNotNull(arguments)) {
|
||||||
val builder = AlertDialog.Builder(requireActivity())
|
val message = this.getString(ARGS_KEY_MESSAGE)
|
||||||
builder.setMessage(message).setCancelable(false).setPositiveButton(R.string.restart) {
|
val builder = AlertDialog.Builder(requireActivity())
|
||||||
_: DialogInterface?,
|
builder.setMessage(message).setCancelable(false).setPositiveButton(R.string.restart) {
|
||||||
_: Int ->
|
_: DialogInterface?,
|
||||||
delayRestart(DELAY_RESTART_DURATION)
|
_: Int ->
|
||||||
// ! @todo elegant way to stop service? A bounded service might be restarted by
|
delayRestart(DELAY_RESTART_DURATION)
|
||||||
// framework automatically.
|
// ! @todo elegant way to stop service? A bounded service might be restarted by
|
||||||
Process.killProcess(Process.myPid())
|
// framework automatically.
|
||||||
|
Process.killProcess(Process.myPid())
|
||||||
|
}
|
||||||
|
return builder.create()
|
||||||
}
|
}
|
||||||
return builder.create()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun delayRestart(delayMillis: Long) {
|
private fun delayRestart(delayMillis: Long) {
|
||||||
|
|
Loading…
Reference in a new issue