From fc7c385a121e2e51b568899ae9a46a0e7d7b2253 Mon Sep 17 00:00:00 2001 From: Tim Su Date: Tue, 28 Jun 2011 02:14:53 -0700 Subject: [PATCH] Fixed bug where remoteid = 0 would break comments on future update because of adapter --- .../todoroo/astrid/actfm/TagViewActivity.java | 26 ++++---- .../astrid/notes/EditNoteActivity.java | 59 +++++++++++++------ .../todoroo/astrid/adapter/FilterAdapter.java | 1 + .../astrid/service/TagDataService.java | 4 +- 4 files changed, 60 insertions(+), 30 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewActivity.java index 0a46379ea..26bb88a00 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/TagViewActivity.java @@ -260,13 +260,6 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList } protected void setUpUpdateList() { - TodorooCursor 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); addCommentField = (EditText) findViewById(R.id.commentField); addCommentField.setOnEditorActionListener(new OnEditorActionListener() { @@ -299,6 +292,8 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList addComment(); } }); + + refreshUpdatesList(); } // --- data loading @@ -347,9 +342,20 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList } private void refreshUpdatesList() { - Cursor cursor = updateAdapter.getCursor(); - cursor.requery(); - startManagingCursor(cursor); + if(tagData.getValue(TagData.REMOTE_ID) == 0) + return; + if(updateAdapter == null) { + TodorooCursor 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 diff --git a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java index 0e01b3a44..e5cc10b87 100644 --- a/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/notes/EditNoteActivity.java @@ -87,18 +87,22 @@ public class EditNoteActivity extends ListActivity { setUpInterface(); setUpListAdapter(); - if(actFmPreferenceService.isLoggedIn() && task.getValue(Task.REMOTE_ID) > 0) { + if(actFmPreferenceService.isLoggedIn()) { findViewById(R.id.add_comment).setVisibility(View.VISIBLE); - String fetchKey = LAST_FETCH_KEY + task.getId(); - long lastFetchDate = Preferences.getLong(fetchKey, 0); - if(DateUtilities.now() > lastFetchDate + 300000L) { - refreshData(false); - Preferences.setLong(fetchKey, DateUtilities.now()); - } else { - loadingText.setText(R.string.ENA_no_comments); - if(items.size() == 0) - loadingText.setVisibility(View.VISIBLE); + if(task.getValue(Task.REMOTE_ID) == 0) + refreshData(true); + else { + String fetchKey = LAST_FETCH_KEY + task.getId(); + long lastFetchDate = Preferences.getLong(fetchKey, 0); + if(DateUtilities.now() > lastFetchDate + 300000L) { + refreshData(false); + Preferences.setLong(fetchKey, DateUtilities.now()); + } 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 { notes.close(); } - TodorooCursor updates = updateDao.query(Query.select(Update.PROPERTIES).where( - Update.TASK.eq(task.getValue(Task.REMOTE_ID))).orderBy(Order.desc(Update.CREATION_DATE))); - try { - Update update = new Update(); - for(updates.moveToFirst(); !updates.isAfterLast(); updates.moveToNext()) { - update.readFromCursor(updates); - items.add(NoteOrUpdate.fromUpdate(update)); + + if(task.getValue(Task.REMOTE_ID) > 0) { + TodorooCursor updates = updateDao.query(Query.select(Update.PROPERTIES).where( + Update.TASK.eq(task.getValue(Task.REMOTE_ID))).orderBy(Order.desc(Update.CREATION_DATE))); + try { + Update update = new 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() { @Override public int compare(NoteOrUpdate a, NoteOrUpdate b) { @@ -211,6 +219,19 @@ public class EditNoteActivity extends ListActivity { else 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() { @Override public void run() { diff --git a/astrid/src/com/todoroo/astrid/adapter/FilterAdapter.java b/astrid/src/com/todoroo/astrid/adapter/FilterAdapter.java index 1df13efaf..309b4001c 100644 --- a/astrid/src/com/todoroo/astrid/adapter/FilterAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/FilterAdapter.java @@ -442,6 +442,7 @@ public class FilterAdapter extends BaseExpandableListAdapter { add.setTextColor(Color.WHITE); add.setCompoundDrawablesWithIntrinsicBounds(R.drawable.tango_add,0,0,0); viewHolder.decoration = add; + add.setHeight((int)(35 * metrics.density)); ((ViewGroup)viewHolder.view).addView(add); add.setOnClickListener(new View.OnClickListener() { diff --git a/astrid/src/com/todoroo/astrid/service/TagDataService.java b/astrid/src/com/todoroo/astrid/service/TagDataService.java index 2bb0e7bdb..e98a1c5d4 100644 --- a/astrid/src/com/todoroo/astrid/service/TagDataService.java +++ b/astrid/src/com/todoroo/astrid/service/TagDataService.java @@ -133,8 +133,10 @@ public class TagDataService { */ @SuppressWarnings("nls") public TodorooCursor 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( - Update.TAGS.like("%" + tagData.getValue(Task.REMOTE_ID) + ",%")). + Update.TAGS.like("%," + tagData.getValue(Task.REMOTE_ID) + ",%")). orderBy(Order.desc(Update.CREATION_DATE))); }