Added the function of deleting duplicate configurations

This commit is contained in:
2dust committed 2023-03-25 21:16:21 +08:00
1 parent f70be5bce9
commit 3d7ed12d4b
9 files changed
+46 -1

No files matched your search

@@ -297,7 +297,14 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
.show()
true
}
R.id.del_duplicate_config-> {
AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm)
.setPositiveButton(android.R.string.ok) { _, _ ->
mainViewModel.removeDuplicateServer()
}
.show()
true
}
R.id.del_invalid_config -> {
AlertDialog.Builder(this).setMessage(R.string.del_config_comfirm)
.setPositiveButton(android.R.string.ok) { _, _ ->
@@ -201,6 +201,27 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
return -1
}
fun removeDuplicateServer() {
val deleteServer = mutableListOf<String>()
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)
}
}
}
}
for(it in deleteServer){
MmkvManager.removeServer(it)
}
reloadServerList()
getApplication<AngApplication>().toast(getApplication<AngApplication>().getString(R.string.title_del_duplicate_config_count, deleteServer.count()))
}
private val mMsgReceiver = object : BroadcastReceiver() {
override fun onReceive(ctx: Context?, intent: Intent?) {
when (intent?.getIntExtra("key", 0)) {