diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/RoutingType.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/RoutingType.kt new file mode 100644 index 000000000..a98ac167c --- /dev/null +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/RoutingType.kt @@ -0,0 +1,20 @@ +package com.v2ray.ang.dto + +enum class RoutingType(val fileName: String) { + WHITE("custom_routing_white"), + BLACK("custom_routing_black"), + GLOBAL("custom_routing_global"), + WHITE_IRAN("custom_routing_white_iran"); + + companion object { + fun fromIndex(index: Int): RoutingType { + return when (index) { + 0 -> WHITE + 1 -> BLACK + 2 -> GLOBAL + 3 -> WHITE_IRAN + else -> WHITE + } + } + } +} diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/SettingsManager.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/SettingsManager.kt index 0b1b4a124..f14caa829 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/SettingsManager.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/SettingsManager.kt @@ -6,7 +6,12 @@ import android.text.TextUtils import com.v2ray.ang.AppConfig import com.v2ray.ang.AppConfig.GEOIP_PRIVATE import com.v2ray.ang.AppConfig.GEOSITE_PRIVATE +import com.v2ray.ang.AppConfig.ROUTING_BLACK +import com.v2ray.ang.AppConfig.ROUTING_GLOBAL +import com.v2ray.ang.AppConfig.ROUTING_WHITE +import com.v2ray.ang.AppConfig.ROUTING_WHITE_IRAN import com.v2ray.ang.AppConfig.TAG_DIRECT +import com.v2ray.ang.dto.RoutingType import com.v2ray.ang.dto.RulesetItem import com.v2ray.ang.dto.ServerConfig import com.v2ray.ang.util.MmkvManager.decodeProfileConfig @@ -27,13 +32,7 @@ object SettingsManager { } private fun getPresetRoutingRulesets(context: Context, index: Int = 0): MutableList? { - val fileName = when (index) { - 0 -> "custom_routing_white" - 1 -> "custom_routing_black" - 2 -> "custom_routing_global" - 3 -> "custom_routing_white_iran" - else -> "custom_routing_white" - } + val fileName = RoutingType.fromIndex(index).fileName val assets = Utils.readTextFromAssets(context, fileName) if (TextUtils.isEmpty(assets)) { return null @@ -42,6 +41,7 @@ object SettingsManager { return JsonUtil.fromJson(assets, Array::class.java).toMutableList() } + fun resetRoutingRulesets(context: Context, index: Int) { val rulesetList = getPresetRoutingRulesets(context, index) ?: return resetRoutingRulesetsCommon(rulesetList)