2018-01-04 19:52:25 +01:00
|
|
|
package jp.juggler.subwaytooter
|
|
|
|
|
|
|
|
import android.content.Context
|
2019-12-15 20:12:57 +01:00
|
|
|
import android.content.res.Configuration
|
2019-01-16 13:33:07 +01:00
|
|
|
import android.graphics.PorterDuff
|
|
|
|
import android.graphics.drawable.Drawable
|
2018-01-04 19:52:25 +01:00
|
|
|
import android.text.SpannableStringBuilder
|
|
|
|
import android.text.Spanned
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.ImageButton
|
|
|
|
import android.widget.ImageView
|
2020-09-09 21:46:50 +02:00
|
|
|
import androidx.core.content.ContextCompat
|
2021-05-19 22:14:30 +02:00
|
|
|
import jp.juggler.subwaytooter.emoji.EmojiMap
|
2018-01-04 19:52:25 +01:00
|
|
|
import jp.juggler.subwaytooter.api.entity.TootAccount
|
2018-08-20 19:37:42 +02:00
|
|
|
import jp.juggler.subwaytooter.api.entity.TootVisibility
|
2018-01-04 19:52:25 +01:00
|
|
|
import jp.juggler.subwaytooter.span.EmojiImageSpan
|
2019-09-14 22:09:52 +02:00
|
|
|
import jp.juggler.subwaytooter.span.createSpan
|
2018-08-20 19:37:42 +02:00
|
|
|
import jp.juggler.subwaytooter.table.UserRelation
|
2020-09-09 21:46:50 +02:00
|
|
|
import jp.juggler.util.LogCategory
|
2021-01-04 02:11:45 +01:00
|
|
|
import jp.juggler.util.attrColor
|
2020-09-09 21:46:50 +02:00
|
|
|
import jp.juggler.util.notZero
|
|
|
|
import jp.juggler.util.setIconDrawableId
|
2019-12-15 20:12:57 +01:00
|
|
|
import kotlin.math.max
|
2019-09-14 22:09:52 +02:00
|
|
|
import kotlin.math.min
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2019-12-15 20:12:57 +01:00
|
|
|
private val log = LogCategory("Styler")
|
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
object Styler {
|
|
|
|
|
2019-01-16 13:33:07 +01:00
|
|
|
fun defaultColorIcon(context : Context, iconId : Int) : Drawable? =
|
|
|
|
ContextCompat.getDrawable(context, iconId)?.also {
|
2021-01-04 02:11:45 +01:00
|
|
|
it.setTint(context.attrColor(R.attr.colorVectorDrawable))
|
2019-01-16 13:33:07 +01:00
|
|
|
it.setTintMode(PorterDuff.Mode.SRC_IN)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun getVisibilityIconId(isMisskeyData : Boolean, visibility : TootVisibility) : Int {
|
2018-11-18 03:38:52 +01:00
|
|
|
val isMisskey = when(Pref.ipVisibilityStyle(App1.pref)) {
|
2018-08-20 19:37:42 +02:00
|
|
|
Pref.VS_MASTODON -> false
|
2018-11-18 03:38:52 +01:00
|
|
|
Pref.VS_MISSKEY -> true
|
|
|
|
else -> isMisskeyData
|
2018-08-20 19:37:42 +02:00
|
|
|
}
|
2018-11-18 03:38:52 +01:00
|
|
|
return when {
|
2018-08-20 19:37:42 +02:00
|
|
|
isMisskey -> when(visibility) {
|
2019-01-16 13:33:07 +01:00
|
|
|
TootVisibility.Public -> R.drawable.ic_public
|
|
|
|
TootVisibility.UnlistedHome -> R.drawable.ic_home
|
|
|
|
TootVisibility.PrivateFollowers -> R.drawable.ic_lock_open
|
|
|
|
TootVisibility.DirectSpecified -> R.drawable.ic_mail
|
|
|
|
TootVisibility.DirectPrivate -> R.drawable.ic_lock
|
|
|
|
TootVisibility.WebSetting -> R.drawable.ic_question
|
2019-06-04 01:24:54 +02:00
|
|
|
TootVisibility.AccountSetting -> R.drawable.ic_question
|
2018-11-16 00:43:10 +01:00
|
|
|
|
2019-01-16 13:33:07 +01:00
|
|
|
TootVisibility.LocalPublic -> R.drawable.ic_local_ltl
|
|
|
|
TootVisibility.LocalHome -> R.drawable.ic_local_home
|
|
|
|
TootVisibility.LocalFollowers -> R.drawable.ic_local_lock_open
|
2021-02-10 09:08:00 +01:00
|
|
|
|
|
|
|
TootVisibility.Unknown-> R.drawable.ic_question
|
|
|
|
TootVisibility.Limited ->R.drawable.ic_account_circle
|
|
|
|
TootVisibility.Mutual -> R.drawable.ic_bidirectional
|
2018-08-20 19:37:42 +02:00
|
|
|
}
|
2018-11-18 03:38:52 +01:00
|
|
|
else -> when(visibility) {
|
2019-01-16 13:33:07 +01:00
|
|
|
TootVisibility.Public -> R.drawable.ic_public
|
|
|
|
TootVisibility.UnlistedHome -> R.drawable.ic_lock_open
|
|
|
|
TootVisibility.PrivateFollowers -> R.drawable.ic_lock
|
|
|
|
TootVisibility.DirectSpecified -> R.drawable.ic_mail
|
|
|
|
TootVisibility.DirectPrivate -> R.drawable.ic_mail
|
|
|
|
TootVisibility.WebSetting -> R.drawable.ic_question
|
2019-06-04 01:24:54 +02:00
|
|
|
TootVisibility.AccountSetting -> R.drawable.ic_question
|
2018-11-16 00:43:10 +01:00
|
|
|
|
2019-01-16 13:33:07 +01:00
|
|
|
TootVisibility.LocalPublic -> R.drawable.ic_local_ltl
|
|
|
|
TootVisibility.LocalHome -> R.drawable.ic_local_lock_open
|
|
|
|
TootVisibility.LocalFollowers -> R.drawable.ic_local_lock
|
2021-02-10 09:08:00 +01:00
|
|
|
|
|
|
|
TootVisibility.Unknown-> R.drawable.ic_question
|
|
|
|
TootVisibility.Limited ->R.drawable.ic_account_circle
|
|
|
|
TootVisibility.Mutual -> R.drawable.ic_bidirectional
|
2018-08-20 19:37:42 +02:00
|
|
|
}
|
2018-01-11 10:31:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-18 03:38:52 +01:00
|
|
|
fun getVisibilityString(
|
|
|
|
context : Context,
|
|
|
|
isMisskeyData : Boolean,
|
|
|
|
visibility : TootVisibility
|
|
|
|
) : String {
|
|
|
|
val isMisskey = when(Pref.ipVisibilityStyle(App1.pref)) {
|
2018-08-20 19:37:42 +02:00
|
|
|
Pref.VS_MASTODON -> false
|
2018-11-18 03:38:52 +01:00
|
|
|
Pref.VS_MISSKEY -> true
|
|
|
|
else -> isMisskeyData
|
2018-08-20 19:37:42 +02:00
|
|
|
}
|
2018-11-18 03:38:52 +01:00
|
|
|
return context.getString(
|
|
|
|
when {
|
|
|
|
isMisskey -> when(visibility) {
|
|
|
|
TootVisibility.Public -> R.string.visibility_public
|
|
|
|
TootVisibility.UnlistedHome -> R.string.visibility_home
|
|
|
|
TootVisibility.PrivateFollowers -> R.string.visibility_followers
|
|
|
|
TootVisibility.DirectSpecified -> R.string.visibility_direct
|
|
|
|
TootVisibility.DirectPrivate -> R.string.visibility_private
|
|
|
|
TootVisibility.WebSetting -> R.string.visibility_web_setting
|
2019-09-14 22:09:52 +02:00
|
|
|
TootVisibility.AccountSetting -> R.string.visibility_account_setting
|
2018-11-18 03:38:52 +01:00
|
|
|
|
|
|
|
TootVisibility.LocalPublic -> R.string.visibility_local_public
|
|
|
|
TootVisibility.LocalHome -> R.string.visibility_local_home
|
|
|
|
TootVisibility.LocalFollowers -> R.string.visibility_local_followers
|
2021-02-10 09:08:00 +01:00
|
|
|
|
|
|
|
TootVisibility.Unknown-> R.string.visibility_unknown
|
|
|
|
TootVisibility.Limited ->R.string.visibility_limited
|
|
|
|
TootVisibility.Mutual -> R.string.visibility_mutual
|
2018-11-18 03:38:52 +01:00
|
|
|
}
|
|
|
|
else -> when(visibility) {
|
|
|
|
TootVisibility.Public -> R.string.visibility_public
|
|
|
|
TootVisibility.UnlistedHome -> R.string.visibility_unlisted
|
|
|
|
TootVisibility.PrivateFollowers -> R.string.visibility_followers
|
|
|
|
TootVisibility.DirectSpecified -> R.string.visibility_direct
|
|
|
|
TootVisibility.DirectPrivate -> R.string.visibility_direct
|
|
|
|
TootVisibility.WebSetting -> R.string.visibility_web_setting
|
2019-09-14 22:09:52 +02:00
|
|
|
TootVisibility.AccountSetting -> R.string.visibility_account_setting
|
2018-11-18 03:38:52 +01:00
|
|
|
|
|
|
|
TootVisibility.LocalPublic -> R.string.visibility_local_public
|
|
|
|
TootVisibility.LocalHome -> R.string.visibility_local_unlisted
|
|
|
|
TootVisibility.LocalFollowers -> R.string.visibility_local_followers
|
2021-02-10 09:08:00 +01:00
|
|
|
|
|
|
|
TootVisibility.Unknown-> R.string.visibility_unknown
|
|
|
|
TootVisibility.Limited ->R.string.visibility_limited
|
|
|
|
TootVisibility.Mutual -> R.string.visibility_mutual
|
2018-11-18 03:38:52 +01:00
|
|
|
}
|
2018-08-20 19:37:42 +02:00
|
|
|
}
|
2018-11-18 03:38:52 +01:00
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// アイコン付きの装飾テキストを返す
|
2018-11-18 03:38:52 +01:00
|
|
|
fun getVisibilityCaption(
|
|
|
|
context : Context,
|
|
|
|
isMisskeyData : Boolean,
|
|
|
|
visibility : TootVisibility
|
|
|
|
) : CharSequence {
|
|
|
|
|
2019-01-16 13:33:07 +01:00
|
|
|
val icon_id = getVisibilityIconId(isMisskeyData, visibility)
|
2018-11-18 03:38:52 +01:00
|
|
|
val sv = getVisibilityString(context, isMisskeyData, visibility)
|
2021-01-04 02:11:45 +01:00
|
|
|
val color = context.attrColor(R.attr.colorVectorDrawable)
|
2018-01-04 19:52:25 +01:00
|
|
|
val sb = SpannableStringBuilder()
|
2018-11-18 03:38:52 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
// アイコン部分
|
|
|
|
val start = sb.length
|
2018-08-20 19:37:42 +02:00
|
|
|
sb.append(" ")
|
2018-01-04 19:52:25 +01:00
|
|
|
val end = sb.length
|
2019-01-16 13:33:07 +01:00
|
|
|
sb.setSpan(
|
|
|
|
EmojiImageSpan(
|
|
|
|
context,
|
|
|
|
icon_id,
|
|
|
|
useColorShader = true,
|
|
|
|
color = color
|
|
|
|
),
|
|
|
|
start,
|
|
|
|
end,
|
|
|
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
|
|
)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
// 文字列部分
|
|
|
|
sb.append(' ')
|
2018-08-20 19:37:42 +02:00
|
|
|
sb.append(sv)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
return sb
|
|
|
|
}
|
|
|
|
|
|
|
|
fun setFollowIcon(
|
2020-09-09 21:46:50 +02:00
|
|
|
context : Context,
|
|
|
|
ibFollow : ImageButton,
|
|
|
|
ivDot : ImageView,
|
|
|
|
relation : UserRelation,
|
|
|
|
who : TootAccount,
|
|
|
|
defaultColor : Int,
|
|
|
|
alphaMultiplier : Float
|
2018-01-04 19:52:25 +01:00
|
|
|
) {
|
2020-06-24 20:46:18 +02:00
|
|
|
fun colorAccent() =
|
2020-09-29 19:44:56 +02:00
|
|
|
Pref.ipButtonFollowingColor(context.pref()).notZero()
|
2021-01-04 02:11:45 +01:00
|
|
|
?: context.attrColor(R.attr.colorImageButtonAccent)
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2020-06-24 20:46:18 +02:00
|
|
|
fun colorError() =
|
2020-09-29 19:44:56 +02:00
|
|
|
Pref.ipButtonFollowRequestColor(context.pref()).notZero()
|
2021-01-04 02:11:45 +01:00
|
|
|
?: context.attrColor(R.attr.colorRegexFilterError)
|
2018-11-18 03:38:52 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
// 被フォロー状態
|
2018-10-30 20:29:00 +01:00
|
|
|
when {
|
|
|
|
|
|
|
|
relation.blocked_by -> {
|
|
|
|
ivDot.visibility = View.VISIBLE
|
2018-11-19 23:46:14 +01:00
|
|
|
setIconDrawableId(
|
|
|
|
context,
|
|
|
|
ivDot,
|
|
|
|
R.drawable.ic_blocked_by,
|
|
|
|
color = colorError(),
|
|
|
|
alphaMultiplier = alphaMultiplier
|
|
|
|
)
|
2018-10-30 20:29:00 +01:00
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
|
2018-10-30 20:29:00 +01:00
|
|
|
relation.requested_by -> {
|
|
|
|
ivDot.visibility = View.VISIBLE
|
2018-11-19 23:46:14 +01:00
|
|
|
setIconDrawableId(
|
|
|
|
context,
|
|
|
|
ivDot,
|
|
|
|
R.drawable.ic_requested_by,
|
|
|
|
color = colorError(),
|
|
|
|
alphaMultiplier = alphaMultiplier
|
|
|
|
)
|
2018-10-30 20:29:00 +01:00
|
|
|
}
|
|
|
|
|
2018-11-18 03:38:52 +01:00
|
|
|
relation.followed_by -> {
|
2018-10-30 20:29:00 +01:00
|
|
|
ivDot.visibility = View.VISIBLE
|
2019-01-16 13:33:07 +01:00
|
|
|
setIconDrawableId(
|
2018-11-19 23:46:14 +01:00
|
|
|
context,
|
|
|
|
ivDot,
|
2019-01-16 13:33:07 +01:00
|
|
|
R.drawable.ic_followed_by,
|
2018-11-19 23:46:14 +01:00
|
|
|
color = colorAccent(),
|
|
|
|
alphaMultiplier = alphaMultiplier
|
|
|
|
)
|
2018-10-30 20:29:00 +01:00
|
|
|
// 被フォローリクエスト状態の時に followed_by が 真と偽の両方がありえるようなので
|
|
|
|
// Relationshipだけを見ても被フォローリクエスト状態は分からないっぽい
|
|
|
|
// 仕方ないので馬鹿正直に「 followed_byが真ならバッジをつける」しかできない
|
|
|
|
}
|
|
|
|
|
|
|
|
else -> {
|
|
|
|
ivDot.visibility = View.GONE
|
|
|
|
}
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// フォローボタン
|
|
|
|
// follow button
|
2018-11-18 03:38:52 +01:00
|
|
|
val color : Int
|
2019-01-16 13:33:07 +01:00
|
|
|
val iconId : Int
|
2018-08-19 06:19:33 +02:00
|
|
|
val contentDescription : String
|
2018-01-04 19:52:25 +01:00
|
|
|
|
|
|
|
when {
|
|
|
|
relation.blocking -> {
|
2019-01-16 13:33:07 +01:00
|
|
|
iconId = R.drawable.ic_block
|
2018-11-18 03:38:52 +01:00
|
|
|
color = defaultColor
|
2018-08-19 06:19:33 +02:00
|
|
|
contentDescription = context.getString(R.string.follow)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
relation.muting -> {
|
2019-01-16 13:33:07 +01:00
|
|
|
iconId = R.drawable.ic_volume_off
|
2018-11-18 03:38:52 +01:00
|
|
|
color = defaultColor
|
2018-08-19 06:19:33 +02:00
|
|
|
contentDescription = context.getString(R.string.follow)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
relation.getFollowing(who) -> {
|
2019-01-16 13:33:07 +01:00
|
|
|
iconId = R.drawable.ic_follow_cross
|
2018-11-18 03:38:52 +01:00
|
|
|
color = colorAccent()
|
2018-08-19 06:19:33 +02:00
|
|
|
contentDescription = context.getString(R.string.unfollow)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
relation.getRequested(who) -> {
|
2019-01-16 13:33:07 +01:00
|
|
|
iconId = R.drawable.ic_follow_wait
|
2018-11-18 03:38:52 +01:00
|
|
|
color = colorError()
|
2018-08-19 06:19:33 +02:00
|
|
|
contentDescription = context.getString(R.string.unfollow)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
else -> {
|
2019-01-16 13:33:07 +01:00
|
|
|
iconId = R.drawable.ic_follow_plus
|
2018-11-18 03:38:52 +01:00
|
|
|
color = defaultColor
|
2018-08-19 06:19:33 +02:00
|
|
|
contentDescription = context.getString(R.string.follow)
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 13:33:07 +01:00
|
|
|
setIconDrawableId(
|
|
|
|
context,
|
|
|
|
ibFollow,
|
|
|
|
iconId,
|
|
|
|
color = color,
|
|
|
|
alphaMultiplier = alphaMultiplier
|
|
|
|
)
|
2018-08-19 06:19:33 +02:00
|
|
|
ibFollow.contentDescription = contentDescription
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2020-09-09 21:46:50 +02:00
|
|
|
private fun getHorizontalPadding(v : View, delta_dp : Float) : Int {
|
2020-02-01 08:53:48 +01:00
|
|
|
// Essential Phone PH-1は 短辺439dp
|
|
|
|
val form_width_max = 460f
|
2018-01-04 19:52:25 +01:00
|
|
|
val dm = v.resources.displayMetrics
|
|
|
|
val screen_w = dm.widthPixels
|
|
|
|
val content_w = (0.5f + form_width_max * dm.density).toInt()
|
2019-12-15 20:12:57 +01:00
|
|
|
val pad_lr = max(0, (screen_w - content_w) / 2)
|
|
|
|
return pad_lr + (0.5f + delta_dp * dm.density).toInt()
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2019-12-15 20:12:57 +01:00
|
|
|
private fun getOrientationString(orientation : Int?) = when(orientation) {
|
|
|
|
null -> "null"
|
|
|
|
Configuration.ORIENTATION_LANDSCAPE -> "landscape"
|
|
|
|
Configuration.ORIENTATION_PORTRAIT -> "portrait"
|
|
|
|
Configuration.ORIENTATION_UNDEFINED -> "undefined"
|
|
|
|
else -> orientation.toString()
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
|
|
|
|
2020-09-09 21:46:50 +02:00
|
|
|
fun fixHorizontalPadding(v : View, delta_dp : Float = 12f) {
|
2018-01-04 19:52:25 +01:00
|
|
|
val pad_t = v.paddingTop
|
|
|
|
val pad_b = v.paddingBottom
|
2019-12-15 20:12:57 +01:00
|
|
|
|
|
|
|
val dm = v.resources.displayMetrics
|
|
|
|
val widthDp = dm.widthPixels / dm.density
|
|
|
|
if(widthDp >= 640f && v.resources?.configuration?.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
|
|
val pad_lr = (0.5f + delta_dp * dm.density).toInt()
|
|
|
|
when(Pref.ipJustifyWindowContentPortrait(App1.pref)) {
|
|
|
|
Pref.JWCP_START -> {
|
2020-09-09 21:46:50 +02:00
|
|
|
v.setPaddingRelative(pad_lr, pad_t, pad_lr + dm.widthPixels / 2, pad_b)
|
2019-12-15 20:12:57 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
Pref.JWCP_END -> {
|
2020-09-09 21:46:50 +02:00
|
|
|
v.setPaddingRelative(pad_lr + dm.widthPixels / 2, pad_t, pad_lr, pad_b)
|
2019-12-15 20:12:57 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val pad_lr = getHorizontalPadding(v, delta_dp)
|
2018-01-04 19:52:25 +01:00
|
|
|
v.setPaddingRelative(pad_lr, pad_t, pad_lr, pad_b)
|
|
|
|
}
|
|
|
|
|
2020-09-09 21:46:50 +02:00
|
|
|
fun fixHorizontalPadding0(v : View) = fixHorizontalPadding(v, 0f)
|
2019-12-15 20:12:57 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
fun fixHorizontalMargin(v : View) {
|
|
|
|
val lp = v.layoutParams
|
|
|
|
if(lp is ViewGroup.MarginLayoutParams) {
|
2019-12-15 20:12:57 +01:00
|
|
|
|
|
|
|
val dm = v.resources.displayMetrics
|
|
|
|
val orientationString = getOrientationString(v.resources?.configuration?.orientation)
|
|
|
|
val widthDp = dm.widthPixels / dm.density
|
|
|
|
log.d("fixHorizontalMargin: orientation=$orientationString, w=${widthDp}dp, h=${dm.heightPixels / dm.density}")
|
|
|
|
|
|
|
|
if(widthDp >= 640f && v.resources?.configuration?.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
|
|
when(Pref.ipJustifyWindowContentPortrait(App1.pref)) {
|
|
|
|
Pref.JWCP_START -> {
|
|
|
|
lp.marginStart = 0
|
|
|
|
lp.marginEnd = dm.widthPixels / 2
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
Pref.JWCP_END -> {
|
|
|
|
lp.marginStart = dm.widthPixels / 2
|
|
|
|
lp.marginEnd = 0
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val pad_lr = getHorizontalPadding(v, 0f)
|
2018-01-04 19:52:25 +01:00
|
|
|
lp.leftMargin = pad_lr
|
|
|
|
lp.rightMargin = pad_lr
|
|
|
|
}
|
|
|
|
}
|
2018-01-18 08:53:32 +01:00
|
|
|
|
|
|
|
// ActMainの初期化時に更新される
|
2018-01-19 10:27:35 +01:00
|
|
|
var round_ratio : Float = 0.33f * 0.5f
|
2019-01-17 20:40:51 +01:00
|
|
|
var boost_alpha : Float = 1f
|
2018-01-18 08:53:32 +01:00
|
|
|
|
2018-01-19 10:27:35 +01:00
|
|
|
fun calcIconRound(wh : Int) = wh.toFloat() * round_ratio
|
|
|
|
|
|
|
|
fun calcIconRound(lp : ViewGroup.LayoutParams) =
|
2019-09-14 22:09:52 +02:00
|
|
|
min(lp.width, lp.height).toFloat() * round_ratio
|
2018-01-18 08:53:32 +01:00
|
|
|
|
2018-01-04 19:52:25 +01:00
|
|
|
}
|
2018-04-21 01:16:44 +02:00
|
|
|
|
|
|
|
fun SpannableStringBuilder.appendColorShadeIcon(
|
2018-11-18 03:38:52 +01:00
|
|
|
context : Context,
|
|
|
|
drawable_id : Int,
|
|
|
|
text : String,
|
2018-10-28 14:08:10 +01:00
|
|
|
color : Int? = null
|
2018-11-18 03:38:52 +01:00
|
|
|
) : SpannableStringBuilder {
|
2018-04-21 01:16:44 +02:00
|
|
|
val start = this.length
|
|
|
|
this.append(text)
|
|
|
|
val end = this.length
|
|
|
|
this.setSpan(
|
2018-11-18 03:38:52 +01:00
|
|
|
EmojiImageSpan(context, drawable_id, useColorShader = true, color = color),
|
2018-04-21 01:16:44 +02:00
|
|
|
start,
|
|
|
|
end,
|
|
|
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
|
|
)
|
2018-08-21 03:53:52 +02:00
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
2019-09-14 22:09:52 +02:00
|
|
|
fun SpannableStringBuilder.appendMisskeyReaction(
|
2018-11-18 03:38:52 +01:00
|
|
|
context : Context,
|
2019-09-14 22:09:52 +02:00
|
|
|
emojiUtf16 : String,
|
2018-11-18 03:38:52 +01:00
|
|
|
text : String
|
|
|
|
) : SpannableStringBuilder {
|
2018-08-21 03:53:52 +02:00
|
|
|
val start = this.length
|
|
|
|
this.append(text)
|
|
|
|
val end = this.length
|
2019-09-14 22:09:52 +02:00
|
|
|
|
2018-08-21 03:53:52 +02:00
|
|
|
this.setSpan(
|
2021-02-22 22:33:54 +01:00
|
|
|
EmojiMap.unicodeMap[emojiUtf16] !!.createSpan(context),
|
2019-09-14 22:09:52 +02:00
|
|
|
start, end,
|
2018-08-21 03:53:52 +02:00
|
|
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
|
|
)
|
|
|
|
return this
|
2018-04-21 01:16:44 +02:00
|
|
|
}
|