Skip to content

Commit

Permalink
add getLatestVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
GuoXiCheng committed Nov 5, 2023
1 parent 27d31a2 commit cc4f5fe
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
env:
LATEST_VERSION: "1.4"
LATEST_VERSION: "1.4.1"

jobs:
build-and-deploy:
Expand Down
Binary file added apk/SKIP-v1.4.1.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdk 24
targetSdk 32
versionCode 1
versionName "1.4"
versionName "1.4.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
80 changes: 34 additions & 46 deletions app/src/main/java/com/android/skip/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ var isPowerSavingBtnClicked by mutableStateOf(false)
// 检查更新按钮
var isCheckUpdateBtnClicked by mutableStateOf(false)

// 是否需要更新
var isNeedUpdateAPK by mutableStateOf(false)

// 最新版本号
var latestVersionText by mutableStateOf("")


class MainActivity : ComponentActivity() {

Expand Down Expand Up @@ -159,19 +165,35 @@ class MainActivity : ComponentActivity() {
message = "已下载的应用 > SKIP > 打开「使用SKIP」",
negativeText = "再想想",
positiveText = "去开启"
)
) {
alertDialogPositiveButtonClickState = true
}
} else {
AlertDialog(
context = this,
title = "停用无障碍服务",
message = "已下载的应用 > SKIP > 关闭「使用SKIP」",
negativeText = "再想想",
positiveText = "去停用"
)
) {
alertDialogPositiveButtonClickState = true
}
}
isAccessibilityBtnClicked = false
}

if (isNeedUpdateAPK) {
AlertDialog(
context = this,
title = "发现新版本",
message = "${BuildConfig.VERSION_NAME} -> $latestVersionText",
negativeText = "暂不更新",
positiveText = "立即更新"
) {

}
isNeedUpdateAPK = false
}

when {
alertDialogPositiveButtonClickState -> {
Expand All @@ -192,9 +214,16 @@ class MainActivity : ComponentActivity() {
}
isCheckUpdateBtnClicked -> {
thread {
ToastManager.showToast(this, "开始更新")
ToastManager.showToast(this, "开始检查更新")
val updateSkipConfigResult = if (HttpManager.updateSkipConfig()) "配置更新成功" else "配置更新失败"
ToastManager.showToast(this, updateSkipConfigResult)

val latestVersion = HttpManager.getLatestVersion()
if (latestVersion != BuildConfig.VERSION_NAME.trim()) {
isNeedUpdateAPK = true
latestVersionText = latestVersion
}

isCheckUpdateBtnClicked = false
}
}
Expand All @@ -211,47 +240,6 @@ class MainActivity : ComponentActivity() {
override fun onResume() {
super.onResume()
accessibilityState = MyUtils.isAccessibilitySettingsOn(this)
// syncSkipConfig()
}

private fun syncSkipConfig() {
thread {
try {
val client = OkHttpClient()
val request = Request.Builder()
.url("https://guoxicheng.github.io/SKIP/skip_config.yaml")
.build()
client.newCall(request).execute().use { response ->
val bodyContent = response.body()?.string()
val yaml = Yaml().load<Any>(bodyContent)
SkipConfigManager.setConfig(yaml)
ToastManager.showToast(this, "更新配置成功")
}

} catch (e: Exception) {
println(e)
}
}


// var connection: HttpURLConnection? = null
// try {
// val apiUrl = "https://guoxicheng.github.io/SKIP/skip_config.yaml"
// connection = URL(apiUrl).openConnection() as HttpURLConnection
// connection.requestMethod = "GET"
// connection.readTimeout = 30000
// connection.connectTimeout = 30000
// val input = connection.inputStream
// val yaml = Yaml().load<Any>(input)
// SkipConfigManager.setConfig(yaml)
// ToastManager.showToast(this, "更新配置成功")
// } catch (e: Exception) {
// LogManager.i(e.toString())
// ToastManager.showToast(this, "更新配置失败")
// } finally {
// connection?.disconnect()
// }
// }
}
}

Expand Down Expand Up @@ -506,14 +494,14 @@ fun PageFooter() {
fun AlertDialog(
context: Context, title: CharSequence,
message: CharSequence?, negativeText: CharSequence,
positiveText: CharSequence
positiveText: CharSequence, onPositiveButtonClick: ()->Unit
) {
MaterialAlertDialogBuilder(context)
.setTitle(title)
.setMessage(message)
.setNegativeButton(negativeText, null)
.setPositiveButton(positiveText) { _, _ ->
alertDialogPositiveButtonClickState = true
onPositiveButtonClick()
}
.show()
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/android/skip/manager/HttpManager.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.android.skip.manager

import com.android.skip.BuildConfig
import okhttp3.OkHttpClient
import okhttp3.Request
import org.yaml.snakeyaml.Yaml
Expand All @@ -21,4 +22,15 @@ object HttpManager {
false
}
}

fun getLatestVersion(): String {
return try {
val request = Request.Builder().url("$BASE_URL/latest_version.txt").build()
client.newCall(request).execute().use { response ->
return response.body()?.string()?.trim().toString()
}
} catch (e: Exception) {
BuildConfig.VERSION_NAME.trim()
}
}
}

0 comments on commit cc4f5fe

Please sign in to comment.