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

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

@ -260,13 +260,6 @@ public class TagViewActivity extends TaskListActivity implements OnTabChangeList
}
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);
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<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

@ -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<Update> 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<Update> 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<NoteOrUpdate>() {
@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() {

@ -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() {

@ -133,8 +133,10 @@ public class TagDataService {
*/
@SuppressWarnings("nls")
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(
Update.TAGS.like("%" + tagData.getValue(Task.REMOTE_ID) + ",%")).
Update.TAGS.like("%," + tagData.getValue(Task.REMOTE_ID) + ",%")).
orderBy(Order.desc(Update.CREATION_DATE)));
}

Loading…
Cancel
Save