自分の行ったリアクションの背景に色をつける

This commit is contained in:
tateisu 2021-01-04 10:11:45 +09:00
parent 1902b58fc0
commit c2378f2d1d
35 changed files with 2848 additions and 2858 deletions

View File

@ -542,7 +542,7 @@ class ActAccountSetting : AsyncActivity(), View.OnClickListener,
tvUserCustom.backgroundColor = ac.color_bg
tvUserCustom.text = ac.nickname
tvUserCustom.textColor = ac.color_fg.notZero()
?: getAttributeColor(R.attr.colorTimeSmall)
?: attrColor(R.attr.colorTimeSmall)
}
private fun saveUIToData() {

View File

@ -373,7 +373,7 @@ class ActAppSetting : AsyncActivity(), ColorPickerDialogListener, View.OnClickLi
val margin_tb = dip(6)
setMargins(margin_lr, margin_tb, margin_lr, margin_tb)
}
setBackgroundColor(context.getAttributeColor(R.attr.colorSettingDivider))
setBackgroundColor(context.attrColor(R.attr.colorSettingDivider))
})
}

View File

@ -200,7 +200,7 @@ class ActColumnList : AppCompatActivity() {
val type = ColumnType.parse(json.optInt(Column.KEY_TYPE))
val acct_color_bg = json.optInt(Column.KEY_COLUMN_ACCESS_COLOR_BG, 0)
val acct_color_fg = json.optInt(Column.KEY_COLUMN_ACCESS_COLOR, 0)
.notZero() ?: context.getAttributeColor(R.attr.colorColumnListItemText)
.notZero() ?: context.attrColor(R.attr.colorColumnListItemText)
var bOldSelection : Boolean = false
fun setOldSelection(b : Boolean) {
@ -274,7 +274,7 @@ class ActColumnList : AppCompatActivity() {
clickedView.findViewById<View>(R.id.ivBookmark).visibility
dragView.findViewById<View>(R.id.item_layout)
.setBackgroundColor(getAttributeColor(R.attr.list_item_bg_pressed_dragged))
.setBackgroundColor(attrColor(R.attr.list_item_bg_pressed_dragged))
}
}

View File

@ -172,7 +172,7 @@ class ActFavMute : AppCompatActivity() {
clickedView.findViewById<TextView>(R.id.tvName).text
dragView.findViewById<View>(R.id.item_layout)
.setBackgroundColor(getAttributeColor(R.attr.list_item_bg_pressed_dragged))
.setBackgroundColor(attrColor(R.attr.list_item_bg_pressed_dragged))
}
}

View File

@ -142,7 +142,7 @@ class ActHighlightWordEdit
tvName.text = item.name
tvName.setBackgroundColor(item.color_bg) // may 0
tvName.textColor = item.color_fg.notZero()
?: getAttributeColor(android.R.attr.textColorPrimary)
?: attrColor(android.R.attr.textColorPrimary)
} finally {
bBusy = false

View File

@ -160,7 +160,7 @@ class ActHighlightWordList : AppCompatActivity(), View.OnClickListener {
tvName.setBackgroundColor(item.color_bg)
tvName.setTextColor(
item.color_fg.notZero()
?: getAttributeColor(android.R.attr.textColorPrimary)
?: attrColor(android.R.attr.textColorPrimary)
)
btnSound.vg(item.sound_type != HighlightWord.SOUND_TYPE_NONE)?.apply {
@ -219,7 +219,7 @@ class ActHighlightWordList : AppCompatActivity(), View.OnClickListener {
clickedView.findViewById<View>(R.id.ivSpeech).visibility
dragView.findViewById<View>(R.id.item_layout)
.setBackgroundColor(getAttributeColor(R.attr.list_item_bg_pressed_dragged))
.setBackgroundColor(attrColor(R.attr.list_item_bg_pressed_dragged))
}
}

View File

@ -240,7 +240,7 @@ class ActLanguageFilter : AsyncActivity(), View.OnClickListener {
getDesc(item),
getString(if(item.allow) R.string.language_show else R.string.language_hide)
)
tv.textColor = getAttributeColor(
tv.textColor = attrColor(
when(item.allow) {
true -> R.attr.colorContentText
false -> R.attr.colorRegexFilterError
@ -373,7 +373,7 @@ class ActLanguageFilter : AsyncActivity(), View.OnClickListener {
btnPresets.setEnabledColor(
activity,
R.drawable.ic_edit,
activity.getAttributeColor(R.attr.colorVectorDrawable),
activity.attrColor(R.attr.colorVectorDrawable),
false
)
}

View File

@ -540,7 +540,7 @@ class ActMain : AsyncActivity(), View.OnClickListener,
ItemViewHolder.toot_color_direct_me = Pref.ipTootColorDirectMe(pref)
MyClickableSpan.showLinkUnderline = Pref.bpShowLinkUnderline(pref)
MyClickableSpan.defaultLinkColor = Pref.ipLinkColor(pref).notZero()
?: getAttributeColor(R.attr.colorLink)
?: attrColor(R.attr.colorLink)
CustomShare.reloadCache(this, pref)
@ -2316,7 +2316,7 @@ class ActMain : AsyncActivity(), View.OnClickListener,
val footer_tab_indicator_color = Pref.ipFooterTabIndicatorColor(pref)
val colorColumnStripBackground = footer_tab_bg_color.notZero()
?: getAttributeColor(R.attr.colorColumnStripBackground)
?: attrColor(R.attr.colorColumnStripBackground)
svColumnStrip.setBackgroundColor(colorColumnStripBackground)
llQuickTootBar.setBackgroundColor(colorColumnStripBackground)
@ -2325,7 +2325,7 @@ class ActMain : AsyncActivity(), View.OnClickListener,
?: colorColumnStripBackground
val colorButtonFg = footer_button_fg_color.notZero()
?: getAttributeColor(R.attr.colorRippleEffect)
?: attrColor(R.attr.colorRippleEffect)
btnMenu.backgroundDrawable =
getAdaptiveRippleDrawableRound(this, colorButtonBg, colorButtonFg)
@ -2338,7 +2338,7 @@ class ActMain : AsyncActivity(), View.OnClickListener,
val csl = ColorStateList.valueOf(
footer_button_fg_color.notZero()
?: getAttributeColor(R.attr.colorVectorDrawable)
?: attrColor(R.attr.colorVectorDrawable)
)
btnToot.imageTintList = csl
btnMenu.imageTintList = csl
@ -2351,7 +2351,7 @@ class ActMain : AsyncActivity(), View.OnClickListener,
vFooterDivider2.setBackgroundColor(c)
llColumnStrip.indicatorColor = footer_tab_indicator_color.notZero()
?: getAttributeColor(R.attr.colorAccent)
?: attrColor(R.attr.colorAccent)
}
/////////////////////////////////////////////////////////////////////////

View File

@ -8,7 +8,7 @@ import android.view.ViewGroup
import android.widget.TextView
import jp.juggler.subwaytooter.table.MutedApp
import jp.juggler.util.LogCategory
import jp.juggler.util.getAttributeColor
import jp.juggler.util.attrColor
import java.util.*
import com.woxthebox.draglistview.DragItem
import com.woxthebox.draglistview.DragItemAdapter
@ -170,7 +170,7 @@ class ActMutedApp : AppCompatActivity() {
clickedView.findViewById<TextView>(R.id.tvName).text
dragView.findViewById<View>(R.id.item_layout)
.setBackgroundColor(getAttributeColor(R.attr.list_item_bg_pressed_dragged))
.setBackgroundColor(attrColor(R.attr.list_item_bg_pressed_dragged))
}
}

View File

@ -13,7 +13,7 @@ import com.woxthebox.draglistview.swipe.ListSwipeHelper
import com.woxthebox.draglistview.swipe.ListSwipeItem
import jp.juggler.subwaytooter.table.UserRelation
import jp.juggler.util.LogCategory
import jp.juggler.util.getAttributeColor
import jp.juggler.util.attrColor
import java.util.*
class ActMutedPseudoAccount : AppCompatActivity() {
@ -169,7 +169,7 @@ class ActMutedPseudoAccount : AppCompatActivity() {
clickedView.findViewById<TextView>(R.id.tvName).text
dragView.findViewById<View>(R.id.item_layout)
.setBackgroundColor(getAttributeColor(R.attr.list_item_bg_pressed_dragged))
.setBackgroundColor(attrColor(R.attr.list_item_bg_pressed_dragged))
}
}

View File

@ -13,7 +13,7 @@ import com.woxthebox.draglistview.swipe.ListSwipeHelper
import com.woxthebox.draglistview.swipe.ListSwipeItem
import jp.juggler.subwaytooter.table.MutedWord
import jp.juggler.util.LogCategory
import jp.juggler.util.getAttributeColor
import jp.juggler.util.attrColor
import java.util.*
class ActMutedWord : AppCompatActivity() {
@ -169,7 +169,7 @@ class ActMutedWord : AppCompatActivity() {
clickedView.findViewById<TextView>(R.id.tvName).text
dragView.findViewById<View>(R.id.item_layout)
.setBackgroundColor(getAttributeColor(R.attr.list_item_bg_pressed_dragged))
.setBackgroundColor(attrColor(R.attr.list_item_bg_pressed_dragged))
}
}

View File

@ -180,7 +180,7 @@ class ActNickname : AppCompatActivity(), View.OnClickListener, ColorPickerDialog
private fun show() {
val s = etNickname.text.toString().trim { it <= ' ' }
tvPreview.text = s.notEmpty() ?: acctPretty
tvPreview.textColor = color_fg.notZero() ?: getAttributeColor(R.attr.colorTimeSmall)
tvPreview.textColor = color_fg.notZero() ?: attrColor(R.attr.colorTimeSmall)
tvPreview.backgroundColor = color_bg
}

View File

@ -1414,7 +1414,7 @@ class ActPost : AsyncActivity(),
tvCharCount.text = remain.toString()
tvCharCount.setTextColor(
getAttributeColor(
attrColor(
if (remain < 0)
R.attr.colorRegexFilterError
else
@ -1496,7 +1496,7 @@ class ActPost : AsyncActivity(),
if (a == null) {
btnAccount.text = getString(R.string.not_selected)
btnAccount.setTextColor(getAttributeColor(android.R.attr.textColorPrimary))
btnAccount.setTextColor(attrColor(android.R.attr.textColorPrimary))
btnAccount.setBackgroundResource(R.drawable.btn_bg_transparent_round6dp)
} else {
@ -1516,7 +1516,7 @@ class ActPost : AsyncActivity(),
}
btnAccount.textColor = ac.color_fg.notZero()
?: getAttributeColor(android.R.attr.textColorPrimary)
?: attrColor(android.R.attr.textColorPrimary)
}
updateTextCount()
updateFeaturedTags()

View File

@ -830,12 +830,12 @@ val appSettingRoot = AppSettingItem(null, SettingType.Section, R.string.app_sett
val header_bg = when {
color_column_header_bg != 0 -> color_column_header_bg
else -> activity.getAttributeColor(R.attr.color_column_header)
else -> activity.attrColor(R.attr.color_column_header)
}
val header_fg = when {
color_column_header_fg != 0 -> color_column_header_fg
else -> activity.getAttributeColor(R.attr.colorColumnHeaderName)
else -> activity.attrColor(R.attr.colorColumnHeaderName)
}
llColumnHeader.background = getAdaptiveRippleDrawable(header_bg, header_fg)
@ -866,12 +866,12 @@ val appSettingRoot = AppSettingItem(null, SettingType.Section, R.string.app_sett
tvSampleAcct.setTextColor(
color_column_acct.notZero()
?: activity.getAttributeColor(R.attr.colorTimeSmall)
?: activity.attrColor(R.attr.colorTimeSmall)
)
tvSampleContent.setTextColor(
color_column_text.notZero()
?: activity.getAttributeColor(R.attr.colorContentText)
?: activity.attrColor(R.attr.colorContentText)
)
}
@ -906,7 +906,7 @@ val appSettingRoot = AppSettingItem(null, SettingType.Section, R.string.app_sett
val footer_tab_indicator_color = Pref.ipFooterTabIndicatorColor(pref)
val colorColumnStripBackground = footer_tab_bg_color.notZero()
?: activity.getAttributeColor(R.attr.colorColumnStripBackground)
?: activity.attrColor(R.attr.colorColumnStripBackground)
llFooterBG.setBackgroundColor(colorColumnStripBackground)
@ -914,7 +914,7 @@ val appSettingRoot = AppSettingItem(null, SettingType.Section, R.string.app_sett
?: colorColumnStripBackground
val colorButtonFg = footer_button_fg_color.notZero()
?: activity.getAttributeColor(R.attr.colorRippleEffect)
?: activity.attrColor(R.attr.colorRippleEffect)
ivFooterMenu.backgroundDrawable =
getAdaptiveRippleDrawableRound(activity, colorButtonBg, colorButtonFg)
@ -923,7 +923,7 @@ val appSettingRoot = AppSettingItem(null, SettingType.Section, R.string.app_sett
val csl = ColorStateList.valueOf(
footer_button_fg_color.notZero()
?: activity.getAttributeColor(R.attr.colorVectorDrawable)
?: activity.attrColor(R.attr.colorVectorDrawable)
)
ivFooterToot.imageTintList = csl
ivFooterMenu.imageTintList = csl
@ -935,7 +935,7 @@ val appSettingRoot = AppSettingItem(null, SettingType.Section, R.string.app_sett
vIndicator.setBackgroundColor(
footer_tab_indicator_color.notZero()
?: activity.getAttributeColor(R.attr.colorAccent)
?: activity.attrColor(R.attr.colorAccent)
)
}

View File

@ -348,22 +348,22 @@ class Column(
fun reloadDefaultColor(activity: AppCompatActivity, pref: SharedPreferences) {
defaultColorHeaderBg = Pref.ipCcdHeaderBg(pref).notZero()
?: activity.getAttributeColor(R.attr.color_column_header)
?: activity.attrColor(R.attr.color_column_header)
defaultColorHeaderName = Pref.ipCcdHeaderFg(pref).notZero()
?: activity.getAttributeColor(R.attr.colorColumnHeaderName)
?: activity.attrColor(R.attr.colorColumnHeaderName)
defaultColorHeaderPageNumber = Pref.ipCcdHeaderFg(pref).notZero()
?: activity.getAttributeColor(R.attr.colorColumnHeaderPageNumber)
?: activity.attrColor(R.attr.colorColumnHeaderPageNumber)
defaultColorContentBg = Pref.ipCcdContentBg(pref)
// may zero
defaultColorContentAcct = Pref.ipCcdContentAcct(pref).notZero()
?: activity.getAttributeColor(R.attr.colorTimeSmall)
?: activity.attrColor(R.attr.colorTimeSmall)
defaultColorContentText = Pref.ipCcdContentText(pref).notZero()
?: activity.getAttributeColor(R.attr.colorContentText)
?: activity.attrColor(R.attr.colorContentText)
}

View File

@ -720,7 +720,7 @@ class ColumnViewHolder(
val context = activity
val announcementsBgColor = Pref.ipAnnouncementsBgColor(App1.pref).notZero()
?: context.getAttributeColor(R.attr.colorSearchFormBackground)
?: context.attrColor(R.attr.colorSearchFormBackground)
btnAnnouncementsCutout.apply {
color = announcementsBgColor
@ -733,7 +733,7 @@ class ColumnViewHolder(
}
val searchBgColor = Pref.ipSearchBgColor(App1.pref).notZero()
?: context.getAttributeColor(R.attr.colorSearchFormBackground)
?: context.attrColor(R.attr.colorSearchFormBackground)
llSearch.apply {
backgroundColor = searchBgColor
@ -1231,7 +1231,7 @@ class ColumnViewHolder(
tvColumnContext.text = ac.nickname
tvColumnContext.setTextColor(
ac.color_fg.notZero()
?: activity.getAttributeColor(R.attr.colorTimeSmall)
?: activity.attrColor(R.attr.colorTimeSmall)
)
tvColumnContext.setBackgroundColor(ac.color_bg)
@ -1585,10 +1585,10 @@ class ColumnViewHolder(
if (insideColumnSetting) {
svQuickFilter.setBackgroundColor(0)
val colorFg = activity.getAttributeColor(R.attr.colorContentText)
val colorFg = activity.attrColor(R.attr.colorContentText)
val colorBgSelected = colorFg.applyAlphaMultiplier(0.25f)
val colorFgList = ColorStateList.valueOf(colorFg)
val colorBg = activity.getAttributeColor(R.attr.colorColumnSettingBackground)
val colorBg = activity.attrColor(R.attr.colorColumnSettingBackground)
showQuickFilterButton = { btn, iconId, selected ->
btn.backgroundDrawable =
getAdaptiveRippleDrawableRound(
@ -1720,7 +1720,7 @@ class ColumnViewHolder(
gravity = Gravity.END
startPadding = dip(4)
endPadding = dip(4)
textColor = context.getAttributeColor(R.attr.colorColumnHeaderAcct)
textColor = context.attrColor(R.attr.colorColumnHeaderAcct)
textSize = 12f
}.lparams(0, wrapContent) {
@ -1729,7 +1729,7 @@ class ColumnViewHolder(
tvColumnStatus = textView {
gravity = Gravity.END
textColor = context.getAttributeColor(R.attr.colorColumnHeaderPageNumber)
textColor = context.attrColor(R.attr.colorColumnHeaderPageNumber)
textSize = 12f
}.lparams(wrapContent, wrapContent) {
@ -1738,7 +1738,7 @@ class ColumnViewHolder(
tvColumnIndex = textView {
gravity = Gravity.END
textColor = context.getAttributeColor(R.attr.colorColumnHeaderPageNumber)
textColor = context.attrColor(R.attr.colorColumnHeaderPageNumber)
textSize = 12f
}.lparams(wrapContent, wrapContent) {
@ -1842,7 +1842,7 @@ class ColumnViewHolder(
val paint = Paint().apply {
isAntiAlias = true
color =
context.getAttributeColor(R.attr.colorColumnSettingBackground)
context.attrColor(R.attr.colorColumnSettingBackground)
}
val path = Path()
addOutsideDrawer(this) { canvas, parent, view, left, top ->
@ -1908,7 +1908,7 @@ class ColumnViewHolder(
maxHeight = dip(240)
backgroundColor =
context.getAttributeColor(R.attr.colorColumnSettingBackground)
context.attrColor(R.attr.colorColumnSettingBackground)
llColumnSettingInside = verticalLayout {
lparams(matchParent, wrapContent)
@ -1923,7 +1923,7 @@ class ColumnViewHolder(
label = textView {
textColor =
context.getAttributeColor(R.attr.colorColumnHeaderPageNumber)
context.attrColor(R.attr.colorColumnHeaderPageNumber)
text = context.getString(R.string.hashtag_extra_any)
}.lparams(matchParent, wrapContent)
@ -1938,7 +1938,7 @@ class ColumnViewHolder(
label = textView {
textColor =
context.getAttributeColor(R.attr.colorColumnHeaderPageNumber)
context.attrColor(R.attr.colorColumnHeaderPageNumber)
text = context.getString(R.string.hashtag_extra_all)
}.lparams(matchParent, wrapContent)
@ -1953,7 +1953,7 @@ class ColumnViewHolder(
label = textView {
textColor =
context.getAttributeColor(R.attr.colorColumnHeaderPageNumber)
context.attrColor(R.attr.colorColumnHeaderPageNumber)
text = context.getString(R.string.hashtag_extra_none)
}.lparams(matchParent, wrapContent)
@ -2048,12 +2048,12 @@ class ColumnViewHolder(
label = textView {
textColor =
context.getAttributeColor(R.attr.colorColumnHeaderPageNumber)
context.attrColor(R.attr.colorColumnHeaderPageNumber)
text = context.getString(R.string.regex_filter)
}.lparams(wrapContent, wrapContent)
tvRegexFilterError = textView {
textColor = context.getAttributeColor(R.attr.colorRegexFilterError)
textColor = context.attrColor(R.attr.colorRegexFilterError)
}.lparams(0, wrapContent) {
weight = 1f
startMargin = dip(4)
@ -2219,7 +2219,7 @@ class ColumnViewHolder(
contentDescription = context.getString(R.string.clear)
imageResource = R.drawable.ic_close
imageTintList = ColorStateList.valueOf(
context.getAttributeColor(R.attr.colorVectorDrawable)
context.attrColor(R.attr.colorVectorDrawable)
)
}.lparams(dip(40), dip(40)) {
startMargin = dip(4)
@ -2230,7 +2230,7 @@ class ColumnViewHolder(
contentDescription = context.getString(R.string.search)
imageResource = R.drawable.ic_search
imageTintList = ColorStateList.valueOf(
context.getAttributeColor(R.attr.colorVectorDrawable)
context.attrColor(R.attr.colorVectorDrawable)
)
}.lparams(dip(40), dip(40)) {
startMargin = dip(4)
@ -2262,7 +2262,7 @@ class ColumnViewHolder(
contentDescription = context.getString(R.string.add)
imageResource = R.drawable.ic_add
imageTintList = ColorStateList.valueOf(
context.getAttributeColor(
context.attrColor(
R.attr.colorVectorDrawable
)
)
@ -2680,8 +2680,8 @@ class ColumnViewHolder(
btn.background = if (reaction.me == true) {
getAdaptiveRippleDrawableRound(
actMain,
actMain.getAttributeColor(R.attr.colorButtonBgCw),
actMain.getAttributeColor(R.attr.colorRippleEffect)
actMain.attrColor(R.attr.colorButtonBgCw),
actMain.attrColor(R.attr.colorRippleEffect)
)
} else {
ContextCompat.getDrawable(actMain, R.drawable.btn_bg_transparent_round6dp)

View File

@ -347,14 +347,14 @@ internal class DlgContextMenu(
val colorButtonAccent =
Pref.ipButtonFollowingColor(activity.pref).notZero()
?: activity.getAttributeColor(R.attr.colorImageButtonAccent)
?: activity.attrColor(R.attr.colorImageButtonAccent)
val colorButtonError =
Pref.ipButtonFollowRequestColor(activity.pref).notZero()
?: activity.getAttributeColor(R.attr.colorRegexFilterError)
?: activity.attrColor(R.attr.colorRegexFilterError)
val colorButtonNormal =
activity.getAttributeColor(R.attr.colorImageButton)
activity.attrColor(R.attr.colorImageButton)
fun showRelation(relation : UserRelation) {
@ -405,7 +405,7 @@ internal class DlgContextMenu(
ivFollowedBy.vg(false)
btnFollow.setImageResource(R.drawable.ic_follow_plus)
btnFollow.imageTintList =
ColorStateList.valueOf(activity.getAttributeColor(R.attr.colorImageButton))
ColorStateList.valueOf(activity.attrColor(R.attr.colorImageButton))
btnNotificationFrom.visibility = View.GONE
} else {
@ -583,7 +583,7 @@ internal class DlgContextMenu(
R.drawable.ic_arrow_drop_down
}
val iconColor = activity.getAttributeColor(R.attr.colorTimeSmall)
val iconColor = activity.attrColor(R.attr.colorTimeSmall)
val drawable = createColoredDrawable(activity, iconId, iconColor, 1f)
btn.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null)
}

File diff suppressed because it is too large Load Diff

View File

@ -122,7 +122,7 @@ class SideMenuAdapter(
)
setSpan(
ForegroundColorSpan(
appContext.getAttributeColor(R.attr.colorRegexFilterError)
appContext.attrColor(R.attr.colorRegexFilterError)
),
start, length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
@ -362,7 +362,7 @@ class SideMenuAdapter(
}
)
private val iconColor = actMain.getAttributeColor(R.attr.colorTimeSmall)
private val iconColor = actMain.attrColor(R.attr.colorTimeSmall)
override fun getCount() : Int = list.size
override fun getItem(position : Int) : Any = list[position]
@ -427,7 +427,7 @@ class SideMenuAdapter(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
)
backgroundColor = actMain.getAttributeColor(R.attr.colorWindowBackground)
backgroundColor = actMain.attrColor(R.attr.colorWindowBackground)
selector = StateListDrawable()
divider = null
dividerHeight = 0

View File

@ -66,7 +66,7 @@ internal class StatusButtons(
private val color_normal = column.getContentColor()
private val color_accent : Int
get() = activity.getAttributeColor(R.attr.colorImageButtonAccent)
get() = activity.attrColor(R.attr.colorImageButtonAccent)
init {
this.access_info = column.access_info

View File

@ -18,7 +18,7 @@ import jp.juggler.subwaytooter.span.EmojiImageSpan
import jp.juggler.subwaytooter.span.createSpan
import jp.juggler.subwaytooter.table.UserRelation
import jp.juggler.util.LogCategory
import jp.juggler.util.getAttributeColor
import jp.juggler.util.attrColor
import jp.juggler.util.notZero
import jp.juggler.util.setIconDrawableId
import kotlin.math.max
@ -30,7 +30,7 @@ object Styler {
fun defaultColorIcon(context : Context, iconId : Int) : Drawable? =
ContextCompat.getDrawable(context, iconId)?.also {
it.setTint(context.getAttributeColor(R.attr.colorVectorDrawable))
it.setTint(context.attrColor(R.attr.colorVectorDrawable))
it.setTintMode(PorterDuff.Mode.SRC_IN)
}
@ -123,7 +123,7 @@ object Styler {
val icon_id = getVisibilityIconId(isMisskeyData, visibility)
val sv = getVisibilityString(context, isMisskeyData, visibility)
val color = context.getAttributeColor(R.attr.colorVectorDrawable)
val color = context.attrColor(R.attr.colorVectorDrawable)
val sb = SpannableStringBuilder()
// アイコン部分
@ -160,11 +160,11 @@ object Styler {
) {
fun colorAccent() =
Pref.ipButtonFollowingColor(context.pref()).notZero()
?: context.getAttributeColor(R.attr.colorImageButtonAccent)
?: context.attrColor(R.attr.colorImageButtonAccent)
fun colorError() =
Pref.ipButtonFollowRequestColor(context.pref()).notZero()
?: context.getAttributeColor(R.attr.colorRegexFilterError)
?: context.attrColor(R.attr.colorRegexFilterError)
// 被フォロー状態
when {

View File

@ -141,7 +141,7 @@ internal class ViewHolderHeaderProfile(
override fun showColor() {
llProfile.setBackgroundColor(
when(val c = column.column_bg_color) {
0 -> activity.getAttributeColor(R.attr.colorProfileBackgroundMask)
0 -> activity.attrColor(R.attr.colorProfileBackgroundMask)
else -> - 0x40000000 or (0x00ffffff and c)
}
)

View File

@ -26,7 +26,7 @@ import jp.juggler.subwaytooter.util.EmojiDecoder
//}
object MisskeyReaction {
private val oldReactions = mapOf(
private val oldReactions = mapOf(
"like" to "\ud83d\udc4d",
"love" to "\u2665",
"laugh" to "\ud83d\ude06",
@ -42,6 +42,20 @@ object MisskeyReaction {
private val reCustomEmoji = """\A:([^:]+):\z""".toRegex()
fun getAnotherExpression(reaction: String): String? {
val customCode = reCustomEmoji.find(reaction)?.groupValues?.elementAtOrNull(1) ?: return null
val cols = customCode.split("@")
val name = cols.elementAtOrNull(0)
val domain = cols.elementAtOrNull(1)
return if (domain == null) ":$name@.:" else if (domain == ".") ":$name:" else null
}
fun equals(a:String?,b:String?) = when {
a==null -> b==null
b==null -> false
else -> a ==b || getAnotherExpression(a) == b || a == getAnotherExpression(b)
}
fun toSpannableStringBuilder(
code: String,
options: DecodeOptions,

View File

@ -928,17 +928,7 @@ class TootStatus(parser: TootParser, src: JsonObject) : TimelineItem() {
return list
}
private fun getAnotherReactionExpression(reaction:String):String{
// :reaction: => reaction
// :reaction@xxx: => reaction@xxx
val customCode = reaction.replace(":","")
// reaction => :reaction@.:
return if( customCode != reaction && !customCode.contains("@"))
":${customCode}@.:"
else
reaction
}
// return true if updated
fun increaseReaction(reaction: String?, byMe: Boolean, caller: String): Boolean {
@ -962,16 +952,14 @@ class TootStatus(parser: TootParser, src: JsonObject) : TimelineItem() {
this.reactionCounts = map
}
val anotherExpression = getAnotherReactionExpression(reaction)
for( entry in map){
if( entry.key == reaction || entry.key == anotherExpression){
map[entry.key] = entry.value +1
return true
}
when (
val key = reaction.takeIf { map.containsKey(it) }
?: MisskeyReaction.getAnotherExpression(reaction)?.takeIf { map.containsKey(it) }
) {
null -> map[reaction] = 1
else -> map[key] = max(0, map[key]!! + 1)
}
map[reaction] = 1
return true
}
}
@ -998,15 +986,14 @@ class TootStatus(parser: TootParser, src: JsonObject) : TimelineItem() {
this.reactionCounts = map
}
val anotherExpression = getAnotherReactionExpression(reaction)
when (
val key = reaction.takeIf { map.containsKey(it) }
?: MisskeyReaction.getAnotherExpression(reaction)?.takeIf { map.containsKey(it) }
) {
null -> map[reaction] = 0
else -> map[key] = max(0, map[key]!! - 1)
}
for( entry in map){
if( entry.key == reaction || entry.key == anotherExpression){
map[entry.key] = max(0,entry.value -1)
return true
}
}
map[reaction] = 0
return true
}
}
@ -1214,34 +1201,34 @@ class TootStatus(parser: TootParser, src: JsonObject) : TimelineItem() {
fun formatTime(context: Context, t: Long, bAllowRelative: Boolean, onlyDate: Boolean = false): String {
val now = System.currentTimeMillis()
var delta = now - t
val now = System.currentTimeMillis()
var delta = now - t
@StringRes val phraseId = if (delta >= 0)
R.string.relative_time_phrase_past
else
R.string.relative_time_phrase_future
@StringRes val phraseId = if (delta >= 0)
R.string.relative_time_phrase_past
else
R.string.relative_time_phrase_future
fun f(v: Long, unit1: Int, units: Int): String {
val vi = v.toInt()
return context.getString(
fun f(v: Long, unit1: Int, units: Int): String {
val vi = v.toInt()
return context.getString(
phraseId,
vi,
context.getString(if (vi <= 1) unit1 else units)
)
}
}
if( onlyDate) return when{
delta < 40 * 86400000L -> f(
if (onlyDate) return when {
delta < 40 * 86400000L -> f(
delta / 86400000L,
R.string.relative_time_unit_day1,
R.string.relative_time_unit_days
)
else ->
formatDate(t, date_format2, omitZeroSecond = false, omitYear = true)
}
else ->
formatDate(t, date_format2, omitZeroSecond = false, omitYear = true)
}
if (bAllowRelative && Pref.bpRelativeTimestamp(App1.pref)) {
if (bAllowRelative && Pref.bpRelativeTimestamp(App1.pref)) {
delta = abs(delta)
@ -1268,13 +1255,13 @@ class TootStatus(parser: TootParser, src: JsonObject) : TimelineItem() {
R.string.relative_time_unit_hours
)
delta < 40 * 86400000L -> return f(
delta < 40 * 86400000L -> return f(
delta / 86400000L,
R.string.relative_time_unit_day1,
R.string.relative_time_unit_days
)
}
// fall back to absolute time
// fall back to absolute time
}
return formatDate(t, date_format, omitZeroSecond = false, omitYear = false)
@ -1299,8 +1286,8 @@ class TootStatus(parser: TootParser, src: JsonObject) : TimelineItem() {
val dateNow = format.format(Date())
val delm = dateNow.indexOf('-')
if (delm != -1 &&
dateNow.substring(0, delm + 1) == dateTarget.substring(0,delm + 1)
) {
dateNow.substring(0, delm + 1) == dateTarget.substring(0, delm + 1)
) {
dateTarget = dateTarget.substring(delm + 1)
}
}

View File

@ -150,7 +150,7 @@ class DlgAppPicker(
activity,
ivImage,
R.drawable.ic_question,
color = activity.getAttributeColor(R.attr.colorVectorDrawable),
color = activity.attrColor(R.attr.colorVectorDrawable),
alphaMultiplier = 1f
)
}

View File

@ -134,7 +134,7 @@ class DlgListMember(
this.list_owner = a
if(a == null) {
btnListOwner.setText(R.string.not_selected)
btnListOwner.setTextColor(activity.getAttributeColor( android.R.attr.textColorPrimary))
btnListOwner.setTextColor(activity.attrColor( android.R.attr.textColorPrimary))
btnListOwner.setBackgroundResource(R.drawable.btn_bg_transparent_round6dp)
//
@ -148,7 +148,7 @@ class DlgListMember(
btnListOwner.setBackgroundResource(R.drawable.btn_bg_transparent_round6dp)
}
btnListOwner.textColor = ac.color_fg.notZero()
?: activity.getAttributeColor( android.R.attr.textColorPrimary)
?: activity.attrColor( android.R.attr.textColorPrimary)
}
loadLists()

View File

@ -269,7 +269,7 @@ class EmojiPicker(
setTypeface(typeface, Typeface.BOLD)
textColor = this@EmojiPicker.activity.getAttributeColor(R.attr.colorContentText)
textColor = this@EmojiPicker.activity.attrColor(R.attr.colorContentText)
textSize = 16f // SP単位
text = when(val name = it.key) {

View File

@ -149,7 +149,7 @@ fun Activity.openCustomTab(url: String?, pref:SharedPreferences = pref()) {
CustomTabsIntent.Builder()
.setDefaultColorSchemeParams(
CustomTabColorSchemeParams.Builder()
.setToolbarColor(getAttributeColor(R.attr.colorPrimary))
.setToolbarColor(attrColor(R.attr.colorPrimary))
.build()
)
.setShowTitle(true)

View File

@ -10,7 +10,7 @@ import jp.juggler.subwaytooter.R
import jp.juggler.subwaytooter.api.entity.TootStatus
import jp.juggler.subwaytooter.table.SavedAccount
import jp.juggler.util.LogCategory
import jp.juggler.util.getAttributeColor
import jp.juggler.util.attrColor
import jp.juggler.util.showToast
import jp.juggler.util.systemService
@ -71,7 +71,7 @@ object CustomShare {
label =
"${context.getString(R.string.copy_to_clipboard)}(${context.getString(R.string.app_name)})"
icon = ContextCompat.getDrawable(context, R.drawable.ic_copy)?.mutate()?.apply {
setTint(context.getAttributeColor(R.attr.colorVectorDrawable))
setTint(context.attrColor(R.attr.colorVectorDrawable))
setTintMode(PorterDuff.Mode.SRC_IN)
}
} else {

View File

@ -19,7 +19,7 @@ import jp.juggler.subwaytooter.api.entity.Acct
import jp.juggler.subwaytooter.view.MyEditText
import jp.juggler.util.LogCategory
import jp.juggler.util.asciiPattern
import jp.juggler.util.getAttributeColor
import jp.juggler.util.attrColor
import jp.juggler.util.groupEx
import java.util.*
import kotlin.math.min
@ -97,7 +97,7 @@ internal class PopupAutoCompleteAcct(
run {
val v = activity.layoutInflater
.inflate(R.layout.lv_spinner_dropdown, llItems, false) as CheckedTextView
v.setTextColor(activity.getAttributeColor(android.R.attr.textColorPrimary))
v.setTextColor(activity.attrColor(android.R.attr.textColorPrimary))
v.setText(R.string.close)
v.setOnClickListener { acct_popup.dismiss() }
llItems.addView(v)
@ -107,7 +107,7 @@ internal class PopupAutoCompleteAcct(
if(picker_caption != null && picker_callback != null) {
val v = activity.layoutInflater
.inflate(R.layout.lv_spinner_dropdown, llItems, false) as CheckedTextView
v.setTextColor(activity.getAttributeColor(android.R.attr.textColorPrimary))
v.setTextColor(activity.attrColor(android.R.attr.textColorPrimary))
v.text = picker_caption
v.setOnClickListener {
acct_popup.dismiss()
@ -125,7 +125,7 @@ internal class PopupAutoCompleteAcct(
val acct = acct_list[i]
val v = activity.layoutInflater
.inflate(R.layout.lv_spinner_dropdown, llItems, false) as CheckedTextView
v.setTextColor(activity.getAttributeColor(android.R.attr.textColorPrimary))
v.setTextColor(activity.attrColor(android.R.attr.textColorPrimary))
v.text = acct
if(acct is Spannable) {
NetworkEmojiInvalidator(handler, v).register(acct)

View File

@ -893,7 +893,7 @@ class PostHelper(
sb.append(item.alias)
sb.append(": → ")
sb.setSpan(
ForegroundColorSpan(activity.getAttributeColor(R.attr.colorTimeSmall)),
ForegroundColorSpan(activity.attrColor(R.attr.colorTimeSmall)),
start,
sb.length,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE

View File

@ -7,7 +7,7 @@ import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import jp.juggler.subwaytooter.R
import jp.juggler.util.getAttributeDrawable
import jp.juggler.util.attrDrawable
class ListDivider(context : Context) : RecyclerView.ItemDecoration() {
@ -18,7 +18,7 @@ class ListDivider(context : Context) : RecyclerView.ItemDecoration() {
var marginH : Int = 0
}
private val drawable = getAttributeDrawable(context, R.attr.colorSettingDivider)
private val drawable = context.attrDrawable( R.attr.colorSettingDivider)
private val paint = Paint()
private val rect = Rect()

View File

@ -7,7 +7,7 @@ import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import jp.juggler.subwaytooter.R
import jp.juggler.util.getAttributeDrawable
import jp.juggler.util.attrDrawable
class TabletColumnDivider(context : Context) : RecyclerView.ItemDecoration() {
@ -19,7 +19,7 @@ class TabletColumnDivider(context : Context) : RecyclerView.ItemDecoration() {
var barWidth : Int = 0
}
private val drawable = getAttributeDrawable(context, R.attr.colorSettingDivider)
private val drawable = context.attrDrawable( R.attr.colorSettingDivider)
private val paint = Paint()
private val rect = Rect()

View File

@ -5,6 +5,7 @@ import android.content.ClipboardManager
import android.content.Context
import android.content.DialogInterface
import android.content.res.ColorStateList
import android.content.res.TypedArray
import android.graphics.Color
import android.graphics.ColorFilter
import android.graphics.PorterDuff
@ -37,40 +38,25 @@ fun Int.applyAlphaMultiplier(alphaMultiplier : Float? = null) : Int {
}
}
fun Context.getAttributeColor(attrId : Int) : Int {
fun Context.attrColor(attrId : Int) : Int {
val a = theme.obtainStyledAttributes(intArrayOf(attrId))
val color = a.getColor(0, Color.BLACK)
a.recycle()
return color
}
fun getAttributeDrawable(context : Context, attrId : Int) : Drawable {
fun getAttributeResourceId(context : Context, attrId : Int) : Int {
val theme = context.theme
val a = theme.obtainStyledAttributes(intArrayOf(attrId))
val resourceId = a.getResourceId(0, 0)
a.recycle()
if(resourceId == 0)
throw RuntimeException(
String.format(
Locale.JAPAN,
"attr not defined.attr_id=0x%x",
attrId
)
)
return resourceId
}
val drawableId = getAttributeResourceId(context, attrId)
val d = ContextCompat.getDrawable(context, drawableId)
return d ?: throw RuntimeException(
String.format(
Locale.JAPAN,
"getDrawable failed. drawableId=0x%x",
drawableId
)
)
fun<T> TypedArray.use(block:(TypedArray)->T):T =
try{ block(this) }finally{ recycle() }
fun Context.getAttributeResourceId( attrId : Int) =
theme.obtainStyledAttributes(intArrayOf(attrId))
.use{ it.getResourceId(0, 0) }
.notZero() ?: error("missing resource id. attr_id=0x${attrId.toString(16)}")
fun Context.attrDrawable( attrId : Int) : Drawable {
val drawableId = getAttributeResourceId( attrId)
return ContextCompat.getDrawable(this, drawableId)
?: error("getDrawable failed. drawableId=0x${drawableId.toString(16)}")
}
/////////////////////////////////////////////////////////

View File

@ -108,10 +108,10 @@ fun Context.setSwitchColor(
pref : SharedPreferences,
root : View?
) {
val colorBg = getAttributeColor(R.attr.colorWindowBackground)
val colorBg = attrColor(R.attr.colorWindowBackground)
val colorOn = Pref.ipSwitchOnColor(pref)
val colorOff = /* Pref.ipSwitchOffColor(pref).notZero() ?: */
getAttributeColor(android.R.attr.colorPrimary)
attrColor(android.R.attr.colorPrimary)
val colorDisabled = mixColor(colorBg, colorOff)
@ -207,7 +207,7 @@ fun AppCompatActivity.setStatusBarColor(forceDark : Boolean = false) {
var c = when {
forceDark -> Color.BLACK
else -> Pref.ipStatusBarColor(App1.pref).notZero()
?: getAttributeColor(R.attr.colorPrimaryDark)
?: attrColor(R.attr.colorPrimaryDark)
}
statusBarColor = c or Color.BLACK