Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
display timestamp in notification header
Browse files Browse the repository at this point in the history
closes #668
  • Loading branch information
sk22 committed Oct 7, 2023
1 parent c930db6 commit 44912b7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ public class NotificationHeaderStatusDisplayItem extends StatusDisplayItem{
private final String accountID;
private final CustomEmojiHelper emojiHelper=new CustomEmojiHelper();
private final CharSequence text;
private final CharSequence timestamp;

public NotificationHeaderStatusDisplayItem(String parentID, BaseStatusListFragment parentFragment, Notification notification, String accountID){
super(parentID, parentFragment);
this.notification=notification;
this.accountID=accountID;
this.timestamp=notification.createdAt==null ? null : UiUtils.formatRelativeTimestamp(context, notification.createdAt);

if(notification.type==Notification.Type.POLL){
text=parentFragment.getString(R.string.poll_ended);
Expand Down Expand Up @@ -112,14 +114,15 @@ public ImageLoaderRequest getImageRequest(int index){

public static class Holder extends StatusDisplayItem.Holder<NotificationHeaderStatusDisplayItem> implements ImageLoaderViewHolder{
private final ImageView icon, avatar;
private final TextView text;
private final TextView text, timestamp;
private final int selectableItemBackground;

public Holder(Activity activity, ViewGroup parent){
super(activity, R.layout.display_item_notification_header, parent);
icon=findViewById(R.id.icon);
avatar=findViewById(R.id.avatar);
text=findViewById(R.id.text);
timestamp=findViewById(R.id.timestamp);

avatar.setOutlineProvider(OutlineProviders.roundedRect(8));
avatar.setClipToOutline(true);
Expand Down Expand Up @@ -152,6 +155,7 @@ public void clearImage(int index){
@Override
public void onBind(NotificationHeaderStatusDisplayItem item){
text.setText(item.text);
timestamp.setText(item.timestamp);
avatar.setVisibility(item.notification.type==Notification.Type.POLL ? View.GONE : View.VISIBLE);
icon.setImageResource(switch(item.notification.type){
case FAVORITE -> R.drawable.ic_fluent_star_24_filled;
Expand Down
46 changes: 37 additions & 9 deletions mastodon/src/main/res/layout/display_item_notification_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,42 @@
android:layout_height="32dp"
android:layout_marginStart="12dp"/>

<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:textAppearance="@style/m3_body_large"
android:textColor="?colorM3OnSurface"
android:singleLine="true"
tools:text="Notification text"/>
<org.joinmastodon.android.ui.views.HeaderSubtitleLinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:textAppearance="@style/m3_body_large"
android:textColor="?colorM3OnSurface"
android:singleLine="true"
android:ellipsize="end"
tools:text="Notification text"/>

<TextView
android:id="@+id/separator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="4sp"
android:importantForAccessibility="no"
android:singleLine="true"
android:textAppearance="@style/m3_body_medium"
android:textColor="?colorM3OnSurfaceVariant"
android:text="@string/sk_separator"/>

<TextView
android:id="@+id/timestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="56sp"
android:textAppearance="@style/m3_body_medium"
android:textColor="?colorM3OnSurfaceVariant"
android:maxLines="1"
tools:text="42m ago"/>

</org.joinmastodon.android.ui.views.HeaderSubtitleLinearLayout>

</LinearLayout>

0 comments on commit 44912b7

Please sign in to comment.