everysync: update syncing
- Commit
54ec423db587073d625a4509cdb6a5870ee03631- Author
- Vayun Mathur <[email protected]>
- When
- 2026-07-18 16:20 UTC (4 months ago)
- Parents
eb2f077
Diff
everysync/src/main/java/com/vayunmathur/everysync/sink/CalendarSink.kt
diff --git a/everysync/src/main/java/com/vayunmathur/everysync/sink/CalendarSink.kt b/everysync/src/main/java/com/vayunmathur/everysync/sink/CalendarSink.ktindex a18372cddb..066111cd22 100644--- a/everysync/src/main/java/com/vayunmathur/everysync/sink/CalendarSink.kt+++ b/everysync/src/main/java/com/vayunmathur/everysync/sink/CalendarSink.kt@@ -175,6 +175,24 @@ object CalendarSink { } } + /**+ * Removes every calendar (and, by cascade, its events) for this account from+ * the on-device provider. Used when the user turns calendar sync off; the+ * account itself stays, so a later re-enable can repopulate it from a fresh+ * pull. Deleting via the sync-adapter URI hard-removes the rows.+ */+ fun purge(context: Context, accountName: String) {+ try {+ context.contentResolver.delete(+ CalendarContract.Calendars.CONTENT_URI.asSyncAdapter(accountName),+ "${CalendarContract.Calendars.ACCOUNT_NAME} = ? AND ${CalendarContract.Calendars.ACCOUNT_TYPE} = ?",+ arrayOf(accountName, ACCOUNT_TYPE),+ )+ } catch (e: Exception) {+ Log.e(TAG, "purge failed", e)+ }+ }+ fun localCalendars(context: Context, accountName: String): List<Long> { val ids = mutableListOf<Long>() try {
everysync/src/main/java/com/vayunmathur/everysync/sink/ContactsSink.kt
diff --git a/everysync/src/main/java/com/vayunmathur/everysync/sink/ContactsSink.kt b/everysync/src/main/java/com/vayunmathur/everysync/sink/ContactsSink.ktindex e13b7ecd5a..e7aa81de96 100644--- a/everysync/src/main/java/com/vayunmathur/everysync/sink/ContactsSink.kt+++ b/everysync/src/main/java/com/vayunmathur/everysync/sink/ContactsSink.kt@@ -128,6 +128,24 @@ object ContactsSink { } } + /**+ * Removes every raw contact for this account from the on-device provider.+ * Used when the user turns contact sync off; the account itself stays, so a+ * later re-enable can repopulate it from a fresh pull. Deleting via the+ * sync-adapter URI hard-removes the rows rather than marking them DELETED.+ */+ fun purge(context: Context, accountName: String) {+ try {+ context.contentResolver.delete(+ ContactsContract.RawContacts.CONTENT_URI.asSyncAdapter(accountName),+ "${ContactsContract.RawContacts.ACCOUNT_NAME} = ? AND ${ContactsContract.RawContacts.ACCOUNT_TYPE} = ?",+ arrayOf(accountName, ACCOUNT_TYPE),+ )+ } catch (e: Exception) {+ Log.e(TAG, "purge failed", e)+ }+ }+ /** Contacts the user edited/deleted locally (DIRTY/DELETED set by other apps). */ fun getLocalChanges(context: Context, accountName: String): List<LocalContactChange> { val changes = mutableListOf<LocalContactChange>()
everysync/src/main/java/com/vayunmathur/everysync/ui/EverySyncViewModel.kt
diff --git a/everysync/src/main/java/com/vayunmathur/everysync/ui/EverySyncViewModel.kt b/everysync/src/main/java/com/vayunmathur/everysync/ui/EverySyncViewModel.ktindex bf398d6ec8..65a9cde248 100644--- a/everysync/src/main/java/com/vayunmathur/everysync/ui/EverySyncViewModel.kt+++ b/everysync/src/main/java/com/vayunmathur/everysync/ui/EverySyncViewModel.kt@@ -11,12 +11,16 @@ import com.vayunmathur.everysync.auth.OAuthManager import com.vayunmathur.everysync.auth.TokenStore import com.vayunmathur.everysync.provider.DataType import com.vayunmathur.everysync.provider.ProviderRegistry+import com.vayunmathur.everysync.sink.CalendarSink+import com.vayunmathur.everysync.sink.ContactsSink import com.vayunmathur.everysync.sync.SyncScheduler import com.vayunmathur.everysync.sync.SyncStatus+import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch+import kotlinx.coroutines.withContext class EverySyncViewModel(app: Application) : AndroidViewModel(app) { private val store = AccountStore.getInstance(app)@@ -84,6 +88,21 @@ class EverySyncViewModel(app: Application) : AndroidViewModel(app) { val config = store.get(accountName) ?: return@launch val types = if (enabled) config.enabledTypes + type else config.enabledTypes - type store.upsert(config.copy(enabledTypes = types))+ val app = getApplication<Application>()+ if (enabled) {+ // Re-sync so the just-enabled type is repopulated on-device.+ SyncScheduler.syncNow(app, accountName)+ } else {+ // Remove the disabled type's data from the on-device provider so it+ // doesn't linger; it will be pulled again if re-enabled.+ withContext(Dispatchers.IO) {+ when (type) {+ DataType.CONTACTS -> ContactsSink.purge(app, accountName)+ DataType.CALENDAR -> CalendarSink.purge(app, accountName)+ DataType.HEALTH -> {}+ }+ }+ } } }