Skip to content

Commit

Permalink
Merge pull request #74 from GuoXiCheng/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
GuoXiCheng authored Nov 4, 2023
2 parents 52e22d2 + 8259175 commit ec9cb94
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 34 deletions.
1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ android {
}

dependencies {
implementation 'com.squareup.okhttp3:okhttp:3.14.9'
implementation 'org.yaml:snakeyaml:1.29'
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'androidx.core:core-ktx:1.8.0'
Expand Down
8 changes: 1 addition & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.OneClick"
android:networkSecurityConfig="@xml/network_security_config"
tools:targetApi="31">
<activity
android:name="com.android.skip.MainActivity"
Expand All @@ -28,13 +29,6 @@
</intent-filter>
</activity>

<activity
android:name=".WhitelistActivity"
android:exported="false"
android:theme="@style/Theme.AppCompat.DayNight">

</activity>

<service
android:name="com.android.skip.service.MyAccessibilityService"
android:exported="true"
Expand Down
96 changes: 69 additions & 27 deletions app/src/main/java/com/android/skip/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@ import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.android.skip.dataclass.PackageInfo
import com.android.skip.manager.LogManager
import com.android.skip.manager.RectManager
import com.android.skip.manager.SkipConfigManager
import com.android.skip.manager.ToastManager
import com.android.skip.manager.*
import com.android.skip.ui.theme.OneClickTheme
import com.android.skip.ui.theme.green
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.launch
import okhttp3.OkHttpClient
import okhttp3.Request
import org.yaml.snakeyaml.Yaml
import java.net.HttpURLConnection
import java.net.URL
import java.util.*
import kotlin.concurrent.thread


var accessibilityState by mutableStateOf(false)

var alertDialogPositiveButtonClickState by mutableStateOf(false)
Expand All @@ -60,6 +58,9 @@ var isAutoStartBtnClicked by mutableStateOf(false)
// 省电策略按钮
var isPowerSavingBtnClicked by mutableStateOf(false)

// 检查更新按钮
var isCheckUpdateBtnClicked by mutableStateOf(false)


class MainActivity : ComponentActivity() {

Expand Down Expand Up @@ -189,6 +190,14 @@ class MainActivity : ComponentActivity() {
isBackendTaskBtnClicked -> {
ImageDialog()
}
isCheckUpdateBtnClicked -> {
thread {
ToastManager.showToast(this, "开始更新")
val updateSkipConfigResult = if (HttpManager.updateSkipConfig()) "配置更新成功" else "配置更新失败"
ToastManager.showToast(this, updateSkipConfigResult)
isCheckUpdateBtnClicked = false
}
}
}

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

private fun syncSkipConfig() {
thread {
var connection: HttpURLConnection? = null
try {
val apiUrl = "https://ghproxy.com/https://raw.githubusercontent.com/GuoXiCheng/SKIP/main/app/src/main/assets/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, "更新配置成功")
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) {
LogManager.i(e.toString())
ToastManager.showToast(this, "更新配置失败")
} finally {
connection?.disconnect()
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 @@ -441,17 +468,32 @@ fun PageFooter() {
append(" | ")
append(RectManager.getMaxRect())
append(" | version " + BuildConfig.VERSION_NAME)
append(" | ")
append("检查更新")
addStringAnnotation(
tag = "CHECK_UPDATE",
annotation = "",
start = length - 4,
end = length
)
}
}
ClickableText(
text = annotatedString,
onClick = { offset ->
annotatedString.getStringAnnotations("URL", start = offset, end = offset)
.firstOrNull()?.let { annotation ->
val url = annotation.item
coroutineScope.launch {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
context.startActivity(intent)
annotatedString.getStringAnnotations(start = offset, end = offset).firstOrNull()
?.let { annotation ->
when (annotation.tag) {
"URL" -> {
val url = annotation.item
coroutineScope.launch {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
context.startActivity(intent)
}
}
"CHECK_UPDATE" -> {
isCheckUpdateBtnClicked = true
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/com/android/skip/manager/HttpManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.android.skip.manager

import okhttp3.OkHttpClient
import okhttp3.Request
import org.yaml.snakeyaml.Yaml

object HttpManager {
private const val BASE_URL = "https://guoxicheng.github.io/SKIP"
private val client = OkHttpClient()

fun updateSkipConfig(): Boolean {
return try {
val request = Request.Builder().url("$BASE_URL/skip_config.yaml").build()
client.newCall(request).execute().use { response ->
val bodyContent = response.body()?.string()
val yaml = Yaml().load<Any>(bodyContent)
SkipConfigManager.setConfig(yaml)
}
true
} catch (e: Exception) {
false
}
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">guoxicheng.top</domain>
<domain includeSubdomains="true">guoxicheng.site</domain>
</domain-config>
</network-security-config>

0 comments on commit ec9cb94

Please sign in to comment.