Support opening unknown attachment types via `openLink` (#2044)
* Support opening unknown attachment types via openLink. #1970 * Fix label text for unknown attachment types
This commit is contained in:
parent
e162583309
commit
72865a0138
|
@ -567,7 +567,6 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
@DrawableRes
|
||||
private static int getLabelIcon(Attachment.Type type) {
|
||||
switch (type) {
|
||||
default:
|
||||
case IMAGE:
|
||||
return R.drawable.ic_photo_24dp;
|
||||
case GIFV:
|
||||
|
@ -575,6 +574,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
return R.drawable.ic_videocam_24dp;
|
||||
case AUDIO:
|
||||
return R.drawable.ic_music_box_24dp;
|
||||
default:
|
||||
return R.drawable.ic_attach_file_24dp;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -789,7 +790,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
setBookmarked(status.isBookmarked());
|
||||
List<Attachment> attachments = status.getAttachments();
|
||||
boolean sensitive = status.isSensitive();
|
||||
if (statusDisplayOptions.mediaPreviewEnabled() && !hasAudioAttachment(attachments)) {
|
||||
if (statusDisplayOptions.mediaPreviewEnabled() && hasPreviewableAttachment(attachments)) {
|
||||
setMediaPreviews(attachments, sensitive, listener, status.isShowingContent(), statusDisplayOptions.useBlurhash());
|
||||
|
||||
if (attachments.size() == 0) {
|
||||
|
@ -840,13 +841,13 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
}
|
||||
}
|
||||
|
||||
protected static boolean hasAudioAttachment(List<Attachment> attachments) {
|
||||
protected static boolean hasPreviewableAttachment(List<Attachment> attachments) {
|
||||
for (Attachment attachment : attachments) {
|
||||
if (attachment.getType() == Attachment.Type.AUDIO) {
|
||||
return true;
|
||||
if (attachment.getType() == Attachment.Type.AUDIO || attachment.getType() == Attachment.Type.UNKNOWN) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setDescriptionForStatus(@NonNull StatusViewData.Concrete status,
|
||||
|
|
|
@ -83,7 +83,7 @@ public class ConversationViewHolder extends StatusBaseViewHolder {
|
|||
setBookmarked(status.getBookmarked());
|
||||
List<Attachment> attachments = status.getAttachments();
|
||||
boolean sensitive = status.getSensitive();
|
||||
if (statusDisplayOptions.mediaPreviewEnabled() && !hasAudioAttachment(attachments)) {
|
||||
if (statusDisplayOptions.mediaPreviewEnabled() && hasPreviewableAttachment(attachments)) {
|
||||
setMediaPreviews(attachments, sensitive, listener, status.getShowingHiddenContent(),
|
||||
statusDisplayOptions.useBlurhash());
|
||||
|
||||
|
|
|
@ -147,6 +147,7 @@ class SearchStatusesFragment : SearchFragment<Pair<Status, StatusViewData.Concre
|
|||
}
|
||||
}
|
||||
Attachment.Type.UNKNOWN -> {
|
||||
LinkHelper.openLink(actionable.attachments[attachmentIndex].url, context)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import com.keylesspalace.tusky.entity.Status
|
|||
import com.keylesspalace.tusky.interfaces.RefreshableFragment
|
||||
import com.keylesspalace.tusky.network.MastodonApi
|
||||
import com.keylesspalace.tusky.settings.PrefKeys
|
||||
import com.keylesspalace.tusky.util.LinkHelper
|
||||
import com.keylesspalace.tusky.util.ThemeUtils
|
||||
import com.keylesspalace.tusky.util.hide
|
||||
import com.keylesspalace.tusky.util.show
|
||||
|
@ -273,10 +274,8 @@ class AccountMediaFragment : BaseFragment(), RefreshableFragment, Injectable {
|
|||
}
|
||||
}
|
||||
Attachment.Type.UNKNOWN -> {
|
||||
}/* Intentionally do nothing. This case is here is to handle when new attachment
|
||||
* types are added to the API before code is added here to handle them. So, the
|
||||
* best fallback is to just show the preview and ignore requests to view them. */
|
||||
|
||||
LinkHelper.openLink(items[currentIndex].attachment.url, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -437,8 +437,9 @@ public abstract class SFragment extends BaseFragment implements Injectable {
|
|||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case UNKNOWN: {
|
||||
onViewUrl(active.getUrl());
|
||||
LinkHelper.openLink(active.getUrl(), getContext());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,7 +228,8 @@ class StatusViewHelper(private val itemView: View) {
|
|||
return when (type) {
|
||||
Attachment.Type.IMAGE -> context.getString(R.string.status_media_images)
|
||||
Attachment.Type.GIFV, Attachment.Type.VIDEO -> context.getString(R.string.status_media_video)
|
||||
else -> context.getString(R.string.status_media_images)
|
||||
Attachment.Type.AUDIO -> context.getString(R.string.status_media_audio)
|
||||
else -> context.getString(R.string.status_media_attachments)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,7 +238,8 @@ class StatusViewHelper(private val itemView: View) {
|
|||
return when (type) {
|
||||
Attachment.Type.IMAGE -> R.drawable.ic_photo_24dp
|
||||
Attachment.Type.GIFV, Attachment.Type.VIDEO -> R.drawable.ic_videocam_24dp
|
||||
else -> R.drawable.ic_photo_24dp
|
||||
Attachment.Type.AUDIO -> R.drawable.ic_music_box_24dp
|
||||
else -> R.drawable.ic_attach_file_24dp
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue