3335: Use a resource integer for aspect ratio values
This commit is contained in:
parent
602ec7ab5d
commit
394395cb34
|
@ -3,6 +3,7 @@ package com.keylesspalace.tusky.adapter;
|
|||
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;
|
||||
|
@ -497,9 +498,11 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
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);
|
||||
|
|
|
@ -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 ->
|
||||
|
||||
|
|
|
@ -27,13 +27,7 @@ private fun formatDuration(durationInSeconds: Double): String {
|
|||
return "%d:%02d:%02d".format(hours, minutes, seconds)
|
||||
}
|
||||
|
||||
fun List<Attachment>.aspectRatios(): List<Double> {
|
||||
val displayMetrics = Resources.getSystem().displayMetrics
|
||||
val deviceIsHigher = displayMetrics.heightPixels > displayMetrics.widthPixels
|
||||
|
||||
val minAspect = if (deviceIsHigher) 0.5 else 1.2
|
||||
val maxAspect = if (deviceIsHigher) 2.0 else 3.0
|
||||
|
||||
fun List<Attachment>.aspectRatios(minAspect: Double, maxAspect: Double): List<Double> {
|
||||
return map { attachment ->
|
||||
// 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
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<integer name="image_aspect_min_tenth">12</integer>
|
||||
<integer name="image_aspect_max_tenth">30</integer>
|
||||
</resources>
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue