From 0434cda2daabf8aef282ae695f1ce9b511f3834d Mon Sep 17 00:00:00 2001 From: Grishka Date: Sun, 30 Apr 2023 23:04:45 +0300 Subject: [PATCH] Thread view M3 redesign --- .../fragments/BaseStatusListFragment.java | 11 +- .../android/fragments/ThreadFragment.java | 30 +++ .../ExtendedFooterStatusDisplayItem.java | 13 +- .../res/drawable/divider_inset_16dp_start.xml | 9 + .../src/main/res/drawable/ic_repeat_24px.xml | 9 + .../src/main/res/drawable/thread_end_mark.xml | 9 + .../layout/display_item_extended_footer.xml | 197 ++++++------------ mastodon/src/main/res/values-v31/colors.xml | 2 + mastodon/src/main/res/values/attrs.xml | 1 + mastodon/src/main/res/values/colors.xml | 2 + mastodon/src/main/res/values/styles.xml | 2 + 11 files changed, 138 insertions(+), 147 deletions(-) create mode 100644 mastodon/src/main/res/drawable/divider_inset_16dp_start.xml create mode 100644 mastodon/src/main/res/drawable/ic_repeat_24px.xml create mode 100644 mastodon/src/main/res/drawable/thread_end_mark.xml diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 8e447ed24..dba169270 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -324,6 +324,10 @@ public abstract class BaseStatusListFragment exten c.drawLine(0, y, parent.getWidth(), y, paint); } + protected boolean needDividerForExtraItem(View child, View bottomSibling, RecyclerView.ViewHolder holder, RecyclerView.ViewHolder siblingHolder){ + return false; + } + public abstract void onItemClick(String id); protected void updatePoll(String itemID, Status status, Poll poll){ @@ -596,7 +600,7 @@ public abstract class BaseStatusListFragment exten private Paint dividerPaint=new Paint(); { - dividerPaint.setColor(UiUtils.getThemeColor(getActivity(), R.attr.colorM3Outline)); + dividerPaint.setColor(UiUtils.getThemeColor(getActivity(), R.attr.colorM3OutlineVariant)); dividerPaint.setStyle(Paint.Style.STROKE); dividerPaint.setStrokeWidth(V.dp(0.5f)); } @@ -608,8 +612,9 @@ public abstract class BaseStatusListFragment exten View bottomSibling=parent.getChildAt(i+1); RecyclerView.ViewHolder holder=parent.getChildViewHolder(child); RecyclerView.ViewHolder siblingHolder=parent.getChildViewHolder(bottomSibling); - if(holder instanceof StatusDisplayItem.Holder ih && siblingHolder instanceof StatusDisplayItem.Holder sh - && (!ih.getItemID().equals(sh.getItemID()) || sh instanceof ExtendedFooterStatusDisplayItem.Holder) && ih.getItem().getType()!=StatusDisplayItem.Type.GAP){ + if((holder instanceof StatusDisplayItem.Holder ih && siblingHolder instanceof StatusDisplayItem.Holder sh + && (!ih.getItemID().equals(sh.getItemID()) || sh instanceof ExtendedFooterStatusDisplayItem.Holder) && ih.getItem().getType()!=StatusDisplayItem.Type.GAP) + || needDividerForExtraItem(child, bottomSibling, holder, siblingHolder)){ drawDivider(child, bottomSibling, holder, siblingHolder, parent, c, dividerPaint); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java index 4578617c4..c2d4087d5 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ThreadFragment.java @@ -1,7 +1,12 @@ package org.joinmastodon.android.fragments; +import android.content.res.ColorStateList; +import android.graphics.Canvas; +import android.graphics.Paint; import android.os.Bundle; import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.statuses.GetStatusContext; @@ -23,10 +28,15 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import androidx.recyclerview.widget.RecyclerView; import me.grishka.appkit.api.SimpleCallback; +import me.grishka.appkit.utils.MergeRecyclerAdapter; +import me.grishka.appkit.utils.SingleViewRecyclerAdapter; +import me.grishka.appkit.utils.V; public class ThreadFragment extends StatusListFragment{ private Status mainStatus; + private ImageView endMark; @Override public void onCreate(Bundle savedInstanceState){ @@ -132,4 +142,24 @@ public class ThreadFragment extends StatusListFragment{ public boolean isItemEnabled(String id){ return !id.equals(mainStatus.id); } + + @Override + protected RecyclerView.Adapter getAdapter(){ + MergeRecyclerAdapter a=new MergeRecyclerAdapter(); + a.addAdapter(super.getAdapter()); + + endMark=new ImageView(getActivity()); + endMark.setScaleType(ImageView.ScaleType.CENTER); + endMark.setImageTintList(ColorStateList.valueOf(UiUtils.getThemeColor(getActivity(), R.attr.colorM3OutlineVariant))); + endMark.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, V.dp(25))); + endMark.setImageResource(R.drawable.thread_end_mark); + a.addAdapter(new SingleViewRecyclerAdapter(endMark)); + + return a; + } + + @Override + protected boolean needDividerForExtraItem(View child, View bottomSibling, RecyclerView.ViewHolder holder, RecyclerView.ViewHolder siblingHolder){ + return bottomSibling==endMark; + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ExtendedFooterStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ExtendedFooterStatusDisplayItem.java index c21ee992f..6c5679179 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ExtendedFooterStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ExtendedFooterStatusDisplayItem.java @@ -45,8 +45,8 @@ public class ExtendedFooterStatusDisplayItem extends StatusDisplayItem{ } public static class Holder extends StatusDisplayItem.Holder{ - private final TextView time, favoritesCount, reblogsCount, lastEditTime; - private final View favorites, reblogs, editHistory; + private final TextView time; + private final TextView favorites, reblogs, editHistory; public Holder(Context context, ViewGroup parent){ super(context, R.layout.display_item_extended_footer, parent); @@ -54,9 +54,6 @@ public class ExtendedFooterStatusDisplayItem extends StatusDisplayItem{ favorites=findViewById(R.id.favorites); editHistory=findViewById(R.id.edit_history); time=findViewById(R.id.timestamp); - favoritesCount=findViewById(R.id.favorites_count); - reblogsCount=findViewById(R.id.reblogs_count); - lastEditTime=findViewById(R.id.last_edited); reblogs.setOnClickListener(v->startAccountListFragment(StatusReblogsListFragment.class)); favorites.setOnClickListener(v->startAccountListFragment(StatusFavoritesListFragment.class)); @@ -67,11 +64,11 @@ public class ExtendedFooterStatusDisplayItem extends StatusDisplayItem{ @Override public void onBind(ExtendedFooterStatusDisplayItem item){ Status s=item.status; - favoritesCount.setText(String.format("%,d", s.favouritesCount)); - reblogsCount.setText(String.format("%,d", s.reblogsCount)); + favorites.setText(itemView.getResources().getQuantityString(R.plurals.x_favorites, (int)item.status.favouritesCount, item.status.favouritesCount)); + reblogs.setText(itemView.getResources().getQuantityString(R.plurals.x_reblogs, (int)item.status.reblogsCount, item.status.reblogsCount)); if(s.editedAt!=null){ editHistory.setVisibility(View.VISIBLE); - lastEditTime.setText(item.parentFragment.getString(R.string.last_edit_at_x, UiUtils.formatRelativeTimestampAsMinutesAgo(itemView.getContext(), s.editedAt))); + editHistory.setText(item.parentFragment.getString(R.string.last_edit_at_x, UiUtils.formatRelativeTimestampAsMinutesAgo(itemView.getContext(), s.editedAt))); }else{ editHistory.setVisibility(View.GONE); } diff --git a/mastodon/src/main/res/drawable/divider_inset_16dp_start.xml b/mastodon/src/main/res/drawable/divider_inset_16dp_start.xml new file mode 100644 index 000000000..4b9a0fae1 --- /dev/null +++ b/mastodon/src/main/res/drawable/divider_inset_16dp_start.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/mastodon/src/main/res/drawable/ic_repeat_24px.xml b/mastodon/src/main/res/drawable/ic_repeat_24px.xml new file mode 100644 index 000000000..7bf54f969 --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_repeat_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/mastodon/src/main/res/drawable/thread_end_mark.xml b/mastodon/src/main/res/drawable/thread_end_mark.xml new file mode 100644 index 000000000..15afde530 --- /dev/null +++ b/mastodon/src/main/res/drawable/thread_end_mark.xml @@ -0,0 +1,9 @@ + + + diff --git a/mastodon/src/main/res/layout/display_item_extended_footer.xml b/mastodon/src/main/res/layout/display_item_extended_footer.xml index 0ffb41f21..b376012da 100644 --- a/mastodon/src/main/res/layout/display_item_extended_footer.xml +++ b/mastodon/src/main/res/layout/display_item_extended_footer.xml @@ -3,149 +3,74 @@ xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" - android:layout_height="wrap_content"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="wrap_content" + android:divider="@drawable/divider_inset_16dp_start" + android:showDividers="middle"> + + + + + + \ No newline at end of file diff --git a/mastodon/src/main/res/values-v31/colors.xml b/mastodon/src/main/res/values-v31/colors.xml index f1346b2ab..f87cf2e00 100644 --- a/mastodon/src/main/res/values-v31/colors.xml +++ b/mastodon/src/main/res/values-v31/colors.xml @@ -22,6 +22,7 @@ @android:color/system_neutral2_100 @android:color/system_neutral2_700 @android:color/system_neutral2_500 + @android:color/system_neutral2_200 @android:color/system_accent1_200 @@ -43,4 +44,5 @@ @android:color/system_neutral2_700 @android:color/system_neutral2_200 @android:color/system_neutral2_400 + @android:color/system_neutral2_700 diff --git a/mastodon/src/main/res/values/attrs.xml b/mastodon/src/main/res/values/attrs.xml index 9afc752b1..88d025bb6 100644 --- a/mastodon/src/main/res/values/attrs.xml +++ b/mastodon/src/main/res/values/attrs.xml @@ -35,6 +35,7 @@ + diff --git a/mastodon/src/main/res/values/colors.xml b/mastodon/src/main/res/values/colors.xml index a66197aaa..28594779a 100644 --- a/mastodon/src/main/res/values/colors.xml +++ b/mastodon/src/main/res/values/colors.xml @@ -119,6 +119,7 @@ #E7E0EC #49454F #79747E + #CAC4D0 #D0BCFF @@ -140,5 +141,6 @@ #49454F #CAC4D0 #938F99 + #49454F \ No newline at end of file diff --git a/mastodon/src/main/res/values/styles.xml b/mastodon/src/main/res/values/styles.xml index e8f2d2395..fda87789b 100644 --- a/mastodon/src/main/res/values/styles.xml +++ b/mastodon/src/main/res/values/styles.xml @@ -59,6 +59,7 @@ @color/m3_sys_light_surface_variant @color/m3_sys_light_on_surface_variant @color/m3_sys_light_outline + @color/m3_sys_light_outline_variant #1F1F1F1F @color/m3_sys_light_on_primary #B3261E @@ -136,6 +137,7 @@ @color/m3_sys_dark_surface_variant @color/m3_sys_dark_on_surface_variant @color/m3_sys_dark_outline + @color/m3_sys_dark_outline_variant #1FE3E3E3 @color/m3_sys_dark_primary #F2B8B5