From 36f4770cae58841b0da9364bf3d3bae853243782 Mon Sep 17 00:00:00 2001 From: Grishka Date: Tue, 2 Apr 2024 05:09:55 +0300 Subject: [PATCH] Media layout: improve the case of two horizontal attachments --- .../android/ui/PhotoLayoutHelper.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/PhotoLayoutHelper.java b/mastodon/src/main/java/org/joinmastodon/android/ui/PhotoLayoutHelper.java index 93bf60a5..61457260 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/PhotoLayoutHelper.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/PhotoLayoutHelper.java @@ -58,7 +58,7 @@ public class PhotoLayoutHelper{ float avgRatio=!ratios.isEmpty() ? sum(ratios)/ratios.size() : 1.0f; if(cnt==2){ - if(allAreWide && avgRatio>1.4*maxRatio && (ratios.get(1)-ratios.get(0))<0.2){ // two wide photos, one above the other + if(allAreWide && avgRatio>1.4*maxRatio && Math.abs(ratios.get(1)-ratios.get(0))<0.2){ // two wide photos, one above the other float h=Math.max(Math.min(MAX_WIDTH/ratios.get(0), Math.min(MAX_WIDTH/ratios.get(1), (MAX_HEIGHT-GAP)/2.0f)), MIN_HEIGHT/2f); result.width=MAX_WIDTH; @@ -69,7 +69,23 @@ public class PhotoLayoutHelper{ new TiledLayoutResult.Tile(1, 1, 0, 0), new TiledLayoutResult.Tile(1, 1, 0, 1) }; - }else if(allAreWide || allAreSquare){ // next to each other, same ratio + }else if(allAreWide){ // two wide photos, one above the other, different ratios + result.width=MAX_WIDTH; + float h0=MAX_WIDTH/ratios.get(0); + float h1=MAX_WIDTH/ratios.get(1); + if(h0+h1