Merge 7e8ed0116e
into fe7103f2b9
This commit is contained in:
commit
95a06848f7
|
@ -17,12 +17,12 @@ import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.DrawableRes;
|
import androidx.annotation.DrawableRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.widget.PopupMenu;
|
import androidx.appcompat.widget.PopupMenu;
|
||||||
|
import androidx.appcompat.widget.TooltipCompat;
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.text.HtmlCompat;
|
import androidx.core.text.HtmlCompat;
|
||||||
|
@ -74,7 +74,6 @@ import java.text.NumberFormat;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import at.connyduck.sparkbutton.SparkButton;
|
import at.connyduck.sparkbutton.SparkButton;
|
||||||
import at.connyduck.sparkbutton.helpers.Utils;
|
import at.connyduck.sparkbutton.helpers.Utils;
|
||||||
|
@ -541,7 +540,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
imageView.setForeground(null);
|
imageView.setForeground(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
setAttachmentClickListener(imageView, listener, i, attachment, true);
|
final CharSequence formattedDescription = AttachmentHelper.getFormattedDescription(attachment, imageView.getContext());
|
||||||
|
setAttachmentClickListener(imageView, listener, i, formattedDescription, true);
|
||||||
|
|
||||||
if (sensitive) {
|
if (sensitive) {
|
||||||
sensitiveMediaWarning.setText(R.string.post_sensitive_media_title);
|
sensitiveMediaWarning.setText(R.string.post_sensitive_media_title);
|
||||||
|
@ -613,15 +613,15 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
int drawableId = getLabelIcon(attachments.get(0).getType());
|
int drawableId = getLabelIcon(attachments.get(0).getType());
|
||||||
mediaLabel.setCompoundDrawablesWithIntrinsicBounds(drawableId, 0, 0, 0);
|
mediaLabel.setCompoundDrawablesWithIntrinsicBounds(drawableId, 0, 0, 0);
|
||||||
|
|
||||||
setAttachmentClickListener(mediaLabel, listener, i, attachment, false);
|
setAttachmentClickListener(mediaLabel, listener, i, mediaDescriptions[i], false);
|
||||||
} else {
|
} else {
|
||||||
mediaLabel.setVisibility(View.GONE);
|
mediaLabel.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAttachmentClickListener(View view, @NonNull StatusActionListener listener,
|
private void setAttachmentClickListener(@NonNull View view, @NonNull StatusActionListener listener,
|
||||||
int index, Attachment attachment, boolean animateTransition) {
|
int index, CharSequence description, boolean animateTransition) {
|
||||||
view.setOnClickListener(v -> {
|
view.setOnClickListener(v -> {
|
||||||
int position = getBindingAdapterPosition();
|
int position = getBindingAdapterPosition();
|
||||||
if (position != RecyclerView.NO_POSITION) {
|
if (position != RecyclerView.NO_POSITION) {
|
||||||
|
@ -632,11 +632,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
view.setOnLongClickListener(v -> {
|
TooltipCompat.setTooltipText(view, description);
|
||||||
CharSequence description = AttachmentHelper.getFormattedDescription(attachment, view.getContext());
|
|
||||||
Toast.makeText(view.getContext(), description, Toast.LENGTH_LONG).show();
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void hideSensitiveMediaWarning() {
|
protected void hideSensitiveMediaWarning() {
|
||||||
|
|
|
@ -5,8 +5,8 @@ import android.graphics.Color
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.appcompat.content.res.AppCompatResources
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
|
import androidx.appcompat.widget.TooltipCompat
|
||||||
import androidx.core.view.setPadding
|
import androidx.core.view.setPadding
|
||||||
import androidx.paging.PagingDataAdapter
|
import androidx.paging.PagingDataAdapter
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
|
@ -141,11 +141,7 @@ class AccountMediaGridAdapter(
|
||||||
onAttachmentClickListener(item, imageView)
|
onAttachmentClickListener(item, imageView)
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.binding.root.setOnLongClickListener { view ->
|
TooltipCompat.setTooltipText(holder.binding.root, imageView.contentDescription)
|
||||||
val description = item.attachment.getFormattedDescription(view.context)
|
|
||||||
Toast.makeText(view.context, description, Toast.LENGTH_LONG).show()
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,24 +6,22 @@ import android.content.Context
|
||||||
import com.keylesspalace.tusky.R
|
import com.keylesspalace.tusky.R
|
||||||
import com.keylesspalace.tusky.entity.Attachment
|
import com.keylesspalace.tusky.entity.Attachment
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
fun Attachment.getFormattedDescription(context: Context): CharSequence {
|
fun Attachment.getFormattedDescription(context: Context): CharSequence {
|
||||||
var duration = ""
|
val durationInSeconds = meta?.duration ?: 0f
|
||||||
if (meta?.duration != null && meta.duration > 0) {
|
val duration = if (durationInSeconds > 0f) {
|
||||||
duration = formatDuration(meta.duration.toDouble()) + " "
|
durationInSeconds.roundToInt().seconds.toComponents { hours, minutes, seconds, _ ->
|
||||||
}
|
"%d:%02d:%02d ".format(hours, minutes, seconds)
|
||||||
return if (description.isNullOrEmpty()) {
|
}
|
||||||
duration + context.getString(R.string.description_post_media_no_description_placeholder)
|
|
||||||
} else {
|
} else {
|
||||||
duration + description
|
""
|
||||||
|
}
|
||||||
|
return duration + if (description.isNullOrEmpty()) {
|
||||||
|
context.getString(R.string.description_post_media_no_description_placeholder)
|
||||||
|
} else {
|
||||||
|
description
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun formatDuration(durationInSeconds: Double): String {
|
|
||||||
val seconds = durationInSeconds.roundToInt() % 60
|
|
||||||
val minutes = durationInSeconds.toInt() % 3600 / 60
|
|
||||||
val hours = durationInSeconds.toInt() / 3600
|
|
||||||
return "%d:%02d:%02d".format(hours, minutes, seconds)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun List<Attachment>.aspectRatios(): List<Double> {
|
fun List<Attachment>.aspectRatios(): List<Double> {
|
||||||
|
|
Loading…
Reference in New Issue