update for a comment being able to belong to multiple tags

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

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

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

@ -605,12 +605,16 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList
}).start();
}
@SuppressWarnings("nls")
private void addComment() {
if(tagData.getValue(TagData.REMOTE_ID) == 0L)
return;
Update update = new Update();
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.TAG, tagData.getId());
update.setValue(Update.TAGS, "," + tagData.getValue(TagData.REMOTE_ID) + ",");
update.setValue(Update.CREATION_DATE, DateUtilities.now());
Flags.checkAndClear(Flags.SUPPRESS_SYNC);
updateDao.createNew(update);

@ -32,7 +32,7 @@ public class ActFmInvoker {
public static final String PROVIDER_GOOGLE= "google";
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;

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

@ -125,7 +125,7 @@ public class Database extends AbstractDatabase {
sql.append("CREATE INDEX IF NOT EXISTS up_pid ON ").
append(Update.TABLE).append('(').
append(Update.TAG.name).
append(Update.TAGS.name).
append(')');
database.execSQL(sql.toString());
sql.setLength(0);
@ -196,7 +196,7 @@ public class Database extends AbstractDatabase {
}
case 12: try {
database.execSQL("ALTER TABLE " + Update.TABLE.name + " ADD " +
Update.TAG.accept(visitor, null));
Update.TAGS.accept(visitor, null));
} catch (SQLiteException 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.UpdateDao;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
/**
@ -123,9 +124,11 @@ public class TagDataService {
* Get updates for this tagData
* @return
*/
@SuppressWarnings("nls")
public TodorooCursor<Update> getUpdates(TagData tagData) {
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