Support opening unknown attachment types via `openLink` (#2044)

* Support opening unknown attachment types via openLink. #1970

* Fix label text for unknown attachment types
main
Levi Bard 3 years ago committed by Alibek Omarov
parent e162583309
commit 72865a0138
  1. 13
      app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java
  2. 2
      app/src/main/java/com/keylesspalace/tusky/components/conversation/ConversationViewHolder.java
  3. 1
      app/src/main/java/com/keylesspalace/tusky/components/search/fragments/SearchStatusesFragment.kt
  4. 7
      app/src/main/java/com/keylesspalace/tusky/fragment/AccountMediaFragment.kt
  5. 3
      app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java
  6. 6
      app/src/main/java/com/keylesspalace/tusky/util/StatusViewHelper.kt

@ -567,7 +567,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:
@ -575,6 +574,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;
} }
} }
@ -789,7 +790,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) {
@ -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) { 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,

@ -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());

@ -147,6 +147,7 @@ class SearchStatusesFragment : SearchFragment<Pair<Status, StatusViewData.Concre
} }
} }
Attachment.Type.UNKNOWN -> { 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.interfaces.RefreshableFragment
import com.keylesspalace.tusky.network.MastodonApi import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.settings.PrefKeys import com.keylesspalace.tusky.settings.PrefKeys
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
@ -273,10 +274,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. */
} }
} }

@ -437,8 +437,9 @@ public abstract class SFragment extends BaseFragment implements Injectable {
} }
break; break;
} }
default:
case UNKNOWN: { case UNKNOWN: {
onViewUrl(active.getUrl()); LinkHelper.openLink(active.getUrl(), getContext());
break; break;
} }
} }

@ -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
} }
} }

Loading…
Cancel
Save