private void setupUserActivityRow(View view, UserActivity activity, User user) { final AsyncImageView pictureView = (AsyncImageView) view.findViewById(R.id.picture); { if (user.containsNonNullValue(USER_PICTURE)) { String pictureUrl = user.getPictureUrl(USER_PICTURE, RemoteModel.PICTURE_THUMB); pictureView.setUrl(pictureUrl); } else { pictureView.setUrl(null); } pictureView.setVisibility(View.VISIBLE); } final AsyncImageView commentPictureView = (AsyncImageView) view.findViewById(R.id.comment_picture); { String pictureThumb = activity.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_MEDIUM); String pictureFull = activity.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_LARGE); Bitmap updateBitmap = null; if (TextUtils.isEmpty(pictureThumb)) updateBitmap = activity.getPictureBitmap(UserActivity.PICTURE); setupImagePopupForCommentView( view, commentPictureView, pictureThumb, pictureFull, updateBitmap, activity.getValue(UserActivity.MESSAGE), fragment, imageCache); } // name final TextView nameView = (TextView) view.findViewById(R.id.title); { nameView.setText( getUpdateComment( (AstridActivity) fragment.getActivity(), activity, user, linkColor, fromView)); nameView.setMovementMethod(new LinkMovementMethod()); nameView.setTextColor(color); } // date final TextView date = (TextView) view.findViewById(R.id.date); { CharSequence dateString = DateUtils.getRelativeTimeSpanString( activity.getValue(UserActivity.CREATED_AT), DateUtilities.now(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); date.setText(dateString); } }
private static CharSequence getLinkSpan( final AstridActivity activity, UserActivity update, String targetName, String linkColor, String linkType) { if (TASK_LINK_TYPE.equals(linkType)) { final String taskId = update.getValue(UserActivity.TARGET_ID); if (RemoteModel.isValidUuid(taskId)) { SpannableString taskSpan = new SpannableString(targetName); taskSpan.setSpan( new ClickableSpan() { @Override public void onClick(View widget) { if (activity != null) // TODO: This shouldn't happen, but sometimes does activity.onTaskListItemClicked(taskId); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }, 0, targetName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); return taskSpan; } else { return Html.fromHtml(linkify(targetName, linkColor)); } } return null; }
/** 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); }
public static NoteOrUpdate fromUpdateOrHistory( AstridActivity context, UserActivity u, History history, User user, String linkColor) { String userImage = ""; // $NON-NLS-1$ String pictureThumb = ""; // $NON-NLS-1$ String pictureFull = ""; // $NON-NLS-1$ Spanned title; Bitmap commentBitmap = null; long createdAt = 0; String type = null; if (u != null) { pictureThumb = u.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_MEDIUM); pictureFull = u.getPictureUrl(UserActivity.PICTURE, RemoteModel.PICTURE_LARGE); if (TextUtils.isEmpty(pictureThumb)) commentBitmap = u.getPictureBitmap(UserActivity.PICTURE); title = UpdateAdapter.getUpdateComment( context, u, user, linkColor, UpdateAdapter.FROM_TASK_VIEW); userImage = ""; // $NON-NLS-1$ if (user.containsNonNullValue(UpdateAdapter.USER_PICTURE)) userImage = user.getPictureUrl(UpdateAdapter.USER_PICTURE, RemoteModel.PICTURE_THUMB); createdAt = u.getValue(UserActivity.CREATED_AT); type = NameMaps.TABLE_ID_USER_ACTIVITY; } else { if (user.containsNonNullValue(UpdateAdapter.USER_PICTURE)) userImage = user.getPictureUrl(UpdateAdapter.USER_PICTURE, RemoteModel.PICTURE_THUMB); title = new SpannableString( UpdateAdapter.getHistoryComment( context, history, user, linkColor, UpdateAdapter.FROM_TASK_VIEW)); createdAt = history.getValue(History.CREATED_AT); type = NameMaps.TABLE_ID_HISTORY; } return new NoteOrUpdate( userImage, title, pictureThumb, pictureFull, commentBitmap, createdAt, type); }
public static Spanned getUpdateComment( final AstridActivity context, UserActivity activity, User user, String linkColor, String fromView) { String userDisplay; if (activity.getValue(UserActivity.USER_UUID).equals(Task.USER_ID_SELF)) { userDisplay = context.getString(R.string.update_string_user_self); } else if (user == null) { userDisplay = context.getString(R.string.ENA_no_user); } else { userDisplay = user.getDisplayName(USER_NAME, USER_FIRST_NAME, USER_LAST_NAME); } if (TextUtils.isEmpty(userDisplay)) userDisplay = context.getString(R.string.ENA_no_user); String targetName = activity.getValue(UserActivity.TARGET_NAME); String action = activity.getValue(UserActivity.ACTION); String message = activity.getValue(UserActivity.MESSAGE); int commentResource = 0; if (UserActivity.ACTION_TASK_COMMENT.equals(action)) { if (fromView.equals(FROM_TASK_VIEW) || TextUtils.isEmpty(targetName)) commentResource = R.string.update_string_default_comment; else commentResource = R.string.update_string_task_comment; } else if (UserActivity.ACTION_TAG_COMMENT.equals(action)) { if (fromView.equals(FROM_TAG_VIEW) || TextUtils.isEmpty(targetName)) commentResource = R.string.update_string_default_comment; else commentResource = R.string.update_string_tag_comment; } if (commentResource == 0) return Html.fromHtml(String.format("%s %s", userDisplay, message)); // $NON-NLS-1$ String original = context.getString(commentResource, userDisplay, targetName, message); int taskLinkIndex = original.indexOf(TARGET_LINK_PREFIX); if (taskLinkIndex < 0) return Html.fromHtml(original); String[] components = original.split(" "); // $NON-NLS-1$ SpannableStringBuilder builder = new SpannableStringBuilder(); StringBuilder htmlStringBuilder = new StringBuilder(); for (String comp : components) { Matcher m = TARGET_LINK_PATTERN.matcher(comp); if (m.find()) { builder.append(Html.fromHtml(htmlStringBuilder.toString())); htmlStringBuilder.setLength(0); String linkType = m.group(1); CharSequence link = getLinkSpan(context, activity, targetName, linkColor, linkType); if (link != null) { builder.append(link); if (!m.hitEnd()) { builder.append(comp.substring(m.end())); } builder.append(' '); } } else { htmlStringBuilder.append(comp); htmlStringBuilder.append(' '); } } if (htmlStringBuilder.length() > 0) builder.append(Html.fromHtml(htmlStringBuilder.toString())); return builder; }
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(); } }