1
0
mirror of https://github.com/etesync/android synced 2024-12-22 22:58:29 +00:00

Cleanup handling of notification errors.

This commit is contained in:
Tom Hacohen 2017-02-20 19:57:03 +00:00
parent d832ae9bc6
commit 2225ee0a03
8 changed files with 25 additions and 27 deletions

View File

@ -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";
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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:

View File

@ -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<AccountSettings> onCreateLoader(int id, Bundle args) {
return new AccountSettingsLoader(getContext(), (Account)args.getParcelable(EXTRA_ACCOUNT));
return new AccountSettingsLoader(getContext(), (Account)args.getParcelable(KEY_ACCOUNT));
}
@Override

View File

@ -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<String> {
public static final String
KEY_THROWABLE = "throwable",
KEY_LOGS = "logs",
KEY_ACCOUNT = "account",
KEY_AUTHORITY = "authority",
KEY_PHASE = "phase";

View File

@ -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);
}
})