Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
Signed-off-by: Arnau Mora Gras <arnyminerz@proton.me>
  • Loading branch information
ArnyminerZ committed Oct 10, 2024
1 parent 473e1a2 commit 04e183f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PushNotificationManager @Inject constructor(
Intent(context, AccountActivity::class.java).apply {
putExtra(AccountActivity.EXTRA_ACCOUNT, account)
},
PendingIntent.FLAG_IMMUTABLE
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
)
.build()
Expand All @@ -57,8 +57,9 @@ class PushNotificationManager @Inject constructor(
* Once the sync has been started, the notification is no longer needed and can be dismissed.
* It's safe to call this method even if the notification has not been shown.
*/
fun dismissScheduled(account: Account, authority: String) {
fun dismiss(account: Account, authority: String) {
NotificationManagerCompat.from(context)
.cancel(notificationId(account, authority))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ class UnifiedPushReceiver: MessagingReceiver() {
collectionRepository.getSyncableByTopic(topic)?.let { collection ->
serviceRepository.get(collection.serviceId)?.let { service ->
val account = accountRepository.fromName(service.accountName)
syncWorkerManager.enqueueOneTimeAllAuthorities(account, isPush = true)
syncWorkerManager.enqueueOneTimeAllAuthorities(account, fromPush = true)
}
}

} else {
logger.warning("Got push message without topic, syncing all accounts")
for (account in accountRepository.getAll())
syncWorkerManager.enqueueOneTimeAllAuthorities(account, isPush = true)
syncWorkerManager.enqueueOneTimeAllAuthorities(account, fromPush = true)

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ abstract class BaseSyncWorker(
}

// Dismiss any pending push notification
pushNotificationManager.dismissScheduled(account, authority)
pushNotificationManager.dismiss(account, authority)

try {
val accountSettings = try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class SyncWorkerManager @Inject constructor(
* @param manual user-initiated sync (ignores network checks)
* @param resync whether to request (full) re-synchronization or not
* @param upload see [ContentResolver.SYNC_EXTRAS_UPLOAD] – only used for contacts sync and Android 7 workaround
* @param isPush whether this sync is initiated by a push notification
* @param fromPush whether this sync is initiated by a push notification
*
* @return existing or newly created worker name
*/
Expand All @@ -118,7 +118,7 @@ class SyncWorkerManager @Inject constructor(
manual: Boolean = false,
@InputResync resync: Int = NO_RESYNC,
upload: Boolean = false,
isPush: Boolean = false
fromPush: Boolean = false
): String {
// enqueue and start syncing
val name = workerName(account, authority)
Expand All @@ -129,7 +129,7 @@ class SyncWorkerManager @Inject constructor(
resync = resync,
upload = upload
)
if (isPush) {
if (fromPush) {
logger.fine("Showing push sync pending notification for $name")
pushNotificationManager.notify(account, authority)
}
Expand All @@ -156,7 +156,7 @@ class SyncWorkerManager @Inject constructor(
manual: Boolean = false,
@InputResync resync: Int = NO_RESYNC,
upload: Boolean = false,
isPush: Boolean = false
fromPush: Boolean = false
) {
for (authority in SyncUtils.syncAuthorities(context))
enqueueOneTime(
Expand All @@ -165,7 +165,7 @@ class SyncWorkerManager @Inject constructor(
manual = manual,
resync = resync,
upload = upload,
isPush = isPush
fromPush = fromPush
)
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@
<string name="sync_invalid_task">Received invalid task from server</string>
<string name="sync_invalid_resources_ignoring">Ignoring one or more invalid resources</string>
<string name="sync_notification_pending_push_title">Sync pending</string>
<string name="sync_notification_pending_push_message">Received a push notification from server. Waiting to sync…</string>
<string name="sync_notification_pending_push_message">Remote data have changed</string>

<!-- widgets -->
<string name="widget_sync_all">Sync all</string>
Expand Down

0 comments on commit 04e183f

Please sign in to comment.