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
cb2296f248
commit
baa915a0a3
7 changed files with 22 additions and 16 deletions
|
@ -533,7 +533,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:
|
||||
|
@ -541,6 +540,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -718,7 +719,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) {
|
||||
|
@ -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) {
|
||||
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());
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ import com.keylesspalace.tusky.interfaces.AccountSelectionListener
|
|||
import com.keylesspalace.tusky.interfaces.StatusActionListener
|
||||
import com.keylesspalace.tusky.settings.PrefKeys
|
||||
import com.keylesspalace.tusky.util.CardViewMode
|
||||
import com.keylesspalace.tusky.util.LinkHelper
|
||||
import com.keylesspalace.tusky.util.NetworkState
|
||||
import com.keylesspalace.tusky.util.StatusDisplayOptions
|
||||
import com.keylesspalace.tusky.view.showMuteAccountDialog
|
||||
|
@ -143,6 +144,7 @@ class SearchStatusesFragment : SearchFragment<Pair<Status, StatusViewData.Concre
|
|||
}
|
||||
}
|
||||
Attachment.Type.UNKNOWN -> {
|
||||
LinkHelper.openLink(actionable.attachments[attachmentIndex].url, context)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import com.keylesspalace.tusky.entity.Attachment
|
|||
import com.keylesspalace.tusky.entity.Status
|
||||
import com.keylesspalace.tusky.interfaces.RefreshableFragment
|
||||
import com.keylesspalace.tusky.network.MastodonApi
|
||||
import com.keylesspalace.tusky.util.LinkHelper
|
||||
import com.keylesspalace.tusky.util.ThemeUtils
|
||||
import com.keylesspalace.tusky.util.hide
|
||||
import com.keylesspalace.tusky.util.show
|
||||
|
@ -260,10 +261,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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ import com.keylesspalace.tusky.entity.PollOption;
|
|||
import com.keylesspalace.tusky.entity.Status;
|
||||
import com.keylesspalace.tusky.network.MastodonApi;
|
||||
import com.keylesspalace.tusky.network.TimelineCases;
|
||||
import com.keylesspalace.tusky.util.LinkHelper;
|
||||
import com.keylesspalace.tusky.view.MuteAccountDialog;
|
||||
import com.keylesspalace.tusky.viewdata.AttachmentViewData;
|
||||
|
||||
|
@ -395,10 +396,9 @@ public abstract class SFragment extends BaseFragment implements Injectable {
|
|||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
case 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(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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -326,6 +326,8 @@
|
|||
<string name="status_share_link">Share link to toot</string>
|
||||
<string name="status_media_images">Images</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>
|
||||
|
||||
|
|
Loading…
Reference in a new issue