Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3335: Use different bounding aspect ratios for landscape #3396

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.keylesspalace.tusky.viewdata.PollViewDataKt.buildDescription;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
Expand Down Expand Up @@ -497,9 +498,11 @@ protected void setMediaPreviews(
boolean showingContent,
boolean useBlurhash
) {

mediaPreview.setVisibility(View.VISIBLE);
mediaPreview.setAspectRatios(AttachmentHelper.aspectRatios(attachments));
Resources resources = this.content.getContext().getResources();
double minAspect = resources.getInteger(R.integer.image_aspect_min_tenth) / 10.0;
double maxAspect = resources.getInteger(R.integer.image_aspect_max_tenth) / 10.0;
mediaPreview.setAspectRatios(AttachmentHelper.aspectRatios(attachments, minAspect, maxAspect));

mediaPreview.forEachIndexed((i, imageView, descriptionIndicator) -> {
Attachment attachment = attachments.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ class ViewEditsAdapter(
binding.statusEditMediaSensitivity.hide()
} else {
binding.statusEditMediaPreview.show()
binding.statusEditMediaPreview.aspectRatios = edit.mediaAttachments.aspectRatios()
val minAspect: Double = context.resources.getInteger(R.integer.image_aspect_min_tenth) / 10.0
val maxAspect: Double = context.resources.getInteger(R.integer.image_aspect_max_tenth) / 10.0
binding.statusEditMediaPreview.aspectRatios = edit.mediaAttachments.aspectRatios(minAspect, maxAspect)

binding.statusEditMediaPreview.forEachIndexed { index, imageView, descriptionIndicator ->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ private fun formatDuration(durationInSeconds: Double): String {
return "%d:%02d:%02d".format(hours, minutes, seconds)
}

fun List<Attachment>.aspectRatios(): List<Double> {
fun List<Attachment>.aspectRatios(minAspect: Double, maxAspect: Double): List<Double> {
return map { attachment ->
// clamp ratio between 2:1 & 1:2, defaulting to 16:9
// clamp ratio between min & max, defaulting to 16:9 if there is no metadata
val size = (attachment.meta?.small ?: attachment.meta?.original) ?: return@map 1.7778
val aspect = if (size.aspect > 0) size.aspect else size.width.toDouble() / size.height
aspect.coerceIn(0.5, 2.0)
aspect.coerceIn(minAspect, maxAspect)
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/values-land/integers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="image_aspect_min_tenth">10</integer>
<integer name="image_aspect_max_tenth">30</integer>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values-large-land/integers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="image_aspect_min_tenth">10</integer>
<integer name="image_aspect_max_tenth">30</integer>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values/integers.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="image_aspect_min_tenth">5</integer>
<integer name="image_aspect_max_tenth">20</integer>
<integer name="profile_media_column_count">3</integer>

<integer name="trending_column_count">1</integer>
</resources>