Skip to content

Commit

Permalink
feat(gui): remote duplicate servers
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Apr 17, 2023
1 parent 61c17e1 commit 5c38ab8
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ object RawUpdater : GroupUpdater() {
val uniqueProxies = LinkedHashSet<Protocols.Deduplication>()
val uniqueNames = HashMap<Protocols.Deduplication, String>()
for (_proxy in proxies) {
val proxy = Protocols.Deduplication(_proxy)
val proxy = Protocols.Deduplication(_proxy, _proxy.javaClass.toString())
if (!uniqueProxies.add(proxy)) {
val index = uniqueProxies.indexOf(proxy)
if (uniqueNames.containsKey(proxy)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,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 -> {
pingTest(true)
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/moe/matsuri/nya/Protocols.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ object Protocols {
// Deduplication

class Deduplication(
val bean: AbstractBean
val bean: AbstractBean, val type: String
) {

fun hash(): String {
return bean.serverAddress + bean.serverPort
return bean.serverAddress + bean.serverPort + type
}

override fun hashCode(): Int {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/menu/add_profile_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
<item
android:id="@+id/action_clear_traffic_statistics"
android:title="@string/clear_traffic_statistics" />
<item
android:id="@+id/action_remove_duplicate"
android:title="@string/remove_duplicate" />
<item
android:id="@+id/action_connection_test"
android:title="@string/connection_test">
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,5 @@
<string name="share_subscription">分享订阅</string>
<string name="show_group_in_notification">在通知中显示组名</string>
<string name="reset_connections">重置连接</string>
<string name="remove_duplicate">删除重复的服务器</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -524,5 +524,6 @@ Anyone can write advanced plugins, which can control Matsuri. please download an
<string name="share_subscription">Share Subscription</string>
<string name="show_group_in_notification">Show group name in in notification</string>
<string name="reset_connections">Reset Connections</string>
<string name="remove_duplicate">Remove duplicate servers</string>

</resources>

0 comments on commit 5c38ab8

Please sign in to comment.