Add audio support for timelines (#1466)
* Add minimal audio support for timelines * fix attachment description formatting
This commit is contained in:
parent
d4f80f308d
commit
344863b5d4
|
@ -334,8 +334,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
favouriteButton.setChecked(favourited);
|
||||
}
|
||||
|
||||
private void loadImage(MediaPreviewImageView imageView, String previewUrl, String description,
|
||||
MetaData meta) {
|
||||
private void loadImage(MediaPreviewImageView imageView, String previewUrl, MetaData meta) {
|
||||
if (TextUtils.isEmpty(previewUrl)) {
|
||||
Glide.with(imageView)
|
||||
.load(mediaPreviewUnloadedId)
|
||||
|
@ -385,7 +384,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
}
|
||||
|
||||
if (!sensitive || showingContent) {
|
||||
loadImage(imageView, previewUrl, description, attachments.get(i).getMeta());
|
||||
loadImage(imageView, previewUrl, attachments.get(i).getMeta());
|
||||
} else {
|
||||
imageView.setImageResource(mediaPreviewUnloadedId);
|
||||
}
|
||||
|
@ -458,6 +457,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
case GIFV:
|
||||
case VIDEO:
|
||||
return R.drawable.ic_videocam_24dp;
|
||||
case AUDIO:
|
||||
return R.drawable.ic_music_box_24dp;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -505,11 +506,14 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
}
|
||||
|
||||
private static CharSequence getAttachmentDescription(Context context, Attachment attachment) {
|
||||
String duration = "";
|
||||
if(attachment.getMeta().getDuration() != null && attachment.getMeta().getDuration() > 0) {
|
||||
duration = formatDuration(attachment.getMeta().getDuration()) + " ";
|
||||
}
|
||||
if (TextUtils.isEmpty(attachment.getDescription())) {
|
||||
return context
|
||||
.getString(R.string.description_status_media_no_description_placeholder);
|
||||
return duration + context.getString(R.string.description_status_media_no_description_placeholder);
|
||||
} else {
|
||||
return attachment.getDescription();
|
||||
return duration + attachment.getDescription();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -605,7 +609,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
setFavourited(status.isFavourited());
|
||||
List<Attachment> attachments = status.getAttachments();
|
||||
boolean sensitive = status.isSensitive();
|
||||
if (mediaPreviewEnabled) {
|
||||
if (mediaPreviewEnabled && !hasAudioAttachment(attachments)) {
|
||||
setMediaPreviews(attachments, sensitive, listener, status.isShowingContent());
|
||||
|
||||
if (attachments.size() == 0) {
|
||||
|
@ -651,6 +655,15 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
}
|
||||
}
|
||||
|
||||
protected static boolean hasAudioAttachment(List<Attachment> attachments) {
|
||||
for(Attachment attachment: attachments) {
|
||||
if (attachment.getType() == Attachment.Type.AUDIO) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setDescriptionForStatus(@NonNull StatusViewData.Concrete status) {
|
||||
Context context = itemView.getContext();
|
||||
|
||||
|
@ -848,4 +861,12 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
return pollDescription.getContext().getString(R.string.poll_info_format, votesText, pollDurationInfo);
|
||||
}
|
||||
|
||||
private static String formatDuration(double durationInSeconds) {
|
||||
int seconds = (int) Math.round(durationInSeconds) % 60;
|
||||
int minutes = (int) durationInSeconds % 3600 / 60;
|
||||
int hours = (int) durationInSeconds / 3600;
|
||||
|
||||
return String.format("%d:%02d:%02d", hours, minutes, seconds);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public class ConversationViewHolder extends StatusBaseViewHolder {
|
|||
setFavourited(status.getFavourited());
|
||||
List<Attachment> attachments = status.getAttachments();
|
||||
boolean sensitive = status.getSensitive();
|
||||
if(mediaPreviewEnabled) {
|
||||
if(mediaPreviewEnabled && !hasAudioAttachment(attachments)) {
|
||||
setMediaPreviews(attachments, sensitive, listener, status.getShowingHiddenContent());
|
||||
|
||||
if (attachments.size() == 0) {
|
||||
|
|
|
@ -42,6 +42,8 @@ data class Attachment(
|
|||
GIFV,
|
||||
@SerializedName("video")
|
||||
VIDEO,
|
||||
@SerializedName("audio")
|
||||
AUDIO,
|
||||
@SerializedName("unknown")
|
||||
UNKNOWN
|
||||
}
|
||||
|
@ -53,6 +55,7 @@ data class Attachment(
|
|||
"\"image\"" -> Type.IMAGE
|
||||
"\"gifv\"" -> Type.GIFV
|
||||
"\"video\"" -> Type.VIDEO
|
||||
"\"audio\"" -> Type.AUDIO
|
||||
else -> Type.UNKNOWN
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +66,8 @@ data class Attachment(
|
|||
*/
|
||||
@Parcelize
|
||||
data class MetaData (
|
||||
val focus: Focus?
|
||||
val focus: Focus?,
|
||||
val duration: Float?
|
||||
) : Parcelable
|
||||
|
||||
/**
|
||||
|
|
|
@ -310,7 +310,8 @@ public abstract class SFragment extends BaseFragment implements Injectable {
|
|||
switch (type) {
|
||||
case GIFV:
|
||||
case VIDEO:
|
||||
case IMAGE: {
|
||||
case IMAGE:
|
||||
case AUDIO: {
|
||||
final List<AttachmentViewData> attachments = AttachmentViewData.list(actionable);
|
||||
final Intent intent = ViewMediaActivity.newIntent(getContext(), attachments,
|
||||
urlIndex);
|
||||
|
|
|
@ -51,7 +51,8 @@ abstract class ViewMediaFragment : BaseFragment(), SharedElementTransitionListen
|
|||
val fragment = when (attachment.type) {
|
||||
Attachment.Type.IMAGE -> ViewImageFragment()
|
||||
Attachment.Type.VIDEO,
|
||||
Attachment.Type.GIFV -> ViewVideoFragment()
|
||||
Attachment.Type.GIFV,
|
||||
Attachment.Type.AUDIO -> ViewVideoFragment()
|
||||
else -> ViewImageFragment() // it probably won't show anything, but its better than crashing
|
||||
}
|
||||
fragment.arguments = arguments
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path android:fillColor="#000" android:pathData="M16,9H13V14.5A2.5,2.5 0 0,1 10.5,17A2.5,2.5 0 0,1 8,14.5A2.5,2.5 0 0,1 10.5,12C11.07,12 11.58,12.19 12,12.5V7H16M19,3H5A2,2 0 0,0 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5A2,2 0 0,0 19,3Z" />
|
||||
</vector>
|
Loading…
Reference in New Issue