Cloning reusable lists working, naming of copies not handled well

pull/14/head
Sam Bosley 13 years ago
parent aac0b196fe
commit 5af9915ef5

@ -206,7 +206,7 @@ public final class ActFmDataService {
@SuppressWarnings("nls")
public void saveFeaturedList(JSONObject featObject) throws JSONException {
TodorooCursor<TagData> cursor = tagDataService.query(Query.select(TagData.PROPERTIES).where(
Criterion.and(Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_FEATURED).gt(0),TagData.REMOTE_ID.eq(featObject.get("id")))));
Criterion.and(Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_FEATURED).gt(0), TagData.REMOTE_ID.eq(featObject.get("id")))));
try {
cursor.moveToNext();
TagData tagData = new TagData();

@ -40,6 +40,7 @@ import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
@ -827,7 +828,9 @@ public final class ActFmSyncService {
if(serverTime == 0) {
Long[] remoteIdArray = remoteIds.toArray(new Long[remoteIds.size()]);
tagDataService.deleteWhere(Criterion.not(TagData.REMOTE_ID.in(remoteIdArray)));
tagDataService.deleteWhere(Criterion.and(
Criterion.not(Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_FEATURED).gt(0)),
Criterion.not(TagData.REMOTE_ID.in(remoteIdArray))));
}
return result.optInt("time", 0);
@ -1201,6 +1204,7 @@ public final class ActFmSyncService {
} catch (SQLiteConstraintException e) {
taskDao.handleSQLiteConstraintException(remote);
}
ids.add(remote.getId());
metadataService.synchronizeMetadata(remote.getId(), metadata, MetadataCriteria.withKey(TagService.KEY));
synchronizeAttachments(item, remote);
@ -1435,6 +1439,7 @@ public final class ActFmSyncService {
model.clearValue(TagData.REMOTE_ID);
model.setValue(TagData.REMOTE_ID, json.getLong("id"));
model.setValue(TagData.NAME, json.getString("name"));
if (!featuredList)
readUser(json.getJSONObject("user"), model, TagData.USER_ID, TagData.USER);

@ -19,6 +19,7 @@ import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.Preferences;
@ -366,10 +367,12 @@ public class ActFmSyncV2Provider extends SyncV2Provider {
private void pushQueuedTags(final SyncResultCallback callback,
final AtomicInteger finisher, int lastTagSyncTime) {
TodorooCursor<TagData> tagDataCursor = tagDataService.query(Query.select(TagData.PROPERTIES)
.where(Criterion.or(
.where(Criterion.and(
Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_FEATURED).eq(0),
Criterion.or(
TagData.REMOTE_ID.eq(0),
Criterion.and(TagData.REMOTE_ID.gt(0),
TagData.MODIFICATION_DATE.gt(lastTagSyncTime)))));
TagData.MODIFICATION_DATE.gt(lastTagSyncTime))))));
try {
pushQueued(callback, finisher, tagDataCursor, true, tagPusher);
} finally {

@ -19,7 +19,9 @@ public class FeaturedListActivity extends TaskListActivity {
private static final int[] FORBIDDEN_MENU_ITEMS = {
TaskListFragment.MENU_NEW_FILTER_ID,
TaskListFragment.MENU_ADDONS_ID,
MainMenuPopover.MAIN_MENU_ITEM_FRIENDS
TaskListFragment.MENU_SORT_ID,
MainMenuPopover.MAIN_MENU_ITEM_FRIENDS,
MainMenuPopover.MAIN_MENU_ITEM_FEATURED_LISTS,
};
@Override

@ -2,15 +2,23 @@ package com.todoroo.astrid.tags.reusable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.adapter.TaskAdapter;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.TagDataService;
public class FeaturedTaskListFragment extends TagViewFragment {
@Autowired private TagDataService tagDataService;
@Override
protected TaskAdapter createTaskAdapter(TodorooCursor<Task> cursor) {
return new ReusableTaskAdapter(this, R.layout.reusable_task_adapter_row,
@ -35,13 +43,52 @@ public class FeaturedTaskListFragment extends TagViewFragment {
@Override
protected void setUpMembersGallery() {
// Repurposed this method to set up listener for clone list button
View clone = getView().findViewById(R.id.clone_list);
clone.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.err.println("Cloning list");
}
});
if (taskAdapter == null || taskAdapter.getCount() == 0) {
clone.setOnClickListener(null);
} else {
clone.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Clone list
String localName = tagData.getValue(TagData.NAME) + " (Copy)";
long remoteId = 0;
TodorooCursor<TagData> existing = tagDataService.query(Query.select(TagData.REMOTE_ID)
.where(TagData.NAME.eqCaseInsensitive(localName)));
try {
if (existing.getCount() > 0) {
existing.moveToFirst();
TagData match = new TagData(existing);
remoteId = match.getValue(TagData.REMOTE_ID);
}
} finally {
existing.close();
}
TodorooCursor<Task> tasks = taskService.fetchFiltered(taskAdapter.getQuery(), null, Task.PROPERTIES);
try {
Task t = new Task();
for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) {
t.readFromCursor(tasks);
taskService.cloneReusableTask(t,
localName, remoteId);
}
DialogUtilities.okDialog(getActivity(), "Success!", null);
} finally {
tasks.close();
}
}
});
}
}
@Override
protected void refresh() {
loadTaskListContent(true);
((TextView)taskListView.findViewById(android.R.id.empty)).setText(R.string.TLA_no_items);
setUpMembersGallery();
}
}

@ -48,7 +48,7 @@ public class ReusableTaskAdapter extends TaskAdapter {
@Override
public void onClick(View v) {
ReusableTaskViewHolder holder = (ReusableTaskViewHolder) v.getTag();
taskService.cloneReusableTask(holder.task);
taskService.cloneReusableTask(holder.task, null, 0);
Flags.set(Flags.REFRESH);
}
});

@ -127,7 +127,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
public static final int MENU_ADDONS_ID = R.string.TLA_menu_addons;
protected static final int MENU_SETTINGS_ID = R.string.TLA_menu_settings;
protected static final int MENU_SORT_ID = R.string.TLA_menu_sort;
public static final int MENU_SORT_ID = R.string.TLA_menu_sort;
protected static final int MENU_SYNC_ID = R.string.TLA_menu_sync;
protected static final int MENU_SUPPORT_ID = R.string.TLA_menu_support;
public static final int MENU_NEW_FILTER_ID = R.string.FLA_new_filter;

@ -258,6 +258,10 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
return newCursor;
}
public String getQuery() {
return query.get();
}
/* ======================================================================
* =========================================================== view setup
* ====================================================================== */

@ -184,7 +184,7 @@ public class TaskService {
return newTask;
}
public Task cloneReusableTask(Task task) {
public Task cloneReusableTask(Task task, String listName, long remoteId) {
Task newTask = fetchById(task.getId(), Task.PROPERTIES);
if (newTask == null)
return new Task();
@ -194,6 +194,16 @@ public class TaskService {
newTask.clearValue(Task.USER_ID);
taskDao.save(newTask);
if (listName != null) {
Metadata tag = new Metadata();
tag.setValue(Metadata.TASK, newTask.getId());
tag.setValue(Metadata.KEY, TagService.KEY);
tag.setValue(TagService.TAG, listName);
if (remoteId > 0)
tag.setValue(TagService.REMOTE_ID, remoteId);
metadataDao.createNew(tag);
}
return newTask;
}

Loading…
Cancel
Save