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:
Levi Bard 2021-01-18 13:53:13 +01:00 committed by GitHub
parent cb2296f248
commit baa915a0a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 16 deletions

View file

@ -533,7 +533,6 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
@DrawableRes @DrawableRes
private static int getLabelIcon(Attachment.Type type) { private static int getLabelIcon(Attachment.Type type) {
switch (type) { switch (type) {
default:
case IMAGE: case IMAGE:
return R.drawable.ic_photo_24dp; return R.drawable.ic_photo_24dp;
case GIFV: case GIFV:
@ -541,6 +540,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
return R.drawable.ic_videocam_24dp; return R.drawable.ic_videocam_24dp;
case AUDIO: case AUDIO:
return R.drawable.ic_music_box_24dp; return R.drawable.ic_music_box_24dp;
default:
return R.drawable.ic_attach_file_24dp;
} }
} }
@ -718,7 +719,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
setBookmarked(status.isBookmarked()); setBookmarked(status.isBookmarked());
List<Attachment> attachments = status.getAttachments(); List<Attachment> attachments = status.getAttachments();
boolean sensitive = status.isSensitive(); boolean sensitive = status.isSensitive();
if (statusDisplayOptions.mediaPreviewEnabled() && !hasAudioAttachment(attachments)) { if (statusDisplayOptions.mediaPreviewEnabled() && hasPreviewableAttachment(attachments)) {
setMediaPreviews(attachments, sensitive, listener, status.isShowingContent(), statusDisplayOptions.useBlurhash()); setMediaPreviews(attachments, sensitive, listener, status.isShowingContent(), statusDisplayOptions.useBlurhash());
if (attachments.size() == 0) { if (attachments.size() == 0) {
@ -767,13 +768,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) { for (Attachment attachment : attachments) {
if (attachment.getType() == Attachment.Type.AUDIO) { if (attachment.getType() == Attachment.Type.AUDIO || attachment.getType() == Attachment.Type.UNKNOWN) {
return true; return false;
} }
} }
return false; return true;
} }
private void setDescriptionForStatus(@NonNull StatusViewData.Concrete status, private void setDescriptionForStatus(@NonNull StatusViewData.Concrete status,

View file

@ -83,7 +83,7 @@ public class ConversationViewHolder extends StatusBaseViewHolder {
setBookmarked(status.getBookmarked()); setBookmarked(status.getBookmarked());
List<Attachment> attachments = status.getAttachments(); List<Attachment> attachments = status.getAttachments();
boolean sensitive = status.getSensitive(); boolean sensitive = status.getSensitive();
if (statusDisplayOptions.mediaPreviewEnabled() && !hasAudioAttachment(attachments)) { if (statusDisplayOptions.mediaPreviewEnabled() && hasPreviewableAttachment(attachments)) {
setMediaPreviews(attachments, sensitive, listener, status.getShowingHiddenContent(), setMediaPreviews(attachments, sensitive, listener, status.getShowingHiddenContent(),
statusDisplayOptions.useBlurhash()); statusDisplayOptions.useBlurhash());

View file

@ -54,6 +54,7 @@ import com.keylesspalace.tusky.interfaces.AccountSelectionListener
import com.keylesspalace.tusky.interfaces.StatusActionListener import com.keylesspalace.tusky.interfaces.StatusActionListener
import com.keylesspalace.tusky.settings.PrefKeys import com.keylesspalace.tusky.settings.PrefKeys
import com.keylesspalace.tusky.util.CardViewMode import com.keylesspalace.tusky.util.CardViewMode
import com.keylesspalace.tusky.util.LinkHelper
import com.keylesspalace.tusky.util.NetworkState import com.keylesspalace.tusky.util.NetworkState
import com.keylesspalace.tusky.util.StatusDisplayOptions import com.keylesspalace.tusky.util.StatusDisplayOptions
import com.keylesspalace.tusky.view.showMuteAccountDialog import com.keylesspalace.tusky.view.showMuteAccountDialog
@ -143,6 +144,7 @@ class SearchStatusesFragment : SearchFragment<Pair<Status, StatusViewData.Concre
} }
} }
Attachment.Type.UNKNOWN -> { Attachment.Type.UNKNOWN -> {
LinkHelper.openLink(actionable.attachments[attachmentIndex].url, context)
} }
} }

View file

@ -34,6 +34,7 @@ import com.keylesspalace.tusky.entity.Attachment
import com.keylesspalace.tusky.entity.Status import com.keylesspalace.tusky.entity.Status
import com.keylesspalace.tusky.interfaces.RefreshableFragment import com.keylesspalace.tusky.interfaces.RefreshableFragment
import com.keylesspalace.tusky.network.MastodonApi import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.util.LinkHelper
import com.keylesspalace.tusky.util.ThemeUtils import com.keylesspalace.tusky.util.ThemeUtils
import com.keylesspalace.tusky.util.hide import com.keylesspalace.tusky.util.hide
import com.keylesspalace.tusky.util.show import com.keylesspalace.tusky.util.show
@ -260,10 +261,8 @@ class AccountMediaFragment : BaseFragment(), RefreshableFragment, Injectable {
} }
} }
Attachment.Type.UNKNOWN -> { Attachment.Type.UNKNOWN -> {
}/* Intentionally do nothing. This case is here is to handle when new attachment LinkHelper.openLink(items[currentIndex].attachment.url, context)
* 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. */
} }
} }

View file

@ -63,6 +63,7 @@ import com.keylesspalace.tusky.entity.PollOption;
import com.keylesspalace.tusky.entity.Status; import com.keylesspalace.tusky.entity.Status;
import com.keylesspalace.tusky.network.MastodonApi; import com.keylesspalace.tusky.network.MastodonApi;
import com.keylesspalace.tusky.network.TimelineCases; import com.keylesspalace.tusky.network.TimelineCases;
import com.keylesspalace.tusky.util.LinkHelper;
import com.keylesspalace.tusky.view.MuteAccountDialog; import com.keylesspalace.tusky.view.MuteAccountDialog;
import com.keylesspalace.tusky.viewdata.AttachmentViewData; import com.keylesspalace.tusky.viewdata.AttachmentViewData;
@ -395,10 +396,9 @@ public abstract class SFragment extends BaseFragment implements Injectable {
} }
break; break;
} }
default:
case UNKNOWN: { case UNKNOWN: {
/* Intentionally do nothing. This case is here is to handle when new attachment LinkHelper.openLink(active.getUrl(), getContext());
* 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. */
break; break;
} }
} }

View file

@ -228,7 +228,8 @@ class StatusViewHelper(private val itemView: View) {
return when (type) { return when (type) {
Attachment.Type.IMAGE -> context.getString(R.string.status_media_images) Attachment.Type.IMAGE -> context.getString(R.string.status_media_images)
Attachment.Type.GIFV, Attachment.Type.VIDEO -> context.getString(R.string.status_media_video) 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) { return when (type) {
Attachment.Type.IMAGE -> R.drawable.ic_photo_24dp Attachment.Type.IMAGE -> R.drawable.ic_photo_24dp
Attachment.Type.GIFV, Attachment.Type.VIDEO -> R.drawable.ic_videocam_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
} }
} }

View file

@ -326,6 +326,8 @@
<string name="status_share_link">Share link to toot</string> <string name="status_share_link">Share link to toot</string>
<string name="status_media_images">Images</string> <string name="status_media_images">Images</string>
<string name="status_media_video">Video</string> <string name="status_media_video">Video</string>
<string name="status_media_audio">Audio</string>
<string name="status_media_attachments">Attachments</string>
<string name="state_follow_requested">Follow requested</string> <string name="state_follow_requested">Follow requested</string>