From d47eb752a518c2dad8a905479cc0d2e5ef0800c1 Mon Sep 17 00:00:00 2001 From: Grishka Date: Tue, 22 Mar 2022 13:34:06 +0300 Subject: [PATCH] Fix media layout for inset posts --- mastodon/build.gradle | 2 +- .../fragments/BaseStatusListFragment.java | 18 +++++++------ .../android/fragments/ComposeFragment.java | 1 - .../fragments/NotificationsListFragment.java | 25 ++++++++++++++++++- .../report/ReportAddPostsChoiceFragment.java | 17 ++++++++++--- .../displayitems/ImageStatusDisplayItem.java | 3 ++- .../ui/views/ImageAttachmentFrameLayout.java | 6 +++-- mastodon/src/main/res/values/strings.xml | 2 +- 8 files changed, 56 insertions(+), 18 deletions(-) diff --git a/mastodon/build.gradle b/mastodon/build.gradle index a88da3ec..6fede924 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -10,7 +10,7 @@ android { applicationId "org.joinmastodon.android" minSdk 23 targetSdk 31 - versionCode 14 + versionCode 15 versionName "0.1" } 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 352b5f14..ac844726 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -2,7 +2,6 @@ package org.joinmastodon.android.fragments; import android.app.Activity; import android.content.res.Configuration; -import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; @@ -26,8 +25,6 @@ import org.joinmastodon.android.model.Status; import org.joinmastodon.android.ui.BetterItemAnimator; import org.joinmastodon.android.ui.PhotoLayoutHelper; import org.joinmastodon.android.ui.TileGridLayoutManager; -import org.joinmastodon.android.ui.displayitems.AudioStatusDisplayItem; -import org.joinmastodon.android.ui.displayitems.FooterStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.HeaderStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.ImageStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.PollFooterStatusDisplayItem; @@ -285,7 +282,8 @@ public abstract class BaseStatusListFragment exten public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state){ RecyclerView.ViewHolder holder=parent.getChildViewHolder(view); if(holder instanceof ImageStatusDisplayItem.Holder){ - int width=Math.min(parent.getWidth(), V.dp(ImageAttachmentFrameLayout.MAX_WIDTH)); + int listWidth=getListWidthForMediaLayout(); + int width=Math.min(listWidth, V.dp(ImageAttachmentFrameLayout.MAX_WIDTH)); PhotoLayoutHelper.TiledLayoutResult layout=((ImageStatusDisplayItem.Holder) holder).getItem().tiledLayout; PhotoLayoutHelper.TiledLayoutResult.Tile tile=((ImageStatusDisplayItem.Holder) holder).getItem().thisTile; if(tile.startCol+tile.colSpan exten } // ...and for its siblings, offset those on rows below first to the right where they belong if(tile.startCol>0 && layout.tiles[0].rowSpan>1 && tile.startRow>layout.tiles[0].startRow){ - int xOffset=Math.round(layout.tiles[0].width/1000f*parent.getWidth()); + int xOffset=Math.round(layout.tiles[0].width/1000f*listWidth); outRect.left=xOffset; outRect.right=-xOffset; } // If the width of the media block is smaller than that of the RecyclerView, offset the views horizontally to center them - if(parent.getWidth()>width){ - outRect.left+=(parent.getWidth()-V.dp(ImageAttachmentFrameLayout.MAX_WIDTH))/2; + if(listWidth>width){ + outRect.left+=(listWidth-V.dp(ImageAttachmentFrameLayout.MAX_WIDTH))/2; if(tile.startCol>0){ int spanOffset=0; for(int i=0;i exten } } + protected int getListWidthForMediaLayout(){ + return list.getWidth(); + } + protected class DisplayItemsAdapter extends UsableRecyclerView.Adapter> implements ImageLoaderRecyclerAdapter{ public DisplayItemsAdapter(){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java index 6bcd0fd2..4f59fecd 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java @@ -374,7 +374,6 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis while(matcher.find()){ if(editable.getSpans(start+matcher.start(), start+matcher.end(), ComposeAutocompleteSpan.class).length>0) continue; - Log.w("11", "found: "+matcher); ComposeAutocompleteSpan span; if(TextUtils.isEmpty(matcher.group(4))){ // not an emoji span=new ComposeHashtagOrMentionSpan(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java index fa7e39a6..2845e79b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsListFragment.java @@ -5,6 +5,7 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.RectF; +import android.media.Image; import android.os.Bundle; import android.view.View; @@ -14,6 +15,7 @@ import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.model.Notification; import org.joinmastodon.android.model.Poll; import org.joinmastodon.android.model.Status; +import org.joinmastodon.android.ui.PhotoLayoutHelper; import org.joinmastodon.android.ui.displayitems.AccountCardStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.HeaderStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.ImageStatusDisplayItem; @@ -59,6 +61,13 @@ public class NotificationsListFragment extends BaseStatusListFragment items=StatusDisplayItem.buildItems(this, n.status, accountID, n, knownAccounts, titleItem!=null, titleItem==null); + if(titleItem!=null){ + for(StatusDisplayItem item:items){ + if(item instanceof ImageStatusDisplayItem){ + ((ImageStatusDisplayItem) item).horizontalInset=V.dp(32); + } + } + } if(titleItem!=null) items.add(0, titleItem); return items; @@ -205,7 +214,21 @@ public class NotificationsListFragment extends BaseStatusListFragment) holder).getItem().tiledLayout; + PhotoLayoutHelper.TiledLayoutResult.Tile tile=((ImageStatusDisplayItem.Holder) holder).getItem().thisTile; + // only inset those items that are on the edges of the layout + insetLeft=tile.startCol==0; + insetRight=tile.startCol+tile.colSpan==layout.columnSizes.length; + // inset all items in the bottom row + if(tile.startRow+tile.rowSpan==layout.rowSizes.length) + bottomSiblingInset=false; + } + if(insetLeft) + outRect.left=pad; + if(insetRight) + outRect.right=pad; if(!topSiblingInset) outRect.top=pad; if(!bottomSiblingInset) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportAddPostsChoiceFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportAddPostsChoiceFragment.java index e68ad564..0263a707 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportAddPostsChoiceFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/report/ReportAddPostsChoiceFragment.java @@ -21,6 +21,7 @@ import org.joinmastodon.android.events.FinishReportFragmentsEvent; import org.joinmastodon.android.fragments.StatusListFragment; import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.Status; +import org.joinmastodon.android.ui.PhotoLayoutHelper; import org.joinmastodon.android.ui.displayitems.AudioStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.HeaderStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.ImageStatusDisplayItem; @@ -121,16 +122,20 @@ public class ReportAddPostsChoiceFragment extends StatusListFragment{ return; outRect.left=V.dp(40); if(holder instanceof ImageStatusDisplayItem.Holder){ - ImageStatusDisplayItem.Holder imgHolder=(ImageStatusDisplayItem.Holder) holder; + ImageStatusDisplayItem.Holder imgHolder=(ImageStatusDisplayItem.Holder) holder; + PhotoLayoutHelper.TiledLayoutResult layout=imgHolder.getItem().tiledLayout; + PhotoLayoutHelper.TiledLayoutResult.Tile tile=imgHolder.getItem().thisTile; String siblingID; if(holder.getAbsoluteAdapterPosition()0) + outRect.left=0; outRect.left+=V.dp(16); outRect.right=V.dp(16); - if(!imgHolder.getItemID().equals(siblingID) || imgHolder.getItem().thisTile.startRow+imgHolder.getItem().thisTile.rowSpan==imgHolder.getItem().tiledLayout.rowSizes.length) + if(!imgHolder.getItemID().equals(siblingID) || tile.startRow+tile.rowSpan==layout.rowSizes.length) outRect.bottom=V.dp(16); }else if(holder instanceof AudioStatusDisplayItem.Holder){ outRect.bottom=V.dp(16); @@ -222,7 +227,13 @@ public class ReportAddPostsChoiceFragment extends StatusListFragment{ @Override protected List buildDisplayItems(Status s){ - return StatusDisplayItem.buildItems(this, s, accountID, s, knownAccounts, true, false); + List items=StatusDisplayItem.buildItems(this, s, accountID, s, knownAccounts, true, false); + for(StatusDisplayItem item:items){ + if(item instanceof ImageStatusDisplayItem){ + ((ImageStatusDisplayItem) item).horizontalInset=V.dp(40+32); + } + } + return items; } protected void drawDivider(View child, View bottomSibling, RecyclerView.ViewHolder holder, RecyclerView.ViewHolder siblingHolder, RecyclerView parent, Canvas c, Paint paint){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ImageStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ImageStatusDisplayItem.java index d4061b36..8c842460 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ImageStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/ImageStatusDisplayItem.java @@ -27,6 +27,7 @@ public abstract class ImageStatusDisplayItem extends StatusDisplayItem{ public final Status status; public final PhotoLayoutHelper.TiledLayoutResult tiledLayout; public final PhotoLayoutHelper.TiledLayoutResult.Tile thisTile; + public int horizontalInset; public ImageStatusDisplayItem(String parentID, BaseStatusListFragment parentFragment, Attachment photo, Status status, int index, int totalPhotos, PhotoLayoutHelper.TiledLayoutResult tiledLayout, PhotoLayoutHelper.TiledLayoutResult.Tile thisTile){ super(parentID, parentFragment); @@ -63,7 +64,7 @@ public abstract class ImageStatusDisplayItem extends StatusDisplayItem{ @Override public void onBind(ImageStatusDisplayItem item){ - layout.setLayout(item.tiledLayout, item.thisTile); + layout.setLayout(item.tiledLayout, item.thisTile, item.horizontalInset); crossfadeDrawable.setSize(item.attachment.getWidth(), item.attachment.getHeight()); crossfadeDrawable.setBlurhashDrawable(item.attachment.blurhashPlaceholder); crossfadeDrawable.setCrossfadeAlpha(item.status.spoilerRevealed ? 0f : 1f); diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/views/ImageAttachmentFrameLayout.java b/mastodon/src/main/java/org/joinmastodon/android/ui/views/ImageAttachmentFrameLayout.java index 654ba984..dff3aa24 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/views/ImageAttachmentFrameLayout.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/views/ImageAttachmentFrameLayout.java @@ -16,6 +16,7 @@ public class ImageAttachmentFrameLayout extends FrameLayout{ private PhotoLayoutHelper.TiledLayoutResult tileLayout; private PhotoLayoutHelper.TiledLayoutResult.Tile tile; + private int horizontalInset; public ImageAttachmentFrameLayout(@NonNull Context context){ super(context); @@ -35,7 +36,7 @@ public class ImageAttachmentFrameLayout extends FrameLayout{ super.onMeasure(widthMeasureSpec, heightMeasureSpec); return; } - int w=Math.min(((View)getParent()).getMeasuredWidth(), V.dp(MAX_WIDTH)); + int w=Math.min(((View)getParent()).getMeasuredWidth()-horizontalInset, V.dp(MAX_WIDTH)); int actualHeight=Math.round(tile.height/1000f*w)+V.dp(1)*(tile.rowSpan-1); int actualWidth=Math.round(tile.width/1000f*w); if(tile.startCol+tile.colSpanOK Preparing for authentication… Finishing authentication… - %s boosted + boosted your toot In reply to %s Notifications