Only initiate autosync when fragment is swiped into view

pull/14/head
Sam Bosley 13 years ago
parent 44a425bad0
commit 1ddbba41d2

@ -309,7 +309,7 @@ public class TagUpdatesFragment extends ListFragment {
private void refreshActivity(boolean manual) { private void refreshActivity(boolean manual) {
if (actFmPreferenceService.isLoggedIn()) { if (actFmPreferenceService.isLoggedIn()) {
final ProgressBarSyncResultCallback callback = new ProgressBarSyncResultCallback( final ProgressBarSyncResultCallback callback = new ProgressBarSyncResultCallback(
getActivity(), R.id.progressBar, new Runnable() { getActivity(), this, R.id.progressBar, new Runnable() {
@Override @Override
public void run() { public void run() {
refreshUpdatesList(); refreshUpdatesList();

@ -1,7 +1,5 @@
package com.todoroo.astrid.actfm; package com.todoroo.astrid.actfm;
import com.todoroo.astrid.helper.AsyncImageView;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; 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.TagData;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update; import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.helper.AsyncImageView;
import com.todoroo.astrid.helper.ProgressBarSyncResultCallback; import com.todoroo.astrid.helper.ProgressBarSyncResultCallback;
import com.todoroo.astrid.service.SyncV2Service; import com.todoroo.astrid.service.SyncV2Service;
import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.TagDataService;
@ -257,7 +256,9 @@ public class TagViewFragment extends TaskListFragment {
@Override @Override
protected void initiateAutomaticSync() { public void initiateAutomaticSync() {
if (!isCurrentTaskListFragment())
return;
if (tagData != null) { if (tagData != null) {
long lastAutoSync = Preferences.getLong(LAST_FETCH_KEY + tagData.getId(), 0); long lastAutoSync = Preferences.getLong(LAST_FETCH_KEY + tagData.getId(), 0);
if(DateUtilities.now() - lastAutoSync > DateUtilities.ONE_HOUR) if(DateUtilities.now() - lastAutoSync > DateUtilities.ONE_HOUR)
@ -269,7 +270,7 @@ public class TagViewFragment extends TaskListFragment {
private void refreshData(final boolean manual) { private void refreshData(final boolean manual) {
((TextView)taskListView.findViewById(android.R.id.empty)).setText(R.string.DLG_loading); ((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() { R.id.progressBar, new Runnable() {
@Override @Override
public void run() { public void run() {

@ -78,7 +78,9 @@ public class GtasksListFragment extends SubtasksListFragment {
} }
@Override @Override
protected void initiateAutomaticSync() { public void initiateAutomaticSync() {
if (!isCurrentTaskListFragment())
return;
if (list != null && DateUtilities.now() - list.getValue(GtasksList.LAST_SYNC) > DateUtilities.ONE_HOUR) { if (list != null && DateUtilities.now() - list.getValue(GtasksList.LAST_SYNC) > DateUtilities.ONE_HOUR) {
syncService.synchronizeList(list, false, syncActionHelper.syncResultCallback); syncService.synchronizeList(list, false, syncActionHelper.syncResultCallback);
} }

@ -404,6 +404,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
if (tlfPagerAdapter != null) { if (tlfPagerAdapter != null) {
configureIntentAndExtrasWithFilter(getIntent(), tlfPagerAdapter.getFilter(position)); configureIntentAndExtrasWithFilter(getIntent(), tlfPagerAdapter.getFilter(position));
setListsTitle(tlfPagerAdapter.getPageTitle(position).toString()); setListsTitle(tlfPagerAdapter.getPageTitle(position).toString());
getTaskListFragment().initiateAutomaticSync();
} }
} }

@ -584,7 +584,16 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
initiateAutomaticSync(); initiateAutomaticSync();
} }
protected void initiateAutomaticSync() { protected boolean isCurrentTaskListFragment() {
AstridActivity activity = (AstridActivity) getActivity();
if (activity != null) {
return activity.getTaskListFragment() == this;
}
return false;
}
public void initiateAutomaticSync() {
if (isCurrentTaskListFragment())
syncActionHelper.initiateAutomaticSync(filter); syncActionHelper.initiateAutomaticSync(filter);
} }

@ -3,6 +3,7 @@ package com.todoroo.astrid.helper;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import android.app.Activity; import android.app.Activity;
import android.support.v4.app.Fragment;
import android.view.View; import android.view.View;
import android.view.animation.AlphaAnimation; import android.view.animation.AlphaAnimation;
import android.widget.ProgressBar; import android.widget.ProgressBar;
@ -18,9 +19,9 @@ public class ProgressBarSyncResultCallback extends SyncResultCallbackAdapter {
private final AtomicInteger providers = new AtomicInteger(0); private final AtomicInteger providers = new AtomicInteger(0);
public ProgressBarSyncResultCallback(Activity activity, public ProgressBarSyncResultCallback(Activity activity, Fragment fragment,
int progressBarId, Runnable onFinished) { int progressBarId, Runnable onFinished) {
this.progressBar = (ProgressBar) activity.findViewById(progressBarId); this.progressBar = (ProgressBar) fragment.getView().findViewById(progressBarId);
this.activity = activity; this.activity = activity;
this.onFinished = onFinished; this.onFinished = onFinished;

@ -72,7 +72,7 @@ public class SyncActionHelper {
this.activity = activity; this.activity = activity;
this.fragment = fragment; this.fragment = fragment;
syncResultCallback = new ProgressBarSyncResultCallback(activity, syncResultCallback = new ProgressBarSyncResultCallback(activity, fragment,
R.id.progressBar, new Runnable() { R.id.progressBar, new Runnable() {
@Override @Override
public void run() { public void run() {

Loading…
Cancel
Save