diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/ProfileItem.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/ProfileItem.kt new file mode 100644 index 00000000..a906289c --- /dev/null +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/ProfileItem.kt @@ -0,0 +1,9 @@ +package com.v2ray.ang.dto + +data class ProfileItem( + val configType: EConfigType, + var subscriptionId: String = "", + var remarks: String = "", + var server: String?, + var serverPort: Int?, +) \ No newline at end of file diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/ServersCache.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/ServersCache.kt index e686b469..82cea587 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/ServersCache.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/dto/ServersCache.kt @@ -1,4 +1,4 @@ package com.v2ray.ang.dto data class ServersCache(val guid: String, - val config: ServerConfig) \ No newline at end of file + val profile: ProfileItem) \ No newline at end of file diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt index 67077c26..023d2b72 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt @@ -330,7 +330,6 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm) .setPositiveButton(android.R.string.ok) { _, _ -> mainViewModel.removeDuplicateServer() - mainViewModel.reloadServerList() } .setNegativeButton(android.R.string.no) {_, _ -> //do noting diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainRecyclerAdapter.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainRecyclerAdapter.kt index 1fd2c1d4..cc9a062f 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainRecyclerAdapter.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainRecyclerAdapter.kt @@ -26,8 +26,8 @@ import com.v2ray.ang.service.V2RayServiceManager import com.v2ray.ang.util.AngConfigManager import com.v2ray.ang.util.MmkvManager import com.v2ray.ang.util.Utils -import io.reactivex.rxjava3.core.Observable import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers +import io.reactivex.rxjava3.core.Observable import java.util.concurrent.TimeUnit class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter() @@ -51,7 +51,7 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter { holder.itemMainBinding.tvType.text = mActivity.getString(R.string.server_customize_config) shareOptions = shareOptions.takeLast(1) } EConfigType.VLESS -> { - holder.itemMainBinding.tvType.text = config.configType.name + holder.itemMainBinding.tvType.text = profile.configType.name } else -> { - holder.itemMainBinding.tvType.text = config.configType.name.lowercase() + holder.itemMainBinding.tvType.text = profile.configType.name.lowercase() } } - val strState = "${outbound?.getServerAddress()?.dropLast(3)}*** : ${outbound?.getServerPort() ?: ""}" + val strState = "${profile?.server?.dropLast(3)}*** : ${profile?.serverPort ?: ""}" holder.itemMainBinding.tvStatistics.text = strState @@ -107,7 +106,7 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter { - if (config.configType == EConfigType.CUSTOM) { + if (profile.configType == EConfigType.CUSTOM) { shareFullContent(guid) } else { val ivBinding = ItemQrcodeBinding.inflate(LayoutInflater.from(mActivity)) @@ -134,7 +133,7 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter().toast(R.string.connection_test_testing) for (item in serversCache) { - item.config.getProxyOutbound()?.let { outbound -> - val serverAddress = outbound.getServerAddress() - val serverPort = outbound.getServerPort() + item.profile.let { outbound -> + val serverAddress = outbound.server + val serverPort = outbound.serverPort if (serverAddress != null && serverPort != null) { tcpingTestScope.launch { val testResult = SpeedtestUtil.tcping(serverAddress, serverPort) @@ -236,27 +255,33 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { } fun removeDuplicateServer() { - val deleteServer = mutableListOf() - serversCache.forEachIndexed { index, it -> - val outbound = it.config.getProxyOutbound() - serversCache.forEachIndexed { index2, it2 -> - if (index2 > index) { - val outbound2 = it2.config.getProxyOutbound() - if (outbound == outbound2 && !deleteServer.contains(it2.guid)) { - deleteServer.add(it2.guid) + viewModelScope.launch(Dispatchers.Default) { + val deleteServer = mutableListOf() + serversCache.forEachIndexed { index, it -> + val outbound = MmkvManager.decodeServerConfig(it.guid)?.getProxyOutbound() + serversCache.forEachIndexed { index2, it2 -> + if (index2 > index) { + val outbound2 = MmkvManager.decodeServerConfig(it2.guid)?.getProxyOutbound() + if (outbound == outbound2 && !deleteServer.contains(it2.guid)) { + deleteServer.add(it2.guid) + } } } } + for (it in deleteServer) { + MmkvManager.removeServer(it) + } + launch(Dispatchers.Main) { + reloadServerList() + getApplication().toast( + getApplication().getString( + R.string.title_del_duplicate_config_count, + deleteServer.count() + ) + ) + } + } - for (it in deleteServer) { - MmkvManager.removeServer(it) - } - getApplication().toast( - getApplication().getString( - R.string.title_del_duplicate_config_count, - deleteServer.count() - ) - ) } fun copyAssets(assets: AssetManager) {