トゥート時刻表示と内蔵メディアビューアの軽いリファクタ

This commit is contained in:
tateisu 2018-04-06 03:04:45 +09:00
parent b54920cb7f
commit 2b824c3431
3 changed files with 124 additions and 71 deletions

View File

@ -61,6 +61,7 @@
<w>thru</w> <w>thru</w>
<w>timelines</w> <w>timelines</w>
<w>tootsearch</w> <w>tootsearch</w>
<w>unarist</w>
<w>unfavourite</w> <w>unfavourite</w>
<w>unfollow</w> <w>unfollow</w>
<w>unmute</w> <w>unmute</w>

View File

@ -457,7 +457,7 @@ internal class ItemViewHolder(
boost_time = time boost_time = time
llBoosted.visibility = View.VISIBLE llBoosted.visibility = View.VISIBLE
ivBoosted.setImageResource(Styler.getAttributeResourceId(activity, icon_attr_id)) ivBoosted.setImageResource(Styler.getAttributeResourceId(activity, icon_attr_id))
tvBoostedTime.text = TootStatus.formatTime(tvBoostedTime.context, time, true) showStatusTime(activity, tvBoostedTime, who, time = time)
tvBoosted.text = text tvBoosted.text = text
boost_invalidator.register(text) boost_invalidator.register(text)
setAcct(tvBoostedAcct, access_info.getFullAcct(who), who.acct) setAcct(tvBoostedAcct, access_info.getFullAcct(who), who.acct)
@ -484,7 +484,7 @@ internal class ItemViewHolder(
this.status_showing = status this.status_showing = status
llStatus.visibility = View.VISIBLE llStatus.visibility = View.VISIBLE
showStatusTime(activity, status) showStatusTime(activity, tvTime, who = status.account, status = status)
val who = status.account val who = status.account
this.status_account = who this.status_account = who
@ -623,11 +623,33 @@ internal class ItemViewHolder(
} }
} }
private fun showStatusTime(activity : ActMain, status : TootStatus) { private fun showStatusTime(
activity : ActMain,
tv : TextView,
@Suppress("UNUSED_PARAMETER") who : TootAccount,
status : TootStatus? = null,
time : Long? = null
) {
val sb = SpannableStringBuilder() val sb = SpannableStringBuilder()
// if(access_info.getFullAcct(who) == "unarist@mstdn.maud.io") {
// // if(sb.isNotEmpty()) sb.append(' ')
//
// val start = sb.length
// sb.append("unarist")
// val end = sb.length
// val icon_id = R.drawable.unarist
// sb.setSpan(
// EmojiImageSpan(activity, icon_id),
// start,
// end,
// Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
// )
// }
if(status != null) {
if(status.hasMedia() && status.sensitive) { if(status.hasMedia() && status.sensitive) {
// if( sb.length() > 0 ) sb.append( ' ' ); if(sb.isNotEmpty()) sb.append(' ')
val start = sb.length val start = sb.length
sb.append("NSFW") sb.append("NSFW")
@ -670,15 +692,26 @@ internal class ItemViewHolder(
) )
} }
}
if(sb.isNotEmpty()) sb.append(' ') if(sb.isNotEmpty()) sb.append(' ')
sb.append( sb.append(
TootStatus.formatTime( when {
time != null -> TootStatus.formatTime(
activity,
time,
column.column_type != Column.TYPE_CONVERSATION
)
status != null -> TootStatus.formatTime(
activity, activity,
status.time_created_at, status.time_created_at,
column.column_type != Column.TYPE_CONVERSATION column.column_type != Column.TYPE_CONVERSATION
) )
else -> "?"
}
) )
tvTime.text = sb
tv.text = sb
} }
// fun updateRelativeTime() { // fun updateRelativeTime() {
@ -1456,7 +1489,9 @@ internal class ItemViewHolder(
val actMain = activity as? ActMain val actMain = activity as? ActMain
val thumbnailHeight = actMain?.app_state?.media_thumb_height ?: dip(64) val thumbnailHeight = actMain?.app_state?.media_thumb_height ?: dip(64)
val verticalArrangeThumbnails = Pref.bpVerticalArrangeThumbnails( actMain?.pref ?: Pref.pref(context)) val verticalArrangeThumbnails = Pref.bpVerticalArrangeThumbnails(
actMain?.pref ?: Pref.pref(context)
)
flMedia = if(verticalArrangeThumbnails) { flMedia = if(verticalArrangeThumbnails) {
frameLayout { frameLayout {
@ -1548,7 +1583,10 @@ internal class ItemViewHolder(
gravity = Gravity.CENTER_VERTICAL or Gravity.END gravity = Gravity.CENTER_VERTICAL or Gravity.END
text = context.getString(R.string.tap_to_show) text = context.getString(R.string.tap_to_show)
textColor = textColor =
Styler.getAttributeColor(context, R.attr.colorShowMediaText) Styler.getAttributeColor(
context,
R.attr.colorShowMediaText
)
endPadding = dip(4) endPadding = dip(4)
minHeightCompat = dip(32) minHeightCompat = dip(32)
}.lparams(matchParent, matchParent) }.lparams(matchParent, matchParent)
@ -1646,7 +1684,10 @@ internal class ItemViewHolder(
gravity = Gravity.CENTER gravity = Gravity.CENTER
text = context.getString(R.string.tap_to_show) text = context.getString(R.string.tap_to_show)
textColor = textColor =
Styler.getAttributeColor(context, R.attr.colorShowMediaText) Styler.getAttributeColor(
context,
R.attr.colorShowMediaText
)
}.lparams(matchParent, matchParent) }.lparams(matchParent, matchParent)
} }

View File

@ -172,10 +172,14 @@ class PinchBitmapView(context : Context, attrs : AttributeSet?, defStyle : Int)
override fun performClick() : Boolean { override fun performClick() : Boolean {
super.performClick() super.performClick()
initializeScale() initializeScale()
return true return true
} }
var defaultScale :Float = 1f
// 表示位置の初期化 // 表示位置の初期化
// 呼ばれるのは、ビットマップを変更した時、ビューのサイズが変わった時、画像をクリックした時 // 呼ばれるのは、ビットマップを変更した時、ビューのサイズが変わった時、画像をクリックした時
private fun initializeScale() { private fun initializeScale() {
@ -186,23 +190,37 @@ class PinchBitmapView(context : Context, attrs : AttributeSet?, defStyle : Int)
bitmap_h = Math.max(1f, bitmap.height.toFloat()) bitmap_h = Math.max(1f, bitmap.height.toFloat())
bitmap_aspect = bitmap_w / bitmap_h bitmap_aspect = bitmap_w / bitmap_h
current_scale = if(view_aspect > bitmap_aspect) { if(view_aspect > bitmap_aspect) {
scale_min = view_h / bitmap_h / 2f
scale_max = view_w / bitmap_w * 8f
} else {
scale_min = view_w / bitmap_w / 2f
scale_max = view_h / bitmap_h * 8f
}
if(scale_max < scale_min) scale_max = scale_min * 16f
defaultScale = if(view_aspect > bitmap_aspect) {
view_h / bitmap_h view_h / bitmap_h
} else { } else {
view_w / bitmap_w view_w / bitmap_w
} }
val draw_w = bitmap_w * current_scale val draw_w = bitmap_w * defaultScale
val draw_h = bitmap_h * current_scale val draw_h = bitmap_h * defaultScale
current_scale = defaultScale
current_trans_x = (view_w - draw_w) / 2f current_trans_x = (view_w - draw_w) / 2f
current_trans_y = (view_h - draw_h) / 2f current_trans_y = (view_h - draw_h) / 2f
callback?.onMove(bitmap_w, bitmap_h, current_trans_x, current_trans_y, current_scale) callback?.onMove(bitmap_w, bitmap_h, current_trans_x, current_trans_y, current_scale)
} else { } else {
defaultScale = 1f
scale_min = 1f
scale_max = 1f
current_scale = defaultScale
current_trans_y = 0f current_trans_y = 0f
current_trans_x = current_trans_y current_trans_x = 0f
current_scale = 1f
callback?.onMove(0f, 0f, current_trans_x, current_trans_y, current_scale) callback?.onMove(0f, 0f, current_trans_x, current_trans_y, current_scale)
} }
@ -388,14 +406,7 @@ class PinchBitmapView(context : Context, attrs : AttributeSet?, defStyle : Int)
start_image_trans_y = current_trans_y start_image_trans_y = current_trans_y
start_image_scale = current_scale start_image_scale = current_scale
if(view_aspect > bitmap_aspect) {
scale_min = view_h / bitmap_h / 2f
scale_max = view_w / bitmap_w * 8f
} else {
scale_min = view_w / bitmap_w / 2f
scale_max = view_h / bitmap_h * 8f
}
if(scale_max < scale_min) scale_max = scale_min * 16f
} }
// 画面上の指の位置から画像中の指の位置を調べる // 画面上の指の位置から画像中の指の位置を調べる