mirror of
https://github.com/openlibrecommunity/olcng.git
synced 2026-07-03 14:05:17 +02:00
fix server select
This commit is contained in:
@@ -275,6 +275,10 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
|
||||
private fun setButtonsEnabled(enabled: Boolean) {
|
||||
binding.fab.isEnabled = enabled
|
||||
binding.fab.alpha = if (enabled) 1.0f else 0.5f
|
||||
setSecondaryButtonsEnabled(enabled)
|
||||
}
|
||||
|
||||
private fun setSecondaryButtonsEnabled(enabled: Boolean) {
|
||||
binding.btnSummaryLite.isEnabled = enabled
|
||||
binding.btnSummaryLite.alpha = if (enabled) 1.0f else 0.5f
|
||||
val menu = binding.toolbar.menu
|
||||
@@ -316,7 +320,6 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
|
||||
} catch (e: Exception) {
|
||||
Log.e(AppConfig.TAG, "FAB: error", e)
|
||||
applyRunningState(isLoading = false, isRunning = mainViewModel.isRunning.value == true)
|
||||
setButtonsEnabled(true)
|
||||
} finally {
|
||||
isFabOperationInProgress = false
|
||||
}
|
||||
@@ -473,7 +476,10 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
setButtonsEnabled(true)
|
||||
// Подключены: только FAB (отключить) активен, остальное блокируем
|
||||
setSecondaryButtonsEnabled(false)
|
||||
binding.fab.isEnabled = true
|
||||
binding.fab.alpha = 1.0f
|
||||
binding.fab.backgroundTintList = accentColor()
|
||||
binding.btnSummaryLite.backgroundTintList = ColorStateList.valueOf(ContextCompat.getColor(this, R.color.color_fab_inactive))
|
||||
binding.fab.contentDescription = getString(R.string.action_stop_service)
|
||||
@@ -707,7 +713,7 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
|
||||
mainViewModel.reloadServerList()
|
||||
}
|
||||
hideLoading()
|
||||
setButtonsEnabled(true)
|
||||
applyRunningState(isLoading = false, isRunning = mainViewModel.isRunning.value == true)
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -202,13 +202,13 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all known countries from the current full server list (for showing in filter dialog).
|
||||
* Returns all known countries from ALL servers across all subscriptions (for showing in filter dialog).
|
||||
* Key = ISO code, Value = human-readable name + flag.
|
||||
*/
|
||||
fun collectAllCountries(): Map<String, String> {
|
||||
val result = mutableMapOf<String, String>()
|
||||
var hasUnknown = false
|
||||
for (guid in serverList) {
|
||||
for (guid in MmkvManager.decodeAllServerList()) {
|
||||
val profile = MmkvManager.decodeServerConfig(guid) ?: continue
|
||||
val code = CountryDetector.getCountryCode(profile.remarks, profile.server)
|
||||
if (code == CountryDetector.UNKNOWN) {
|
||||
@@ -226,7 +226,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
/** Trigger background geo-lookup for IPs not yet cached. */
|
||||
fun refreshCountryCache() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val ips = serverList.mapNotNull {
|
||||
val ips = MmkvManager.decodeAllServerList().mapNotNull {
|
||||
MmkvManager.decodeServerConfig(it)?.server?.trim()
|
||||
}.distinct()
|
||||
CountryDetector.lookupAndCacheAll(ips)
|
||||
@@ -509,6 +509,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
* @return Number of removed servers.
|
||||
*/
|
||||
fun removeDuplicateByIp(): Int {
|
||||
val selectedGuid = MmkvManager.getSelectServer()
|
||||
// Group all currently visible servers by their IP address
|
||||
val byIp = LinkedHashMap<String, MutableList<ServersCache>>()
|
||||
for (sc in serversCache) {
|
||||
@@ -520,6 +521,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
for ((_, group) in byIp) {
|
||||
if (group.size <= 1) continue
|
||||
val best = group.minWithOrNull(compareBy(
|
||||
{ it.guid != selectedGuid },
|
||||
{ !it.profile.isFavorite },
|
||||
{
|
||||
val d = MmkvManager.decodeServerAffiliationInfo(it.guid)?.testDelayMillis ?: 0L
|
||||
@@ -549,6 +551,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
* @return Number of removed servers.
|
||||
*/
|
||||
fun removeDuplicateByIpAll(): Int {
|
||||
val selectedGuid = MmkvManager.getSelectServer()
|
||||
// Collect every server GUID across all subscriptions
|
||||
data class Entry(val guid: String, val ip: String, val isFav: Boolean)
|
||||
|
||||
@@ -577,6 +580,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
for ((_, group) in byIp) {
|
||||
if (group.size <= 1) continue
|
||||
val best = group.minWith(compareBy(
|
||||
{ it.guid != selectedGuid },
|
||||
{ !it.isFav },
|
||||
{
|
||||
val d = MmkvManager.decodeServerAffiliationInfo(it.guid)?.testDelayMillis ?: 0L
|
||||
|
||||
Reference in New Issue
Block a user