PersonViewFragment syncs tasks for that user

pull/14/head
Sam Bosley 13 years ago
parent 1896fe89c7
commit 3fb9899582

@ -740,6 +740,10 @@ public final class ActFmSyncService {
}, done, "tasks:" + tagData.getId(), "tag_id", tagData.getValue(TagData.REMOTE_ID));
}
public void fetchTasksForUser(final User user, final boolean manual, Runnable done) {
invokeFetchList("task", manual, null, new TaskListItemProcessor(false),
done, "user_" + user.getId(), "user_id", user.getValue(User.REMOTE_ID));
}
/**

@ -25,6 +25,7 @@ import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.service.TaskService;
@ -273,6 +274,11 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
public void synchronizeList(Object list, final boolean manual,
final SyncResultCallback callback) {
if (list instanceof User) {
synchronizeUser((User) list, manual, callback);
return;
}
if(!(list instanceof TagData))
return;
@ -299,6 +305,27 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
}).start();
}
private void synchronizeUser(final User user, final boolean manual, final SyncResultCallback callback) {
if (user.getValue(User.REMOTE_ID) == 0)
return;
new Thread(new Runnable() {
@Override
public void run() {
callback.started();
callback.incrementMax(100);
actFmSyncService.waitUntilEmpty();
actFmSyncService.fetchTasksForUser(user, manual, new Runnable() {
public void run() {
callback.finished();
}
});
callback.incrementProgress(50);
}
}).start();
}
private void fetchTagData(final TagData tagData, final boolean noRemoteId,
final boolean manual, final SyncResultCallback callback,
final AtomicInteger finisher) {

@ -1,27 +1,48 @@
package com.todoroo.astrid.people;
import android.content.Intent;
import android.support.v4.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.dao.UserDao;
import com.todoroo.astrid.data.User;
import com.todoroo.astrid.helper.ProgressBarSyncResultCallback;
import com.todoroo.astrid.service.SyncV2Service;
import com.todoroo.astrid.service.ThemeService;
public class PersonViewFragment extends TaskListFragment {
public static final String EXTRA_USER_ID_LOCAL = "user_local_id"; //$NON-NLS-1$
private static final String LAST_FETCH_KEY = "actfm_last_user_"; //$NON-NLS-1$
protected static final int MENU_REFRESH_ID = MENU_SUPPORT_ID + 1;
@Autowired UserDao userDao;
@Autowired SyncV2Service syncService;
@Autowired ActFmPreferenceService actFmPreferenceService;
protected View taskListView;
private User user;
@Override
protected View getListBody(ViewGroup root) {
ViewGroup parent = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.task_list_body_person, root, false);
View taskListView = super.getListBody(parent);
taskListView = super.getListBody(parent);
parent.addView(taskListView);
return parent;
@ -38,7 +59,56 @@ public class PersonViewFragment extends TaskListFragment {
protected void setupQuickAddBar() {
super.setupQuickAddBar();
quickAddBar.setUsePeopleControl(false);
if (user != null)
quickAddBar.getQuickAddBox().setHint(getString(R.string.TLA_quick_add_hint_assign, user.getDisplayName()));
}
@Override
protected void addSyncRefreshMenuItem(Menu menu, int themeFlags) {
if(actFmPreferenceService.isLoggedIn()) {
addMenuItem(menu, R.string.actfm_TVA_menu_refresh,
ThemeService.getDrawable(R.drawable.icn_menu_refresh, themeFlags), MENU_REFRESH_ID, true);
} else {
super.addSyncRefreshMenuItem(menu, themeFlags);
}
}
@Override
public boolean handleOptionsMenuItemSelected(int id, Intent intent) {
switch (id) {
case MENU_REFRESH_ID:
refreshData(true);
return true;
}
return super.handleOptionsMenuItemSelected(id, intent);
}
@Override
protected void initiateAutomaticSyncImpl() {
if (!isCurrentTaskListFragment())
return;
if (user != null) {
long lastAutoSync = Preferences.getLong(LAST_FETCH_KEY + user.getId(), 0);
if (DateUtilities.now() - lastAutoSync > DateUtilities.ONE_HOUR)
refreshData(false);
}
}
private void refreshData(final boolean manual) {
((TextView)taskListView.findViewById(android.R.id.empty)).setText(R.string.DLG_loading);
syncService.synchronizeList(user, manual, new ProgressBarSyncResultCallback(getActivity(), this,
R.id.progressBar, new Runnable() {
@Override
public void run() {
if (manual)
ContextManager.getContext().sendBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH));
else
refresh();
((TextView)taskListView.findViewById(android.R.id.empty)).setText(R.string.TLA_no_items);
}
}));
}
}

Loading…
Cancel
Save