Skip to content

Commit 0cf2299

Browse files
befroudomdomegg
authored andcommitted
Added an onclick to the middle text of a Notification (#1872)
* Enhancement issue #1862 Added on click to the "middle text" of a Notification item. * Added comment #1862 Added comment to better explain method usage.
1 parent 27123f5 commit 0cf2299

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

app/src/main/java/fr/free/nrw/commons/notification/NotificationRenderer.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package fr.free.nrw.commons.notification;
22

3+
import android.graphics.Color;
34
import android.text.Html;
5+
import android.text.SpannableString;
6+
import android.text.Spanned;
7+
import android.text.TextPaint;
8+
import android.text.style.ClickableSpan;
49
import android.view.LayoutInflater;
510
import android.view.View;
611
import android.view.ViewGroup;
@@ -60,7 +65,25 @@ private void setTitle(String notificationText) {
6065
notificationText = notificationText.trim().replaceAll("(^\\s*)|(\\s*$)", "");
6166
notificationText = Html.fromHtml(notificationText).toString();
6267
notificationText = notificationText.concat(" ");
63-
title.setText(notificationText);
68+
69+
SpannableString ss = new SpannableString(notificationText);
70+
ClickableSpan clickableSpan = new ClickableSpan() {
71+
@Override
72+
public void onClick(View view) {
73+
listener.notificationClicked(getContent());
74+
}
75+
76+
@Override
77+
public void updateDrawState(TextPaint ds) {
78+
super.updateDrawState(ds);
79+
ds.setUnderlineText(false);
80+
ds.setColor(Color.BLACK);
81+
}
82+
};
83+
84+
// Attach a ClickableSpan to the range (start:0, end:notificationText.length()) of the String
85+
ss.setSpan(clickableSpan, 0, notificationText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
86+
title.setText(ss, TextView.BufferType.SPANNABLE);
6487
}
6588

6689
public interface NotificationClicked{

0 commit comments

Comments
 (0)