Skip to content

Commit

Permalink
Merge pull request #235 from GuoXiCheng/dev-c
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
GuoXiCheng authored Sep 18, 2024
2 parents b6912f6 + 013503c commit d82b9e6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions app/src/main/assets/skip_config_v3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@

# 小时工记账
- packageName: com.julangling.xsgjz
skipTexts:
# fileId=28b730a3-5ac7-44c7-8f8a-9daf1b8effbe&nodeId=27
- text: 跳过
length: 4
skipBounds:
# fileId=43bcef4b-4b5b-4b63-a7f2-ad28e4f5f690&nodeId=30
- bound: 1244,176,1384,316
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ConfigReadRepository @Inject constructor(

private lateinit var configReadSchemaList: List<ConfigReadSchema>

suspend fun readConfig() = withContext(Dispatchers.IO) {
suspend fun readConfig(): String = withContext(Dispatchers.IO) {
val configV3 = myApiNetwork.fetchSkipConfigV3()
val yamlContent = Yaml().load<List<ConfigReadSchema>>(configV3)

Expand All @@ -38,7 +38,11 @@ class ConfigReadRepository @Inject constructor(
val type = object : TypeToken<List<ConfigReadSchema>>() {}.type
configReadSchemaList = gson.fromJson(jsonStr, type)

_configHashCode.postValue(md5(jsonStr))
return@withContext jsonStr
}

fun changeConfigHashCode(jsonStrOrNull: String?) {
_configHashCode.postValue(jsonStrOrNull?.let { md5(it) })
}

// fun readConfig(context: Context) {
Expand Down
16 changes: 11 additions & 5 deletions app/src/main/java/com/android/skip/data/config/ConfigViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.android.skip.data.config
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import androidx.lifecycle.viewModelScope
import javax.inject.Inject

@HiltViewModel
Expand All @@ -15,9 +15,11 @@ class ConfigViewModel @Inject constructor(
) : ViewModel() {
var configHashCode: LiveData<String> = configReadRepository.configHashCode

private val observer = Observer<String> {
val configMap = configReadRepository.handleConfig()
configLoadRepository.loadConfig(configMap)
private val observer = Observer<String?> {
if (it != null) {
val configMap = configReadRepository.handleConfig()
configLoadRepository.loadConfig(configMap)
}
}

init {
Expand All @@ -27,10 +29,14 @@ class ConfigViewModel @Inject constructor(
// fun readConfig(context: Context) = configReadRepository.readConfig(context)
fun readConfig() {
viewModelScope.launch {
configReadRepository.readConfig()
val jsonStr = configReadRepository.readConfig()
configReadRepository.changeConfigHashCode(jsonStr)
}
}

fun changeConfigHashCode(jsonStrOrNull: String?) =
configReadRepository.changeConfigHashCode(jsonStrOrNull)

override fun onCleared() {
super.onCleared()
configReadRepository.configHashCode.removeObserver(observer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ fun ConfigVersionButton(configViewModel: ConfigViewModel) {
FlatButton(content = {
RowContent(
title = R.string.about_config_version,
subTitle = configVersion.value
subTitle = if (configVersion.value == null) R.string.checking else configVersion.value
)
}, onClick = {
configViewModel.changeConfigHashCode(null)
configViewModel.readConfig()
})
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<string name="about_docs_url">https://skip.guoxicheng.top/guide/intro/what-is-skip</string>
<string name="about_app_version">应用版本号</string>
<string name="about_config_version">配置版本号</string>
<string name="checking">检查中…</string>

<string name="toast_start_accessibility_first">请先开启无障碍服务</string>
<string name="toast_save_success">保存成功</string>
Expand Down
Binary file added capture/28b730a3-5ac7-44c7-8f8a-9daf1b8effbe.zip
Binary file not shown.

0 comments on commit d82b9e6

Please sign in to comment.