From 2225ee0a03c9d91a4f44acbdd5f114a52df656ea Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 20 Feb 2017 19:57:03 +0000 Subject: [PATCH] Cleanup handling of notification errors. --- app/src/main/java/at/bitfire/davdroid/Constants.java | 2 ++ .../syncadapter/CalendarsSyncAdapterService.java | 9 ++++----- .../syncadapter/ContactsSyncAdapterService.java | 9 ++++----- .../at/bitfire/davdroid/syncadapter/SyncManager.java | 12 ++++-------- .../java/at/bitfire/davdroid/ui/AccountActivity.java | 4 ++-- .../bitfire/davdroid/ui/AccountSettingsActivity.java | 10 +++++----- .../at/bitfire/davdroid/ui/DebugInfoActivity.java | 3 ++- .../bitfire/davdroid/ui/ExceptionInfoFragment.java | 3 ++- 8 files changed, 25 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/Constants.java b/app/src/main/java/at/bitfire/davdroid/Constants.java index e618a805..be1bbde6 100644 --- a/app/src/main/java/at/bitfire/davdroid/Constants.java +++ b/app/src/main/java/at/bitfire/davdroid/Constants.java @@ -38,4 +38,6 @@ public class Constants { public static final int DEFAULT_SYNC_INTERVAL = 4 * 3600; // 4 hours public static final long DEFAULT_RETRY_DELAY = 30 * 60; // 30 minutes + + public final static String KEY_ACCOUNT = "account"; } 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 b44945e7..c087cf6b 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java @@ -38,12 +38,13 @@ import at.bitfire.davdroid.model.ServiceDB; import at.bitfire.davdroid.model.ServiceDB.Collections; import at.bitfire.davdroid.model.ServiceDB.Services; import at.bitfire.davdroid.resource.LocalCalendar; -import at.bitfire.davdroid.ui.AccountSettingsActivity; import at.bitfire.davdroid.ui.DebugInfoActivity; import at.bitfire.ical4android.CalendarStorageException; import lombok.Cleanup; import okhttp3.HttpUrl; +import static at.bitfire.davdroid.Constants.KEY_ACCOUNT; + public class CalendarsSyncAdapterService extends SyncAdapterService { @Override @@ -94,10 +95,8 @@ public class CalendarsSyncAdapterService extends SyncAdapterService { notificationManager.setThrowable(e); final Intent detailsIntent = notificationManager.getDetailsIntent(); - if (e instanceof Exceptions.UnauthorizedException) { - detailsIntent.putExtra(AccountSettingsActivity.EXTRA_ACCOUNT, account); - } else { - detailsIntent.putExtra(DebugInfoActivity.KEY_ACCOUNT, account); + detailsIntent.putExtra(KEY_ACCOUNT, account); + if (!(e instanceof Exceptions.UnauthorizedException)) { detailsIntent.putExtra(DebugInfoActivity.KEY_AUTHORITY, authority); detailsIntent.putExtra(DebugInfoActivity.KEY_PHASE, syncPhase); } 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 dd92544d..e87da668 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncAdapterService.java @@ -34,11 +34,12 @@ import at.bitfire.davdroid.journalmanager.Exceptions; import at.bitfire.davdroid.model.CollectionInfo; import at.bitfire.davdroid.model.ServiceDB; import at.bitfire.davdroid.model.ServiceDB.Collections; -import at.bitfire.davdroid.ui.AccountSettingsActivity; import at.bitfire.davdroid.ui.DebugInfoActivity; import lombok.Cleanup; import okhttp3.HttpUrl; +import static at.bitfire.davdroid.Constants.KEY_ACCOUNT; + public class ContactsSyncAdapterService extends SyncAdapterService { @Override @@ -90,10 +91,8 @@ public class ContactsSyncAdapterService extends SyncAdapterService { notificationManager.setThrowable(e); final Intent detailsIntent = notificationManager.getDetailsIntent(); - if (e instanceof Exceptions.UnauthorizedException) { - detailsIntent.putExtra(AccountSettingsActivity.EXTRA_ACCOUNT, account); - } else { - detailsIntent.putExtra(DebugInfoActivity.KEY_ACCOUNT, account); + detailsIntent.putExtra(KEY_ACCOUNT, account); + if (!(e instanceof Exceptions.UnauthorizedException)) { detailsIntent.putExtra(DebugInfoActivity.KEY_AUTHORITY, authority); detailsIntent.putExtra(DebugInfoActivity.KEY_PHASE, syncPhase); } 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 76ae6a4f..6320f62d 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/SyncManager.java @@ -19,11 +19,8 @@ import org.apache.commons.collections4.ListUtils; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.UUID; import java.util.logging.Level; @@ -40,7 +37,6 @@ import at.bitfire.davdroid.journalmanager.JournalEntryManager; import at.bitfire.davdroid.model.CollectionInfo; import at.bitfire.davdroid.resource.LocalCollection; import at.bitfire.davdroid.resource.LocalResource; -import at.bitfire.davdroid.ui.AccountSettingsActivity; import at.bitfire.davdroid.ui.DebugInfoActivity; import at.bitfire.ical4android.CalendarStorageException; import at.bitfire.ical4android.InvalidCalendarException; @@ -48,6 +44,8 @@ import at.bitfire.vcard4android.ContactsStorageException; import lombok.Getter; import okhttp3.OkHttpClient; +import static at.bitfire.davdroid.Constants.KEY_ACCOUNT; + abstract public class SyncManager { protected final NotificationHelper notificationManager; protected final String uniqueCollectionId; @@ -192,10 +190,8 @@ abstract public class SyncManager { notificationManager.setThrowable(e); final Intent detailsIntent = notificationManager.getDetailsIntent(); - if (e instanceof Exceptions.UnauthorizedException) { - detailsIntent.putExtra(AccountSettingsActivity.EXTRA_ACCOUNT, account); - } else { - detailsIntent.putExtra(DebugInfoActivity.KEY_ACCOUNT, account); + detailsIntent.putExtra(KEY_ACCOUNT, account); + if (!(e instanceof Exceptions.UnauthorizedException)) { detailsIntent.putExtra(DebugInfoActivity.KEY_AUTHORITY, authority); detailsIntent.putExtra(DebugInfoActivity.KEY_PHASE, syncPhase); } diff --git a/app/src/main/java/at/bitfire/davdroid/ui/AccountActivity.java b/app/src/main/java/at/bitfire/davdroid/ui/AccountActivity.java index 057c50e4..892f23e4 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/AccountActivity.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/AccountActivity.java @@ -49,7 +49,6 @@ import android.view.ViewGroup; import android.widget.AbsListView; import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.CheckBox; import android.widget.ListView; import android.widget.PopupMenu; import android.widget.ProgressBar; @@ -63,6 +62,7 @@ import java.util.logging.Level; import at.bitfire.cert4android.CustomCertManager; import at.bitfire.davdroid.AccountUpdateService; import at.bitfire.davdroid.App; +import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.R; import at.bitfire.davdroid.model.CollectionInfo; import at.bitfire.davdroid.model.ServiceDB.Collections; @@ -140,7 +140,7 @@ public class AccountActivity extends AppCompatActivity implements Toolbar.OnMenu break; case R.id.settings: Intent intent = new Intent(this, AccountSettingsActivity.class); - intent.putExtra(AccountSettingsActivity.EXTRA_ACCOUNT, account); + intent.putExtra(Constants.KEY_ACCOUNT, account); startActivity(intent); break; case R.id.delete_account: diff --git a/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java b/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java index 5c35b1d3..7b715736 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java @@ -35,16 +35,16 @@ import at.bitfire.davdroid.R; import at.bitfire.davdroid.ui.setup.LoginCredentials; import at.bitfire.davdroid.ui.setup.LoginCredentialsChangeFragment; -public class AccountSettingsActivity extends AppCompatActivity { - public final static String EXTRA_ACCOUNT = "account"; +import static at.bitfire.davdroid.Constants.KEY_ACCOUNT; +public class AccountSettingsActivity extends AppCompatActivity { private Account account; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - account = getIntent().getParcelableExtra(EXTRA_ACCOUNT); + account = getIntent().getParcelableExtra(KEY_ACCOUNT); setTitle(getString(R.string.settings_title, account.name)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -74,7 +74,7 @@ public class AccountSettingsActivity extends AppCompatActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - account = getArguments().getParcelable(EXTRA_ACCOUNT); + account = getArguments().getParcelable(KEY_ACCOUNT); getLoaderManager().initLoader(0, getArguments(), this); } @@ -86,7 +86,7 @@ public class AccountSettingsActivity extends AppCompatActivity { @Override public Loader onCreateLoader(int id, Bundle args) { - return new AccountSettingsLoader(getContext(), (Account)args.getParcelable(EXTRA_ACCOUNT)); + return new AccountSettingsLoader(getContext(), (Account)args.getParcelable(KEY_ACCOUNT)); } @Override diff --git a/app/src/main/java/at/bitfire/davdroid/ui/DebugInfoActivity.java b/app/src/main/java/at/bitfire/davdroid/ui/DebugInfoActivity.java index ad4e7e31..aa8772f2 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/DebugInfoActivity.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/DebugInfoActivity.java @@ -48,11 +48,12 @@ import at.bitfire.davdroid.journalmanager.Exceptions.HttpException; import at.bitfire.davdroid.model.ServiceDB; import lombok.Cleanup; +import static at.bitfire.davdroid.Constants.KEY_ACCOUNT; + public class DebugInfoActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks { public static final String KEY_THROWABLE = "throwable", KEY_LOGS = "logs", - KEY_ACCOUNT = "account", KEY_AUTHORITY = "authority", KEY_PHASE = "phase"; diff --git a/app/src/main/java/at/bitfire/davdroid/ui/ExceptionInfoFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/ExceptionInfoFragment.java index 68c3e207..c42b5d67 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/ExceptionInfoFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/ExceptionInfoFragment.java @@ -19,6 +19,7 @@ import android.support.v7.app.AlertDialog; import java.io.IOException; +import at.bitfire.davdroid.Constants; import at.bitfire.davdroid.R; import at.bitfire.davdroid.journalmanager.Exceptions.HttpException; @@ -59,7 +60,7 @@ public class ExceptionInfoFragment extends DialogFragment { Intent intent = new Intent(getContext(), DebugInfoActivity.class); intent.putExtra(DebugInfoActivity.KEY_THROWABLE, exception); if (account != null) - intent.putExtra(DebugInfoActivity.KEY_ACCOUNT, account); + intent.putExtra(Constants.KEY_ACCOUNT, account); startActivity(intent); } })