use of com.owncloud.android.lib.resources.notifications.models.RichObject in project android by nextcloud.
the class NotificationListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull NotificationViewHolder holder, int position) {
Notification notification = notificationsList.get(position);
holder.binding.datetime.setText(DisplayUtils.getRelativeTimestamp(notificationsActivity, notification.getDatetime().getTime()));
RichObject file = notification.subjectRichParameters.get(FILE);
String subject = notification.getSubject();
if (file == null && !TextUtils.isEmpty(notification.getLink())) {
subject = subject + " ↗";
holder.binding.subject.setTypeface(holder.binding.subject.getTypeface(), Typeface.BOLD);
holder.binding.subject.setOnClickListener(v -> openLink(notification.getLink()));
holder.binding.subject.setText(subject);
} else {
if (!TextUtils.isEmpty(notification.subjectRich)) {
holder.binding.subject.setText(makeSpecialPartsBold(notification));
} else {
holder.binding.subject.setText(subject);
}
if (file != null && !TextUtils.isEmpty(file.id)) {
holder.binding.subject.setOnClickListener(v -> {
Intent intent = new Intent(notificationsActivity, FileDisplayActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(FileDisplayActivity.KEY_FILE_ID, file.id);
notificationsActivity.startActivity(intent);
});
}
}
holder.binding.message.setText(notification.getMessage());
if (!TextUtils.isEmpty(notification.getIcon())) {
downloadIcon(notification.getIcon(), holder.binding.icon);
}
int nightModeFlag = notificationsActivity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
if (Configuration.UI_MODE_NIGHT_YES == nightModeFlag) {
holder.binding.icon.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
} else {
holder.binding.icon.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
}
setButtons(holder, notification);
holder.binding.dismiss.setOnClickListener(v -> new DeleteNotificationTask(client, notification, holder, notificationsActivity).execute());
}
use of com.owncloud.android.lib.resources.notifications.models.RichObject in project android by nextcloud.
the class NotificationListAdapter method makeSpecialPartsBold.
private SpannableStringBuilder makeSpecialPartsBold(Notification notification) {
String text = notification.getSubjectRich();
SpannableStringBuilder ssb = new SpannableStringBuilder(text);
int openingBrace = text.indexOf('{');
int closingBrace;
String replaceablePart;
while (openingBrace != -1) {
closingBrace = text.indexOf('}', openingBrace) + 1;
replaceablePart = text.substring(openingBrace + 1, closingBrace - 1);
RichObject richObject = notification.subjectRichParameters.get(replaceablePart);
if (richObject != null) {
String name = richObject.getName();
ssb.replace(openingBrace, closingBrace, name);
text = ssb.toString();
closingBrace = openingBrace + name.length();
ssb.setSpan(styleSpanBold, openingBrace, closingBrace, 0);
ssb.setSpan(foregroundColorSpanBlack, openingBrace, closingBrace, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
openingBrace = text.indexOf('{', closingBrace);
}
return ssb;
}
Aggregations