添付メディアの拡張子がオーディオのそれだった場合の表示を改善。mastodonのfeature-audioブランチのtype=audioに対応。

This commit is contained in:
tateisu 2018-12-18 05:41:17 +09:00
parent aa3ab0bb73
commit 6bc570982b
8 changed files with 129 additions and 68 deletions

View File

@ -304,14 +304,15 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
tvDescription.text = description
}
if(TootAttachmentLike.TYPE_IMAGE == ta.type) {
loadBitmap(ta)
} else if(TootAttachmentLike.TYPE_VIDEO == ta.type || TootAttachmentLike.TYPE_GIFV == ta.type) {
loadVideo(ta)
} else {
when(ta.type){
TootAttachmentLike.TYPE_IMAGE ->loadBitmap(ta)
TootAttachmentLike.TYPE_VIDEO,
TootAttachmentLike.TYPE_GIFV,
TootAttachmentLike.TYPE_AUDIO ->loadVideo(ta)
// maybe TYPE_UNKNOWN
showError(getString(R.string.media_attachment_type_error, ta.type))
else-> showError(getString(R.string.media_attachment_type_error, ta.type))
}
}
private fun showError(message : String) {
@ -351,11 +352,10 @@ class ActMediaViewer : AppCompatActivity(), View.OnClickListener {
exoPlayer.prepare(mediaSource)
exoPlayer.playWhenReady = true
if(TootAttachmentLike.TYPE_GIFV == ta.type) {
exoPlayer.repeatMode = Player.REPEAT_MODE_ALL
} else {
exoPlayer.repeatMode = Player.REPEAT_MODE_OFF
exoPlayer.repeatMode = when(ta.type){
TootAttachmentLike.TYPE_VIDEO -> Player.REPEAT_MODE_OFF
// GIFV or AUDIO
else -> Player.REPEAT_MODE_ALL
}
}

View File

@ -1418,63 +1418,89 @@ internal class ItemViewHolder(
idx : Int
) {
val ta = if(idx < media_attachments.size) media_attachments[idx] else null
if(ta != null) {
val url = ta.urlForThumbnail
if(url != null && url.isNotEmpty()) {
iv.visibility = View.VISIBLE
iv.setFocusPoint(ta.focusX, ta.focusY)
if(Pref.bpDontCropMediaThumb(App1.pref)) {
iv.scaleType = ImageView.ScaleType.FIT_CENTER
} else {
iv.setScaleTypeForMedia()
}
val mediaType = ta.type
when(mediaType) {
TootAttachmentLike.TYPE_VIDEO -> iv.setMediaType(R.drawable.media_type_video)
TootAttachmentLike.TYPE_GIFV -> iv.setMediaType(R.drawable.media_type_gifv)
TootAttachmentLike.TYPE_UNKNOWN -> iv.setMediaType(R.drawable.media_type_unknown)
else -> iv.setMediaType(0)
}
iv.setImageUrl(
activity.pref,
0f,
access_info.supplyBaseUrl(url),
access_info.supplyBaseUrl(url)
)
val description = ta.description
if(description != null && description.isNotEmpty()) {
val lp = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
lp.topMargin = (0.5f + activity.density * 3f).toInt()
val tv = MyTextView(activity)
tv.layoutParams = lp
//
tv.movementMethod = MyLinkMovementMethod
if(! activity.timeline_font_size_sp.isNaN()) {
tv.textSize = activity.timeline_font_size_sp
if(ta == null) {
iv.visibility = View.GONE
return
}
iv.visibility = View.VISIBLE
iv.setFocusPoint(ta.focusX, ta.focusY)
if(Pref.bpDontCropMediaThumb(App1.pref)) {
iv.scaleType = ImageView.ScaleType.FIT_CENTER
} else {
iv.setScaleTypeForMedia()
}
when(ta.type) {
TootAttachmentLike.TYPE_AUDIO->{
iv.setMediaType(0)
iv.setDefaultImageResId(getAttributeResourceId(activity,R.attr.ic_music))
iv.setImageUrl(activity.pref,0f,null)
}
TootAttachmentLike.TYPE_UNKNOWN->{
iv.setMediaType(0)
iv.setDefaultImageResId(getAttributeResourceId(activity,R.attr.ic_question))
iv.setImageUrl(activity.pref,0f,null)
}
else->{
val url =ta.urlForThumbnail
when{
url?.isEmpty() != false ->{
iv.setMediaType(0)
iv.setDefaultImageResId(getAttributeResourceId(activity,R.attr.ic_question))
iv.setImageUrl(activity.pref,0f,null)
}
tv.setTextColor(content_color)
if(ta.description?.isNotEmpty() == true) {
if(sbDesc.isNotEmpty()) sbDesc.append("\n")
val desc =
activity.getString(R.string.media_description, idx + 1, ta.description)
sbDesc.append(desc)
else->{
when(ta.type) {
TootAttachmentLike.TYPE_VIDEO -> {
iv.setMediaType(R.drawable.media_type_video)
}
TootAttachmentLike.TYPE_GIFV -> {
iv.setMediaType(R.drawable.media_type_gifv)
}
}
iv.setDefaultImageResId(0)
iv.setImageUrl(
activity.pref,
0f,
access_info.supplyBaseUrl(url),
access_info.supplyBaseUrl(url)
)
}
}
return
}
}
iv.visibility = View.GONE
val description = ta.description
if(description != null && description.isNotEmpty()) {
val lp = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
lp.topMargin = (0.5f + activity.density * 3f).toInt()
val tv = MyTextView(activity)
tv.layoutParams = lp
//
tv.movementMethod = MyLinkMovementMethod
if(! activity.timeline_font_size_sp.isNaN()) {
tv.textSize = activity.timeline_font_size_sp
}
tv.setTextColor(content_color)
if(ta.description?.isNotEmpty() == true) {
if(sbDesc.isNotEmpty()) sbDesc.append("\n")
val desc =
activity.getString(R.string.media_description, idx + 1, ta.description)
sbDesc.append(desc)
}
}
}
private val defaultBoostedAction : () -> Unit = {

View File

@ -3,10 +3,7 @@ package jp.juggler.subwaytooter.api.entity
import android.content.SharedPreferences
import jp.juggler.subwaytooter.Pref
import jp.juggler.subwaytooter.api.TootParser
import jp.juggler.util.clipRange
import jp.juggler.util.jsonObject
import jp.juggler.util.parseLong
import jp.juggler.util.parseString
import jp.juggler.util.*
import org.json.JSONObject
class TootAttachment : TootAttachmentLike {
@ -37,6 +34,19 @@ class TootAttachment : TootAttachmentLike {
private const val KEY_Y = "y"
fun decodeJson(src : JSONObject) = TootAttachment(src, decode = true)
private val ext_audio = arrayOf(".mpga",".mp3",".aac",".ogg")
private fun guessMediaTypeByUrl(src : String?) : String? {
val uri = src.mayUri() ?: return null
if( ext_audio.find { uri.path.endsWith(it) } != null ){
return TootAttachmentLike.TYPE_AUDIO
}
return null
}
}
constructor(parser : TootParser, src : JSONObject) : this(parser.serviceType, src)
@ -85,10 +95,11 @@ class TootAttachment : TootAttachmentLike {
id = EntityId.mayDefault(src.parseString("id"))
val mimeType = src.parseString("type") ?: "?"
this.type = when {
mimeType.startsWith("image/") -> TootAttachmentLike.TYPE_IMAGE
mimeType.startsWith("video/") -> TootAttachmentLike.TYPE_VIDEO
mimeType.startsWith("audio/") -> TootAttachmentLike.TYPE_VIDEO
mimeType.startsWith("audio/") -> TootAttachmentLike.TYPE_AUDIO
else -> TootAttachmentLike.TYPE_UNKNOWN
}
@ -112,13 +123,18 @@ class TootAttachment : TootAttachmentLike {
else -> {
id = EntityId.mayDefault(src.parseLong("id"))
type = src.parseString("type")
url = src.parseString("url")
remote_url = src.parseString("remote_url")
preview_url = src.parseString("preview_url")
text_url = src.parseString("text_url")
description = src.parseString("description")
isSensitive = false
isSensitive = false // Misskey用のパラメータなので、マストドンでは適当な値を使ってOK
var t = src.parseString("type")
if( t ==null || t == TootAttachmentLike.TYPE_UNKNOWN ){
t = guessMediaTypeByUrl( remote_url ?: url)
}
type = t ?: TootAttachmentLike.TYPE_UNKNOWN
val focus = src.optJSONObject("meta")?.optJSONObject("focus")
focusX = parseFocusValue(focus, "x")
@ -128,6 +144,7 @@ class TootAttachment : TootAttachmentLike {
}
override val urlForThumbnail : String?
get() = when {
preview_url?.isNotEmpty() == true -> preview_url

View File

@ -16,6 +16,7 @@ interface TootAttachmentLike{
const val TYPE_VIDEO = "video"
const val TYPE_GIFV = "gifv"
const val TYPE_UNKNOWN = "unknown"
const val TYPE_AUDIO = "audio"
}
}

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="M12,3v10.55c-0.59,-0.34 -1.27,-0.55 -2,-0.55 -2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4V7h4V3h-6z"/>
</vector>

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,3v10.55c-0.59,-0.34 -1.27,-0.55 -2,-0.55 -2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4V7h4V3h-6z"/>
</vector>

View File

@ -156,5 +156,6 @@
<attr name="ic_local_lock" format="reference" />
<attr name="ic_local_lock_open" format="reference" />
<attr name="ic_local_ltl" format="reference" />
<attr name="ic_music" format="reference" />
</resources>

View File

@ -116,6 +116,7 @@
<item name="ic_local_lock">@drawable/ic_local_lock</item>
<item name="ic_local_lock_open">@drawable/ic_local_lock_open</item>
<item name="ic_local_ltl">@drawable/ic_local_ltl</item>
<item name="ic_music">@drawable/ic_music</item>
</style>
@ -242,6 +243,7 @@
<item name="ic_local_lock">@drawable/ic_local_lock_dark</item>
<item name="ic_local_lock_open">@drawable/ic_local_lock_open_dark</item>
<item name="ic_local_ltl">@drawable/ic_local_ltl_dark</item>
<item name="ic_music">@drawable/ic_music_dark</item>
</style>