Skip to content

Commit

Permalink
Fix Bugs
Browse files Browse the repository at this point in the history
Gradle: 整理 Firebase 相关配置
核心模块: 修复错误的用户配置导致的闪退
  • Loading branch information
xz-dev committed Dec 18, 2019
1 parent cccb870 commit 26a2d70
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
5 changes: 2 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
// Firebase
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
apply plugin: 'com.google.firebase.firebase-perf'

android {
Expand All @@ -25,8 +24,8 @@ android {
applicationId "net.xzos.upgradeall"
minSdkVersion 21
targetSdkVersion 29
versionCode 31
versionName "0.1.0-rc.2"
versionCode 32
versionName "0.1.0-rc.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
sourceSets {
Expand Down
2 changes: 1 addition & 1 deletion app/google-services.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"client_info": {
"mobilesdk_app_id": "1:767814426707:android:0afd7305f2aebc4591a6a6",
"android_client_info": {
"package_name": "net.xzos.upgradeall"
"package_name": "net.xzos.upgradeAll"
}
},
"oauth_client": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import com.google.gson.JsonSyntaxException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.xzos.upgradeAll.R
import net.xzos.upgradeAll.application.MyApplication
import net.xzos.upgradeAll.application.MyApplication.Companion.context
import net.xzos.upgradeAll.data.json.gson.AppConfig
import net.xzos.upgradeAll.data.json.gson.CloudConfig
import net.xzos.upgradeAll.data.json.gson.HubConfig
Expand All @@ -25,16 +24,24 @@ object CloudConfigGetter {
private val okHttpApi = OkHttpApi(LogObjectTag)

private val rulesListJsonFileRawUrl: String
get() = getRawRootUrl(
PreferenceManager.getDefaultSharedPreferences(MyApplication.context).getString(
"cloud_rules_hub_url",
MyApplication.context.resources.getString(R.string.default_cloud_rules_hub_url)
).apply {
val separator = '/'
if (this?.last() != separator)
this.plus(separator)
}
) + "rules/rules_list.json"
get() {
val prefKey = "cloud_rules_hub_url"
val defaultCloudRulesHubUrl = context.resources.getString(R.string.default_cloud_rules_hub_url)
val pref = PreferenceManager.getDefaultSharedPreferences(context)
val cloudRulesHubUrl = pref.getString(prefKey, defaultCloudRulesHubUrl)
return try {
getRawRootUrl(cloudRulesHubUrl)
} catch (e: Throwable) {
getRawRootUrl(
defaultCloudRulesHubUrl.also {
pref.edit().putString(prefKey, defaultCloudRulesHubUrl).apply()
GlobalScope.launch(Dispatchers.Main) {
Toast.makeText(context, context.resources.getString(R.string.auto_fixed_wrong_configuration), Toast.LENGTH_LONG).show()
}
}
)
} + "rules/rules_list.json"
}

private val cloudConfig: CloudConfig?
get() = renewCloudConfig()
Expand Down Expand Up @@ -109,7 +116,12 @@ object CloudConfigGetter {
return okHttpApi.getHttpResponse(hubConfigJSRawUrl)
}

private fun getRawRootUrl(gitUrl: String?): String {
private fun getRawRootUrl(rawGitUrl: String?): String {
val gitUrl = rawGitUrl.apply {
val separator = '/'
if (this?.last() != separator)
this.plus(separator)
}
if (gitUrl != null) {
val list = gitUrl.split("github\\.com".toRegex())[1].split("/".toRegex()).filter { it.isNotEmpty() }
if (list.size >= 2) {
Expand All @@ -134,7 +146,7 @@ object CloudConfigGetter {
* @return 1 获取 HubConfig 成功, 2 获取 JS 成功, 3 添加数据库成功, -1 获取 HubConfig 失败, -2 解析 JS 失败, -3 添加数据库失败
*/
fun downloadCloudHubConfig(hubUuid: String?): Int {
val context = MyApplication.context
val context = context
GlobalScope.launch(Dispatchers.Main) { Toast.makeText(context, "开始下载", Toast.LENGTH_LONG).show() } // 下载
val cloudHubConfigGson = getHubCloudConfig(hubUuid)
// TODO: 配置文件地址与仓库地址分离
Expand Down Expand Up @@ -163,7 +175,6 @@ object CloudConfigGetter {
* @return 1 获取 AppConfig 成功, 2 添加数据库成功, -1 获取 AppConfig 失败, -2 添加数据库失败
*/
fun downloadCloudAppConfig(appUuid: String?): Int {
val context = MyApplication.context
GlobalScope.launch(Dispatchers.Main) { Toast.makeText(context, "开始下载", Toast.LENGTH_LONG).show() } // 下载
val cloudHubConfigGson = getAppCloudConfig(appUuid)
return (if (cloudHubConfigGson != null) {
Expand All @@ -172,7 +183,7 @@ object CloudConfigGetter {
2
} else -2
} else -1).apply {
runBlocking(Dispatchers.Main) {
GlobalScope.launch(Dispatchers.Main) {
when (this@apply) {
2 -> Toast.makeText(context, "数据添加成功", Toast.LENGTH_LONG).show()
-1 -> Toast.makeText(context, "获取基础配置文件失败", Toast.LENGTH_LONG).show()
Expand Down
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 @@ -111,6 +111,7 @@
<string name="version_number_is_marked_as_processed">版本号标注为已处理</string>
<string name="long_click_version_number_to_mark_as_processed">长按云端版本号可标记为“已处理”,即跳过此次更新 \n标记后再次长按已标记的版本号即可取消标记</string>
<string name="marked_version_number_is_behind_latest">标注已处理的版本号已落后于最新版本</string>
<string name="auto_fixed_wrong_configuration">已自动修复错误配置</string>
<string name="o_mark">⭕</string>

</resources>

0 comments on commit 26a2d70

Please sign in to comment.