mirror of
https://github.com/fankes/ColorOSNotifyIcon.git
synced 2025-09-06 18:55:37 +08:00
Merge code
This commit is contained in:
@@ -73,8 +73,8 @@ class DialogBuilder(val context: Context, private val isUseBlackTheme: Boolean)
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
if (isUsingAndroidX)
|
if (isUsingAndroidX)
|
||||||
runCatching { instanceAndroidX = MaterialAlertDialogBuilder(context) }
|
runInSafe { instanceAndroidX = MaterialAlertDialogBuilder(context) }
|
||||||
else runCatching {
|
else runInSafe {
|
||||||
instanceAndroid = android.app.AlertDialog.Builder(
|
instanceAndroid = android.app.AlertDialog.Builder(
|
||||||
context,
|
context,
|
||||||
if (isUseBlackTheme) android.R.style.Theme_Material_Dialog else android.R.style.Theme_Material_Light_Dialog
|
if (isUseBlackTheme) android.R.style.Theme_Material_Dialog else android.R.style.Theme_Material_Light_Dialog
|
||||||
@@ -85,8 +85,8 @@ class DialogBuilder(val context: Context, private val isUseBlackTheme: Boolean)
|
|||||||
/** 设置对话框不可关闭 */
|
/** 设置对话框不可关闭 */
|
||||||
fun noCancelable() {
|
fun noCancelable() {
|
||||||
if (isUsingAndroidX)
|
if (isUsingAndroidX)
|
||||||
runCatching { instanceAndroidX?.setCancelable(false) }
|
runInSafe { instanceAndroidX?.setCancelable(false) }
|
||||||
else runCatching { instanceAndroid?.setCancelable(false) }
|
else runInSafe { instanceAndroid?.setCancelable(false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 设置对话框标题 */
|
/** 设置对话框标题 */
|
||||||
@@ -94,8 +94,8 @@ class DialogBuilder(val context: Context, private val isUseBlackTheme: Boolean)
|
|||||||
get() = ""
|
get() = ""
|
||||||
set(value) {
|
set(value) {
|
||||||
if (isUsingAndroidX)
|
if (isUsingAndroidX)
|
||||||
runCatching { instanceAndroidX?.setTitle(value) }
|
runInSafe { instanceAndroidX?.setTitle(value) }
|
||||||
else runCatching { instanceAndroid?.setTitle(value) }
|
else runInSafe { instanceAndroid?.setTitle(value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 设置对话框消息内容 */
|
/** 设置对话框消息内容 */
|
||||||
@@ -103,8 +103,8 @@ class DialogBuilder(val context: Context, private val isUseBlackTheme: Boolean)
|
|||||||
get() = ""
|
get() = ""
|
||||||
set(value) {
|
set(value) {
|
||||||
if (isUsingAndroidX)
|
if (isUsingAndroidX)
|
||||||
runCatching { instanceAndroidX?.setMessage(value) }
|
runInSafe { instanceAndroidX?.setMessage(value) }
|
||||||
else runCatching { instanceAndroid?.setMessage(value) }
|
else runInSafe { instanceAndroid?.setMessage(value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 设置进度条对话框消息内容 */
|
/** 设置进度条对话框消息内容 */
|
||||||
@@ -145,8 +145,8 @@ class DialogBuilder(val context: Context, private val isUseBlackTheme: Boolean)
|
|||||||
*/
|
*/
|
||||||
fun confirmButton(text: String = "确定", it: () -> Unit = {}) {
|
fun confirmButton(text: String = "确定", it: () -> Unit = {}) {
|
||||||
if (isUsingAndroidX)
|
if (isUsingAndroidX)
|
||||||
runCatching { instanceAndroidX?.setPositiveButton(text) { _, _ -> it() } }
|
runInSafe { instanceAndroidX?.setPositiveButton(text) { _, _ -> it() } }
|
||||||
else runCatching { instanceAndroid?.setPositiveButton(text) { _, _ -> it() } }
|
else runInSafe { instanceAndroid?.setPositiveButton(text) { _, _ -> it() } }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,8 +156,8 @@ class DialogBuilder(val context: Context, private val isUseBlackTheme: Boolean)
|
|||||||
*/
|
*/
|
||||||
fun cancelButton(text: String = "取消", it: () -> Unit = {}) {
|
fun cancelButton(text: String = "取消", it: () -> Unit = {}) {
|
||||||
if (isUsingAndroidX)
|
if (isUsingAndroidX)
|
||||||
runCatching { instanceAndroidX?.setNegativeButton(text) { _, _ -> it() } }
|
runInSafe { instanceAndroidX?.setNegativeButton(text) { _, _ -> it() } }
|
||||||
else runCatching { instanceAndroid?.setNegativeButton(text) { _, _ -> it() } }
|
else runInSafe { instanceAndroid?.setNegativeButton(text) { _, _ -> it() } }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,21 +167,21 @@ class DialogBuilder(val context: Context, private val isUseBlackTheme: Boolean)
|
|||||||
*/
|
*/
|
||||||
fun neutralButton(text: String = "更多", it: () -> Unit = {}) {
|
fun neutralButton(text: String = "更多", it: () -> Unit = {}) {
|
||||||
if (isUsingAndroidX)
|
if (isUsingAndroidX)
|
||||||
runCatching { instanceAndroidX?.setNeutralButton(text) { _, _ -> it() } }
|
runInSafe { instanceAndroidX?.setNeutralButton(text) { _, _ -> it() } }
|
||||||
else runCatching { instanceAndroid?.setNeutralButton(text) { _, _ -> it() } }
|
else runInSafe { instanceAndroid?.setNeutralButton(text) { _, _ -> it() } }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 取消对话框 */
|
/** 取消对话框 */
|
||||||
fun cancel() = dialogInstance?.cancel()
|
fun cancel() = dialogInstance?.cancel()
|
||||||
|
|
||||||
/** 显示对话框 */
|
/** 显示对话框 */
|
||||||
internal fun show() {
|
internal fun show() =
|
||||||
if (isUsingAndroidX) runCatching {
|
if (isUsingAndroidX) runInSafe {
|
||||||
instanceAndroidX?.create()?.apply {
|
instanceAndroidX?.create()?.apply {
|
||||||
customLayoutView?.let { setView(it) }
|
customLayoutView?.let { setView(it) }
|
||||||
dialogInstance = this
|
dialogInstance = this
|
||||||
}?.show()
|
}?.show()
|
||||||
} else runCatching {
|
} else runInSafe {
|
||||||
instanceAndroid?.create()?.apply {
|
instanceAndroid?.create()?.apply {
|
||||||
customLayoutView?.let { setView(it) }
|
customLayoutView?.let { setView(it) }
|
||||||
window?.setBackgroundDrawable(
|
window?.setBackgroundDrawable(
|
||||||
@@ -197,5 +197,4 @@ class DialogBuilder(val context: Context, private val isUseBlackTheme: Boolean)
|
|||||||
dialogInstance = this
|
dialogInstance = this
|
||||||
}?.show()
|
}?.show()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
@@ -78,6 +78,6 @@ inline fun <T> safeOf(default: T, result: () -> T) = try {
|
|||||||
* @param msg 出错输出的消息 - 默认为空
|
* @param msg 出错输出的消息 - 默认为空
|
||||||
* @param block 正常回调
|
* @param block 正常回调
|
||||||
*/
|
*/
|
||||||
inline fun <T> T.runSafe(msg: String = "", block: () -> Unit) {
|
inline fun <T> T.runInSafe(msg: String = "", block: () -> Unit) {
|
||||||
runCatching(block).onFailure { if (msg.isNotBlank()) loggerE(msg = msg, e = it) }
|
runCatching(block).onFailure { if (msg.isNotBlank()) loggerE(msg = msg, e = it) }
|
||||||
}
|
}
|
@@ -282,7 +282,7 @@ fun Context.openBrowser(url: String, packageName: String = "") = runCatching {
|
|||||||
* 复制到剪贴板
|
* 复制到剪贴板
|
||||||
* @param content 要复制的文本
|
* @param content 要复制的文本
|
||||||
*/
|
*/
|
||||||
fun Context.copyToClipboard(content: String) = runSafe {
|
fun Context.copyToClipboard(content: String) = runInSafe {
|
||||||
(getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).apply {
|
(getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).apply {
|
||||||
setPrimaryClip(ClipData.newPlainText(null, content))
|
setPrimaryClip(ClipData.newPlainText(null, content))
|
||||||
(primaryClip?.getItemAt(0)?.text ?: "").also {
|
(primaryClip?.getItemAt(0)?.text ?: "").also {
|
||||||
|
Reference in New Issue
Block a user