update for a comment being able to belong to multiple tags

pull/14/head
Tim Su 14 years ago
parent 7179a2fb30
commit d94c10b624

@ -47,8 +47,8 @@ public class Update extends RemoteModel {
public static final LongProperty TASK = new LongProperty( public static final LongProperty TASK = new LongProperty(
TABLE, "task"); TABLE, "task");
/** Associated Tag local-id (if any) */ /** Associated Tag remote-ids (comma separated list with leading and trailing commas) */
public static final LongProperty TAG = new LongProperty( public static final StringProperty TAGS = new StringProperty(
TABLE, "tag"); TABLE, "tag");
/** From user id */ /** From user id */
@ -99,7 +99,7 @@ public class Update extends RemoteModel {
static { static {
defaultValues.put(REMOTE_ID.name, 0); defaultValues.put(REMOTE_ID.name, 0);
defaultValues.put(TASK.name, 0); defaultValues.put(TASK.name, 0);
defaultValues.put(TAG.name, 0); defaultValues.put(TAGS.name, 0);
defaultValues.put(USER_ID.name, 0); defaultValues.put(USER_ID.name, 0);
defaultValues.put(USER.name, ""); defaultValues.put(USER.name, "");
defaultValues.put(ACTION.name, ""); defaultValues.put(ACTION.name, "");

@ -170,7 +170,7 @@ public class C2DMReceiver extends BroadcastReceiver {
message = message.substring(message.indexOf(':') + 2); message = message.substring(message.indexOf(':') + 2);
update.setValue(Update.MESSAGE, message); update.setValue(Update.MESSAGE, message);
update.setValue(Update.CREATION_DATE, DateUtilities.now()); update.setValue(Update.CREATION_DATE, DateUtilities.now());
update.setValue(Update.TAG, tagData.getId()); update.setValue(Update.TAGS, "," + intent.getStringExtra("tag_id") + ",");
updateDao.createNew(update); updateDao.createNew(update);
} catch (JSONException e) { } catch (JSONException e) {
// //

@ -605,12 +605,16 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList
}).start(); }).start();
} }
@SuppressWarnings("nls")
private void addComment() { private void addComment() {
if(tagData.getValue(TagData.REMOTE_ID) == 0L)
return;
Update update = new Update(); Update update = new Update();
update.setValue(Update.MESSAGE, addCommentField.getText().toString()); update.setValue(Update.MESSAGE, addCommentField.getText().toString());
update.setValue(Update.ACTION_CODE, "tag_comment"); //$NON-NLS-1$ update.setValue(Update.ACTION_CODE, "tag_comment");
update.setValue(Update.USER_ID, 0L); update.setValue(Update.USER_ID, 0L);
update.setValue(Update.TAG, tagData.getId()); update.setValue(Update.TAGS, "," + tagData.getValue(TagData.REMOTE_ID) + ",");
update.setValue(Update.CREATION_DATE, DateUtilities.now()); update.setValue(Update.CREATION_DATE, DateUtilities.now());
Flags.checkAndClear(Flags.SUPPRESS_SYNC); Flags.checkAndClear(Flags.SUPPRESS_SYNC);
updateDao.createNew(update); updateDao.createNew(update);

@ -32,7 +32,7 @@ public class ActFmInvoker {
public static final String PROVIDER_GOOGLE= "google"; public static final String PROVIDER_GOOGLE= "google";
public static final String PROVIDER_PASSWORD = "password"; public static final String PROVIDER_PASSWORD = "password";
private static final int API_VERSION = 1; private static final int API_VERSION = 2;
@Autowired private RestClient restClient; @Autowired private RestClient restClient;

@ -150,11 +150,10 @@ public final class ActFmSyncService {
ArrayList<Object> params = new ArrayList<Object>(); ArrayList<Object> params = new ArrayList<Object>();
params.add("message"); params.add(update.getValue(Update.MESSAGE)); params.add("message"); params.add(update.getValue(Update.MESSAGE));
if(update.getValue(Update.TAG) > 0) { if(update.getValue(Update.TAGS).length() > 0) {
TagData tagData = tagDataService.fetchById(update.getValue(Update.TAG), TagData.REMOTE_ID); String tagId = update.getValue(Update.TAGS);
if(tagData == null || tagData.getValue(TagData.REMOTE_ID) == 0) tagId = tagId.substring(1, tagId.indexOf(',', 1));
return; params.add("tag_id"); params.add(tagId);
params.add("tag_id"); params.add(tagData.getValue(TagData.REMOTE_ID));
} }
if(update.getValue(Update.TASK) > 0) { if(update.getValue(Update.TASK) > 0) {
@ -494,7 +493,7 @@ public final class ActFmSyncService {
for(int i = 0; i < list.length(); i++) { for(int i = 0; i < list.length(); i++) {
JSONObject item = list.getJSONObject(i); JSONObject item = list.getJSONObject(i);
readIds(locals, item, remote); readIds(locals, item, remote);
JsonHelper.updateFromJson(item, tagData, remote); JsonHelper.updateFromJson(item, remote);
Flags.set(Flags.SUPPRESS_SYNC); Flags.set(Flags.SUPPRESS_SYNC);
if(remote.getId() == AbstractModel.NO_ID) if(remote.getId() == AbstractModel.NO_ID)
@ -529,7 +528,7 @@ public final class ActFmSyncService {
for(int i = 0; i < list.length(); i++) { for(int i = 0; i < list.length(); i++) {
JSONObject item = list.getJSONObject(i); JSONObject item = list.getJSONObject(i);
readIds(locals, item, remote); readIds(locals, item, remote);
JsonHelper.updateFromJson(item, null, remote); JsonHelper.updateFromJson(item, remote);
System.err.println("GOJI BERRY: (" + remote.getId() + ") - " + remote.getSetValues()); System.err.println("GOJI BERRY: (" + remote.getId() + ") - " + remote.getSetValues());
Flags.set(Flags.SUPPRESS_SYNC); Flags.set(Flags.SUPPRESS_SYNC);
@ -698,8 +697,7 @@ public final class ActFmSyncService {
return item.optLong(key, 0) * 1000L; return item.optLong(key, 0) * 1000L;
} }
public static void updateFromJson(JSONObject json, TagData tag, public static void updateFromJson(JSONObject json, Update model) throws JSONException {
Update model) throws JSONException {
model.setValue(Update.REMOTE_ID, json.getLong("id")); model.setValue(Update.REMOTE_ID, json.getLong("id"));
readUser(json.getJSONObject("user"), model, Update.USER_ID, Update.USER); readUser(json.getJSONObject("user"), model, Update.USER_ID, Update.USER);
model.setValue(Update.ACTION, json.getString("action")); model.setValue(Update.ACTION, json.getString("action"));
@ -711,7 +709,7 @@ public final class ActFmSyncService {
model.setValue(Update.MESSAGE, json.getString("message")); model.setValue(Update.MESSAGE, json.getString("message"));
model.setValue(Update.PICTURE, json.getString("picture")); model.setValue(Update.PICTURE, json.getString("picture"));
model.setValue(Update.CREATION_DATE, readDate(json, "created_at")); model.setValue(Update.CREATION_DATE, readDate(json, "created_at"));
model.setValue(Update.TAG, tag == null ? 0L : tag.getId()); model.setValue(Update.TAGS, json.optString("tag_ids", ""));
model.setValue(Update.TASK, json.optLong("task_id", 0)); model.setValue(Update.TASK, json.optLong("task_id", 0));
} }

@ -125,7 +125,7 @@ public class Database extends AbstractDatabase {
sql.append("CREATE INDEX IF NOT EXISTS up_pid ON "). sql.append("CREATE INDEX IF NOT EXISTS up_pid ON ").
append(Update.TABLE).append('('). append(Update.TABLE).append('(').
append(Update.TAG.name). append(Update.TAGS.name).
append(')'); append(')');
database.execSQL(sql.toString()); database.execSQL(sql.toString());
sql.setLength(0); sql.setLength(0);
@ -196,7 +196,7 @@ public class Database extends AbstractDatabase {
} }
case 12: try { case 12: try {
database.execSQL("ALTER TABLE " + Update.TABLE.name + " ADD " + database.execSQL("ALTER TABLE " + Update.TABLE.name + " ADD " +
Update.TAG.accept(visitor, null)); Update.TAGS.accept(visitor, null));
} catch (SQLiteException e) { } catch (SQLiteException e) {
Log.e("astrid", "db-upgrade-" + oldVersion + "-" + newVersion, e); Log.e("astrid", "db-upgrade-" + oldVersion + "-" + newVersion, e);
} }

@ -13,6 +13,7 @@ import com.todoroo.astrid.dao.TagDataDao;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.UpdateDao; import com.todoroo.astrid.dao.UpdateDao;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update; import com.todoroo.astrid.data.Update;
/** /**
@ -123,9 +124,11 @@ public class TagDataService {
* Get updates for this tagData * Get updates for this tagData
* @return * @return
*/ */
@SuppressWarnings("nls")
public TodorooCursor<Update> getUpdates(TagData tagData) { public TodorooCursor<Update> getUpdates(TagData tagData) {
return updateDao.query(Query.select(Update.PROPERTIES).where( return updateDao.query(Query.select(Update.PROPERTIES).where(
Update.TAG.eq(tagData.getId())).orderBy(Order.desc(Update.CREATION_DATE))); Update.TAGS.like("%" + tagData.getValue(Task.REMOTE_ID) + ",%")).
orderBy(Order.desc(Update.CREATION_DATE)));
} }
} }

Loading…
Cancel
Save