mirror of
https://github.com/bitfireAT/davx5-ose
synced 2024-10-15 15:59:18 +00:00
AccountSettings: don't throw IllegalArgumentException when reading/writing sync interval (bitfireAT/davx5#456)
This commit is contained in:
parent
eeffbdcf6d
commit
2f761facc9
|
@ -226,7 +226,7 @@ class AccountSettings(
|
||||||
KEY_SYNC_INTERVAL_CALENDARS
|
KEY_SYNC_INTERVAL_CALENDARS
|
||||||
TaskProvider.ProviderName.values().any { it.authority == authority } ->
|
TaskProvider.ProviderName.values().any { it.authority == authority } ->
|
||||||
KEY_SYNC_INTERVAL_TASKS
|
KEY_SYNC_INTERVAL_TASKS
|
||||||
else -> throw IllegalArgumentException("Authority does not exist: $authority")
|
else -> return null
|
||||||
}
|
}
|
||||||
return accountManager.getUserData(account, key)?.toLong()
|
return accountManager.getUserData(account, key)?.toLong()
|
||||||
}
|
}
|
||||||
|
@ -241,16 +241,16 @@ class AccountSettings(
|
||||||
* (sync disabled), so it should not be called from the UI thread.
|
* (sync disabled), so it should not be called from the UI thread.
|
||||||
*
|
*
|
||||||
* @param authority sync authority (like [CalendarContract.AUTHORITY])
|
* @param authority sync authority (like [CalendarContract.AUTHORITY])
|
||||||
* @param seconds if [SYNC_INTERVAL_MANUALLY]: automatic sync will be disabled;
|
* @param _seconds if [SYNC_INTERVAL_MANUALLY]: automatic sync will be disabled;
|
||||||
* otherwise (≥ 15 min): automatic sync will be enabled and set to the given number of seconds
|
* otherwise (must be ≥ 15 min): automatic sync will be enabled and set to the given number of seconds
|
||||||
*
|
|
||||||
* @return whether the sync interval was successfully set
|
|
||||||
* @throws IllegalArgumentException when [seconds] is not [SYNC_INTERVAL_MANUALLY] but less than 15 min
|
|
||||||
*/
|
*/
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
fun setSyncInterval(authority: String, seconds: Long): Boolean {
|
fun setSyncInterval(authority: String, _seconds: Long) {
|
||||||
if (seconds != SYNC_INTERVAL_MANUALLY && seconds < 60*15)
|
val seconds =
|
||||||
throw IllegalArgumentException("<15 min is not supported by Android")
|
if (_seconds != SYNC_INTERVAL_MANUALLY && _seconds < 60*15)
|
||||||
|
60*15
|
||||||
|
else
|
||||||
|
_seconds
|
||||||
|
|
||||||
// Store (user defined) sync interval in account settings
|
// Store (user defined) sync interval in account settings
|
||||||
val key = when {
|
val key = when {
|
||||||
|
@ -260,8 +260,10 @@ class AccountSettings(
|
||||||
KEY_SYNC_INTERVAL_CALENDARS
|
KEY_SYNC_INTERVAL_CALENDARS
|
||||||
TaskProvider.ProviderName.values().any { it.authority == authority } ->
|
TaskProvider.ProviderName.values().any { it.authority == authority } ->
|
||||||
KEY_SYNC_INTERVAL_TASKS
|
KEY_SYNC_INTERVAL_TASKS
|
||||||
else ->
|
else -> {
|
||||||
throw IllegalArgumentException("Sync interval not applicable to authority $authority")
|
Logger.log.warning("Sync interval not applicable to authority $authority")
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
accountManager.setAndVerifyUserData(account, key, seconds.toString())
|
accountManager.setAndVerifyUserData(account, key, seconds.toString())
|
||||||
|
|
||||||
|
@ -271,8 +273,6 @@ class AccountSettings(
|
||||||
// Also enable/disable content change triggered syncs (SyncFramework automatic sync).
|
// Also enable/disable content change triggered syncs (SyncFramework automatic sync).
|
||||||
// We could make this a separate user adjustable setting later on.
|
// We could make this a separate user adjustable setting later on.
|
||||||
setSyncOnContentChange(authority, seconds != SYNC_INTERVAL_MANUALLY)
|
setSyncOnContentChange(authority, seconds != SYNC_INTERVAL_MANUALLY)
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue