mirror of
https://github.com/openlibrecommunity/olcng.git
synced 2026-07-03 14:05:17 +02:00
Add preset ruleset routing
This commit is contained in:
@@ -1 +0,0 @@
|
||||
geosite:category-ads-all,
|
||||
@@ -1 +0,0 @@
|
||||
geosite:cn
|
||||
@@ -1 +0,0 @@
|
||||
geosite:geolocation-!cn
|
||||
@@ -29,6 +29,9 @@ class RoutingSettingActivity : BaseActivity() {
|
||||
private val routing_domain_strategy: Array<out String> by lazy {
|
||||
resources.getStringArray(R.array.routing_domain_strategy)
|
||||
}
|
||||
private val preset_rulesets: Array<out String> by lazy {
|
||||
resources.getStringArray(R.array.preset_rulesets)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -76,13 +79,21 @@ class RoutingSettingActivity : BaseActivity() {
|
||||
R.id.import_rulesets -> {
|
||||
AlertDialog.Builder(this).setMessage(R.string.routing_settings_import_rulesets_tip)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
SettingsManager.resetRoutingRulesets(this@RoutingSettingActivity)
|
||||
launch(Dispatchers.Main) {
|
||||
refreshData()
|
||||
toast(R.string.toast_success)
|
||||
AlertDialog.Builder(this).setItems(preset_rulesets.asList().toTypedArray()) { _, i ->
|
||||
try {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
SettingsManager.resetRoutingRulesets(this@RoutingSettingActivity, i)
|
||||
launch(Dispatchers.Main) {
|
||||
refreshData()
|
||||
toast(R.string.toast_success)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}.show()
|
||||
|
||||
|
||||
}
|
||||
.setNegativeButton(android.R.string.no) { _, _ ->
|
||||
//do noting
|
||||
|
||||
@@ -2,32 +2,34 @@ package com.v2ray.ang.util
|
||||
|
||||
import android.content.Context
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import com.google.gson.Gson
|
||||
import com.v2ray.ang.dto.RulesetItem
|
||||
|
||||
object SettingsManager {
|
||||
|
||||
fun initRoutingRulesets(context: Context) {
|
||||
Log.d("=====", "initRoutingRuleset")
|
||||
fun initRoutingRulesets(context: Context, index: Int = 0) {
|
||||
val exist = MmkvManager.decodeRoutingRulesets()
|
||||
|
||||
val fileName = when (index) {
|
||||
0 -> "custom_routing_white"
|
||||
1 -> "custom_routing_black"
|
||||
2 -> "custom_routing_global"
|
||||
else -> "custom_routing_white"
|
||||
}
|
||||
if (exist.isNullOrEmpty()) {
|
||||
Log.d("=====", "isNullOrEmpty")
|
||||
val assets = Utils.readTextFromAssets(context, "custom_routing_white")
|
||||
val assets = Utils.readTextFromAssets(context, fileName)
|
||||
if (TextUtils.isEmpty(assets)) {
|
||||
return
|
||||
}
|
||||
|
||||
val rulesetList = Gson().fromJson(assets, Array<RulesetItem>::class.java).toMutableList()
|
||||
Log.d("=====", "rulesetList==" + rulesetList.count())
|
||||
MmkvManager.encodeRoutingRulesets(rulesetList)
|
||||
}
|
||||
}
|
||||
|
||||
fun resetRoutingRulesets(context: Context) {
|
||||
fun resetRoutingRulesets(context: Context, index: Int) {
|
||||
MmkvManager.encodeRoutingRulesets(null)
|
||||
initRoutingRulesets(context)
|
||||
initRoutingRulesets(context, index)
|
||||
}
|
||||
|
||||
fun getRoutingRuleset(index: Int): RulesetItem? {
|
||||
|
||||
@@ -294,4 +294,10 @@
|
||||
<item>深色</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="preset_rulesets">
|
||||
<item>绕过大陆(Whitelist)</item>
|
||||
<item>黑名单(Blacklist)</item>
|
||||
<item>全局(Global)</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -295,4 +295,10 @@
|
||||
<item>深色</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="preset_rulesets">
|
||||
<item>繞過大陸(Whitelist)</item>
|
||||
<item>黑名單(Blacklist)</item>
|
||||
<item>全域(Global)</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -306,4 +306,10 @@
|
||||
<item>Dark</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="preset_rulesets">
|
||||
<item>China Whitelist</item>
|
||||
<item>China Blacklist</item>
|
||||
<item>Global</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user