mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
adapt Notification layout to server
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
7416082e4f
commit
7549f09ae3
1 changed files with 41 additions and 1 deletions
|
@ -20,6 +20,7 @@
|
|||
package com.owncloud.android.ui.adapter;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.PictureDrawable;
|
||||
|
@ -27,7 +28,11 @@ import android.net.Uri;
|
|||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -48,6 +53,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
|
|||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.notifications.models.Action;
|
||||
import com.owncloud.android.lib.resources.notifications.models.Notification;
|
||||
import com.owncloud.android.lib.resources.notifications.models.RichObject;
|
||||
import com.owncloud.android.ui.activity.NotificationsActivity;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
import com.owncloud.android.utils.ThemeUtils;
|
||||
|
@ -109,10 +115,17 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
|||
subject = subject + " ↗";
|
||||
holder.subject.setTypeface(holder.subject.getTypeface(), Typeface.BOLD);
|
||||
holder.subject.setOnClickListener(v -> openLink(notification.getLink()));
|
||||
holder.subject.setText(subject);
|
||||
} else {
|
||||
if (!TextUtils.isEmpty(notification.subjectRich)) {
|
||||
holder.subject.setText(makeSpecialPartsBold(notification));
|
||||
} else {
|
||||
holder.subject.setText(subject);
|
||||
}
|
||||
}
|
||||
|
||||
holder.subject.setText(subject);
|
||||
holder.message.setText(notification.getMessage());
|
||||
holder.message.setAlpha(0.57f); // TODO set in xml, once there is an own notification_list_item.xml
|
||||
|
||||
// Todo set proper action icon (to be clarified how to pick)
|
||||
if (!TextUtils.isEmpty(notification.getIcon())) {
|
||||
|
@ -139,6 +152,33 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
|||
}
|
||||
}
|
||||
|
||||
private SpannableStringBuilder makeSpecialPartsBold(Notification notification) {
|
||||
String text = notification.getSubjectRich();
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilder(text);
|
||||
|
||||
int openingBrace = text.indexOf("{");
|
||||
int closingBrace;
|
||||
while (openingBrace != -1) {
|
||||
closingBrace = text.indexOf("}", openingBrace) + 1;
|
||||
String 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(new StyleSpan(android.graphics.Typeface.BOLD), openingBrace, closingBrace, 0);
|
||||
ssb.setSpan(new ForegroundColorSpan(Color.BLACK), openingBrace, closingBrace,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
openingBrace = text.indexOf("{", closingBrace);
|
||||
}
|
||||
|
||||
return ssb;
|
||||
}
|
||||
|
||||
private class ExecuteActionTask extends AsyncTask<Action, Void, Boolean> {
|
||||
|
||||
private NotificationViewHolder holder;
|
||||
|
|
Loading…
Reference in a new issue