diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 20f61121..3bd47e00 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -38,6 +38,7 @@ task("downloadGeoFiles") { "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geoip.metadb" to "geoip.metadb", "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/geosite.dat" to "geosite.dat", // "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/country.mmdb" to "country.mmdb", + "https://github.com/MetaCubeX/meta-rules-dat/releases/download/latest/GeoLite2-ASN.mmdb" to "ASN.mmdb", ) doLast { diff --git a/app/src/main/java/com/github/kr328/clash/MainApplication.kt b/app/src/main/java/com/github/kr328/clash/MainApplication.kt index 3cdfb5b5..7f4ddf74 100644 --- a/app/src/main/java/com/github/kr328/clash/MainApplication.kt +++ b/app/src/main/java/com/github/kr328/clash/MainApplication.kt @@ -54,6 +54,13 @@ class MainApplication : Application() { assets.open("geosite.dat").copyTo(it); } } + + val ASNFile = File(clashDir, "ASN.mmdb") + if(!ASNFile.exists()) { + FileOutputStream(ASNFile).use { + assets.open("ASN.mmdb").copyTo(it); + } + } } fun finalize() { diff --git a/app/src/main/java/com/github/kr328/clash/MetaFeatureSettingsActivity.kt b/app/src/main/java/com/github/kr328/clash/MetaFeatureSettingsActivity.kt index 29ebbcb3..913bc07e 100644 --- a/app/src/main/java/com/github/kr328/clash/MetaFeatureSettingsActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/MetaFeatureSettingsActivity.kt @@ -70,6 +70,12 @@ class MetaFeatureSettingsActivity : BaseActivity() { "*/*") importGeoFile(uri, MetaFeatureSettingsDesign.Request.ImportCountry) } + MetaFeatureSettingsDesign.Request.ImportASN -> { + val uri = startActivityForResult( + ActivityResultContracts.GetContent(), + "*/*") + importGeoFile(uri, MetaFeatureSettingsDesign.Request.ImportASN) + } } } } @@ -107,6 +113,8 @@ class MetaFeatureSettingsActivity : BaseActivity() { "geosite$ext" MetaFeatureSettingsDesign.Request.ImportCountry -> "country$ext" + MetaFeatureSettingsDesign.Request.ImportASN -> + "ASN$ext" else -> "" } diff --git a/design/src/main/java/com/github/kr328/clash/design/MetaFeatureSettingsDesign.kt b/design/src/main/java/com/github/kr328/clash/design/MetaFeatureSettingsDesign.kt index 4e9d195e..0d674ca9 100644 --- a/design/src/main/java/com/github/kr328/clash/design/MetaFeatureSettingsDesign.kt +++ b/design/src/main/java/com/github/kr328/clash/design/MetaFeatureSettingsDesign.kt @@ -15,7 +15,7 @@ class MetaFeatureSettingsDesign( configuration: ConfigurationOverride ) : Design(context) { enum class Request { - ResetOverride, ImportGeoIp, ImportGeoSite, ImportCountry + ResetOverride, ImportGeoIp, ImportGeoSite, ImportCountry, ImportASN } private val binding = DesignSettingsMetaFeatureBinding @@ -255,6 +255,15 @@ class MetaFeatureSettingsDesign( requests.trySend(Request.ImportCountry) } } + + clickable ( + title = R.string.import_asn_file, + summary = R.string.press_to_import, + ){ + clicked { + requests.trySend(Request.ImportASN) + } + } } binding.content.addView(screen.root) diff --git a/design/src/main/res/values/strings.xml b/design/src/main/res/values/strings.xml index b1987c7c..f6d20fd1 100644 --- a/design/src/main/res/values/strings.xml +++ b/design/src/main/res/values/strings.xml @@ -316,6 +316,7 @@ Press to import... Import GeoSite Database Import Country Database + Import ASN Database Import failed Unknown Database format Only %1$s are supported