Updated one_account_max to allow to set a different limit

This commit is contained in:
Sylvain Berfini 2024-07-02 16:11:32 +02:00
parent f449763c4e
commit 811a0466d4
2 changed files with 11 additions and 3 deletions

View file

@ -175,8 +175,8 @@ class CorePreferences @UiThread constructor(private val context: Context) {
get() = config.getBool("ui", "disable_call_recordings_feature", false)
@get:WorkerThread
val oneAccountMax: Boolean
get() = config.getBool("ui", "one_account_max", false)
val maxAccountsCount: Int
get() = config.getInt("ui", "max_account", 0) // 0 means no max
@get:WorkerThread
val hideSettings: Boolean

View file

@ -171,6 +171,14 @@ class DrawerMenuViewModel @UiThread constructor() : GenericViewModel() {
}
accounts.postValue(list)
hideAddAccount.postValue(corePreferences.oneAccountMax && list.isNotEmpty())
val maxAccount = corePreferences.maxAccountsCount
val accountsCount = list.size
val maxAccountsReached = maxAccount > 0 && accountsCount >= maxAccount
if (maxAccountsReached) {
Log.w(
"$TAG Max number of allowed accounts reached [$maxAccount], hiding add account button"
)
}
hideAddAccount.postValue(maxAccountsReached)
}
}