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,9 +342,20 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList
} }
private void refreshUpdatesList() { private void refreshUpdatesList() {
Cursor cursor = updateAdapter.getCursor(); if(tagData.getValue(TagData.REMOTE_ID) == 0)
cursor.requery(); return;
startManagingCursor(cursor); 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.requery();
startManagingCursor(cursor);
}
} }
@Override @Override

@ -87,18 +87,22 @@ 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);
String fetchKey = LAST_FETCH_KEY + task.getId(); if(task.getValue(Task.REMOTE_ID) == 0)
long lastFetchDate = Preferences.getLong(fetchKey, 0); refreshData(true);
if(DateUtilities.now() > lastFetchDate + 300000L) { else {
refreshData(false); String fetchKey = LAST_FETCH_KEY + task.getId();
Preferences.setLong(fetchKey, DateUtilities.now()); long lastFetchDate = Preferences.getLong(fetchKey, 0);
} else { if(DateUtilities.now() > lastFetchDate + 300000L) {
loadingText.setText(R.string.ENA_no_comments); refreshData(false);
if(items.size() == 0) Preferences.setLong(fetchKey, DateUtilities.now());
loadingText.setVisibility(View.VISIBLE); } else {
loadingText.setText(R.string.ENA_no_comments);
if(items.size() == 0)
loadingText.setVisibility(View.VISIBLE);
}
} }
} }
} }
@ -166,17 +170,21 @@ public class EditNoteActivity extends ListActivity {
} finally { } finally {
notes.close(); notes.close();
} }
TodorooCursor<Update> updates = updateDao.query(Query.select(Update.PROPERTIES).where(
Update.TASK.eq(task.getValue(Task.REMOTE_ID))).orderBy(Order.desc(Update.CREATION_DATE))); if(task.getValue(Task.REMOTE_ID) > 0) {
try { TodorooCursor<Update> updates = updateDao.query(Query.select(Update.PROPERTIES).where(
Update update = new Update(); Update.TASK.eq(task.getValue(Task.REMOTE_ID))).orderBy(Order.desc(Update.CREATION_DATE)));
for(updates.moveToFirst(); !updates.isAfterLast(); updates.moveToNext()) { try {
update.readFromCursor(updates); Update update = new Update();
items.add(NoteOrUpdate.fromUpdate(update)); for(updates.moveToFirst(); !updates.isAfterLast(); updates.moveToNext()) {
update.readFromCursor(updates);
items.add(NoteOrUpdate.fromUpdate(update));
}
} finally {
updates.close();
} }
} finally {
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