mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2024-11-25 23:06:09 +03:00
chore: code cleanup
This commit is contained in:
parent
ad471f3837
commit
546378b9c4
@ -7,6 +7,7 @@ import com.github.kr328.clash.common.compat.currentProcessName
|
||||
import com.github.kr328.clash.common.log.Log
|
||||
import com.github.kr328.clash.remote.Remote
|
||||
import com.github.kr328.clash.service.util.sendServiceRecreated
|
||||
import com.github.kr328.clash.util.clashDir
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
@ -38,7 +39,6 @@ class MainApplication : Application() {
|
||||
}
|
||||
|
||||
private fun extractGeoFiles() {
|
||||
val clashDir = File(filesDir, "clash")
|
||||
clashDir.mkdirs();
|
||||
|
||||
val geoipFile = File(clashDir, "geoip.metadb")
|
||||
|
@ -8,6 +8,7 @@ import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import com.github.kr328.clash.core.Clash
|
||||
import com.github.kr328.clash.design.MetaFeatureSettingsDesign
|
||||
import com.github.kr328.clash.util.clashDir
|
||||
import com.github.kr328.clash.util.withClash
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -20,22 +21,6 @@ import java.io.FileOutputStream
|
||||
|
||||
|
||||
class MetaFeatureSettingsActivity : BaseActivity<MetaFeatureSettingsDesign>() {
|
||||
|
||||
private val geoipDbImporter = registerForActivityResult(ActivityResultContracts.GetContent()){
|
||||
launch{
|
||||
geoFilesImported(it, MetaFeatureSettingsDesign.Request.ImportGeoIp)
|
||||
}
|
||||
}
|
||||
private val geositeDbImporter = registerForActivityResult(ActivityResultContracts.GetContent()){
|
||||
launch{
|
||||
geoFilesImported(it, MetaFeatureSettingsDesign.Request.ImportGeoSite)
|
||||
}
|
||||
}
|
||||
private val countryDbImporter = registerForActivityResult(ActivityResultContracts.GetContent()){
|
||||
launch{
|
||||
geoFilesImported(it, MetaFeatureSettingsDesign.Request.ImportCountry)
|
||||
}
|
||||
}
|
||||
override suspend fun main() {
|
||||
val configuration = withClash { queryOverride(Clash.OverrideSlot.Persist) }
|
||||
|
||||
@ -70,13 +55,22 @@ class MetaFeatureSettingsActivity : BaseActivity<MetaFeatureSettingsDesign>() {
|
||||
}
|
||||
}
|
||||
MetaFeatureSettingsDesign.Request.ImportGeoIp -> {
|
||||
geoipDbImporter.launch("*/*")
|
||||
val uri = startActivityForResult(
|
||||
ActivityResultContracts.GetContent(),
|
||||
"*/*")
|
||||
geoFilesImported(uri, MetaFeatureSettingsDesign.Request.ImportGeoIp)
|
||||
}
|
||||
MetaFeatureSettingsDesign.Request.ImportGeoSite -> {
|
||||
geositeDbImporter.launch("*/*")
|
||||
val uri = startActivityForResult(
|
||||
ActivityResultContracts.GetContent(),
|
||||
"*/*")
|
||||
geoFilesImported(uri, MetaFeatureSettingsDesign.Request.ImportGeoSite)
|
||||
}
|
||||
MetaFeatureSettingsDesign.Request.ImportCountry -> {
|
||||
countryDbImporter.launch("*/*")
|
||||
val uri = startActivityForResult(
|
||||
ActivityResultContracts.GetContent(),
|
||||
"*/*")
|
||||
geoFilesImported(uri, MetaFeatureSettingsDesign.Request.ImportCountry)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -119,7 +113,7 @@ class MetaFeatureSettingsActivity : BaseActivity<MetaFeatureSettingsDesign>() {
|
||||
}
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
val outputFile = File(File(filesDir, "clash"), outputFileName);
|
||||
val outputFile = File(clashDir, outputFileName);
|
||||
contentResolver.openInputStream(uri).use { ins ->
|
||||
FileOutputStream(outputFile).use { outs ->
|
||||
ins?.copyTo(outs)
|
||||
|
@ -5,3 +5,6 @@ import java.io.File
|
||||
|
||||
val Context.logsDir: File
|
||||
get() = cacheDir.resolve("logs")
|
||||
|
||||
val Context.clashDir: File
|
||||
get() = filesDir.resolve("clash")
|
Loading…
Reference in New Issue
Block a user