Skip to content

Commit

Permalink
We alway have AccountSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc2822 committed May 16, 2024
1 parent c150ec9 commit 7f6f416
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class AccountSettingsActivity: AppCompatActivity() {

setContent {
AccountSettingsScreen(
onNavUp = ::onSupportNavigateUp,
account = account,
onSyncWifiOnlyPermissionsAction = {
onNavWifiPermissionsScreen = {
val intent = Intent(this, WifiPermissionsActivity::class.java)
intent.putExtra(WifiPermissionsActivity.EXTRA_ACCOUNT, account)
startActivity(intent)
}
},
onNavUp = ::onSupportNavigateUp,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AccountSettingsModel @AssistedInject constructor(
fun create(account: Account): AccountSettingsModel
}

private var accountSettings: AccountSettings? = null
private var accountSettings = AccountSettings(context, account)

// settings
val syncIntervalContacts = MutableLiveData<Long>()
Expand All @@ -59,10 +59,7 @@ class AccountSettingsModel @AssistedInject constructor(


init {
accountSettings = AccountSettings(context, account)

settings.addOnChangeListener(this)

reload()
}

Expand All @@ -72,12 +69,11 @@ class AccountSettingsModel @AssistedInject constructor(
}

override fun onSettingsChanged() {
Logger.log.info("Settings changed")
reload()
}

fun reload() {
val accountSettings = accountSettings ?: return
private fun reload() {
Logger.log.info("Reloading settings")

syncIntervalContacts.postValue(
accountSettings.getSyncInterval(context.getString(R.string.address_books_authority))
Expand All @@ -102,49 +98,49 @@ class AccountSettingsModel @AssistedInject constructor(

fun updateCalendarSyncInterval(syncInterval: Long) {
CoroutineScope(Dispatchers.Default).launch {
accountSettings?.setSyncInterval(CalendarContract.AUTHORITY, syncInterval)
accountSettings.setSyncInterval(CalendarContract.AUTHORITY, syncInterval)
reload()
}
}

fun updateContactsSyncInterval(syncInterval: Long) {
CoroutineScope(Dispatchers.Default).launch {
accountSettings?.setSyncInterval(context.getString(R.string.address_books_authority), syncInterval)
accountSettings.setSyncInterval(context.getString(R.string.address_books_authority), syncInterval)
reload()
}
}

fun updateTasksSyncInterval(syncInterval: Long) {
tasksProvider?.authority?.let { tasksAuthority ->
CoroutineScope(Dispatchers.Default).launch {
accountSettings?.setSyncInterval(tasksAuthority, syncInterval)
accountSettings.setSyncInterval(tasksAuthority, syncInterval)
reload()
}
}
}

fun updateSyncWifiOnly(wifiOnly: Boolean) {
accountSettings?.setSyncWiFiOnly(wifiOnly)
accountSettings.setSyncWiFiOnly(wifiOnly)
reload()
}

fun updateSyncWifiOnlySSIDs(ssids: List<String>?) {
accountSettings?.setSyncWifiOnlySSIDs(ssids)
accountSettings.setSyncWifiOnlySSIDs(ssids)
reload()
}

fun updateIgnoreVpns(ignoreVpns: Boolean) {
accountSettings?.setIgnoreVpns(ignoreVpns)
accountSettings.setIgnoreVpns(ignoreVpns)
reload()
}

fun updateCredentials(credentials: Credentials) {
accountSettings?.credentials(credentials)
accountSettings.credentials(credentials)
reload()
}

fun updateTimeRangePastDays(days: Int?) {
accountSettings?.setTimeRangePastDays(days)
accountSettings.setTimeRangePastDays(days)
reload()

/* If the new setting is a certain number of days, no full resync is required,
Expand All @@ -156,28 +152,28 @@ class AccountSettingsModel @AssistedInject constructor(
}

fun updateDefaultAlarm(minBefore: Int?) {
accountSettings?.setDefaultAlarm(minBefore)
accountSettings.setDefaultAlarm(minBefore)
reload()

resyncCalendars(fullResync = true, tasks = false)
}

fun updateManageCalendarColors(manage: Boolean) {
accountSettings?.setManageCalendarColors(manage)
accountSettings.setManageCalendarColors(manage)
reload()

resyncCalendars(fullResync = false, tasks = true)
}

fun updateEventColors(manageColors: Boolean) {
accountSettings?.setEventColors(manageColors)
accountSettings.setEventColors(manageColors)
reload()

resyncCalendars(fullResync = true, tasks = false)
}

fun updateContactGroupMethod(groupMethod: GroupMethod) {
accountSettings?.setGroupMethod(groupMethod)
accountSettings.setGroupMethod(groupMethod)
reload()

resync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import kotlinx.coroutines.launch
fun AccountSettingsScreen(
onNavUp: () -> Unit,
account: Account,
onSyncWifiOnlyPermissionsAction: () -> Unit,
onNavWifiPermissionsScreen: () -> Unit,
) {
val model = hiltViewModel { factory: AccountSettingsModel.Factory ->
factory.create(account)
Expand All @@ -80,7 +80,7 @@ fun AccountSettingsScreen(

// Sync settings
canAccessWifiSsid = canAccessWifiSsid,
onSyncWifiOnlyPermissionsAction = onSyncWifiOnlyPermissionsAction,
onSyncWifiOnlyPermissionsAction = onNavWifiPermissionsScreen,
contactsSyncInterval = model.syncIntervalContacts.observeAsState().value,
onUpdateContactsSyncInterval = model::updateContactsSyncInterval,
calendarSyncInterval = model.syncIntervalCalendars.observeAsState().value,
Expand Down

0 comments on commit 7f6f416

Please sign in to comment.