refactor
This commit is contained in:
parent
447c945fda
commit
46df41f032
|
@ -1660,12 +1660,8 @@ class ActPost : AppCompatActivity(),
|
|||
editAttachmentDescription(pa)
|
||||
}
|
||||
|
||||
when {
|
||||
pa.attachment?.isAudio == true -> {
|
||||
// can't set focus
|
||||
}
|
||||
|
||||
else -> a.addAction(getString(R.string.set_focus_point)) {
|
||||
if( pa.attachment?.canFocus == true){
|
||||
a.addAction(getString(R.string.set_focus_point)) {
|
||||
openFocusPoint(pa)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1744,14 +1744,9 @@ internal class ItemViewHolder(
|
|||
sbDesc.append(desc)
|
||||
}
|
||||
|
||||
val description = ta.description
|
||||
if(description?.isNotEmpty() == true) {
|
||||
appendDescription(description)
|
||||
} else {
|
||||
val urlString = ta.getUrlString()
|
||||
if(showUrl && urlString?.isNotEmpty() == true) {
|
||||
appendDescription(urlString)
|
||||
}
|
||||
when(val description = ta.description.notEmpty()) {
|
||||
null -> if(showUrl) ta.urlForDescription.notEmpty()?.let { appendDescription(it) }
|
||||
else -> appendDescription(description)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2168,8 +2163,15 @@ internal class ItemViewHolder(
|
|||
is TootAttachment -> when {
|
||||
|
||||
// unknownが1枚だけなら内蔵ビューアを使わずにインテントを投げる
|
||||
item.type == TootAttachmentType.Unknown && media_attachments.size == 1 ->
|
||||
App1.openCustomTab(activity, item.remote_url!!)
|
||||
item.type == TootAttachmentType.Unknown && media_attachments.size == 1 -> {
|
||||
// https://github.com/tateisu/SubwayTooter/pull/119
|
||||
// メディアタイプがunknownの場合、そのほとんどはリモートから来たURLである
|
||||
// Pref.bpPriorLocalURL の状態に関わらずリモートURLがあればそれをブラウザで開く
|
||||
when(val remoteUrl = item.remote_url.notEmpty()) {
|
||||
null -> App1.openCustomTab(activity, item)
|
||||
else -> App1.openCustomTab(activity, remoteUrl)
|
||||
}
|
||||
}
|
||||
|
||||
// 内蔵メディアビューアを使う
|
||||
Pref.bpUseInternalMediaViewer(App1.pref) ->
|
||||
|
|
|
@ -94,12 +94,11 @@ class TootAttachment : TootAttachmentLike {
|
|||
else -> false
|
||||
}
|
||||
|
||||
override fun getUrlString() : String? =
|
||||
if(remote_url?.isNotEmpty() == true) {
|
||||
remote_url
|
||||
} else {
|
||||
url
|
||||
}
|
||||
override val urlForDescription: String?
|
||||
get() = remote_url.notEmpty() ?: url
|
||||
|
||||
override val urlForThumbnail : String?
|
||||
get() = preview_url.notEmpty() ?: remote_url.notEmpty() ?: url
|
||||
|
||||
constructor(serviceType : ServiceType, src : JSONObject) {
|
||||
|
||||
|
@ -166,33 +165,24 @@ class TootAttachment : TootAttachmentLike {
|
|||
private fun parseType(src : String?) =
|
||||
TootAttachmentType.values().find { it.id == src }
|
||||
|
||||
override val urlForThumbnail : String?
|
||||
get() = when {
|
||||
preview_url?.isNotEmpty() == true -> preview_url
|
||||
remote_url?.isNotEmpty() == true -> remote_url
|
||||
url?.isNotEmpty() == true -> url
|
||||
else -> null
|
||||
}
|
||||
|
||||
fun getLargeUrl(pref : SharedPreferences) : String? {
|
||||
return if(Pref.bpPriorLocalURL(pref)) {
|
||||
if(url?.isNotEmpty() == true) url else remote_url
|
||||
} else {
|
||||
if(remote_url?.isNotEmpty() == true) remote_url else url
|
||||
}
|
||||
}
|
||||
|
||||
fun getLargeUrlList(pref : SharedPreferences) : ArrayList<String> {
|
||||
val result = ArrayList<String>()
|
||||
fun getLargeUrl(pref : SharedPreferences) =
|
||||
if(Pref.bpPriorLocalURL(pref)) {
|
||||
if(url?.isNotEmpty() == true) result.add(url)
|
||||
if(remote_url?.isNotEmpty() == true) result.add(remote_url)
|
||||
url.notEmpty() ?: remote_url
|
||||
} else {
|
||||
if(remote_url?.isNotEmpty() == true) result.add(remote_url)
|
||||
if(url?.isNotEmpty() == true) result.add(url)
|
||||
remote_url.notEmpty() ?: url
|
||||
}
|
||||
|
||||
fun getLargeUrlList(pref : SharedPreferences) =
|
||||
ArrayList<String>().apply {
|
||||
if(Pref.bpPriorLocalURL(pref)) {
|
||||
url.notEmpty()?.addTo(this)
|
||||
remote_url.notEmpty()?.addTo(this)
|
||||
} else {
|
||||
remote_url.notEmpty()?.addTo(this)
|
||||
url.notEmpty()?.addTo(this)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun encodeJson() = jsonObject {
|
||||
put(KEY_IS_STRING_ID, true)
|
||||
|
|
|
@ -12,22 +12,21 @@ interface TootAttachmentLike{
|
|||
|
||||
val type : TootAttachmentType
|
||||
val description : String?
|
||||
|
||||
// url for thumbnail, or null or empty
|
||||
val urlForThumbnail : String?
|
||||
|
||||
// url for description, or null or empty
|
||||
val urlForDescription :String?
|
||||
|
||||
val focusX : Float
|
||||
val focusY : Float
|
||||
|
||||
|
||||
// true if argument url is included in this attachment.
|
||||
fun hasUrl(url:String):Boolean
|
||||
|
||||
fun getUrlString() :String?
|
||||
|
||||
|
||||
val isAudio : Boolean
|
||||
get()= type == TootAttachmentType.Audio
|
||||
|
||||
// GIFVの考慮漏れに注意?
|
||||
val isVideo : Boolean
|
||||
get()= type == TootAttachmentType.Video
|
||||
|
||||
// true if the attachment can be set focus point.
|
||||
val canFocus : Boolean
|
||||
get()= type != TootAttachmentType.Audio
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package jp.juggler.subwaytooter.api.entity
|
||||
|
||||
import jp.juggler.util.notEmpty
|
||||
import jp.juggler.util.parseString
|
||||
import org.json.JSONArray
|
||||
|
||||
|
@ -7,7 +8,6 @@ class TootAttachmentMSP(
|
|||
val preview_url : String
|
||||
) : TootAttachmentLike {
|
||||
|
||||
|
||||
override val type : TootAttachmentType
|
||||
get() = TootAttachmentType.Unknown
|
||||
|
||||
|
@ -17,26 +17,26 @@ class TootAttachmentMSP(
|
|||
override val urlForThumbnail : String?
|
||||
get() = preview_url
|
||||
|
||||
override val urlForDescription : String?
|
||||
get() = preview_url
|
||||
|
||||
override val focusX : Float
|
||||
get() = 0f
|
||||
|
||||
|
||||
override val focusY : Float
|
||||
get() = 0f
|
||||
|
||||
override fun hasUrl(url:String):Boolean = (url == this.preview_url)
|
||||
|
||||
override fun getUrlString() :String? = preview_url
|
||||
|
||||
override fun hasUrl(url : String) : Boolean = (url == this.preview_url)
|
||||
|
||||
companion object {
|
||||
fun parseList(array : JSONArray?) : ArrayList<TootAttachmentLike>? {
|
||||
if(array != null) {
|
||||
val array_size = array.length()
|
||||
if(array_size > 0) {
|
||||
val result = ArrayList<TootAttachmentLike>()
|
||||
val result = ArrayList<TootAttachmentLike>()
|
||||
result.ensureCapacity(array_size)
|
||||
for(i in 0 until array_size) {
|
||||
val sv = array.parseString( i)
|
||||
val sv = array.parseString(i)
|
||||
if(sv != null && sv.isNotBlank()) {
|
||||
result.add(TootAttachmentMSP(sv))
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package jp.juggler.util
|
||||
|
||||
// same as x?.let{ dst.add(it) }
|
||||
fun <T> T.addTo(dst: ArrayList<T>) = dst.add(this)
|
Loading…
Reference in New Issue