From d832ae9bc62ad1bae506bf1802e94bb87667c644 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 20 Feb 2017 19:47:14 +0000 Subject: [PATCH] Cleanup error messages in notifications. --- .../CalendarsSyncAdapterService.java | 4 +-- .../ContactsSyncAdapterService.java | 4 +-- .../davdroid/syncadapter/SyncManager.java | 33 +++++++------------ app/src/main/res/values/strings.xml | 24 ++++++-------- 4 files changed, 25 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java index cbda25a4..b44945e7 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java @@ -88,7 +88,7 @@ public class CalendarsSyncAdapterService extends SyncAdapterService { syncResult.databaseError = true; } - String syncPhase = SyncManager.SYNC_PHASE_JOURNALS; + int syncPhase = R.string.sync_phase_journals; String title = getContext().getString(R.string.sync_error_calendar, account.name); notificationManager.setThrowable(e); @@ -102,7 +102,7 @@ public class CalendarsSyncAdapterService extends SyncAdapterService { detailsIntent.putExtra(DebugInfoActivity.KEY_PHASE, syncPhase); } - notificationManager.notify(title, syncPhase); + notificationManager.notify(title, getContext().getString(syncPhase)); } App.log.info("Calendar sync complete"); diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java index 2120fb35..dd92544d 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java @@ -84,7 +84,7 @@ public class ContactsSyncAdapterService extends SyncAdapterService { syncResult.stats.numIoExceptions++; syncResult.delayUntil = (e.retryAfter > 0) ? e.retryAfter : Constants.DEFAULT_RETRY_DELAY; } catch (Exception | OutOfMemoryError e) { - String syncPhase = SyncManager.SYNC_PHASE_JOURNALS; + int syncPhase = R.string.sync_phase_journals; String title = getContext().getString(R.string.sync_error_contacts, account.name); notificationManager.setThrowable(e); @@ -97,7 +97,7 @@ public class ContactsSyncAdapterService extends SyncAdapterService { detailsIntent.putExtra(DebugInfoActivity.KEY_AUTHORITY, authority); detailsIntent.putExtra(DebugInfoActivity.KEY_PHASE, syncPhase); } - notificationManager.notify(title, syncPhase); + notificationManager.notify(title, getContext().getString(syncPhase)); } finally { dbHelper.close(); } diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java index 1fd9612f..76ae6a4f 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java @@ -34,6 +34,7 @@ import at.bitfire.davdroid.GsonHelper; import at.bitfire.davdroid.HttpClient; import at.bitfire.davdroid.InvalidAccountException; import at.bitfire.davdroid.NotificationHelper; +import at.bitfire.davdroid.R; import at.bitfire.davdroid.journalmanager.Exceptions; import at.bitfire.davdroid.journalmanager.JournalEntryManager; import at.bitfire.davdroid.model.CollectionInfo; @@ -48,18 +49,6 @@ import lombok.Getter; import okhttp3.OkHttpClient; abstract public class SyncManager { - - final static String SYNC_PHASE_PREPARE = "sync_phase_prepare", - SYNC_PHASE_JOURNALS = "sync_phase_journals", - SYNC_PHASE_QUERY_CAPABILITIES = "sync_phase_query_capabilities", - SYNC_PHASE_PREPARE_LOCAL = "sync_phase_prepare_local", - SYNC_PHASE_CREATE_LOCAL_ENTRIES = "sync_phase_create_local_entries", - SYNC_PHASE_FETCH_ENTRIES = "sync_phase_fetch_entries", - SYNC_PHASE_APPLY_REMOTE_ENTRIES = "sync_phase_apply_remote_entries", - SYNC_PHASE_APPLY_LOCAL_ENTRIES = "sync_phase_apply_local_entries", - SYNC_PHASE_PUSH_ENTRIES = "sync_phase_push_entries", - SYNC_PHASE_POST_PROCESSING = "sync_phase_post_processing"; - protected final NotificationHelper notificationManager; protected final String uniqueCollectionId; @@ -122,7 +111,7 @@ abstract public class SyncManager { @TargetApi(21) public void performSync() { - String syncPhase = SYNC_PHASE_PREPARE; + int syncPhase = R.string.sync_phase_prepare; try { App.log.info("Sync phase: " + syncPhase); if (!prepare()) { @@ -132,51 +121,51 @@ abstract public class SyncManager { if (Thread.interrupted()) return; - syncPhase = SYNC_PHASE_QUERY_CAPABILITIES; + syncPhase = R.string.sync_phase_query_capabilities; App.log.info("Sync phase: " + syncPhase); queryCapabilities(); if (Thread.interrupted()) return; - syncPhase = SYNC_PHASE_PREPARE_LOCAL; + syncPhase = R.string.sync_phase_prepare_local; App.log.info("Sync phase: " + syncPhase); prepareLocal(); if (Thread.interrupted()) return; - syncPhase = SYNC_PHASE_FETCH_ENTRIES; + syncPhase = R.string.sync_phase_fetch_entries; App.log.info("Sync phase: " + syncPhase); fetchEntries(); if (Thread.interrupted()) return; - syncPhase = SYNC_PHASE_APPLY_REMOTE_ENTRIES; + syncPhase = R.string.sync_phase_apply_remote_entries; App.log.info("Sync phase: " + syncPhase); applyRemoteEntries(); /* Create journal entries out of local changes. */ if (Thread.interrupted()) return; - syncPhase = SYNC_PHASE_CREATE_LOCAL_ENTRIES; + syncPhase = R.string.sync_phase_create_local_entries; App.log.info("Sync phase: " + syncPhase); createLocalEntries(); if (Thread.interrupted()) return; - syncPhase = SYNC_PHASE_APPLY_LOCAL_ENTRIES; + syncPhase = R.string.sync_phase_apply_local_entries; App.log.info("Sync phase: " + syncPhase); applyLocalEntries(); if (Thread.interrupted()) return; - syncPhase = SYNC_PHASE_PUSH_ENTRIES; + syncPhase = R.string.sync_phase_push_entries; App.log.info("Sync phase: " + syncPhase); pushEntries(); /* Cleanup and finalize changes */ if (Thread.interrupted()) return; - syncPhase = SYNC_PHASE_POST_PROCESSING; + syncPhase = R.string.sync_phase_post_processing; App.log.info("Sync phase: " + syncPhase); postProcess(); } catch (IOException e) { @@ -211,7 +200,7 @@ abstract public class SyncManager { detailsIntent.putExtra(DebugInfoActivity.KEY_PHASE, syncPhase); } - notificationManager.notify(getSyncErrorTitle(), syncPhase); + notificationManager.notify(getSyncErrorTitle(), context.getString(syncPhase)); } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4c2cd60b..9372a0a7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -269,20 +269,16 @@ Server error while %s Could not connect to server while %s Database error while %s - - preparing synchronization - querying capabilities - processing locally deleted entries - preparing created/modified entries - uploading created/modified entries - checking sync state - listing local entries - listing remote entries - comparing local/remote entries - downloading remote entries - post-processing - saving sync state - + preparing synchronization + syncronizing journals + querying capabilities + preparing local entries + creating local entries + fetching remote entries + applying remote entries + reapplying local entries + pushing entries + post processing Authentication failed