Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e42bd97f authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

AM: add option for default sync interval

parent bc725883
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -157,6 +157,7 @@ class AccountSettings @AssistedInject constructor(
            SyncDataType.CONTACTS -> KEY_SYNC_INTERVAL_ADDRESSBOOKS
            SyncDataType.EVENTS -> KEY_SYNC_INTERVAL_CALENDARS
            SyncDataType.TASKS -> KEY_SYNC_INTERVAL_TASKS
            SyncDataType.DEFAULT -> KEY_SYNC_INTERVAL_DEFAULT
        }
        val seconds = accountManager.getUserData(account, key)?.toLong()
        return when (seconds) {
@@ -177,6 +178,7 @@ class AccountSettings @AssistedInject constructor(
            SyncDataType.CONTACTS -> KEY_SYNC_INTERVAL_ADDRESSBOOKS
            SyncDataType.EVENTS -> KEY_SYNC_INTERVAL_CALENDARS
            SyncDataType.TASKS -> KEY_SYNC_INTERVAL_TASKS
            SyncDataType.DEFAULT -> KEY_SYNC_INTERVAL_DEFAULT
        }
        val newValue = seconds ?: SYNC_INTERVAL_MANUALLY
        accountManager.setAndVerifyUserData(account, key, newValue.toString())
@@ -368,6 +370,7 @@ class AccountSettings @AssistedInject constructor(

        /** Stores the tasks sync interval (in seconds) so that it can be set again when the provider is switched */
        const val KEY_SYNC_INTERVAL_TASKS = "sync_interval_tasks"
        const val KEY_SYNC_INTERVAL_DEFAULT = "sync_interval_default"

        const val KEY_USERNAME = "user_name"
        const val KEY_CERTIFICATE_ALIAS = "certificate_alias"
+2 −0
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ class AutomaticSyncManager @Inject constructor(
                SyncDataType.CONTACTS -> throw IllegalStateException()  // handled above
                SyncDataType.EVENTS -> CalendarContract.AUTHORITY
                SyncDataType.TASKS -> tasksAppManager.get().currentProvider()?.authority
                SyncDataType.DEFAULT -> null
            }
            if (authority != null && syncInterval != null) {
                // enable given authority, but completely disable all other possible authorities
@@ -135,6 +136,7 @@ class AutomaticSyncManager @Inject constructor(
    fun updateAutomaticSync(account: Account, dataType: SyncDataType) {
        val serviceType = when (dataType) {
            SyncDataType.CONTACTS -> Service.TYPE_CARDDAV
            SyncDataType.DEFAULT,
            SyncDataType.EVENTS,
            SyncDataType.TASKS -> Service.TYPE_CALDAV
        }
+3 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ import dagger.hilt.components.SingletonComponent
enum class SyncDataType {

    CONTACTS,
    DEFAULT,
    EVENTS,
    TASKS;

@@ -36,6 +37,7 @@ enum class SyncDataType {
            CONTACTS -> listOf(ContactsContract.AUTHORITY)
            EVENTS -> listOf(CalendarContract.AUTHORITY)
            TASKS -> TaskProvider.ProviderName.entries.map { it.authority }
            DEFAULT -> emptyList()
        }

    /**
@@ -54,6 +56,7 @@ enum class SyncDataType {
                .tasksAppManager()
                .currentProvider()
                ?.authority
            DEFAULT -> ""
        }


+3 −0
Original line number Diff line number Diff line
@@ -173,6 +173,9 @@ abstract class BaseSyncWorker(
                    }
                }
            }
            SyncDataType.DEFAULT -> {
                return Result.success()
            }
        }

        // Start syncing
+9 −0
Original line number Diff line number Diff line
@@ -69,6 +69,8 @@ class AccountSettingsModel @AssistedInject constructor(
        val syncIntervalCalendars: Long? = null,
        val hasTasksSync: Boolean = false,
        val syncIntervalTasks: Long? = null,
        val hasDefaultSync: Boolean = false,
        val syncIntervalDefault: Long? = null,

        val syncWifiOnly: Boolean = false,
        val syncWifiOnlySSIDs: List<String>? = null,
@@ -167,6 +169,13 @@ class AccountSettingsModel @AssistedInject constructor(
        }
    }

    fun updateDefaultSyncInterval(syncInterval: Long) {
        CoroutineScope(defaultDispatcher).launch {
            accountSettings.setSyncInterval(SyncDataType.DEFAULT, syncInterval.takeUnless { it == -1L })
            reload()
        }
    }

    fun updateSyncWifiOnly(wifiOnly: Boolean) = CoroutineScope(defaultDispatcher).launch {
        accountSettings.setSyncWiFiOnly(wifiOnly)
        reload()
Loading