Skip to content

Commit

Permalink
Organize routing files names (#3717)
Browse files Browse the repository at this point in the history
* Organize routing files names

Organize routing files names

* Use enum for routing type

Use enum for routing type
  • Loading branch information
CodeWithTamim authored Oct 21, 2024
1 parent 3de3070 commit ca849fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
20 changes: 20 additions & 0 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/RoutingType.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit ca849fb

Please sign in to comment.