diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagUpdatesFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagUpdatesFragment.java index b00b3e579..8b23289a6 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagUpdatesFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagUpdatesFragment.java @@ -309,7 +309,7 @@ public class TagUpdatesFragment extends ListFragment { private void refreshActivity(boolean manual) { if (actFmPreferenceService.isLoggedIn()) { final ProgressBarSyncResultCallback callback = new ProgressBarSyncResultCallback( - getActivity(), R.id.progressBar, new Runnable() { + getActivity(), this, R.id.progressBar, new Runnable() { @Override public void run() { refreshUpdatesList(); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java index 0f11107ea..be3d28942 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewFragment.java @@ -1,7 +1,5 @@ package com.todoroo.astrid.actfm; -import com.todoroo.astrid.helper.AsyncImageView; - import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -52,6 +50,7 @@ import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Update; +import com.todoroo.astrid.helper.AsyncImageView; import com.todoroo.astrid.helper.ProgressBarSyncResultCallback; import com.todoroo.astrid.service.SyncV2Service; import com.todoroo.astrid.service.TagDataService; @@ -257,7 +256,9 @@ public class TagViewFragment extends TaskListFragment { @Override - protected void initiateAutomaticSync() { + public void initiateAutomaticSync() { + if (!isCurrentTaskListFragment()) + return; if (tagData != null) { long lastAutoSync = Preferences.getLong(LAST_FETCH_KEY + tagData.getId(), 0); if(DateUtilities.now() - lastAutoSync > DateUtilities.ONE_HOUR) @@ -269,7 +270,7 @@ public class TagViewFragment extends TaskListFragment { private void refreshData(final boolean manual) { ((TextView)taskListView.findViewById(android.R.id.empty)).setText(R.string.DLG_loading); - syncService.synchronizeList(tagData, manual, new ProgressBarSyncResultCallback(getActivity(), + syncService.synchronizeList(tagData, manual, new ProgressBarSyncResultCallback(getActivity(), this, R.id.progressBar, new Runnable() { @Override public void run() { diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListFragment.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListFragment.java index aba820a0d..7b3e4c3f7 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListFragment.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksListFragment.java @@ -78,7 +78,9 @@ public class GtasksListFragment extends SubtasksListFragment { } @Override - protected void initiateAutomaticSync() { + public void initiateAutomaticSync() { + if (!isCurrentTaskListFragment()) + return; if (list != null && DateUtilities.now() - list.getValue(GtasksList.LAST_SYNC) > DateUtilities.ONE_HOUR) { syncService.synchronizeList(list, false, syncActionHelper.syncResultCallback); } diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java index 4fa8fa6bb..f1b62f09b 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java @@ -404,6 +404,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener if (tlfPagerAdapter != null) { configureIntentAndExtrasWithFilter(getIntent(), tlfPagerAdapter.getFilter(position)); setListsTitle(tlfPagerAdapter.getPageTitle(position).toString()); + getTaskListFragment().initiateAutomaticSync(); } } diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java index 40de3bcb8..43cadcc8d 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java @@ -584,8 +584,17 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, initiateAutomaticSync(); } - protected void initiateAutomaticSync() { - syncActionHelper.initiateAutomaticSync(filter); + protected boolean isCurrentTaskListFragment() { + AstridActivity activity = (AstridActivity) getActivity(); + if (activity != null) { + return activity.getTaskListFragment() == this; + } + return false; + } + + public void initiateAutomaticSync() { + if (isCurrentTaskListFragment()) + syncActionHelper.initiateAutomaticSync(filter); } @Override diff --git a/astrid/src/com/todoroo/astrid/helper/ProgressBarSyncResultCallback.java b/astrid/src/com/todoroo/astrid/helper/ProgressBarSyncResultCallback.java index 625d59ac3..3446846cf 100644 --- a/astrid/src/com/todoroo/astrid/helper/ProgressBarSyncResultCallback.java +++ b/astrid/src/com/todoroo/astrid/helper/ProgressBarSyncResultCallback.java @@ -3,6 +3,7 @@ package com.todoroo.astrid.helper; import java.util.concurrent.atomic.AtomicInteger; import android.app.Activity; +import android.support.v4.app.Fragment; import android.view.View; import android.view.animation.AlphaAnimation; import android.widget.ProgressBar; @@ -18,9 +19,9 @@ public class ProgressBarSyncResultCallback extends SyncResultCallbackAdapter { private final AtomicInteger providers = new AtomicInteger(0); - public ProgressBarSyncResultCallback(Activity activity, + public ProgressBarSyncResultCallback(Activity activity, Fragment fragment, int progressBarId, Runnable onFinished) { - this.progressBar = (ProgressBar) activity.findViewById(progressBarId); + this.progressBar = (ProgressBar) fragment.getView().findViewById(progressBarId); this.activity = activity; this.onFinished = onFinished; diff --git a/astrid/src/com/todoroo/astrid/helper/SyncActionHelper.java b/astrid/src/com/todoroo/astrid/helper/SyncActionHelper.java index c73950519..ae81d5193 100644 --- a/astrid/src/com/todoroo/astrid/helper/SyncActionHelper.java +++ b/astrid/src/com/todoroo/astrid/helper/SyncActionHelper.java @@ -72,7 +72,7 @@ public class SyncActionHelper { this.activity = activity; this.fragment = fragment; - syncResultCallback = new ProgressBarSyncResultCallback(activity, + syncResultCallback = new ProgressBarSyncResultCallback(activity, fragment, R.id.progressBar, new Runnable() { @Override public void run() {