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

Commit

Permalink
fix deleting notifications
Browse files Browse the repository at this point in the history
closes #677
closes #633
  • Loading branch information
sk22 committed Oct 9, 2023
1 parent 40a34b0 commit 327ceb0
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.joinmastodon.android.ui.displayitems;

import static org.joinmastodon.android.MastodonApp.context;
import static org.joinmastodon.android.model.Notification.Type.PLEROMA_EMOJI_REACTION;
import static org.joinmastodon.android.ui.utils.UiUtils.generateFormattedString;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.util.TypedValue;
Expand All @@ -24,6 +22,7 @@
import org.joinmastodon.android.api.session.AccountSession;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.fragments.BaseStatusListFragment;
import org.joinmastodon.android.fragments.NotificationsListFragment;
import org.joinmastodon.android.fragments.ProfileFragment;
import org.joinmastodon.android.model.Emoji;
import org.joinmastodon.android.model.Notification;
Expand Down Expand Up @@ -116,7 +115,7 @@ public ImageLoaderRequest getImageRequest(int index){
}

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

Expand All @@ -126,9 +125,15 @@ public Holder(Activity activity, ViewGroup parent){
avatar=findViewById(R.id.avatar);
text=findViewById(R.id.text);
timestamp=findViewById(R.id.timestamp);
deleteNotification=findViewById(R.id.delete_notification);

avatar.setOutlineProvider(OutlineProviders.roundedRect(8));
avatar.setClipToOutline(true);
deleteNotification.setOnClickListener(v->UiUtils.confirmDeleteNotification(activity, item.parentFragment.getAccountID(), item.notification, ()->{
if (item.parentFragment instanceof NotificationsListFragment fragment) {
fragment.removeNotification(item.notification);
}
}));

itemView.setOnClickListener(this::onItemClick);
TypedValue outValue = new TypedValue();
Expand Down Expand Up @@ -177,10 +182,13 @@ public void onBind(NotificationHeaderStatusDisplayItem item){
case POLL -> R.attr.colorPoll;
default -> android.R.attr.colorAccent;
})));
deleteNotification.setVisibility(GlobalUserPreferences.enableDeleteNotifications && item.notification != null ? View.VISIBLE : View.GONE);
itemView.setBackgroundResource(item.notification.type != Notification.Type.POLL
&& item.notification.type != Notification.Type.REPORT ?
selectableItemBackground : 0);
itemView.setClickable(item.notification.type != Notification.Type.POLL);
itemView.setPaddingRelative(itemView.getPaddingStart(), itemView.getPaddingTop(),
GlobalUserPreferences.enableDeleteNotifications ? V.dp(4) : V.dp(16), itemView.getPaddingBottom());
}

public void onItemClick(View v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.joinmastodon.android.model.FilterAction;
import org.joinmastodon.android.model.FilterContext;
import org.joinmastodon.android.model.FilterResult;
import org.joinmastodon.android.model.Notification;
import org.joinmastodon.android.model.Poll;
import org.joinmastodon.android.model.ScheduledStatus;
import org.joinmastodon.android.model.Status;
Expand Down Expand Up @@ -145,7 +146,7 @@ public static ArrayList<StatusDisplayItem> buildItems(BaseStatusListFragment<?>
Status statusForContent=status.getContentStatus();
Bundle args=new Bundle();
args.putString("account", accountID);
ScheduledStatus scheduledStatus = parentObject instanceof ScheduledStatus ? (ScheduledStatus) parentObject : null;
ScheduledStatus scheduledStatus = parentObject instanceof ScheduledStatus s ? s : null;

HeaderStatusDisplayItem header=null;
boolean hideCounts=!AccountSessionManager.get(accountID).getLocalPreferences().showInteractionCounts;
Expand Down Expand Up @@ -201,7 +202,7 @@ public static ArrayList<StatusDisplayItem> buildItems(BaseStatusListFragment<?>
if((flags & FLAG_CHECKABLE)!=0)
items.add(header=new CheckableHeaderStatusDisplayItem(parentID, statusForContent.account, statusForContent.createdAt, fragment, accountID, statusForContent, null));
else
items.add(header=new HeaderStatusDisplayItem(parentID, statusForContent.account, statusForContent.createdAt, fragment, accountID, statusForContent, null, null, scheduledStatus));
items.add(header=new HeaderStatusDisplayItem(parentID, statusForContent.account, statusForContent.createdAt, fragment, accountID, statusForContent, null, parentObject instanceof Notification n ? n : null, scheduledStatus));
}

LegacyFilter applyingFilter=null;
Expand Down
26 changes: 13 additions & 13 deletions mastodon/src/main/res/layout/display_item_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="16dp"
android:paddingLeft="16dp">
android:paddingHorizontal="16dp">
<!-- paddingEnd is set programmatically (depending on item.inset) -->

<LinearLayout
android:id="@+id/buttons"
Expand Down Expand Up @@ -73,27 +73,27 @@
</FrameLayout>

<ImageView
android:id="@+id/delete_notification"
android:id="@+id/more"
android:layout_width="36dp"
android:layout_height="48dp"
android:visibility="gone"
android:background="?android:actionBarItemBackground"
android:contentDescription="@string/sk_delete_notification"
android:tooltipText="@string/sk_delete_notification"
android:scaleType="center"
android:src="@drawable/ic_fluent_dismiss_20_filled"
android:tint="?colorM3OnSurfaceVariant" />
android:tint="?colorM3OnSurfaceVariant"
android:tooltipText="@string/more_options"
android:contentDescription="@string/more_options"
android:src="@drawable/ic_fluent_more_vertical_20_filled" />

<ImageView
android:id="@+id/more"
android:id="@+id/delete_notification"
android:layout_width="36dp"
android:layout_height="48dp"
android:visibility="gone"
android:background="?android:actionBarItemBackground"
android:contentDescription="@string/sk_delete_notification"
android:tooltipText="@string/sk_delete_notification"
android:scaleType="center"
android:tint="?colorM3OnSurfaceVariant"
android:tooltipText="@string/more_options"
android:contentDescription="@string/more_options"
android:src="@drawable/ic_fluent_more_vertical_20_filled" />
android:src="@drawable/ic_fluent_dismiss_20_filled"
android:tint="?colorM3OnSurfaceVariant" />
</LinearLayout>

<ImageView
Expand Down
120 changes: 71 additions & 49 deletions mastodon/src/main/res/layout/display_item_notification_header.xml
Original file line number Diff line number Diff line change
@@ -1,63 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="?android:selectableItemBackground"
android:paddingHorizontal="16dp">
<!-- paddingEnd is set programmatically (depending on enableDeleteNotifications) -->

<ImageView
android:id="@+id/icon"
android:layout_width="28dp"
android:layout_height="28dp"
android:importantForAccessibility="no"
tools:tint="#0f0"
tools:src="@drawable/ic_fluent_arrow_repeat_all_24_filled"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="64dp"
android:gravity="center_vertical"
android:background="?android:selectableItemBackground">

<ImageView
android:id="@+id/avatar"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginStart="12dp"/>
<ImageView
android:id="@+id/icon"
android:layout_width="28dp"
android:layout_height="28dp"
android:importantForAccessibility="no"
tools:tint="#0f0"
tools:src="@drawable/ic_fluent_arrow_repeat_all_24_filled"/>

<org.joinmastodon.android.ui.views.HeaderSubtitleLinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/avatar"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginStart="12dp"/>

<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"
<org.joinmastodon.android.ui.views.HeaderSubtitleLinearLayout
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"/>
android:layout_height="wrap_content">

<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"/>
<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>
</org.joinmastodon.android.ui.views.HeaderSubtitleLinearLayout>

</LinearLayout>

<ImageView
android:id="@+id/delete_notification"
android:layout_width="36dp"
android:layout_height="48dp"
android:visibility="gone"
android:background="?android:actionBarItemBackground"
android:contentDescription="@string/sk_delete_notification"
android:tooltipText="@string/sk_delete_notification"
android:scaleType="center"
android:src="@drawable/ic_fluent_dismiss_20_filled"
android:tint="?colorM3OnSurfaceVariant" />

</LinearLayout>
</LinearLayout>

0 comments on commit 327ceb0

Please sign in to comment.