private final ContentResolver mResolver;
private final SelectCalendarsActivity mActivity;
private final View mView;
+ private final static Runnable mStopRefreshing = new Runnable() {
+ public void run() {
+ mRefresh = false;
+ }
+ };
private Map<String, AuthenticatorDescription> mTypeToAuthDescription
= new HashMap<String, AuthenticatorDescription>();
protected AuthenticatorDescription[] mAuthDescs;
private static final int REFRESH_DELAY = 5000;
// How long to keep refreshing for
private static final int REFRESH_DURATION = 60000;
- private boolean mRefresh = true;
+ private static boolean mRefresh = true;
private int mNumAccounts;
private static String syncedVisible;
return;
}
- // Set up a refresh for some point in the future if we haven't reached our max number
- // of requeries yet. To make the code to track this easier we just use one count across
- // all accounts and scale our max by the number of accounts.
- if(mRefresh) {
- mView.postDelayed(new RefreshCalendars(token, cookie), REFRESH_DELAY);
- }
-
Cursor currentCursor = mChildrenCursors.get(cookie);
// Check if the new cursor has the same content as our old cursor
if (currentCursor != null) {
setChildrenCursor(token, newCursor);
mActivity.startManagingCursor(newCursor);
} catch (NullPointerException e) {
- Log.w(TAG, "Adapter expired, try again on the next query: " + e.getMessage());
+ Log.w(TAG, "Adapter expired, try again on the next query: " + e);
}
// Clean up our old cursor if we had one. We have to do this after setting the new
// cursor so that our view doesn't throw on an invalid cursor.
mTypeToAuthDescription.put(mAuthDescs[i].type, mAuthDescs[i]);
}
mView = mActivity.getExpandableListView();
- mView.postDelayed(new Runnable() {
- public void run() {
- mRefresh = false;
- }
- }, REFRESH_DURATION);
+ mRefresh = true;
+ }
+
+ public void startRefreshStopDelay() {
+ mRefresh = true;
+ mView.postDelayed(mStopRefreshing, REFRESH_DURATION);
+ }
+
+ public void cancelRefreshStopDelay() {
+ mView.removeCallbacks(mStopRefreshing);
}
/*
// First see if the user has already changed the state of this calendar
Boolean[] initialState = mCalendarChanges.get(id);
- // if not just grab the initial state
+ // if we haven't already started making changes update the initial state in case it changed
if (initialState == null) {
- initialState = mCalendarInitialStates.get(id);
- }
- // and create a new initial state if we've never seen this calendar before.
- if(initialState == null) {
initialState = new Boolean[CHANGES_SIZE];
initialState[SELECTED_INDEX] = cursor.getInt(SELECTED_COLUMN) == 1;
initialState[SYNCED_INDEX] = cursor.getInt(SYNCED_COLUMN) == 1;
String account = groupCursor.getString(accountColumn);
//Get all the calendars for just this account.
Cursor childCursor = mChildrenCursors.get(account);
- mCalendarsUpdater.startQuery(groupCursor.getPosition(),
- account,
- Calendars.CONTENT_URI, PROJECTION,
- ACCOUNT_SELECTION,
- new String[] { account } /*selectionArgs*/,
- CALENDARS_ORDERBY);
+ new RefreshCalendars(groupCursor.getPosition(), account).run();
return childCursor;
}
}
public void run() {
+ mCalendarsUpdater.cancelOperation(mToken);
+ // Set up a refresh for some point in the future if we haven't stopped updates yet
+ if(mRefresh) {
+ mView.postDelayed(new RefreshCalendars(mToken, mAccount), REFRESH_DELAY);
+ }
mCalendarsUpdater.startQuery(mToken,
mAccount,
Calendars.CONTENT_URI, PROJECTION,