Misskeyで音声アップロード完了後に表示が変わらない問題の修正

This commit is contained in:
tateisu 2019-06-23 23:58:53 +09:00
parent ccd16c52e6
commit 4f43dba3c4
11 changed files with 101 additions and 70 deletions

View File

@ -40,7 +40,7 @@
</value> </value>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -311,12 +311,17 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
} }
when(ta.type) { when(ta.type) {
TootAttachmentLike.TYPE_IMAGE -> loadBitmap(ta)
TootAttachmentLike.TYPE_VIDEO, TootAttachmentType.Unknown ->
TootAttachmentLike.TYPE_GIFV, showError(getString(R.string.media_attachment_type_error, ta.type.id))
TootAttachmentLike.TYPE_AUDIO -> loadVideo(ta, state)
// maybe TYPE_UNKNOWN TootAttachmentType.Image ->
else -> showError(getString(R.string.media_attachment_type_error, ta.type)) loadBitmap(ta)
TootAttachmentType.Video,
TootAttachmentType.GIFV,
TootAttachmentType.Audio ->
loadVideo(ta, state)
} }
} }
@ -358,7 +363,7 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
exoPlayer.prepare(mediaSource) exoPlayer.prepare(mediaSource)
exoPlayer.repeatMode = when(ta.type) { exoPlayer.repeatMode = when(ta.type) {
TootAttachmentLike.TYPE_VIDEO -> Player.REPEAT_MODE_OFF TootAttachmentType.Video -> Player.REPEAT_MODE_OFF
// GIFV or AUDIO // GIFV or AUDIO
else -> Player.REPEAT_MODE_ALL else -> Player.REPEAT_MODE_ALL
} }

View File

@ -1456,21 +1456,20 @@ class ActPost : AppCompatActivity(),
a == null || pa.status != PostAttachment.STATUS_UPLOADED -> { a == null || pa.status != PostAttachment.STATUS_UPLOADED -> {
iv.setDefaultImage(defaultColorIcon(this, R.drawable.ic_upload)) iv.setDefaultImage(defaultColorIcon(this, R.drawable.ic_upload))
iv.setErrorImage(defaultColorIcon(this, R.drawable.ic_unknown)) iv.setErrorImage(defaultColorIcon(this, R.drawable.ic_clip))
iv.setImageUrl(pref, Styler.calcIconRound(iv.layoutParams.width), null) iv.setImageUrl(pref, Styler.calcIconRound(iv.layoutParams.width), null)
} }
else -> { else ->{
iv.setDefaultImage(defaultColorIcon(this, R.drawable.ic_upload)) val defaultIconId = when(a.type) {
iv.setErrorImage( TootAttachmentType.Image -> R.drawable.ic_image
defaultColorIcon( TootAttachmentType.Video,
this, TootAttachmentType.GIFV ->R.drawable.ic_videocam
when { TootAttachmentType.Audio ->R.drawable.ic_music_note
a.isAudio -> R.drawable.ic_music_note else -> R.drawable.ic_clip
else -> R.drawable.ic_unknown }
} iv.setDefaultImage(defaultColorIcon(this,defaultIconId))
) iv.setErrorImage(defaultColorIcon(this,defaultIconId))
)
iv.setImageUrl(pref, Styler.calcIconRound(iv.layoutParams.width), a.preview_url) iv.setImageUrl(pref, Styler.calcIconRound(iv.layoutParams.width), a.preview_url)
} }
} }
@ -1485,25 +1484,25 @@ class ActPost : AppCompatActivity(),
showToast(this, false, ex.withCaption("can't get attachment item[$idx].")) showToast(this, false, ex.withCaption("can't get attachment item[$idx]."))
return return
} }
val a = ActionsDialog() val a = ActionsDialog()
.addAction( getString(R.string.set_description) ){ .addAction(getString(R.string.set_description)) {
editAttachmentDescription(pa) editAttachmentDescription(pa)
} }
if( pa.attachment?.isAudio == true ){ if(pa.attachment?.isAudio == true) {
// can't set focus // can't set focus
}else{ } else {
a.addAction(getString(R.string.set_focus_point)){ a.addAction(getString(R.string.set_focus_point)) {
openFocusPoint(pa) openFocusPoint(pa)
} }
} }
a.addAction(getString(R.string.delete)){ a.addAction(getString(R.string.delete)) {
deleteAttachment(pa) deleteAttachment(pa)
} }
a.show(this,title = getString(R.string.media_attachment)) a.show(this, title = getString(R.string.media_attachment))
} }
private fun openFocusPoint(pa : PostAttachment) { private fun openFocusPoint(pa : PostAttachment) {

View File

@ -1632,14 +1632,14 @@ internal class ItemViewHolder(
val showUrl : Boolean val showUrl : Boolean
when(ta.type) { when(ta.type) {
TootAttachmentLike.TYPE_AUDIO -> { TootAttachmentType.Audio -> {
iv.setMediaType(0) iv.setMediaType(0)
iv.setDefaultImage(defaultColorIcon(activity, R.drawable.wide_music)) iv.setDefaultImage(defaultColorIcon(activity, R.drawable.wide_music))
iv.setImageUrl(activity.pref, 0f, null) iv.setImageUrl(activity.pref, 0f, null)
showUrl = true showUrl = true
} }
TootAttachmentLike.TYPE_UNKNOWN -> { TootAttachmentType.Unknown -> {
iv.setMediaType(0) iv.setMediaType(0)
iv.setDefaultImage(defaultColorIcon(activity, R.drawable.wide_question)) iv.setDefaultImage(defaultColorIcon(activity, R.drawable.wide_question))
iv.setImageUrl(activity.pref, 0f, null) iv.setImageUrl(activity.pref, 0f, null)
@ -1657,8 +1657,8 @@ internal class ItemViewHolder(
else -> { else -> {
iv.setMediaType( iv.setMediaType(
when(ta.type) { when(ta.type) {
TootAttachmentLike.TYPE_VIDEO -> R.drawable.media_type_video TootAttachmentType.Video -> R.drawable.media_type_video
TootAttachmentLike.TYPE_GIFV -> R.drawable.media_type_gifv TootAttachmentType.GIFV -> R.drawable.media_type_gifv
else -> 0 else -> 0
} }
) )
@ -2098,7 +2098,7 @@ internal class ItemViewHolder(
is TootAttachment -> when { is TootAttachment -> when {
// unknownが1枚だけなら内蔵ビューアを使わずにインテントを投げる // unknownが1枚だけなら内蔵ビューアを使わずにインテントを投げる
item.type == TootAttachmentLike.TYPE_UNKNOWN && media_attachments.size == 1 -> item.type == TootAttachmentType.Unknown && media_attachments.size == 1 ->
App1.openCustomTab(activity, item) App1.openCustomTab(activity, item)
// 内蔵メディアビューアを使う // 内蔵メディアビューアを使う

View File

@ -36,13 +36,13 @@ class TootAttachment : TootAttachmentLike {
fun decodeJson(src : JSONObject) = TootAttachment(src, decode = true) fun decodeJson(src : JSONObject) = TootAttachment(src, decode = true)
private val ext_audio = arrayOf(".mpga",".mp3",".aac",".ogg") private val ext_audio = arrayOf(".mpga", ".mp3", ".aac", ".ogg")
private fun guessMediaTypeByUrl(src : String?) : String? { private fun guessMediaTypeByUrl(src : String?) : TootAttachmentType? {
val uri = src.mayUri() ?: return null val uri = src.mayUri() ?: return null
if( ext_audio.find { uri.path?.endsWith(it) == true } != null ){ if(ext_audio.find { uri.path?.endsWith(it) == true } != null) {
return TootAttachmentLike.TYPE_AUDIO return TootAttachmentType.Audio
} }
return null return null
@ -56,7 +56,7 @@ class TootAttachment : TootAttachmentLike {
val id : EntityId val id : EntityId
//One of: "image", "video", "gifv". or may null ? may "unknown" ? //One of: "image", "video", "gifv". or may null ? may "unknown" ?
override val type : String? override val type : TootAttachmentType
//URL of the locally hosted version of the image //URL of the locally hosted version of the image
val url : String? val url : String?
@ -65,6 +65,8 @@ class TootAttachment : TootAttachmentLike {
val remote_url : String? val remote_url : String?
// URL of the preview image // URL of the preview image
// (Mastodon 2.9.2) audioのpreview_url は .mpga のURL
// (Misskey v11) audioのpreview_url は null
val preview_url : String? val preview_url : String?
// Shorter URL for the image, for insertion into text (only present on local images) // Shorter URL for the image, for insertion into text (only present on local images)
@ -92,10 +94,10 @@ class TootAttachment : TootAttachmentLike {
else -> false else -> false
} }
override fun getUrlString() :String? = override fun getUrlString() : String? =
if( remote_url?.isNotEmpty()==true){ if(remote_url?.isNotEmpty() == true) {
remote_url remote_url
}else{ } else {
url url
} }
@ -106,12 +108,12 @@ class TootAttachment : TootAttachmentLike {
id = EntityId.mayDefault(src.parseString("id")) id = EntityId.mayDefault(src.parseString("id"))
val mimeType = src.parseString("type") ?: "?" val mimeType = src.parseString("type") ?: "?"
this.type = when { this.type = when {
mimeType.startsWith("image/") -> TootAttachmentLike.TYPE_IMAGE mimeType.startsWith("image/") -> TootAttachmentType.Image
mimeType.startsWith("video/") -> TootAttachmentLike.TYPE_VIDEO mimeType.startsWith("video/") -> TootAttachmentType.Video
mimeType.startsWith("audio/") -> TootAttachmentLike.TYPE_AUDIO mimeType.startsWith("audio/") -> TootAttachmentType.Audio
else -> TootAttachmentLike.TYPE_UNKNOWN else -> TootAttachmentType.Unknown
} }
url = src.parseString("url") url = src.parseString("url")
@ -142,11 +144,13 @@ class TootAttachment : TootAttachmentLike {
description = src.parseString("description") description = src.parseString("description")
isSensitive = false // Misskey用のパラメータなので、マストドンでは適当な値を使ってOK isSensitive = false // Misskey用のパラメータなので、マストドンでは適当な値を使ってOK
var t = src.parseString("type") type = when(val tmpType = parseType(src.parseString("type"))) {
if( t ==null || t == TootAttachmentLike.TYPE_UNKNOWN ){ null, TootAttachmentType.Unknown -> {
t = guessMediaTypeByUrl( remote_url ?: url) guessMediaTypeByUrl(remote_url ?: url) ?: TootAttachmentType.Unknown
}
else -> tmpType
} }
type = t ?: TootAttachmentLike.TYPE_UNKNOWN
val focus = src.optJSONObject("meta")?.optJSONObject("focus") val focus = src.optJSONObject("meta")?.optJSONObject("focus")
focusX = parseFocusValue(focus, "x") focusX = parseFocusValue(focus, "x")
@ -159,6 +163,8 @@ class TootAttachment : TootAttachmentLike {
} }
private fun parseType(src : String?) =
TootAttachmentType.values().find { it.id == src }
override val urlForThumbnail : String? override val urlForThumbnail : String?
get() = when { get() = when {
@ -191,7 +197,7 @@ class TootAttachment : TootAttachmentLike {
fun encodeJson() = jsonObject { fun encodeJson() = jsonObject {
put(KEY_IS_STRING_ID, true) put(KEY_IS_STRING_ID, true)
put(KEY_ID, id.toString()) put(KEY_ID, id.toString())
put(KEY_TYPE, type) put(KEY_TYPE, type.id)
put(KEY_URL, url) put(KEY_URL, url)
put(KEY_REMOTE_URL, remote_url) put(KEY_REMOTE_URL, remote_url)
put(KEY_PREVIEW_URL, preview_url) put(KEY_PREVIEW_URL, preview_url)
@ -217,12 +223,19 @@ class TootAttachment : TootAttachmentLike {
) { ) {
id = EntityId.mayDefault(src.parseString(KEY_ID)) id = EntityId.mayDefault(src.parseString(KEY_ID))
type = src.parseString(KEY_TYPE)
url = src.parseString(KEY_URL) url = src.parseString(KEY_URL)
remote_url = src.parseString(KEY_REMOTE_URL) remote_url = src.parseString(KEY_REMOTE_URL)
preview_url = src.parseString(KEY_PREVIEW_URL) preview_url = src.parseString(KEY_PREVIEW_URL)
text_url = src.parseString(KEY_TEXT_URL) text_url = src.parseString(KEY_TEXT_URL)
type = when(val tmpType = parseType(src.parseString(KEY_TYPE))) {
null, TootAttachmentType.Unknown -> {
guessMediaTypeByUrl(remote_url ?: url) ?: TootAttachmentType.Unknown
}
else -> tmpType
}
description = src.parseString(KEY_DESCRIPTION) description = src.parseString(KEY_DESCRIPTION)
isSensitive = src.optBoolean(KEY_IS_SENSITIVE) isSensitive = src.optBoolean(KEY_IS_SENSITIVE)

View File

@ -1,16 +1,16 @@
package jp.juggler.subwaytooter.api.entity package jp.juggler.subwaytooter.api.entity
interface TootAttachmentLike{ enum class TootAttachmentType(val id:String){
Unknown("unknown"),
companion object { Image( "image"),
const val TYPE_IMAGE = "image" Video("video"),
const val TYPE_VIDEO = "video" GIFV("gifv"),
const val TYPE_GIFV = "gifv" Audio("audio")
const val TYPE_UNKNOWN = "unknown" }
const val TYPE_AUDIO = "audio"
}
val type : String? interface TootAttachmentLike{
val type : TootAttachmentType
val description : String? val description : String?
val urlForThumbnail : String? val urlForThumbnail : String?
@ -23,6 +23,11 @@ interface TootAttachmentLike{
val isAudio : Boolean val isAudio : Boolean
get()= type == TYPE_AUDIO get()= type == TootAttachmentType.Audio
// GIFVの考慮漏れに注意
val isVideo : Boolean
get()= type == TootAttachmentType.Video
} }

View File

@ -8,8 +8,8 @@ class TootAttachmentMSP(
) : TootAttachmentLike { ) : TootAttachmentLike {
override val type : String? override val type : TootAttachmentType
get() = null get() = TootAttachmentType.Unknown
override val description : String? override val description : String?
get() = null get() = null

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M2,12.5C2,9.46 4.46,7 7.5,7H18c2.21,0 4,1.79 4,4s-1.79,4 -4,4H9.5C8.12,15 7,13.88 7,12.5S8.12,10 9.5,10H17v2H9.41c-0.55,0 -0.55,1 0,1H18c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2H7.5C5.57,9 4,10.57 4,12.5S5.57,16 7.5,16H17v2H7.5C4.46,18 2,15.54 2,12.5z"/>
</vector>

View File

@ -5,5 +5,5 @@
android:viewportHeight="24.0"> android:viewportHeight="24.0">
<path <path
android:fillColor="#FF000000" android:fillColor="#FF000000"
android:pathData="M19,3L5,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM19,19L5,19L5,5h14v14z"/> android:pathData="M17,10.5V7c0,-0.55 -0.45,-1 -1,-1H4c-0.55,0 -1,0.45 -1,1v10c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1v-3.5l4,4v-11l-4,4z"/>
</vector> </vector>

View File

@ -517,7 +517,7 @@
android:layout_height="48dp" android:layout_height="48dp"
android:background="@drawable/btn_bg_transparent" android:background="@drawable/btn_bg_transparent"
android:contentDescription="@string/media_attachment" android:contentDescription="@string/media_attachment"
android:src="@drawable/ic_attachment" android:src="@drawable/ic_clip"
android:tint="?attr/colorVectorDrawable" android:tint="?attr/colorVectorDrawable"
/> />