/** Populates a view with content */ @Override public void bindView(View view, Context context, Cursor c) { TodorooCursor<UserActivity> cursor = (TodorooCursor<UserActivity>) c; ModelHolder mh = ((ModelHolder) view.getTag()); String type = cursor.getString(TYPE_PROPERTY_INDEX); UserActivity update = mh.activity; update.clear(); User user = mh.user; user.clear(); History history = mh.history; boolean isSelf; if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(type)) { readUserActivityProperties(cursor, update); isSelf = Task.USER_ID_SELF.equals(update.getValue(UserActivity.USER_UUID)); } else { readHistoryProperties(cursor, history); isSelf = Task.USER_ID_SELF.equals(history.getValue(History.USER_UUID)); } readUserProperties(cursor, user, self, isSelf); setFieldContentsAndVisibility(view, update, user, history, type); }
private void setUpListAdapter() { items.clear(); this.removeAllViews(); historyCount = 0; TodorooCursor<Metadata> notes = metadataService.query( Query.select(Metadata.PROPERTIES) .where(MetadataCriteria.byTaskAndwithKey(task.getId(), NoteMetadata.METADATA_KEY))); try { Metadata metadata = new Metadata(); for (notes.moveToFirst(); !notes.isAfterLast(); notes.moveToNext()) { metadata.readFromCursor(notes); items.add(NoteOrUpdate.fromMetadata(metadata)); } } finally { notes.close(); } User self = UpdateAdapter.getSelfUser(); TodorooCursor<UserActivity> updates = taskService.getActivityAndHistoryForTask(task); try { UserActivity update = new UserActivity(); History history = new History(); User user = new User(); for (updates.moveToFirst(); !updates.isAfterLast(); updates.moveToNext()) { update.clear(); user.clear(); String type = updates.getString(UpdateAdapter.TYPE_PROPERTY_INDEX); NoteOrUpdate noa; boolean isSelf; if (NameMaps.TABLE_ID_USER_ACTIVITY.equals(type)) { UpdateAdapter.readUserActivityProperties(updates, update); isSelf = Task.USER_ID_SELF.equals(update.getValue(UserActivity.USER_UUID)); UpdateAdapter.readUserProperties(updates, user, self, isSelf); noa = NoteOrUpdate.fromUpdateOrHistory(activity, update, null, user, linkColor); } else { UpdateAdapter.readHistoryProperties(updates, history); isSelf = Task.USER_ID_SELF.equals(history.getValue(History.USER_UUID)); UpdateAdapter.readUserProperties(updates, user, self, isSelf); noa = NoteOrUpdate.fromUpdateOrHistory(activity, null, history, user, linkColor); historyCount++; } if (noa != null) items.add(noa); } } finally { updates.close(); } Collections.sort( items, new Comparator<NoteOrUpdate>() { @Override public int compare(NoteOrUpdate a, NoteOrUpdate b) { if (a.createdAt < b.createdAt) return 1; else if (a.createdAt == b.createdAt) return 0; else return -1; } }); for (int i = 0; i < Math.min(items.size(), commentItems); i++) { View notesView = this.getUpdateNotes(items.get(i), this); this.addView(notesView); } if (items.size() > commentItems || task.getValue(Task.HISTORY_HAS_MORE) > 0) { Button loadMore = new Button(getContext()); loadMore.setText(R.string.TEA_load_more); loadMore.setTextColor(activity.getResources().getColor(R.color.task_edit_deadline_gray)); loadMore.setBackgroundColor(Color.alpha(0)); loadMore.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { // Perform action on click commentItems += 10; setUpListAdapter(); if (task.getValue(Task.HISTORY_HAS_MORE) > 0) new FetchHistory<Task>( taskDao, Task.HISTORY_FETCH_DATE, Task.HISTORY_HAS_MORE, NameMaps.TABLE_ID_TASKS, task.getUuid(), task.getValue(Task.TITLE), 0, historyCount, callback) .execute(); } }); this.addView(loadMore); } else if (items.size() == 0) { TextView noUpdates = new TextView(getContext()); noUpdates.setText(R.string.TEA_no_activity); noUpdates.setTextColor(activity.getResources().getColor(R.color.task_edit_deadline_gray)); noUpdates.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); noUpdates.setPadding(10, 10, 10, 10); noUpdates.setGravity(Gravity.CENTER); noUpdates.setTextSize(16); this.addView(noUpdates); } for (UpdatesChangedListener l : listeners) { l.updatesChanged(); } }