Organize routing files names (#3717)
* Organize routing files names Organize routing files names * Use enum for routing type Use enum for routing type
This commit is contained in:
1 parent
3de3070ab7
commit
ca849fb19e
2 files changed
+27
-7
No files matched your search
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,12 @@ import android.text.TextUtils
|
|||||||
import com.v2ray.ang.AppConfig
|
import com.v2ray.ang.AppConfig
|
||||||
import com.v2ray.ang.AppConfig.GEOIP_PRIVATE
|
import com.v2ray.ang.AppConfig.GEOIP_PRIVATE
|
||||||
import com.v2ray.ang.AppConfig.GEOSITE_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.AppConfig.TAG_DIRECT
|
||||||
|
import com.v2ray.ang.dto.RoutingType
|
||||||
import com.v2ray.ang.dto.RulesetItem
|
import com.v2ray.ang.dto.RulesetItem
|
||||||
import com.v2ray.ang.dto.ServerConfig
|
import com.v2ray.ang.dto.ServerConfig
|
||||||
import com.v2ray.ang.util.MmkvManager.decodeProfileConfig
|
import com.v2ray.ang.util.MmkvManager.decodeProfileConfig
|
||||||
@@ -27,13 +32,7 @@ object SettingsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getPresetRoutingRulesets(context: Context, index: Int = 0): MutableList<RulesetItem>? {
|
private fun getPresetRoutingRulesets(context: Context, index: Int = 0): MutableList<RulesetItem>? {
|
||||||
val fileName = when (index) {
|
val fileName = RoutingType.fromIndex(index).fileName
|
||||||
0 -> "custom_routing_white"
|
|
||||||
1 -> "custom_routing_black"
|
|
||||||
2 -> "custom_routing_global"
|
|
||||||
3 -> "custom_routing_white_iran"
|
|
||||||
else -> "custom_routing_white"
|
|
||||||
}
|
|
||||||
val assets = Utils.readTextFromAssets(context, fileName)
|
val assets = Utils.readTextFromAssets(context, fileName)
|
||||||
if (TextUtils.isEmpty(assets)) {
|
if (TextUtils.isEmpty(assets)) {
|
||||||
return null
|
return null
|
||||||
@@ -42,6 +41,7 @@ object SettingsManager {
|
|||||||
return JsonUtil.fromJson(assets, Array<RulesetItem>::class.java).toMutableList()
|
return JsonUtil.fromJson(assets, Array<RulesetItem>::class.java).toMutableList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun resetRoutingRulesets(context: Context, index: Int) {
|
fun resetRoutingRulesets(context: Context, index: Int) {
|
||||||
val rulesetList = getPresetRoutingRulesets(context, index) ?: return
|
val rulesetList = getPresetRoutingRulesets(context, index) ?: return
|
||||||
resetRoutingRulesetsCommon(rulesetList)
|
resetRoutingRulesetsCommon(rulesetList)
|
||||||
|
|||||||
Reference in new issue
Block a user