Fixed bug where remoteid = 0 would break comments on future update because of adapter

pull/14/head
Tim Su 13 years ago
parent d443ff8502
commit fc7c385a12

@ -260,13 +260,6 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList
} }
protected void setUpUpdateList() { protected void setUpUpdateList() {
TodorooCursor<Update> currentCursor = tagDataService.getUpdates(tagData);
startManagingCursor(currentCursor);
updateAdapter = new UpdateAdapter(this, R.layout.update_adapter_row,
currentCursor, false, null);
((ListView)findViewById(R.id.tab_updates)).setAdapter(updateAdapter);
final ImageButton quickAddButton = (ImageButton) findViewById(R.id.commentButton); final ImageButton quickAddButton = (ImageButton) findViewById(R.id.commentButton);
addCommentField = (EditText) findViewById(R.id.commentField); addCommentField = (EditText) findViewById(R.id.commentField);
addCommentField.setOnEditorActionListener(new OnEditorActionListener() { addCommentField.setOnEditorActionListener(new OnEditorActionListener() {
@ -299,6 +292,8 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList
addComment(); addComment();
} }
}); });
refreshUpdatesList();
} }
// --- data loading // --- data loading
@ -347,10 +342,21 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList
} }
private void refreshUpdatesList() { private void refreshUpdatesList() {
if(tagData.getValue(TagData.REMOTE_ID) == 0)
return;
if(updateAdapter == null) {
TodorooCursor<Update> currentCursor = tagDataService.getUpdates(tagData);
startManagingCursor(currentCursor);
updateAdapter = new UpdateAdapter(this, R.layout.update_adapter_row,
currentCursor, false, null);
((ListView)findViewById(R.id.tab_updates)).setAdapter(updateAdapter);
} else {
Cursor cursor = updateAdapter.getCursor(); Cursor cursor = updateAdapter.getCursor();
cursor.requery(); cursor.requery();
startManagingCursor(cursor); startManagingCursor(cursor);
} }
}
@Override @Override
public void loadTaskListContent(boolean requery) { public void loadTaskListContent(boolean requery) {

@ -87,9 +87,12 @@ public class EditNoteActivity extends ListActivity {
setUpInterface(); setUpInterface();
setUpListAdapter(); setUpListAdapter();
if(actFmPreferenceService.isLoggedIn() && task.getValue(Task.REMOTE_ID) > 0) { if(actFmPreferenceService.isLoggedIn()) {
findViewById(R.id.add_comment).setVisibility(View.VISIBLE); findViewById(R.id.add_comment).setVisibility(View.VISIBLE);
if(task.getValue(Task.REMOTE_ID) == 0)
refreshData(true);
else {
String fetchKey = LAST_FETCH_KEY + task.getId(); String fetchKey = LAST_FETCH_KEY + task.getId();
long lastFetchDate = Preferences.getLong(fetchKey, 0); long lastFetchDate = Preferences.getLong(fetchKey, 0);
if(DateUtilities.now() > lastFetchDate + 300000L) { if(DateUtilities.now() > lastFetchDate + 300000L) {
@ -102,6 +105,7 @@ public class EditNoteActivity extends ListActivity {
} }
} }
} }
}
// --- UI preparation // --- UI preparation
@ -166,6 +170,8 @@ public class EditNoteActivity extends ListActivity {
} finally { } finally {
notes.close(); notes.close();
} }
if(task.getValue(Task.REMOTE_ID) > 0) {
TodorooCursor<Update> updates = updateDao.query(Query.select(Update.PROPERTIES).where( TodorooCursor<Update> updates = updateDao.query(Query.select(Update.PROPERTIES).where(
Update.TASK.eq(task.getValue(Task.REMOTE_ID))).orderBy(Order.desc(Update.CREATION_DATE))); Update.TASK.eq(task.getValue(Task.REMOTE_ID))).orderBy(Order.desc(Update.CREATION_DATE)));
try { try {
@ -177,6 +183,8 @@ public class EditNoteActivity extends ListActivity {
} finally { } finally {
updates.close(); updates.close();
} }
}
Collections.sort(items, new Comparator<NoteOrUpdate>() { Collections.sort(items, new Comparator<NoteOrUpdate>() {
@Override @Override
public int compare(NoteOrUpdate a, NoteOrUpdate b) { public int compare(NoteOrUpdate a, NoteOrUpdate b) {
@ -211,6 +219,19 @@ public class EditNoteActivity extends ListActivity {
else else
progressDialog = null; progressDialog = null;
if(task.getValue(Task.REMOTE_ID) == 0) {
// push task if it hasn't been pushed
new Thread(new Runnable() {
@Override
public void run() {
actFmSyncService.pushTask(task.getId());
refreshData(false);
DialogUtilities.dismissDialog(EditNoteActivity.this, progressDialog);
}
}).start();
return;
}
actFmSyncService.fetchUpdatesForTask(task, manual, new Runnable() { actFmSyncService.fetchUpdatesForTask(task, manual, new Runnable() {
@Override @Override
public void run() { public void run() {

@ -442,6 +442,7 @@ public class FilterAdapter extends BaseExpandableListAdapter {
add.setTextColor(Color.WHITE); add.setTextColor(Color.WHITE);
add.setCompoundDrawablesWithIntrinsicBounds(R.drawable.tango_add,0,0,0); add.setCompoundDrawablesWithIntrinsicBounds(R.drawable.tango_add,0,0,0);
viewHolder.decoration = add; viewHolder.decoration = add;
add.setHeight((int)(35 * metrics.density));
((ViewGroup)viewHolder.view).addView(add); ((ViewGroup)viewHolder.view).addView(add);
add.setOnClickListener(new View.OnClickListener() { add.setOnClickListener(new View.OnClickListener() {

@ -133,8 +133,10 @@ public class TagDataService {
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public TodorooCursor<Update> getUpdates(TagData tagData) { public TodorooCursor<Update> getUpdates(TagData tagData) {
if(tagData.getValue(Task.REMOTE_ID) < 1)
return updateDao.query(Query.select(Update.PROPERTIES).where(Criterion.none));
return updateDao.query(Query.select(Update.PROPERTIES).where( return updateDao.query(Query.select(Update.PROPERTIES).where(
Update.TAGS.like("%" + tagData.getValue(Task.REMOTE_ID) + ",%")). Update.TAGS.like("%," + tagData.getValue(Task.REMOTE_ID) + ",%")).
orderBy(Order.desc(Update.CREATION_DATE))); orderBy(Order.desc(Update.CREATION_DATE)));
} }

Loading…
Cancel
Save