Make block parameter an extension lambda.

This commit is contained in:
Isira Seneviratne 2022-07-23 05:38:33 +05:30
parent 013522c376
commit a9095ca2ad
1 changed files with 14 additions and 19 deletions

View File

@ -64,29 +64,25 @@ private fun getHexRGBColor(context: Context, color: Int): String {
return context.getString(color).substring(3) return context.getString(color).substring(3)
} }
fun showLicense(context: Context?, license: License): Disposable {
return showLicense(context, license) { alertDialog ->
alertDialog.setPositiveButton(R.string.ok) { dialog, _ ->
dialog.dismiss()
}
}
}
fun showLicense(context: Context?, component: SoftwareComponent): Disposable { fun showLicense(context: Context?, component: SoftwareComponent): Disposable {
return showLicense(context, component.license) { alertDialog -> return showLicense(context, component.license) {
alertDialog.setPositiveButton(R.string.dismiss) { dialog, _ -> setPositiveButton(R.string.dismiss) { dialog, _ ->
dialog.dismiss() dialog.dismiss()
} }
alertDialog.setNeutralButton(R.string.open_website_license) { _, _ -> setNeutralButton(R.string.open_website_license) { _, _ ->
ShareUtils.openUrlInBrowser(context!!, component.link) ShareUtils.openUrlInBrowser(context!!, component.link)
} }
} }
} }
fun showLicense(context: Context?, license: License) = showLicense(context, license) {
setPositiveButton(R.string.ok) { dialog, _ -> dialog.dismiss() }
}
private fun showLicense( private fun showLicense(
context: Context?, context: Context?,
license: License, license: License,
block: (AlertDialog.Builder) -> Unit block: AlertDialog.Builder.() -> AlertDialog.Builder
): Disposable { ): Disposable {
return if (context == null) { return if (context == null) {
Disposable.empty() Disposable.empty()
@ -100,13 +96,12 @@ private fun showLicense(
val webView = WebView(context) val webView = WebView(context)
webView.loadData(webViewData, "text/html; charset=UTF-8", "base64") webView.loadData(webViewData, "text/html; charset=UTF-8", "base64")
AlertDialog.Builder(context).apply { Localization.assureCorrectAppLanguage(context)
setTitle(license.name) AlertDialog.Builder(context)
setView(webView) .setTitle(license.name)
Localization.assureCorrectAppLanguage(context) .setView(webView)
block(this) .block()
show() .show()
}
} }
} }
} }