()?.activeNetworkInfo != null }
+
/**
* dp 转换为 pxInt
* @param context 使用的实例
@@ -352,11 +361,25 @@ fun Context.openBrowser(url: String, packageName: String = "") = runCatching {
else snake(msg = "启动系统浏览器失败")
}
+/**
+ * 跳转 APP 自身设置界面
+ * @param packageName 包名
+ */
+fun Context.openSelfSetting(packageName: String = appContext.packageName) = runCatching {
+ if (packageName.isInstall)
+ startActivity(Intent().apply {
+ flags = Intent.FLAG_ACTIVITY_NEW_TASK
+ action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
+ data = Uri.fromParts("package", packageName, null)
+ })
+ else toast(msg = "你没有安装此应用")
+}.onFailure { toast(msg = "启动 $packageName 应用信息失败") }
+
/**
* 复制到剪贴板
* @param content 要复制的文本
*/
-fun Context.copyToClipboard(content: String) = runSafe {
+fun Context.copyToClipboard(content: String) = runInSafe {
(getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).apply {
setPrimaryClip(ClipData.newPlainText(null, content))
(primaryClip?.getItemAt(0)?.text ?: "").also {
diff --git a/app/src/main/java/com/fankes/miui/notify/utils/tool/GithubReleaseTool.kt b/app/src/main/java/com/fankes/miui/notify/utils/tool/GithubReleaseTool.kt
new file mode 100644
index 0000000..2761da5
--- /dev/null
+++ b/app/src/main/java/com/fankes/miui/notify/utils/tool/GithubReleaseTool.kt
@@ -0,0 +1,128 @@
+/*
+ * MIUINativeNotifyIcon - Fix the native notification bar icon function abandoned by the MIUI development team.
+ * Copyright (C) 2019-2022 Fankes Studio(qzmmcn@163.com)
+ * https://github.com/fankes/MIUINativeNotifyIcon
+ *
+ * This software is non-free but opensource software: you can redistribute it
+ * and/or modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * and eula along with this software. If not, see
+ *
+ *
+ * This file is Created by fankes on 2022/3/20.
+ */
+package com.fankes.miui.notify.utils.tool
+
+import android.app.Activity
+import android.content.Context
+import com.fankes.miui.notify.utils.factory.*
+import okhttp3.*
+import org.json.JSONObject
+import java.io.IOException
+import java.io.Serializable
+
+/**
+ * 获取 Github Release 最新版本工具类
+ */
+object GithubReleaseTool {
+
+ /** 仓库作者 */
+ private const val repoAuthor = "fankes"
+
+ /** 仓库名称 */
+ private const val repoName = "MIUINativeNotifyIcon"
+
+ /**
+ * 获取最新版本信息
+ * @param context 实例
+ * @param version 当前版本
+ * @param it 成功后回调 - ([String] 最新版本,[Function] 更新对话框方法体)
+ */
+ fun checkingForUpdate(context: Context, version: String, it: (String, () -> Unit) -> Unit) = checkingInternetConnect(context) {
+ OkHttpClient().newBuilder().build().newCall(
+ Request.Builder()
+ .url("https://api.github.com/repos/$repoAuthor/$repoName/releases/latest")
+ .get()
+ .build()
+ ).enqueue(object : Callback {
+ override fun onFailure(call: Call, e: IOException) {}
+
+ override fun onResponse(call: Call, response: Response) = runInSafe {
+ JSONObject(response.body?.string() ?: "").apply {
+ GithubReleaseBean(
+ name = getString("name"),
+ htmlUrl = getString("html_url"),
+ content = getString("body"),
+ date = getString("published_at").replace(oldValue = "T", newValue = " ").replace(oldValue = "Z", newValue = "")
+ ).apply {
+ fun showUpdate() = context.showDialog {
+ title = "最新版本 $name"
+ msg = "发布于 $date\n\n" +
+ "更新日志\n\n" + content
+ confirmButton(text = "更新") { context.openBrowser(htmlUrl) }
+ cancelButton()
+ }
+ if (name != version) (context as? Activity?)?.runOnUiThread {
+ showUpdate()
+ it(name) { showUpdate() }
+ }
+ }
+ }
+ }
+ })
+ }
+
+ /**
+ * 检查网络连接情况
+ * @param context 实例
+ * @param it 已连接回调
+ */
+ private fun checkingInternetConnect(context: Context, it: () -> Unit) = runInSafe {
+ if (isNetWorkSuccess)
+ OkHttpClient().newBuilder().build().newCall(
+ Request.Builder()
+ .url("https://www.baidu.com")
+ .get()
+ .build()
+ ).enqueue(object : Callback {
+ override fun onFailure(call: Call, e: IOException) {
+ (context as? Activity?)?.runOnUiThread {
+ context.showDialog {
+ title = "网络不可用"
+ msg = "模块的联网权限可能已被禁用,请开启联网权限以定期检查更新。"
+ confirmButton(text = "去开启") { context.openSelfSetting() }
+ cancelButton()
+ noCancelable()
+ }
+ }
+ }
+
+ override fun onResponse(call: Call, response: Response) = runInSafe {
+ (context as? Activity?)?.runOnUiThread { runInSafe { it() } }
+ }
+ })
+ }
+
+ /**
+ * Github Release bean
+ * @param name 版本名称
+ * @param htmlUrl 网页地址
+ * @param content 更新日志
+ * @param date 发布时间
+ */
+ private data class GithubReleaseBean(
+ var name: String,
+ var htmlUrl: String,
+ var content: String,
+ var date: String
+ ) : Serializable
+}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/bg_orange_round.xml b/app/src/main/res/drawable/bg_orange_round.xml
new file mode 100755
index 0000000..043d002
--- /dev/null
+++ b/app/src/main/res/drawable/bg_orange_round.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 840142a..6fbd83b 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -91,15 +91,37 @@
android:textColor="@color/white"
android:textSize="18sp" />
-
+ android:gravity="center|start"
+ android:orientation="horizontal">
+
+
+
+
+