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:
20
V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/RoutingType.kt
Normal file
20
V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/RoutingType.kt
Normal file
@@ -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.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<RulesetItem>? {
|
||||
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<RulesetItem>::class.java).toMutableList()
|
||||
}
|
||||
|
||||
|
||||
fun resetRoutingRulesets(context: Context, index: Int) {
|
||||
val rulesetList = getPresetRoutingRulesets(context, index) ?: return
|
||||
resetRoutingRulesetsCommon(rulesetList)
|
||||
|
||||
Reference in New Issue
Block a user