2021-06-28 09:09:00 +02:00
package jp.juggler.subwaytooter.columnviewholder
2018-01-04 19:52:25 +01:00
import android.annotation.SuppressLint
2019-01-17 20:40:51 +01:00
import android.content.res.ColorStateList
2018-01-04 19:52:25 +01:00
import android.graphics.Bitmap
2018-11-20 10:32:30 +01:00
import android.graphics.Color
2020-02-11 09:59:41 +01:00
import android.graphics.Paint
import android.graphics.Path
2019-10-05 14:28:04 +02:00
import android.text.InputType
2018-08-04 21:56:53 +02:00
import android.text.SpannableStringBuilder
2019-10-05 14:28:04 +02:00
import android.view.*
2018-01-04 19:52:25 +01:00
import android.view.inputmethod.EditorInfo
2018-08-04 21:56:53 +02:00
import android.widget.*
2021-11-18 18:09:22 +01:00
import androidx.appcompat.widget.AppCompatButton
2019-02-25 09:00:36 +01:00
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
2021-05-21 10:20:14 +02:00
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayout
import com.google.android.flexbox.JustifyContent
2019-02-25 09:00:36 +01:00
import com.omadahealth.github.swipyrefreshlayout.library.SwipyRefreshLayout
import com.omadahealth.github.swipyrefreshlayout.library.SwipyRefreshLayoutDirection
2021-06-28 09:09:00 +02:00
import jp.juggler.subwaytooter.*
import jp.juggler.subwaytooter.column.*
2021-11-06 04:00:29 +01:00
import jp.juggler.subwaytooter.pref.PrefB
2020-12-21 03:13:03 +01:00
import jp.juggler.subwaytooter.streaming.*
2023-02-04 21:52:26 +01:00
import jp.juggler.subwaytooter.table.daoAcctColor
2019-10-05 14:28:04 +02:00
import jp.juggler.subwaytooter.util.*
2020-04-07 06:52:54 +02:00
import jp.juggler.subwaytooter.view.MyLinkMovementMethod
import jp.juggler.subwaytooter.view.MyTextView
import jp.juggler.subwaytooter.view.OutsideDrawerLayout
2018-12-01 00:02:18 +01:00
import jp.juggler.util.*
2023-01-13 13:22:25 +01:00
import jp.juggler.util.data.*
import jp.juggler.util.log.Benchmark
import jp.juggler.util.log.LogCategory
import jp.juggler.util.ui.CustomTextWatcher
import jp.juggler.util.ui.attrColor
import jp.juggler.util.ui.scan
2020-04-07 06:52:54 +02:00
import kotlinx.coroutines.*
2019-10-05 14:28:04 +02:00
import org.jetbrains.anko.*
2020-02-11 09:59:41 +01:00
import org.jetbrains.anko.custom.customView
2020-04-07 06:52:54 +02:00
import java.lang.Runnable
2018-01-17 18:39:16 +01:00
import java.lang.reflect.Field
2018-01-04 19:52:25 +01:00
2019-01-09 09:08:51 +01:00
@SuppressLint ( " ClickableViewAccessibility " )
2018-01-17 18:39:16 +01:00
class ColumnViewHolder (
2020-12-21 03:13:03 +01:00
val activity : ActMain ,
2021-06-20 15:12:25 +02:00
parent : ViewGroup ,
2018-01-17 18:39:16 +01:00
) : View . OnClickListener ,
2020-12-21 03:13:03 +01:00
SwipyRefreshLayout . OnRefreshListener ,
CompoundButton . OnCheckedChangeListener , View . OnLongClickListener {
companion object {
2021-05-19 09:51:34 +02:00
val log = LogCategory ( " ColumnViewHolder " )
2020-12-21 03:13:03 +01:00
val fieldRecycler : Field by lazy {
val field = RecyclerView :: class . java . getDeclaredField ( " mRecycler " )
field . isAccessible = true
field
}
val fieldState : Field by lazy {
val field = RecyclerView :: class . java . getDeclaredField ( " mState " )
field . isAccessible = true
field
}
val heightSpec = View . MeasureSpec . makeMeasureSpec ( 0 , View . MeasureSpec . UNSPECIFIED )
// var lastRefreshError : String = ""
// var lastRefreshErrorShown : Long = 0L
}
var column : Column ? = null
2021-06-20 15:12:25 +02:00
var statusAdapter : ItemListAdapter ? = null
var pageIdx : Int = 0
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
lateinit var llLoading : View
2021-11-18 18:09:22 +01:00
lateinit var btnConfirmMail : AppCompatButton
2021-11-08 11:04:30 +01:00
lateinit var tvLoading : MyTextView
2021-05-10 23:30:42 +02:00
2020-12-21 03:13:03 +01:00
lateinit var listView : RecyclerView
lateinit var refreshLayout : SwipyRefreshLayout
lateinit var listLayoutManager : LinearLayoutManager
2021-05-19 09:51:34 +02:00
lateinit var llColumnHeader : View
2021-11-08 11:04:30 +01:00
lateinit var tvColumnIndex : MyTextView
lateinit var tvColumnStatus : MyTextView
private lateinit var tvColumnContext : MyTextView
2021-05-19 09:51:34 +02:00
lateinit var ivColumnIcon : ImageView
2021-11-08 11:04:30 +01:00
lateinit var tvColumnName : MyTextView
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
lateinit var llColumnSetting : View
2020-12-21 03:13:03 +01:00
private lateinit var llColumnSettingInside : LinearLayout
2021-05-19 09:51:34 +02:00
lateinit var btnSearch : ImageButton
lateinit var btnSearchClear : ImageButton
2021-05-21 10:20:14 +02:00
lateinit var btnEmojiAdd : ImageButton
2021-05-19 09:51:34 +02:00
lateinit var etSearch : EditText
2021-05-21 10:20:14 +02:00
lateinit var flEmoji : FlexboxLayout
2021-11-08 11:04:30 +01:00
lateinit var tvEmojiDesc : MyTextView
2021-05-19 09:51:34 +02:00
lateinit var cbResolve : CheckBox
lateinit var etRegexFilter : EditText
2021-11-08 11:04:30 +01:00
lateinit var tvRegexFilterError : MyTextView
2021-05-19 09:51:34 +02:00
lateinit var btnAnnouncementsBadge : ImageView
lateinit var btnAnnouncements : ImageButton
lateinit var btnAnnouncementsCutout : Paint
lateinit var btnColumnSetting : ImageButton
lateinit var btnColumnReload : ImageButton
lateinit var btnColumnClose : ImageButton
lateinit var flColumnBackground : View
lateinit var ivColumnBackgroundImage : ImageView
lateinit var llSearch : View
lateinit var cbDontCloseColumn : CheckBox
2021-11-06 04:00:29 +01:00
lateinit var cbShowMediaDescription : CheckBox
2021-05-19 09:51:34 +02:00
lateinit var cbRemoteOnly : CheckBox
lateinit var cbWithAttachment : CheckBox
lateinit var cbWithHighlight : CheckBox
lateinit var cbDontShowBoost : CheckBox
lateinit var cbDontShowFollow : CheckBox
lateinit var cbDontShowFavourite : CheckBox
lateinit var cbDontShowReply : CheckBox
lateinit var cbDontShowReaction : CheckBox
lateinit var cbDontShowVote : CheckBox
lateinit var cbDontShowNormalToot : CheckBox
lateinit var cbDontShowNonPublicToot : CheckBox
lateinit var cbInstanceLocal : CheckBox
lateinit var cbDontStreaming : CheckBox
lateinit var cbDontAutoRefresh : CheckBox
lateinit var cbHideMediaDefault : CheckBox
lateinit var cbSystemNotificationNotRelated : CheckBox
lateinit var cbEnableSpeech : CheckBox
lateinit var cbOldApi : CheckBox
lateinit var llRegexFilter : View
2021-11-18 18:09:22 +01:00
lateinit var btnDeleteNotification : AppCompatButton
lateinit var btnColor : AppCompatButton
lateinit var btnLanguageFilter : AppCompatButton
2021-05-19 09:51:34 +02:00
lateinit var svQuickFilter : HorizontalScrollView
2021-11-18 18:09:22 +01:00
lateinit var btnQuickFilterAll : AppCompatButton
2021-05-19 09:51:34 +02:00
lateinit var btnQuickFilterMention : ImageButton
lateinit var btnQuickFilterFavourite : ImageButton
lateinit var btnQuickFilterBoost : ImageButton
lateinit var btnQuickFilterFollow : ImageButton
lateinit var btnQuickFilterPost : ImageButton
lateinit var btnQuickFilterReaction : ImageButton
lateinit var btnQuickFilterVote : ImageButton
lateinit var llRefreshError : FrameLayout
2021-10-27 22:58:19 +02:00
private lateinit var ivRefreshError : ImageView
2021-11-08 11:04:30 +01:00
lateinit var tvRefreshError : MyTextView
2021-05-19 09:51:34 +02:00
lateinit var llListList : View
lateinit var etListName : EditText
lateinit var btnListAdd : View
lateinit var llHashtagExtra : LinearLayout
lateinit var etHashtagExtraAny : EditText
lateinit var etHashtagExtraAll : EditText
lateinit var etHashtagExtraNone : EditText
lateinit var llAnnouncementsBox : View
2021-11-08 11:04:30 +01:00
lateinit var tvAnnouncementsCaption : MyTextView
lateinit var tvAnnouncementsIndex : MyTextView
2021-05-19 09:51:34 +02:00
lateinit var btnAnnouncementsPrev : ImageButton
lateinit var btnAnnouncementsNext : ImageButton
lateinit var llAnnouncements : View
2021-11-08 11:04:30 +01:00
lateinit var tvAnnouncementPeriod : MyTextView
2021-05-19 09:51:34 +02:00
lateinit var tvAnnouncementContent : MyTextView
lateinit var llAnnouncementExtra : LinearLayout
2020-12-21 03:13:03 +01:00
var lastAnnouncementShown = 0L
2021-06-20 15:12:25 +02:00
var bindingBusy : Boolean = false
2020-12-21 03:13:03 +01:00
2021-06-20 15:12:25 +02:00
var lastImageUri : String ? = null
var lastImageBitmap : Bitmap ? = null
var lastImageTask : Job ? = null
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
var bRefreshErrorWillShown = false
2020-12-21 03:13:03 +01:00
2021-06-20 15:12:25 +02:00
val extraInvalidatorList = ArrayList < NetworkEmojiInvalidator > ( )
2021-05-21 10:20:14 +02:00
val emojiQueryInvalidatorList = ArrayList < NetworkEmojiInvalidator > ( )
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
val announcementContentInvalidator : NetworkEmojiInvalidator
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
val viewRoot : View = inflate ( activity , parent )
/////////////////////////////////
val scrollPosition : ScrollPosition
get ( ) = ScrollPosition ( this )
2020-12-21 03:13:03 +01:00
val isColumnSettingShown : Boolean
get ( ) = llColumnSetting . visibility == View . VISIBLE
// val headerView : HeaderViewHolderBase?
// get() = status_adapter?.header
2021-05-19 09:51:34 +02:00
/////////////////////////////////
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
val isPageDestroyed : Boolean
get ( ) = column == null || activity . isFinishing
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
/////////////////////////////////
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
private val procStartLoading : Runnable = Runnable {
2021-06-20 15:12:25 +02:00
if ( bindingBusy || isPageDestroyed ) return @Runnable
2021-05-19 09:51:34 +02:00
column ?. startLoading ( )
}
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
val procShowColumnHeader : Runnable = Runnable {
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
val column = this . column
2021-06-20 15:12:25 +02:00
if ( column == null || column . isDispose . get ( ) ) return @Runnable
2020-12-21 03:13:03 +01:00
2023-02-04 21:52:26 +01:00
val ac = daoAcctColor . load ( column . accessInfo )
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
tvColumnContext . text = ac . nickname
tvColumnContext . setTextColor (
2023-02-04 21:52:26 +01:00
ac . colorFg . notZero ( )
2021-05-19 09:51:34 +02:00
?: activity . attrColor ( R . attr . colorTimeSmall )
)
2020-12-21 03:13:03 +01:00
2023-02-04 21:52:26 +01:00
tvColumnContext . setBackgroundColor ( ac . colorBg )
2021-06-20 15:12:25 +02:00
tvColumnContext . setPaddingRelative ( activity . acctPadLr , 0 , activity . acctPadLr , 0 )
2021-05-19 09:51:34 +02:00
tvColumnName . text = column . getColumnName ( false )
showColumnCloseButton ( )
showAnnouncements ( force = false )
}
2021-06-22 10:31:51 +02:00
val procRestoreScrollPosition = object : Runnable {
2021-05-19 09:51:34 +02:00
override fun run ( ) {
activity . handler . removeCallbacks ( this )
if ( isPageDestroyed ) {
log . d ( " restoreScrollPosition [%d], page is destroyed. " )
return
}
val column = this @ColumnViewHolder . column
if ( column == null ) {
2021-06-20 15:12:25 +02:00
log . d ( " restoreScrollPosition [ $pageIdx ], column==null " )
2021-05-19 09:51:34 +02:00
return
}
2021-06-20 15:12:25 +02:00
if ( column . isDispose . get ( ) ) {
log . d ( " restoreScrollPosition [ $pageIdx ], column is disposed " )
2021-05-19 09:51:34 +02:00
return
}
if ( column . hasMultipleViewHolder ( ) ) {
2021-06-20 15:12:25 +02:00
log . d ( " restoreScrollPosition [ $pageIdx ] ${column.getColumnName(true)} , column has multiple view holder. retry later. " )
2021-05-19 09:51:34 +02:00
// タブレットモードでカラムを追加/削除した際に発生する。
// このタイミングでスクロール位置を復元してもうまくいかないので延期する
activity . handler . postDelayed ( this , 100L )
return
}
//復元後にもここを通るがこれは正常である
2021-06-20 15:12:25 +02:00
val sp = column . scrollSave
2021-05-19 09:51:34 +02:00
if ( sp == null ) {
// val lvi = column.last_viewing_item_id
// if( lvi != null ){
// column.last_viewing_item_id = null
// val listIndex = column.findListIndexByTimelineId(lvi)
// if( listIndex != null){
// log.d(
// "restoreScrollPosition [$page_idx] %s , restore from last_viewing_item_id %d"
// , column.getColumnName( true )
// ,listIndex
// )
// ScrollPosition(column.toAdapterIndex(listIndex),0).restore(this@ColumnViewHolder)
// return
// }
// }
2021-06-20 15:12:25 +02:00
log . d ( " restoreScrollPosition [ $pageIdx ] ${column.getColumnName(true)} , column has no saved scroll position. " )
2021-05-19 09:51:34 +02:00
return
}
2020-12-21 03:13:03 +01:00
2021-06-20 15:12:25 +02:00
column . scrollSave = null
2021-05-19 09:51:34 +02:00
if ( listView . visibility != View . VISIBLE ) {
2021-06-20 15:12:25 +02:00
log . d ( " restoreScrollPosition [ $pageIdx ] ${column.getColumnName(true)} , listView is not visible. saved position ${sp.adapterIndex} , ${sp.offset} is dropped. " )
2020-12-21 03:13:03 +01:00
} else {
2021-06-20 15:12:25 +02:00
log . d ( " restoreScrollPosition [ $pageIdx ] ${column.getColumnName(true)} , listView is visible. resume ${sp.adapterIndex} , ${sp.offset} " )
2021-05-19 09:51:34 +02:00
sp . restore ( this @ColumnViewHolder )
}
}
}
val procShowColumnStatus : Runnable = Runnable {
val column = this . column
2021-06-20 15:12:25 +02:00
if ( column == null || column . isDispose . get ( ) ) return @Runnable
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
val sb = SpannableStringBuilder ( )
try {
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
val task = column . lastTask
if ( task != null ) {
sb . append ( task . ctType . marker ) // L,T,B,G
sb . append (
when {
task . isCancelled -> " ~ "
task . ctClosed . get ( ) -> " ! "
task . ctStarted . get ( ) -> " "
else -> " ? "
2020-12-21 03:13:03 +01:00
}
2021-05-19 09:51:34 +02:00
)
}
val streamStatus = column . getStreamingStatus ( )
log . d (
2021-06-20 15:12:25 +02:00
" procShowColumnStatus: streamStatus= $streamStatus , column= ${column.accessInfo.acct} / $ {
2021-05-19 09:51:34 +02:00
column . getColumnName (
true
)
} "
)
when ( streamStatus ) {
StreamStatus . Missing , StreamStatus . Closed -> {
}
StreamStatus . Connecting , StreamStatus . Open -> {
sb . appendColorShadeIcon ( activity , R . drawable . ic _pulse , " Streaming " )
sb . append ( " ? " )
}
StreamStatus . Subscribed -> {
sb . appendColorShadeIcon ( activity , R . drawable . ic _pulse , " Streaming " )
2020-12-21 03:13:03 +01:00
}
}
2021-05-19 09:51:34 +02:00
} finally {
2021-06-20 15:12:25 +02:00
log . d ( " showColumnStatus $sb " )
2021-05-19 09:51:34 +02:00
tvColumnStatus . text = sb
}
2020-12-21 03:13:03 +01:00
}
init {
viewRoot . scan { v ->
try {
// ボタンではないTextViewのフォントを変更する
2021-11-18 18:09:22 +01:00
if ( v is MyTextView && v !is Button ) {
2021-06-20 15:12:25 +02:00
v . typeface = ActMain . timelineFont
2020-12-21 03:13:03 +01:00
}
} catch ( ex : Throwable ) {
2022-12-27 03:54:52 +01:00
log . e ( ex , " can't change typeface. " )
2020-12-21 03:13:03 +01:00
}
}
2023-02-04 21:52:26 +01:00
if ( PrefB . bpShareViewPool . value ) {
2020-12-21 03:13:03 +01:00
listView . setRecycledViewPool ( activity . viewPool )
}
listView . itemAnimator = null
//
// val animator = listView.itemAnimator
// if( animator is DefaultItemAnimator){
// animator.supportsChangeAnimations = false
// }
etListName . setOnEditorActionListener { _ , actionId , _ ->
var handled = false
if ( actionId == EditorInfo . IME _ACTION _SEND ) {
btnListAdd . performClick ( )
handled = true
}
handled
}
refreshLayout . setOnRefreshListener ( this )
refreshLayout . setDistanceToTriggerSync ( ( 0.5f + 20f * activity . density ) . toInt ( ) )
2021-05-21 10:20:14 +02:00
arrayOf (
btnAnnouncements ,
btnAnnouncementsNext ,
btnAnnouncementsPrev ,
btnColor ,
btnColumnClose ,
btnColumnReload ,
btnColumnSetting ,
btnConfirmMail ,
btnDeleteNotification ,
btnEmojiAdd ,
btnLanguageFilter ,
btnListAdd ,
btnQuickFilterAll ,
btnQuickFilterBoost ,
btnQuickFilterFavourite ,
btnQuickFilterFollow ,
btnQuickFilterMention ,
btnQuickFilterPost ,
btnQuickFilterReaction ,
btnQuickFilterVote ,
btnSearch ,
btnSearchClear ,
llColumnHeader ,
llRefreshError ,
2021-06-20 15:12:25 +02:00
) . forEach { it . setOnClickListener ( this ) }
2021-05-21 10:20:14 +02:00
btnColumnClose . setOnLongClickListener ( this )
arrayOf (
cbDontAutoRefresh ,
cbDontCloseColumn ,
2021-11-06 04:00:29 +01:00
cbShowMediaDescription ,
2021-05-21 10:20:14 +02:00
cbDontShowBoost ,
cbDontShowFavourite ,
cbDontShowFollow ,
cbDontShowNonPublicToot ,
cbDontShowNormalToot ,
cbDontShowReaction ,
cbDontShowReply ,
cbDontShowVote ,
cbDontStreaming ,
cbEnableSpeech ,
cbHideMediaDefault ,
cbInstanceLocal ,
cbOldApi ,
cbRemoteOnly ,
cbSystemNotificationNotRelated ,
cbWithAttachment ,
cbWithHighlight ,
) . forEach { it . setOnCheckedChangeListener ( this ) }
2020-12-21 03:13:03 +01:00
2023-02-04 21:52:26 +01:00
if ( PrefB . bpMoveNotificationsQuickFilter . value ) {
2020-12-21 03:13:03 +01:00
( svQuickFilter . parent as ? ViewGroup ) ?. removeView ( svQuickFilter )
llColumnSettingInside . addView ( svQuickFilter , 0 )
svQuickFilter . setOnTouchListener { v , event ->
2021-05-19 09:51:34 +02:00
val action = event . action
if ( action == MotionEvent . ACTION _DOWN ) {
val sv = v as ? HorizontalScrollView
if ( sv != null && sv . getChildAt ( 0 ) . width > sv . width ) {
sv . requestDisallowInterceptTouchEvent ( true )
}
2020-12-21 03:13:03 +01:00
}
2021-05-19 09:51:34 +02:00
v . onTouchEvent ( event )
2020-12-21 03:13:03 +01:00
}
}
2021-06-20 15:12:25 +02:00
if ( ! activity . headerTextSizeSp . isNaN ( ) ) {
tvColumnName . textSize = activity . headerTextSizeSp
2020-12-21 03:13:03 +01:00
2021-06-20 15:12:25 +02:00
val acctSize = activity . headerTextSizeSp * 0.857f
2021-05-19 09:51:34 +02:00
tvColumnContext . textSize = acctSize
tvColumnStatus . textSize = acctSize
tvColumnIndex . textSize = acctSize
2021-05-21 10:20:14 +02:00
tvEmojiDesc . textSize = acctSize
2020-12-21 03:13:03 +01:00
}
2021-05-19 09:51:34 +02:00
initLoadingTextView ( )
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
var pad = 0
var wh = ActMain . headerIconSize + pad * 2
ivColumnIcon . layoutParams . width = wh
ivColumnIcon . layoutParams . height = wh
ivColumnIcon . setPaddingRelative ( pad , pad , pad , pad )
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
pad = ( ActMain . headerIconSize * 0.125f + 0.5f ) . toInt ( )
wh = ActMain . headerIconSize + pad * 2
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
btnAnnouncements . layoutParams . width = wh
btnAnnouncements . layoutParams . height = wh
btnAnnouncements . setPaddingRelative ( pad , pad , pad , pad )
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
btnColumnSetting . layoutParams . width = wh
btnColumnSetting . layoutParams . height = wh
btnColumnSetting . setPaddingRelative ( pad , pad , pad , pad )
btnColumnReload . layoutParams . width = wh
btnColumnReload . layoutParams . height = wh
btnColumnReload . setPaddingRelative ( pad , pad , pad , pad )
btnColumnClose . layoutParams . width = wh
btnColumnClose . layoutParams . height = wh
btnColumnClose . setPaddingRelative ( pad , pad , pad , pad )
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
etSearch . setOnEditorActionListener ( TextView . OnEditorActionListener { _ , actionId , _ ->
2021-06-20 15:12:25 +02:00
if ( ! bindingBusy ) {
2021-05-19 09:51:34 +02:00
if ( actionId == EditorInfo . IME _ACTION _SEARCH ) {
btnSearch . performClick ( )
return @OnEditorActionListener true
}
}
false
} )
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
// 入力の追跡
etRegexFilter . addTextChangedListener ( CustomTextWatcher {
2021-06-20 15:12:25 +02:00
if ( bindingBusy || isPageDestroyed ) return @CustomTextWatcher
2021-05-19 09:51:34 +02:00
if ( !is RegexValid ( ) ) return @CustomTextWatcher
2021-06-20 15:12:25 +02:00
column ?. regexText = etRegexFilter . text . toString ( )
activity . appState . saveColumnList ( )
2021-05-19 09:51:34 +02:00
activity . handler . removeCallbacks ( procStartLoading )
activity . handler . postDelayed ( procStartLoading , 666L )
} )
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
etHashtagExtraAny . addTextChangedListener ( CustomTextWatcher {
2021-06-20 15:12:25 +02:00
if ( bindingBusy || isPageDestroyed ) return @CustomTextWatcher
column ?. hashtagAny = etHashtagExtraAny . text . toString ( )
activity . appState . saveColumnList ( )
2021-05-19 09:51:34 +02:00
activity . handler . removeCallbacks ( procStartLoading )
activity . handler . postDelayed ( procStartLoading , 666L )
} )
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
etHashtagExtraAll . addTextChangedListener ( CustomTextWatcher {
2021-06-20 15:12:25 +02:00
if ( bindingBusy || isPageDestroyed ) return @CustomTextWatcher
column ?. hashtagAll = etHashtagExtraAll . text . toString ( )
activity . appState . saveColumnList ( )
2021-05-19 09:51:34 +02:00
activity . handler . removeCallbacks ( procStartLoading )
activity . handler . postDelayed ( procStartLoading , 666L )
} )
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
etHashtagExtraNone . addTextChangedListener ( CustomTextWatcher {
2021-06-20 15:12:25 +02:00
if ( bindingBusy || isPageDestroyed ) return @CustomTextWatcher
column ?. hashtagNone = etHashtagExtraNone . text . toString ( )
activity . appState . saveColumnList ( )
2021-05-19 09:51:34 +02:00
activity . handler . removeCallbacks ( procStartLoading )
activity . handler . postDelayed ( procStartLoading , 666L )
} )
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
announcementContentInvalidator =
NetworkEmojiInvalidator ( activity . handler , tvAnnouncementContent )
tvAnnouncementContent . movementMethod = MyLinkMovementMethod
2020-12-21 03:13:03 +01:00
}
2021-05-19 09:51:34 +02:00
override fun onRefresh ( direction : SwipyRefreshLayoutDirection ) {
2020-12-21 03:13:03 +01:00
val column = this . column ?: return
2021-05-19 09:51:34 +02:00
// カラムを追加/削除したときに ColumnからColumnViewHolderへの参照が外れることがある
// リロードやリフレッシュ操作で直るようにする
column . addColumnViewHolder ( this )
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
if ( direction == SwipyRefreshLayoutDirection . TOP && column . canReloadWhenRefreshTop ( ) ) {
refreshLayout . isRefreshing = false
activity . handler . post {
this @ColumnViewHolder . column ?. startLoading ( )
2020-12-21 03:13:03 +01:00
}
2021-05-19 09:51:34 +02:00
return
2020-12-21 03:13:03 +01:00
}
2021-05-19 09:51:34 +02:00
column . startRefresh ( false , direction == SwipyRefreshLayoutDirection . BOTTOM )
}
2020-12-21 03:13:03 +01:00
2021-05-19 09:51:34 +02:00
override fun onClick ( v : View ? ) = onClickImpl ( v )
override fun onLongClick ( v : View ? ) : Boolean = onLongClickImpl ( v )
override fun onCheckedChanged ( buttonView : CompoundButton ? , isChecked : Boolean ) =
onCheckedChangedImpl ( buttonView , isChecked )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
private fun _LinearLayout . inflateColumnHeader ( ) {
llColumnHeader = customView < OutsideDrawerLayout > {
lparams ( matchParent , wrapContent )
orientation = LinearLayout . VERTICAL
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
background = ContextCompat . getDrawable ( context , R . drawable . bg _column _header )
startPadding = dip ( 12 )
endPadding = dip ( 12 )
topPadding = dip ( 3 )
bottomPadding = dip ( 3 )
linearLayout {
2020-12-21 03:13:03 +01:00
lparams ( matchParent , wrapContent )
2021-06-22 10:31:51 +02:00
gravity = Gravity . BOTTOM
2020-12-21 03:13:03 +01:00
2021-11-08 11:04:30 +01:00
tvColumnContext = myTextView {
2021-06-22 10:31:51 +02:00
gravity = Gravity . END
startPadding = dip ( 4 )
endPadding = dip ( 4 )
textColor = context . attrColor ( R . attr . colorColumnHeaderAcct )
textSize = 12f
} . lparams ( 0 , wrapContent ) {
weight = 1f
}
2020-12-21 03:13:03 +01:00
2021-11-08 11:04:30 +01:00
tvColumnStatus = myTextView {
2021-06-22 10:31:51 +02:00
gravity = Gravity . END
textColor = context . attrColor ( R . attr . colorColumnHeaderPageNumber )
textSize = 12f
} . lparams ( wrapContent , wrapContent ) {
marginStart = dip ( 12 )
}
2020-12-21 03:13:03 +01:00
2021-11-08 11:04:30 +01:00
tvColumnIndex = myTextView {
2021-06-22 10:31:51 +02:00
gravity = Gravity . END
textColor = context . attrColor ( R . attr . colorColumnHeaderPageNumber )
textSize = 12f
} . lparams ( wrapContent , wrapContent ) {
marginStart = dip ( 4 )
}
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
linearLayout {
lparams ( matchParent , wrapContent ) {
topMargin = dip ( 0 )
}
gravity = Gravity . CENTER _VERTICAL
isBaselineAligned = false
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
ivColumnIcon = imageView {
importantForAccessibility = View . IMPORTANT _FOR _ACCESSIBILITY _NO
scaleType = ImageView . ScaleType . FIT _CENTER
} . lparams ( dip ( 32 ) , dip ( 32 ) ) {
endMargin = dip ( 4 )
}
2020-12-21 03:13:03 +01:00
2021-11-08 11:04:30 +01:00
tvColumnName = myTextView {
2021-06-22 10:31:51 +02:00
// Kannada語の "ಸ್ಥಳೀಯ ಟೈಮ್ ಲೈನ್" の上下が途切れることがあるらしい
// GS10+では再現しなかった
} . lparams ( dip ( 0 ) , wrapContent ) {
weight = 1f
2020-12-21 03:13:03 +01:00
}
2021-06-22 10:31:51 +02:00
frameLayout {
lparams ( wrapContent , wrapContent ) {
gravity = Gravity . CENTER _VERTICAL
startMargin = dip ( 2 )
2020-12-21 03:13:03 +01:00
}
2021-06-22 10:31:51 +02:00
clipChildren = false
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
btnAnnouncements = imageButton {
background = ContextCompat . getDrawable (
context ,
R . drawable . btn _bg _transparent _round6dp
)
contentDescription = context . getString ( R . string . announcements )
setImageResource ( R . drawable . ic _info _outline )
padding = dip ( 8 )
2020-12-21 03:13:03 +01:00
scaleType = ImageView . ScaleType . FIT _CENTER
2021-06-22 10:31:51 +02:00
btnAnnouncementsCutout = Paint ( ) . apply {
isAntiAlias = true
2020-12-21 03:13:03 +01:00
}
2021-06-22 10:31:51 +02:00
val path = Path ( )
addOutsideDrawer ( this ) { canvas , parent , view , left , top ->
if ( llAnnouncementsBox . visibility == View . VISIBLE ) {
val viewW = view . width
val viewH = view . height
val triTopX = ( left + viewW / 2 ) . toFloat ( )
val triTopY = top . toFloat ( ) + viewH * 0.75f
val triBottomLeft = left . toFloat ( )
val triBottomRight = ( left + viewW ) . toFloat ( )
val triBottom = parent . height . toFloat ( )
path . reset ( )
path . moveTo ( triTopX , triTopY )
path . lineTo ( triBottomRight , triBottom )
path . lineTo ( triBottomLeft , triBottom )
path . lineTo ( triTopX , triTopY )
canvas . drawPath ( path , btnAnnouncementsCutout )
2020-12-21 03:13:03 +01:00
}
}
2021-06-22 10:31:51 +02:00
} . lparams ( dip ( 40 ) , dip ( 40 ) )
btnAnnouncementsBadge = imageView {
setImageResource ( R . drawable . announcements _dot )
scaleType = ImageView . ScaleType . FIT _CENTER
} . lparams ( dip ( 7 ) , dip ( 7 ) ) {
gravity = Gravity . END or Gravity . TOP
endMargin = dip ( 4 )
topMargin = dip ( 4 )
2020-12-21 03:13:03 +01:00
}
2021-06-22 10:31:51 +02:00
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
frameLayout {
lparams ( wrapContent , wrapContent ) {
gravity = Gravity . CENTER _VERTICAL
startMargin = dip ( 2 )
2020-12-21 03:13:03 +01:00
}
2021-06-22 10:31:51 +02:00
clipChildren = false
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
btnColumnSetting = imageButton {
2020-12-21 03:13:03 +01:00
background =
ContextCompat . getDrawable (
context ,
R . drawable . btn _bg _transparent _round6dp
)
2021-06-22 10:31:51 +02:00
contentDescription = context . getString ( R . string . setting )
setImageResource ( R . drawable . ic _tune )
2020-12-21 03:13:03 +01:00
padding = dip ( 8 )
scaleType = ImageView . ScaleType . FIT _CENTER
2021-06-22 10:31:51 +02:00
val paint = Paint ( ) . apply {
isAntiAlias = true
color =
context . attrColor ( R . attr . colorColumnSettingBackground )
}
val path = Path ( )
addOutsideDrawer ( this ) { canvas , parent , view , left , top ->
if ( llColumnSetting . visibility == View . VISIBLE ) {
val viewW = view . width
val viewH = view . height
val triTopX = ( left + viewW / 2 ) . toFloat ( )
val triTopY = top . toFloat ( ) + viewH * 0.75f
val triBottomLeft = left . toFloat ( )
val triBottomRight = ( left + viewW ) . toFloat ( )
val triBottom = parent . height . toFloat ( )
path . reset ( )
path . moveTo ( triTopX , triTopY )
path . lineTo ( triBottomRight , triBottom )
path . lineTo ( triBottomLeft , triBottom )
path . lineTo ( triTopX , triTopY )
canvas . drawPath ( path , paint )
}
}
} . lparams ( dip ( 40 ) , dip ( 40 ) )
}
btnColumnReload = imageButton {
background =
ContextCompat . getDrawable (
2021-06-20 15:12:25 +02:00
context ,
R . drawable . btn _bg _transparent _round6dp
)
2021-06-22 10:31:51 +02:00
contentDescription = context . getString ( R . string . reload )
setImageResource ( R . drawable . ic _refresh )
padding = dip ( 8 )
scaleType = ImageView . ScaleType . FIT _CENTER
} . lparams ( dip ( 40 ) , dip ( 40 ) ) {
gravity = Gravity . CENTER _VERTICAL
startMargin = dip ( 2 )
2020-12-21 03:13:03 +01:00
}
2021-06-22 10:31:51 +02:00
btnColumnClose = imageButton {
background = ContextCompat . getDrawable (
context ,
R . drawable . btn _bg _transparent _round6dp
)
contentDescription = context . getString ( R . string . close _column )
setImageResource ( R . drawable . ic _close )
padding = dip ( 8 )
scaleType = ImageView . ScaleType . FIT _CENTER
} . lparams ( dip ( 40 ) , dip ( 40 ) ) {
gravity = Gravity . CENTER _VERTICAL
startMargin = dip ( 2 )
}
}
} // end of column header
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
private fun _LinearLayout . inflateColumnSetting ( ) {
2021-11-08 11:04:30 +01:00
var label : MyTextView ? = null
2021-06-22 10:31:51 +02:00
llColumnSetting = maxHeightScrollView {
lparams ( matchParent , wrapContent )
isScrollbarFadingEnabled = false
maxHeight = dip ( 240 )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
backgroundColor =
context . attrColor ( R . attr . colorColumnSettingBackground )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
llColumnSettingInside = verticalLayout {
lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
startPadding = dip ( 12 )
endPadding = dip ( 12 )
topPadding = dip ( 3 )
bottomPadding = dip ( 3 )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
llHashtagExtra = verticalLayout {
lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-11-08 11:04:30 +01:00
label = myTextView {
2021-06-22 10:31:51 +02:00
textColor =
context . attrColor ( R . attr . colorColumnHeaderPageNumber )
text = context . getString ( R . string . hashtag _extra _any )
2020-12-21 03:13:03 +01:00
} . lparams ( matchParent , wrapContent )
2021-11-08 11:04:30 +01:00
etHashtagExtraAny = myEditText {
2021-06-22 10:31:51 +02:00
id = View . generateViewId ( )
inputType = InputType . TYPE _CLASS _TEXT
maxLines = 1
setHorizontallyScrolling ( true )
isHorizontalScrollBarEnabled = true
2020-12-21 03:13:03 +01:00
} . lparams ( matchParent , wrapContent )
2021-06-22 10:31:51 +02:00
label ?. labelFor = etHashtagExtraAny . id
2020-12-21 03:13:03 +01:00
2021-11-08 11:04:30 +01:00
label = myTextView {
2021-06-22 10:31:51 +02:00
textColor =
context . attrColor ( R . attr . colorColumnHeaderPageNumber )
text = context . getString ( R . string . hashtag _extra _all )
2020-12-21 03:13:03 +01:00
} . lparams ( matchParent , wrapContent )
2021-11-08 11:04:30 +01:00
etHashtagExtraAll = myEditText {
2021-06-22 10:31:51 +02:00
id = View . generateViewId ( )
inputType = InputType . TYPE _CLASS _TEXT
maxLines = 1
setHorizontallyScrolling ( true )
isHorizontalScrollBarEnabled = true
2020-12-21 03:13:03 +01:00
} . lparams ( matchParent , wrapContent )
2021-06-22 10:31:51 +02:00
label ?. labelFor = etHashtagExtraAll . id
2020-12-21 03:13:03 +01:00
2021-11-08 11:04:30 +01:00
label = myTextView {
2021-06-22 10:31:51 +02:00
textColor =
context . attrColor ( R . attr . colorColumnHeaderPageNumber )
text = context . getString ( R . string . hashtag _extra _none )
2020-12-21 03:13:03 +01:00
} . lparams ( matchParent , wrapContent )
2021-11-08 11:04:30 +01:00
etHashtagExtraNone = myEditText {
2021-06-22 10:31:51 +02:00
id = View . generateViewId ( )
inputType = InputType . TYPE _CLASS _TEXT
maxLines = 1
setHorizontallyScrolling ( true )
isHorizontalScrollBarEnabled = true
2020-12-21 03:13:03 +01:00
} . lparams ( matchParent , wrapContent )
2021-06-22 10:31:51 +02:00
label ?. labelFor = etHashtagExtraNone . id
} // end of hashtag extra
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbDontCloseColumn = checkBox {
text = context . getString ( R . string . dont _close _column )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbRemoteOnly = checkBox {
text = context . getString ( R . string . remote _only )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-11-06 04:00:29 +01:00
cbShowMediaDescription = checkBox {
text = context . getString ( R . string . show _media _description )
2021-06-22 10:31:51 +02:00
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbWithHighlight = checkBox {
text = context . getString ( R . string . with _highlight )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbDontShowBoost = checkBox {
text = context . getString ( R . string . dont _show _boost )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbDontShowFavourite = checkBox {
text = context . getString ( R . string . dont _show _favourite )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbDontShowFollow = checkBox {
text = context . getString ( R . string . dont _show _follow )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbDontShowReply = checkBox {
text = context . getString ( R . string . dont _show _reply )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbDontShowReaction = checkBox {
text = context . getString ( R . string . dont _show _reaction )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbDontShowVote = checkBox {
text = context . getString ( R . string . dont _show _vote )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbDontShowNormalToot = checkBox {
text = context . getString ( R . string . dont _show _normal _toot )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbDontShowNonPublicToot = checkBox {
text = context . getString ( R . string . dont _show _non _public _toot )
} . lparams ( matchParent , wrapContent )
2021-06-20 15:12:25 +02:00
2021-06-22 10:31:51 +02:00
cbInstanceLocal = checkBox {
text = context . getString ( R . string . instance _local )
} . lparams ( matchParent , wrapContent )
2021-06-20 15:12:25 +02:00
2021-06-22 10:31:51 +02:00
cbDontStreaming = checkBox {
text = context . getString ( R . string . dont _use _streaming _api )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbDontAutoRefresh = checkBox {
text = context . getString ( R . string . dont _refresh _on _activity _resume )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbHideMediaDefault = checkBox {
text = context . getString ( R . string . hide _media _default )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-11-06 04:00:29 +01:00
cbWithAttachment = checkBox {
text = context . getString ( R . string . with _attachment )
} . lparams ( matchParent , wrapContent )
2021-06-22 10:31:51 +02:00
cbSystemNotificationNotRelated = checkBox {
text = context . getString ( R . string . system _notification _not _related )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbEnableSpeech = checkBox {
text = context . getString ( R . string . enable _speech )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbOldApi = checkBox {
text = context . getString ( R . string . use _old _api )
} . lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
llRegexFilter = linearLayout {
2020-12-21 03:13:03 +01:00
lparams ( matchParent , wrapContent )
2021-11-08 11:04:30 +01:00
label = myTextView {
2021-06-22 10:31:51 +02:00
textColor =
context . attrColor ( R . attr . colorColumnHeaderPageNumber )
text = context . getString ( R . string . regex _filter )
} . lparams ( wrapContent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-11-08 11:04:30 +01:00
tvRegexFilterError = myTextView {
2021-06-22 10:31:51 +02:00
textColor = context . attrColor ( R . attr . colorRegexFilterError )
2020-12-21 03:13:03 +01:00
} . lparams ( 0 , wrapContent ) {
weight = 1f
2021-06-22 10:31:51 +02:00
startMargin = dip ( 4 )
2020-12-21 03:13:03 +01:00
}
2021-06-22 10:31:51 +02:00
}
2020-12-21 03:13:03 +01:00
2021-11-08 11:04:30 +01:00
etRegexFilter = myEditText {
2021-06-22 10:31:51 +02:00
id = View . generateViewId ( )
inputType = InputType . TYPE _CLASS _TEXT
maxLines = 1
setHorizontallyScrolling ( true )
isHorizontalScrollBarEnabled = true
} . lparams ( matchParent , wrapContent )
label ?. labelFor = etRegexFilter . id
2021-11-08 11:04:30 +01:00
btnDeleteNotification = compatButton {
2021-06-22 10:31:51 +02:00
isAllCaps = false
text = context . getString ( R . string . notification _delete )
} . lparams ( matchParent , wrapContent )
2021-11-08 11:04:30 +01:00
btnColor = compatButton {
2021-06-22 10:31:51 +02:00
isAllCaps = false
text = context . getString ( R . string . color _and _background )
} . lparams ( matchParent , wrapContent )
2021-11-08 11:04:30 +01:00
btnLanguageFilter = compatButton {
2021-06-22 10:31:51 +02:00
isAllCaps = false
text = context . getString ( R . string . language _filter )
} . lparams ( matchParent , wrapContent )
}
} // end of column setting scroll view
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
private fun _LinearLayout . inflateAnnouncementsBox ( ) {
llAnnouncementsBox = verticalLayout {
lparams ( matchParent , wrapContent ) {
startMargin = dip ( 6 )
endMargin = dip ( 6 )
bottomMargin = dip ( 2 )
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
val buttonHeight = ActMain . boostButtonSize
val paddingH = ( buttonHeight . toFloat ( ) * 0.1f + 0.5f ) . toInt ( )
val paddingV = ( buttonHeight . toFloat ( ) * 0.1f + 0.5f ) . toInt ( )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
linearLayout {
lparams ( matchParent , wrapContent )
val padLr = dip ( 6 )
setPadding ( padLr , 0 , padLr , 0 )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
background = ContextCompat . getDrawable (
context ,
R . drawable . btn _bg _transparent _round6dp
)
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
gravity = Gravity . CENTER _VERTICAL or Gravity . END
2020-12-21 03:13:03 +01:00
2021-11-08 11:04:30 +01:00
tvAnnouncementsCaption = myTextView {
2021-06-22 10:31:51 +02:00
gravity = Gravity . END or Gravity . CENTER _VERTICAL
text = context . getString ( R . string . announcements )
} . lparams ( 0 , wrapContent ) {
weight = 1f
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
btnAnnouncementsPrev = imageButton {
background = ContextCompat . getDrawable (
context ,
R . drawable . btn _bg _transparent _round6dp
)
contentDescription = context . getString ( R . string . previous )
imageResource = R . drawable . ic _arrow _start
setPadding ( paddingH , paddingV , paddingH , paddingV )
scaleType = ImageView . ScaleType . FIT _CENTER
} . lparams ( buttonHeight , buttonHeight ) {
marginStart = dip ( 4 )
}
2020-12-21 03:13:03 +01:00
2021-11-08 11:04:30 +01:00
tvAnnouncementsIndex = myTextView {
2021-06-22 10:31:51 +02:00
} . lparams ( wrapContent , wrapContent ) {
marginStart = dip ( 4 )
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
btnAnnouncementsNext = imageButton {
background = ContextCompat . getDrawable (
context ,
R . drawable . btn _bg _transparent _round6dp
)
contentDescription = context . getString ( R . string . next )
imageResource = R . drawable . ic _arrow _end
setPadding ( paddingH , paddingV , paddingH , paddingV )
scaleType = ImageView . ScaleType . FIT _CENTER
} . lparams ( buttonHeight , buttonHeight ) {
marginStart = dip ( 4 )
2020-12-21 03:13:03 +01:00
}
}
2021-06-22 10:31:51 +02:00
llAnnouncements = maxHeightScrollView {
lparams ( matchParent , wrapContent ) {
topMargin = dip ( 1 )
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
val padLr = dip ( 6 )
val padTb = dip ( 2 )
setPadding ( padLr , padTb , padLr , padTb )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
scrollBarStyle = View . SCROLLBARS _OUTSIDE _OVERLAY
isScrollbarFadingEnabled = false
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
maxHeight = dip ( 240 )
2021-05-21 10:20:14 +02:00
2021-06-22 10:31:51 +02:00
verticalLayout {
lparams ( matchParent , wrapContent )
// 期間があれば表示する
2021-11-08 11:04:30 +01:00
tvAnnouncementPeriod = myTextView {
2021-06-22 10:31:51 +02:00
gravity = Gravity . END
} . lparams ( matchParent , wrapContent ) {
bottomMargin = dip ( 3 )
2021-05-21 10:20:14 +02:00
}
2021-06-22 10:31:51 +02:00
tvAnnouncementContent = myTextView {
setLineSpacing ( lineSpacingExtra , 1.1f )
// tools:text="Contents\nContents"
} . lparams ( matchParent , wrapContent ) {
topMargin = dip ( 3 )
2020-12-21 03:13:03 +01:00
}
2021-06-22 10:31:51 +02:00
llAnnouncementExtra = verticalLayout {
lparams ( matchParent , wrapContent ) {
topMargin = dip ( 3 )
}
2020-12-21 03:13:03 +01:00
}
}
2021-06-22 10:31:51 +02:00
}
}
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
private fun _LinearLayout . inflateSearchBar ( ) {
llSearch = verticalLayout {
lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
linearLayout {
2020-12-21 03:13:03 +01:00
lparams ( matchParent , wrapContent )
isBaselineAligned = false
gravity = Gravity . CENTER
2021-11-08 11:04:30 +01:00
etSearch = myEditText {
2021-06-22 10:31:51 +02:00
id = View . generateViewId ( )
imeOptions = EditorInfo . IME _ACTION _SEARCH
2020-12-21 03:13:03 +01:00
inputType = InputType . TYPE _CLASS _TEXT
2021-06-22 10:31:51 +02:00
maxLines = 1
} . lparams ( 0 , wrapContent ) {
weight = 1f
}
flEmoji = flexboxLayout {
flexWrap = FlexWrap . WRAP
justifyContent = JustifyContent . FLEX _START
2020-12-21 03:13:03 +01:00
} . lparams ( 0 , wrapContent ) {
weight = 1f
}
2021-06-22 10:31:51 +02:00
btnEmojiAdd = imageButton {
2020-12-21 03:13:03 +01:00
backgroundResource = R . drawable . btn _bg _transparent _round6dp
contentDescription = context . getString ( R . string . add )
imageResource = R . drawable . ic _add
imageTintList = ColorStateList . valueOf (
2023-01-14 21:37:23 +01:00
context . attrColor ( R . attr . colorTextContent )
2020-12-21 03:13:03 +01:00
)
} . lparams ( dip ( 40 ) , dip ( 40 ) ) {
startMargin = dip ( 4 )
}
2021-06-22 10:31:51 +02:00
btnSearchClear = imageButton {
backgroundResource = R . drawable . btn _bg _transparent _round6dp
contentDescription = context . getString ( R . string . clear )
imageResource = R . drawable . ic _close
imageTintList = ColorStateList . valueOf (
2023-01-14 21:37:23 +01:00
context . attrColor ( R . attr . colorTextContent )
2021-06-22 10:31:51 +02:00
)
} . lparams ( dip ( 40 ) , dip ( 40 ) ) {
startMargin = dip ( 4 )
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
btnSearch = imageButton {
backgroundResource = R . drawable . btn _bg _transparent _round6dp
contentDescription = context . getString ( R . string . search )
imageResource = R . drawable . ic _search
imageTintList = ColorStateList . valueOf (
2023-01-14 21:37:23 +01:00
context . attrColor ( R . attr . colorTextContent )
2021-06-22 10:31:51 +02:00
)
} . lparams ( dip ( 40 ) , dip ( 40 ) ) {
startMargin = dip ( 4 )
}
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
cbResolve = checkBox {
text = context . getString ( R . string . resolve _non _local _account )
} . lparams ( wrapContent , wrapContent ) // チェックボックスの余白はタッチ判定外
2020-12-21 03:13:03 +01:00
2021-11-08 11:04:30 +01:00
tvEmojiDesc = myTextView {
2021-06-22 10:31:51 +02:00
text = context . getString ( R . string . long _tap _to _delete )
textColor = context . attrColor ( R . attr . colorColumnHeaderPageNumber )
textSize = 12f
} . lparams ( wrapContent , wrapContent )
} // end of search bar
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
private fun _LinearLayout . inflateListBar ( ) {
llListList = linearLayout {
lparams ( matchParent , wrapContent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
isBaselineAligned = false
gravity = Gravity . CENTER
2020-12-21 03:13:03 +01:00
2021-11-08 11:04:30 +01:00
etListName = myEditText {
2021-06-22 10:31:51 +02:00
hint = context . getString ( R . string . list _create _hint )
imeOptions = EditorInfo . IME _ACTION _SEND
inputType = InputType . TYPE _CLASS _TEXT
} . lparams ( 0 , wrapContent ) {
weight = 1f
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
btnListAdd = imageButton {
backgroundResource = R . drawable . btn _bg _transparent _round6dp
contentDescription = context . getString ( R . string . add )
imageResource = R . drawable . ic _add
imageTintList = ColorStateList . valueOf (
2023-01-14 21:37:23 +01:00
context . attrColor ( R . attr . colorTextContent )
2021-06-22 10:31:51 +02:00
)
} . lparams ( dip ( 40 ) , dip ( 40 ) ) {
startMargin = dip ( 4 )
}
} // end of list bar header
}
private fun _LinearLayout . inflateQuickFilter ( ) {
svQuickFilter = horizontalScrollView {
lparams ( matchParent , wrapContent )
isFillViewport = true
linearLayout {
lparams ( matchParent , dip ( 40 ) )
2021-11-08 11:04:30 +01:00
btnQuickFilterAll = compatButton {
2021-06-22 10:31:51 +02:00
backgroundResource = R . drawable . btn _bg _transparent _round6dp
minWidthCompat = dip ( 40 )
startPadding = dip ( 4 )
endPadding = dip ( 4 )
isAllCaps = false
stateListAnimator = null
text = context . getString ( R . string . all )
} . lparams ( wrapContent , matchParent ) {
margin = 0
2020-12-21 03:13:03 +01:00
}
2021-06-22 10:31:51 +02:00
btnQuickFilterMention = imageButton {
backgroundResource = R . drawable . btn _bg _transparent _round6dp
contentDescription = context . getString ( R . string . mention2 )
} . lparams ( dip ( 40 ) , matchParent ) {
margin = 0
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
btnQuickFilterFavourite = imageButton {
backgroundResource = R . drawable . btn _bg _transparent _round6dp
contentDescription = context . getString ( R . string . favourite )
} . lparams ( dip ( 40 ) , matchParent ) {
margin = 0
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
btnQuickFilterBoost = imageButton {
backgroundResource = R . drawable . btn _bg _transparent _round6dp
contentDescription = context . getString ( R . string . boost )
} . lparams ( dip ( 40 ) , matchParent ) {
margin = 0
}
2021-05-10 23:30:42 +02:00
2021-06-22 10:31:51 +02:00
btnQuickFilterFollow = imageButton {
backgroundResource = R . drawable . btn _bg _transparent _round6dp
contentDescription = context . getString ( R . string . follow )
} . lparams ( dip ( 40 ) , matchParent ) {
margin = 0
}
2021-05-10 23:30:42 +02:00
2021-06-22 10:31:51 +02:00
btnQuickFilterPost = imageButton {
backgroundResource = R . drawable . btn _bg _transparent _round6dp
contentDescription = context . getString ( R . string . notification _type _post )
} . lparams ( dip ( 40 ) , matchParent ) {
margin = 0
}
2021-05-10 23:30:42 +02:00
2021-06-22 10:31:51 +02:00
btnQuickFilterReaction = imageButton {
backgroundResource = R . drawable . btn _bg _transparent _round6dp
contentDescription = context . getString ( R . string . reaction )
} . lparams ( dip ( 40 ) , matchParent ) {
margin = 0
}
2021-05-10 23:30:42 +02:00
2021-06-22 10:31:51 +02:00
btnQuickFilterVote = imageButton {
backgroundResource = R . drawable . btn _bg _transparent _round6dp
contentDescription = context . getString ( R . string . vote _polls )
} . lparams ( dip ( 40 ) , matchParent ) {
margin = 0
2021-05-10 23:30:42 +02:00
}
2021-06-22 10:31:51 +02:00
}
} // end of notification quick filter bar
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
private fun _LinearLayout . inflateColumnBody ( actMain : ActMain ) {
flColumnBackground = frameLayout {
ivColumnBackgroundImage = imageView {
importantForAccessibility = View . IMPORTANT _FOR _ACCESSIBILITY _NO
scaleType = ImageView . ScaleType . CENTER _CROP
visibility = View . GONE
} . lparams ( matchParent , matchParent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
llLoading = verticalLayout {
lparams ( matchParent , matchParent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
isBaselineAligned = false
gravity = Gravity . CENTER
2021-11-08 11:04:30 +01:00
tvLoading = myTextView {
2021-06-22 10:31:51 +02:00
gravity = Gravity . CENTER
} . lparams ( matchParent , wrapContent )
2021-11-08 11:04:30 +01:00
btnConfirmMail = compatButton {
2021-06-22 10:31:51 +02:00
text = context . getString ( R . string . resend _confirm _mail )
background = ContextCompat . getDrawable (
context ,
R . drawable . btn _bg _transparent _round6dp
)
} . lparams ( matchParent , wrapContent ) {
topMargin = dip ( 8 )
2020-12-21 03:13:03 +01:00
}
2021-06-22 10:31:51 +02:00
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
refreshLayout = swipyRefreshLayout {
lparams ( matchParent , matchParent )
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
direction = SwipyRefreshLayoutDirection . BOTH
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
// スタイルで指定しないとAndroid 6 で落ちる…
listView = recyclerView {
listLayoutManager = LinearLayoutManager ( actMain )
layoutManager = listLayoutManager
} . lparams ( matchParent , matchParent ) {
}
}
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
llRefreshError = frameLayout {
foregroundGravity = Gravity . BOTTOM
backgroundResource = R . drawable . bg _refresh _error
2020-12-21 03:13:03 +01:00
2021-06-22 10:31:51 +02:00
startPadding = dip ( 6 )
endPadding = dip ( 6 )
topPadding = dip ( 3 )
bottomPadding = dip ( 3 )
ivRefreshError = imageView {
importantForAccessibility = View . IMPORTANT _FOR _ACCESSIBILITY _NO
scaleType = ImageView . ScaleType . FIT _CENTER
imageResource = R . drawable . ic _error
imageTintList = ColorStateList . valueOf ( Color . RED )
} . lparams ( dip ( 24 ) , dip ( 24 ) ) {
gravity = Gravity . START or Gravity . CENTER _VERTICAL
startMargin = dip ( 4 )
}
2021-11-08 11:04:30 +01:00
tvRefreshError = myTextView {
2021-06-22 10:31:51 +02:00
textColor = Color . WHITE
2020-12-21 03:13:03 +01:00
} . lparams ( matchParent , wrapContent ) {
2021-06-22 10:31:51 +02:00
gravity = Gravity . TOP or Gravity . START
startMargin = dip ( 32 )
2020-12-21 03:13:03 +01:00
}
2021-06-22 10:31:51 +02:00
} . lparams ( matchParent , wrapContent ) {
margin = dip ( 6 )
}
} . lparams ( matchParent , 0 ) {
weight = 1f
}
}
fun inflate ( actMain : ActMain , parent : ViewGroup ) = with ( actMain . UI { } ) {
val b = Benchmark ( log , " Item-Inflate " , 40L )
val rv = verticalLayout {
// トップレベルのViewGroupのlparamsはイニシャライザ内部に置くしかないみたい
val lp = parent . generateLayoutParamsEx ( )
if ( lp != null ) {
lp . width = matchParent
lp . height = matchParent
if ( lp is ViewGroup . MarginLayoutParams ) {
lp . setMargins ( 0 , 0 , 0 , 0 )
}
layoutParams = lp
2020-12-21 03:13:03 +01:00
}
2021-06-22 10:31:51 +02:00
inflateColumnHeader ( )
inflateColumnSetting ( )
inflateAnnouncementsBox ( )
inflateSearchBar ( )
inflateListBar ( )
inflateQuickFilter ( )
inflateColumnBody ( actMain )
2020-12-21 03:13:03 +01:00
}
b . report ( )
rv
}
2018-01-04 19:52:25 +01:00
}