mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 14:40:06 +08:00
feat(gui): remote duplicate servers
This commit is contained in:
parent
abcf912a53
commit
21e700e162
@ -91,7 +91,7 @@ object RawUpdater : GroupUpdater() {
|
|||||||
val uniqueProxies = LinkedHashSet<Protocols.Deduplication>()
|
val uniqueProxies = LinkedHashSet<Protocols.Deduplication>()
|
||||||
val uniqueNames = HashMap<Protocols.Deduplication, String>()
|
val uniqueNames = HashMap<Protocols.Deduplication, String>()
|
||||||
for (_proxy in proxies) {
|
for (_proxy in proxies) {
|
||||||
val proxy = Protocols.Deduplication(_proxy)
|
val proxy = Protocols.Deduplication(_proxy, _proxy.javaClass.toString())
|
||||||
if (!uniqueProxies.add(proxy)) {
|
if (!uniqueProxies.add(proxy)) {
|
||||||
val index = uniqueProxies.indexOf(proxy)
|
val index = uniqueProxies.indexOf(proxy)
|
||||||
if (uniqueNames.containsKey(proxy)) {
|
if (uniqueNames.containsKey(proxy)) {
|
||||||
|
|||||||
@ -466,6 +466,57 @@ class ConfigurationFragment @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
R.id.action_remove_duplicate -> {
|
||||||
|
runOnDefaultDispatcher {
|
||||||
|
val profiles = SagerDatabase.proxyDao.getByGroup(DataStore.currentGroupId())
|
||||||
|
val toClear = mutableListOf<ProxyEntity>()
|
||||||
|
val uniqueProxies = LinkedHashSet<Protocols.Deduplication>()
|
||||||
|
for (pf in profiles) {
|
||||||
|
val proxy = Protocols.Deduplication(pf.requireBean(), pf.displayType())
|
||||||
|
if (!uniqueProxies.add(proxy)) {
|
||||||
|
toClear += pf
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (toClear.isNotEmpty()) {
|
||||||
|
onMainDispatcher {
|
||||||
|
MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.confirm)
|
||||||
|
.setMessage(
|
||||||
|
getString(R.string.delete_confirm_prompt) + "\n" +
|
||||||
|
toClear.mapIndexedNotNull { index, proxyEntity ->
|
||||||
|
if (index < 20) {
|
||||||
|
proxyEntity.displayName()
|
||||||
|
} else if (index == 20) {
|
||||||
|
"......"
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}.joinToString("\n")
|
||||||
|
)
|
||||||
|
.setPositiveButton(R.string.yes) { _, _ ->
|
||||||
|
for (profile in toClear) {
|
||||||
|
adapter.groupFragments[DataStore.selectedGroup]?.adapter?.apply {
|
||||||
|
val index = configurationIdList.indexOf(profile.id)
|
||||||
|
if (index >= 0) {
|
||||||
|
configurationIdList.removeAt(index)
|
||||||
|
configurationList.remove(profile.id)
|
||||||
|
notifyItemRemoved(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
runOnDefaultDispatcher {
|
||||||
|
for (profile in toClear) {
|
||||||
|
ProfileManager.deleteProfile2(
|
||||||
|
profile.groupId, profile.id
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.setNegativeButton(R.string.no, null)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
R.id.action_connection_icmp_ping -> {
|
R.id.action_connection_icmp_ping -> {
|
||||||
pingTest(true)
|
pingTest(true)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,11 +34,11 @@ object Protocols {
|
|||||||
// Deduplication
|
// Deduplication
|
||||||
|
|
||||||
class Deduplication(
|
class Deduplication(
|
||||||
val bean: AbstractBean
|
val bean: AbstractBean, val type: String
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun hash(): String {
|
fun hash(): String {
|
||||||
return bean.serverAddress + bean.serverPort
|
return bean.serverAddress + bean.serverPort + type
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
|
|||||||
@ -86,6 +86,9 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/action_clear_traffic_statistics"
|
android:id="@+id/action_clear_traffic_statistics"
|
||||||
android:title="@string/clear_traffic_statistics" />
|
android:title="@string/clear_traffic_statistics" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_remove_duplicate"
|
||||||
|
android:title="@string/remove_duplicate" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_connection_test"
|
android:id="@+id/action_connection_test"
|
||||||
android:title="@string/connection_test">
|
android:title="@string/connection_test">
|
||||||
|
|||||||
@ -469,4 +469,5 @@
|
|||||||
<string name="share_subscription">分享订阅</string>
|
<string name="share_subscription">分享订阅</string>
|
||||||
<string name="show_group_in_notification">在通知中显示组名</string>
|
<string name="show_group_in_notification">在通知中显示组名</string>
|
||||||
<string name="reset_connections">重置连接</string>
|
<string name="reset_connections">重置连接</string>
|
||||||
|
<string name="remove_duplicate">删除重复的服务器</string>
|
||||||
</resources>
|
</resources>
|
||||||
@ -510,5 +510,6 @@ Anyone can write advanced plugins, which can control NekoBox. please download an
|
|||||||
<string name="share_subscription">Share Subscription</string>
|
<string name="share_subscription">Share Subscription</string>
|
||||||
<string name="show_group_in_notification">Show group name in in notification</string>
|
<string name="show_group_in_notification">Show group name in in notification</string>
|
||||||
<string name="reset_connections">Reset Connections</string>
|
<string name="reset_connections">Reset Connections</string>
|
||||||
|
<string name="remove_duplicate">Remove duplicate servers</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Reference in New Issue
Block a user