/
ItemViewHolder.kt
3664 lines (3074 loc) · 101 KB
/
ItemViewHolder.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package jp.juggler.subwaytooter
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Typeface
import android.os.SystemClock
import androidx.core.content.ContextCompat
import androidx.appcompat.app.AlertDialog
import android.text.Spannable
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.TextUtils
import android.text.style.BackgroundColorSpan
import android.util.TypedValue
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.*
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayout
import com.google.android.flexbox.JustifyContent
import jp.juggler.subwaytooter.Styler.defaultColorIcon
import jp.juggler.subwaytooter.action.*
import jp.juggler.subwaytooter.api.*
import jp.juggler.subwaytooter.api.entity.*
import jp.juggler.subwaytooter.dialog.ActionsDialog
import jp.juggler.subwaytooter.dialog.DlgConfirm
import jp.juggler.subwaytooter.drawable.PollPlotDrawable
import jp.juggler.subwaytooter.drawable.PreviewCardBorder
import jp.juggler.subwaytooter.span.MyClickableSpan
import jp.juggler.subwaytooter.table.*
import jp.juggler.subwaytooter.util.*
import jp.juggler.subwaytooter.view.*
import jp.juggler.util.*
import org.jetbrains.anko.*
import org.json.JSONArray
import org.json.JSONObject
import kotlin.math.max
internal class ItemViewHolder(
val activity : ActMain
) : View.OnClickListener, View.OnLongClickListener {
companion object {
private val log = LogCategory("ItemViewHolder")
var toot_color_unlisted : Int = 0
var toot_color_follower : Int = 0
var toot_color_direct_user : Int = 0
var toot_color_direct_me : Int = 0
}
val viewRoot : View
private var bSimpleList : Boolean = false
lateinit var column : Column
internal lateinit var list_adapter : ItemListAdapter
private lateinit var llBoosted : View
private lateinit var ivBoosted : ImageView
private lateinit var tvBoosted : TextView
private lateinit var tvBoostedAcct : TextView
private lateinit var tvBoostedTime : TextView
private lateinit var llReply : View
private lateinit var ivReply : ImageView
private lateinit var tvReply : TextView
private lateinit var llFollow : View
private lateinit var ivFollow : MyNetworkImageView
private lateinit var tvFollowerName : TextView
private lateinit var tvFollowerAcct : TextView
private lateinit var btnFollow : ImageButton
private lateinit var ivFollowedBy : ImageView
private lateinit var llStatus : View
private lateinit var ivThumbnail : MyNetworkImageView
private lateinit var tvName : TextView
private lateinit var tvTime : TextView
private lateinit var tvAcct : TextView
private lateinit var llContentWarning : View
private lateinit var tvContentWarning : MyTextView
private lateinit var btnContentWarning : Button
private lateinit var llContents : View
private lateinit var tvMentions : MyTextView
internal lateinit var tvContent : MyTextView
private lateinit var flMedia : View
private lateinit var llMedia : View
private lateinit var btnShowMedia : BlurhashView
private lateinit var ivMedia1 : MyNetworkImageView
private lateinit var ivMedia2 : MyNetworkImageView
private lateinit var ivMedia3 : MyNetworkImageView
private lateinit var ivMedia4 : MyNetworkImageView
private lateinit var btnHideMedia : ImageButton
private lateinit var statusButtonsViewHolder : StatusButtonsViewHolder
private lateinit var llButtonBar : View
private lateinit var llSearchTag : View
private lateinit var btnSearchTag : Button
private lateinit var llTrendTag : View
private lateinit var tvTrendTagName : TextView
private lateinit var tvTrendTagDesc : TextView
private lateinit var tvTrendTagCount : TextView
private lateinit var cvTagHistory : TagHistoryView
private lateinit var llList : View
private lateinit var btnListTL : Button
private lateinit var btnListMore : ImageButton
private lateinit var llFollowRequest : View
private lateinit var btnFollowRequestAccept : ImageButton
private lateinit var btnFollowRequestDeny : ImageButton
private lateinit var llFilter : View
private lateinit var tvFilterPhrase : TextView
private lateinit var tvFilterDetail : TextView
private lateinit var tvMediaDescription : TextView
private lateinit var llCardOuter : View
private lateinit var tvCardText : MyTextView
private lateinit var ivCardImage : MyNetworkImageView
private lateinit var llExtra : LinearLayout
private lateinit var llConversationIcons : View
private lateinit var ivConversationIcon1 : MyNetworkImageView
private lateinit var ivConversationIcon2 : MyNetworkImageView
private lateinit var ivConversationIcon3 : MyNetworkImageView
private lateinit var ivConversationIcon4 : MyNetworkImageView
private lateinit var tvConversationIconsMore : TextView
private lateinit var tvConversationParticipants : TextView
private lateinit var tvApplication : TextView
private lateinit var tvMessageHolder : TextView
private lateinit var llInstanceTicker : View
private lateinit var ivInstanceTicker : MyNetworkImageView
private lateinit var tvInstanceTicker : TextView
private lateinit var tvLastStatusAt : TextView
private lateinit var access_info : SavedAccount
private var buttons_for_status : StatusButtons? = null
private var item : TimelineItem? = null
private var status_showing : TootStatus? = null
private var status_reply : TootStatus? = null
private var status_account : TootAccountRef? = null
private var boost_account : TootAccountRef? = null
private var follow_account : TootAccountRef? = null
private var boost_time : Long = 0L
private var content_color : Int = 0
private var acct_color : Int = 0
private var content_color_csl : ColorStateList = ColorStateList.valueOf(0)
private val boost_invalidator : NetworkEmojiInvalidator
private val reply_invalidator : NetworkEmojiInvalidator
private val follow_invalidator : NetworkEmojiInvalidator
private val name_invalidator : NetworkEmojiInvalidator
private val content_invalidator : NetworkEmojiInvalidator
private val spoiler_invalidator : NetworkEmojiInvalidator
private val extra_invalidator_list = ArrayList<NetworkEmojiInvalidator>()
init {
this.viewRoot = inflate(activity)
btnListTL.setOnClickListener(this)
btnListMore.setOnClickListener(this)
btnSearchTag.setOnClickListener(this)
btnSearchTag.setOnLongClickListener(this)
btnContentWarning.setOnClickListener(this)
btnShowMedia.setOnClickListener(this)
ivMedia1.setOnClickListener(this)
ivMedia2.setOnClickListener(this)
ivMedia3.setOnClickListener(this)
ivMedia4.setOnClickListener(this)
btnFollow.setOnClickListener(this)
btnFollow.setOnLongClickListener(this)
ivCardImage.setOnClickListener(this)
ivCardImage.setOnLongClickListener(this)
ivThumbnail.setOnClickListener(this)
llBoosted.setOnClickListener(this)
llBoosted.setOnLongClickListener(this)
llReply.setOnClickListener(this)
llReply.setOnLongClickListener(this)
llFollow.setOnClickListener(this)
llFollow.setOnLongClickListener(this)
llConversationIcons.setOnLongClickListener(this)
btnFollow.setOnClickListener(this)
btnFollowRequestAccept.setOnClickListener(this)
btnFollowRequestDeny.setOnClickListener(this)
// ロングタップ
ivThumbnail.setOnLongClickListener(this)
//
tvContent.movementMethod = MyLinkMovementMethod
tvMentions.movementMethod = MyLinkMovementMethod
tvContentWarning.movementMethod = MyLinkMovementMethod
tvMediaDescription.movementMethod = MyLinkMovementMethod
tvCardText.movementMethod = MyLinkMovementMethod
btnHideMedia.setOnClickListener(this)
llTrendTag.setOnClickListener(this)
llTrendTag.setOnLongClickListener(this)
llFilter.setOnClickListener(this)
var f : Float
f = activity.timeline_font_size_sp
if(! f.isNaN()) {
tvFollowerName.textSize = f
tvName.textSize = f
tvMentions.textSize = f
tvContentWarning.textSize = f
tvContent.textSize = f
btnShowMedia.textSize = f
tvApplication.textSize = f
tvMessageHolder.textSize = f
btnListTL.textSize = f
tvTrendTagName.textSize = f
tvTrendTagCount.textSize = f
tvFilterPhrase.textSize = f
tvMediaDescription.textSize = f
tvCardText.textSize = f
tvConversationIconsMore.textSize = f
tvConversationParticipants.textSize = f
}
f = activity.notification_tl_font_size_sp
if(! f.isNaN()) {
tvBoosted.textSize = f
tvReply.textSize = f
}
f = activity.acct_font_size_sp
if(! f.isNaN()) {
tvBoostedAcct.textSize = f
tvBoostedTime.textSize = f
tvFollowerAcct.textSize = f
tvLastStatusAt.textSize = f
tvAcct.textSize = f
tvTime.textSize = f
tvTrendTagDesc.textSize = f
tvFilterDetail.textSize = f
}
var s = activity.avatarIconSize
ivThumbnail.layoutParams.height = s
ivThumbnail.layoutParams.width = s
ivFollow.layoutParams.width = s
ivBoosted.layoutParams.width = s
s = ActMain.replyIconSize + (activity.density * 8).toInt()
ivReply.layoutParams.width = s
ivReply.layoutParams.height = s
s = activity.notificationTlIconSize
ivBoosted.layoutParams.height = s
this.content_invalidator = NetworkEmojiInvalidator(activity.handler, tvContent)
this.spoiler_invalidator = NetworkEmojiInvalidator(activity.handler, tvContentWarning)
this.boost_invalidator = NetworkEmojiInvalidator(activity.handler, tvBoosted)
this.reply_invalidator = NetworkEmojiInvalidator(activity.handler, tvReply)
this.follow_invalidator = NetworkEmojiInvalidator(activity.handler, tvFollowerName)
this.name_invalidator = NetworkEmojiInvalidator(activity.handler, tvName)
val cardBackground = llCardOuter.background
if(cardBackground is PreviewCardBorder) {
val density = activity.density
cardBackground.round = (density * 8f)
cardBackground.width = (density * 1f)
}
btnShowMedia.text =
SpannableString(activity.getString(R.string.tap_to_show))
.apply {
val colorBg = getAttributeColor(activity, R.attr.colorShowMediaBackground)
.applyAlphaMultiplier(0.5f)
setSpan(
BackgroundColorSpan(colorBg),
0,
this.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}
fun onViewRecycled() {
}
fun bind(
list_adapter : ItemListAdapter,
column : Column,
bSimpleList : Boolean,
item : TimelineItem
) {
val b = Benchmark(log, "Item-bind", 40L)
this.list_adapter = list_adapter
this.column = column
this.bSimpleList = bSimpleList
this.access_info = column.access_info
val font_bold = ActMain.timeline_font_bold
val font_normal = ActMain.timeline_font
viewRoot.scan { v ->
try {
when(v) {
// ボタンは太字なので触らない
is CountImageButton -> {
}
// ボタンは太字なので触らない
is Button -> {
}
is TextView -> v.typeface = when {
v === tvName ||
v === tvFollowerName ||
v === tvBoosted ||
v === tvReply ||
v === tvTrendTagCount ||
v === tvTrendTagName ||
v === tvConversationIconsMore ||
v === tvConversationParticipants ||
v === tvFilterPhrase -> font_bold
else -> font_normal
}
}
} catch(ex : Throwable) {
log.trace(ex)
}
}
if(bSimpleList) {
viewRoot.setOnTouchListener { _, ev ->
// ポップアップを閉じた時にクリックでリストを触ったことになってしまう不具合の回避
val now = SystemClock.elapsedRealtime()
// ポップアップを閉じた直後はタッチダウンを無視する
if(now - StatusButtonsPopup.last_popup_close >= 30L) {
false
} else {
val action = ev.action
log.d("onTouchEvent action=$action")
true
}
}
viewRoot.setOnClickListener { viewClicked ->
activity.closeListItemPopup()
status_showing?.let { status ->
val popup =
StatusButtonsPopup(activity, column, bSimpleList, this@ItemViewHolder)
activity.listItemPopup = popup
popup.show(
list_adapter.columnVh.listView,
viewClicked,
status,
item as? TootNotification
)
}
}
llButtonBar.visibility = View.GONE
this.buttons_for_status = null
} else {
viewRoot.isClickable = false
llButtonBar.visibility = View.VISIBLE
this.buttons_for_status = StatusButtons(
activity,
column,
false,
statusButtonsViewHolder,
this
)
}
this.status_showing = null
this.status_reply = null
this.status_account = null
this.boost_account = null
this.follow_account = null
this.boost_time = 0L
this.viewRoot.setBackgroundColor(0)
this.boostedAction = defaultBoostedAction
llInstanceTicker.visibility = View.GONE
llBoosted.visibility = View.GONE
llReply.visibility = View.GONE
llFollow.visibility = View.GONE
llStatus.visibility = View.GONE
llSearchTag.visibility = View.GONE
llList.visibility = View.GONE
llFollowRequest.visibility = View.GONE
tvMessageHolder.visibility = View.GONE
llTrendTag.visibility = View.GONE
llFilter.visibility = View.GONE
tvMediaDescription.visibility = View.GONE
llCardOuter.visibility = View.GONE
tvCardText.visibility = View.GONE
ivCardImage.visibility = View.GONE
llConversationIcons.visibility = View.GONE
removeExtraView()
var c : Int
c = column.getContentColor()
this.content_color = c
this.content_color_csl = ColorStateList.valueOf(c)
tvBoosted.setTextColor(c)
tvReply.setTextColor(c)
tvFollowerName.setTextColor(c)
tvName.setTextColor(c)
tvMentions.setTextColor(c)
tvContentWarning.setTextColor(c)
tvContent.setTextColor(c)
//NSFWは文字色固定 btnShowMedia.setTextColor( c );
tvApplication.setTextColor(c)
tvMessageHolder.setTextColor(c)
tvTrendTagName.setTextColor(c)
tvTrendTagCount.setTextColor(c)
cvTagHistory.setColor(c)
tvFilterPhrase.setTextColor(c)
tvMediaDescription.setTextColor(c)
tvCardText.setTextColor(c)
tvConversationIconsMore.setTextColor(c)
tvConversationParticipants.setTextColor(c)
(llCardOuter.background as? PreviewCardBorder)?.let {
val rgb = c and 0xffffff
val alpha = max(1, c ushr (24 + 1)) // 本来の値の半分にする
it.color = rgb or (alpha shl 24)
}
c = column.getAcctColor()
this.acct_color = c
tvBoostedTime.setTextColor(c)
tvTime.setTextColor(c)
tvTrendTagDesc.setTextColor(c)
tvFilterDetail.setTextColor(c)
tvFilterPhrase.setTextColor(c)
// 以下のビューの文字色はsetAcct() で設定される
// tvBoostedAcct.setTextColor(c)
// tvFollowerAcct.setTextColor(c)
// tvAcct.setTextColor(c)
this.item = item
when(item) {
is TootStatus -> {
val reblog = item.reblog
when {
reblog == null -> showStatusOrReply(item)
item.hasAnyContent() -> {
// 引用Renote
val colorBg = Pref.ipEventBgColorBoost(activity.pref)
showReply(reblog, R.drawable.ic_repeat, R.string.renote_to)
showStatus(item, colorBg)
}
else -> {
// 引用なしブースト
val colorBg = Pref.ipEventBgColorBoost(activity.pref)
showBoost(
item.accountRef,
item.time_created_at,
R.drawable.ic_repeat,
R.string.display_name_boosted_by,
boost_status = item
)
showStatusOrReply(item.reblog, colorBg)
}
}
}
is TootAccountRef -> showAccount(item)
is TootNotification -> showNotification(item)
is TootGap -> showGap()
is TootSearchGap -> showSearchGap(item)
is TootDomainBlock -> showDomainBlock(item)
is TootList -> showList(item)
is TootMessageHolder -> showMessageHolder(item)
is TootTag -> showSearchTag(item)
is TootFilter -> showFilter(item)
is TootConversationSummary -> {
showStatusOrReply(item.last_status)
showConversationIcons(item)
}
is TootScheduled -> {
showScheduled(item)
}
else -> {
}
}
b.report()
}
private fun showScheduled(item : TootScheduled) {
try {
llStatus.visibility = View.VISIBLE
this.viewRoot.setBackgroundColor(0)
showStatusTimeScheduled(activity, tvTime, item)
val who = access_info.loginAccount !!
val whoRef = TootAccountRef(TootParser(activity, access_info), who)
this.status_account = whoRef
setAcct(tvAcct, access_info.getFullAcct(who), who.acct)
tvName.text = whoRef.decoded_display_name
name_invalidator.register(whoRef.decoded_display_name)
ivThumbnail.setImageUrl(
activity.pref,
Styler.calcIconRound(ivThumbnail.layoutParams),
access_info.supplyBaseUrl(who.avatar_static),
access_info.supplyBaseUrl(who.avatar)
)
val content = SpannableString(item.text ?: "")
tvMentions.visibility = View.GONE
tvContent.text = content
content_invalidator.register(content)
tvContent.minLines = - 1
val decoded_spoiler_text = SpannableString(item.spoiler_text ?: "")
when {
decoded_spoiler_text.isNotEmpty() -> {
// 元データに含まれるContent Warning を使う
llContentWarning.visibility = View.VISIBLE
tvContentWarning.text = decoded_spoiler_text
spoiler_invalidator.register(decoded_spoiler_text)
val cw_shown = ContentWarning.isShown(item.uri, access_info.expand_cw)
showContent(cw_shown)
}
else -> {
// CWしない
llContentWarning.visibility = View.GONE
llContents.visibility = View.VISIBLE
}
}
val media_attachments = item.media_attachments
if(media_attachments?.isEmpty() != false) {
flMedia.visibility = View.GONE
llMedia.visibility = View.GONE
btnShowMedia.visibility = View.GONE
} else {
flMedia.visibility = View.VISIBLE
// hide sensitive media
val default_shown = when {
column.hide_media_default -> false
access_info.dont_hide_nsfw -> true
else -> ! item.sensitive
}
val is_shown = MediaShown.isShown(item.uri, default_shown)
btnShowMedia.visibility = if(! is_shown) View.VISIBLE else View.GONE
llMedia.visibility = if(! is_shown) View.GONE else View.VISIBLE
val sb = StringBuilder()
setMedia(media_attachments, sb, ivMedia1, 0)
setMedia(media_attachments, sb, ivMedia2, 1)
setMedia(media_attachments, sb, ivMedia3, 2)
setMedia(media_attachments, sb, ivMedia4, 3)
if(sb.isNotEmpty()) {
tvMediaDescription.visibility = View.VISIBLE
tvMediaDescription.text = sb
}
setIconDrawableId(
activity,
btnHideMedia,
R.drawable.ic_close,
color = content_color,
alphaMultiplier = Styler.boost_alpha
)
}
buttons_for_status?.hide()
tvApplication.visibility = View.GONE
} catch(ex : Throwable) {
}
llSearchTag.visibility = View.VISIBLE
btnSearchTag.text = activity.getString(R.string.scheduled_status) + " " +
TootStatus.formatTime(
activity,
item.timeScheduledAt,
true
)
}
private fun removeExtraView() {
llExtra.scan { v ->
if(v is MyNetworkImageView) {
v.cancelLoading()
}
}
llExtra.removeAllViews()
for(invalidator in extra_invalidator_list) {
invalidator.register(null)
}
extra_invalidator_list.clear()
}
private fun showConversationIcons(cs : TootConversationSummary) {
val last_account_id = cs.last_status.account.id
val accountsOther = cs.accounts.filter { it.get().id != last_account_id }
if(accountsOther.isNotEmpty()) {
llConversationIcons.visibility = View.VISIBLE
val size = accountsOther.size
tvConversationParticipants.text = if(size <= 1) {
activity.getString(R.string.conversation_to)
} else {
activity.getString(R.string.participants)
}
fun showIcon(iv : MyNetworkImageView, idx : Int) {
val bShown = idx < size
iv.visibility = if(bShown) View.VISIBLE else View.GONE
if(! bShown) return
val who = accountsOther[idx].get()
iv.setImageUrl(
activity.pref,
Styler.calcIconRound(iv.layoutParams),
access_info.supplyBaseUrl(who.avatar_static),
access_info.supplyBaseUrl(who.avatar)
)
}
showIcon(ivConversationIcon1, 0)
showIcon(ivConversationIcon2, 1)
showIcon(ivConversationIcon3, 2)
showIcon(ivConversationIcon4, 3)
tvConversationIconsMore.text = when {
size <= 4 -> ""
else -> activity.getString(R.string.participants_and_more)
}
}
if(cs.last_status.in_reply_to_id != null) {
llSearchTag.visibility = View.VISIBLE
btnSearchTag.text = activity.getString(R.string.show_conversation)
}
}
private fun openConversationSummary() {
val cs = item as? TootConversationSummary ?: return
if(cs.unread) {
cs.unread = false
// 表示の更新
list_adapter.notifyChange(
reason = "ConversationSummary reset unread",
reset = true
)
// 未読フラグのクリアをサーバに送る
Action_Toot.clearConversationUnread(activity, access_info, cs)
}
Action_Toot.conversation(
activity,
activity.nextPosition(column),
access_info,
cs.last_status
)
}
private fun showStatusOrReply(item : TootStatus, colorBgArg : Int = 0) {
var colorBg = colorBgArg
val reply = item.reply
val in_reply_to_id = item.in_reply_to_id
val in_reply_to_account_id = item.in_reply_to_account_id
when {
reply != null -> {
showReply(reply, R.drawable.ic_reply, R.string.reply_to)
if(colorBgArg == 0) colorBg = Pref.ipEventBgColorMention(activity.pref)
}
in_reply_to_id != null && in_reply_to_account_id != null -> {
showReply(item, in_reply_to_account_id)
if(colorBgArg == 0) colorBg = Pref.ipEventBgColorMention(activity.pref)
}
}
showStatus(item, colorBg)
}
private fun showMessageHolder(item : TootMessageHolder) {
tvMessageHolder.visibility = View.VISIBLE
tvMessageHolder.text = item.text
tvMessageHolder.gravity = item.gravity
}
private fun showNotification(n : TootNotification) {
val n_status = n.status
val n_accountRef = n.accountRef
val n_account = n_accountRef?.get()
fun showNotificationStatus(item : TootStatus, colorBgDefault : Int) {
val reblog = item.reblog
when {
reblog == null -> showStatusOrReply(item, colorBgDefault)
! item.hasAnyContent() -> {
// 通常のブースト。引用なしブースト。
// ブースト表示は通知イベントと被るのでしない
showStatusOrReply(reblog, Pref.ipEventBgColorBoost(activity.pref))
}
else -> {
// 引用Renote
showReply(reblog, R.drawable.ic_repeat, R.string.renote_to)
showStatus(item, Pref.ipEventBgColorQuote(activity.pref))
}
}
}
when(n.type) {
TootNotification.TYPE_FAVOURITE -> {
val colorBg = Pref.ipEventBgColorFavourite(activity.pref)
if(n_account != null) showBoost(
n_accountRef,
n.time_created_at,
if(access_info.isNicoru(n_account)) R.drawable.ic_nicoru else R.drawable.ic_star,
R.string.display_name_favourited_by
)
if(n_status != null) {
showNotificationStatus(n_status, colorBg)
}
}
TootNotification.TYPE_REBLOG -> {
val colorBg = Pref.ipEventBgColorBoost(activity.pref)
if(n_account != null) showBoost(
n_accountRef,
n.time_created_at,
R.drawable.ic_repeat,
R.string.display_name_boosted_by,
boost_status = n_status
)
if(n_status != null) {
showNotificationStatus(n_status, colorBg)
}
}
TootNotification.TYPE_RENOTE -> {
// 引用のないreblog
val colorBg = Pref.ipEventBgColorBoost(activity.pref)
if(n_account != null) showBoost(
n_accountRef,
n.time_created_at,
R.drawable.ic_repeat,
R.string.display_name_boosted_by,
boost_status = n_status
)
if(n_status != null) {
showNotificationStatus(n_status, colorBg)
}
}
TootNotification.TYPE_FOLLOW -> {
val colorBg = Pref.ipEventBgColorFollow(activity.pref)
if(n_account != null) {
showBoost(
n_accountRef,
n.time_created_at,
R.drawable.ic_follow_plus,
R.string.display_name_followed_by
)
showAccount(n_accountRef)
if(colorBg != 0) this.viewRoot.backgroundColor = colorBg
}
}
TootNotification.TYPE_UNFOLLOW -> {
val colorBg = Pref.ipEventBgColorUnfollow(activity.pref)
if(n_account != null) {
showBoost(
n_accountRef,
n.time_created_at,
R.drawable.ic_follow_cross,
R.string.display_name_unfollowed_by
)
showAccount(n_accountRef)
if(colorBg != 0) this.viewRoot.backgroundColor = colorBg
}
}
TootNotification.TYPE_MENTION,
TootNotification.TYPE_REPLY -> {
val colorBg = Pref.ipEventBgColorMention(activity.pref)
if(! bSimpleList && ! access_info.isMisskey) {
when {
n_account == null -> {
}
n_status?.in_reply_to_id != null || n_status?.reply != null -> {
// トゥート内部に「~への返信」を表示するので、
// 通知イベントの「~からの返信」は表示しない
}
else -> // 返信ではなくメンションの場合は「~からの返信」を表示する
showBoost(
n_accountRef,
n.time_created_at,
R.drawable.ic_reply,
R.string.display_name_mentioned_by
)
}
}
if(n_status != null) {
showNotificationStatus(n_status, colorBg)
}
}
TootNotification.TYPE_REACTION -> {
val colorBg = Pref.ipEventBgColorReaction(activity.pref)
val reaction = MisskeyReaction.shortcodeMap[n.reaction ?: ""]
if(n_account != null) showBoost(
n_accountRef,
n.time_created_at,
R.drawable.ic_question, // not used
R.string.display_name_reaction_by,
reactionDrawableId = reaction?.btnDrawableId
)
if(n_status != null) {
showNotificationStatus(n_status, colorBg)
}
}
TootNotification.TYPE_QUOTE -> {
val colorBg = Pref.ipEventBgColorQuote(activity.pref)
if(n_account != null) showBoost(
n_accountRef,
n.time_created_at,
R.drawable.ic_repeat,
R.string.display_name_quoted_by
)
if(n_status != null) {
showNotificationStatus(n_status, colorBg)
}
}
TootNotification.TYPE_VOTE -> {
val colorBg = Pref.ipEventBgColorVote(activity.pref)
if(n_account != null) showBoost(
n_accountRef,
n.time_created_at,
R.drawable.ic_vote,
R.string.display_name_voted_by
)
if(n_status != null) {
showNotificationStatus(n_status, colorBg)
}
}
TootNotification.TYPE_FOLLOW_REQUEST -> {
val colorBg = Pref.ipEventBgColorFollowRequest(activity.pref)
if(n_account != null) showBoost(
n_accountRef,
n.time_created_at,
R.drawable.ic_follow_wait,
R.string.display_name_follow_request_by
)
viewRoot.backgroundColor = colorBg
boostedAction = {
activity.addColumn(
activity.nextPosition(column)
, access_info
, ColumnType.FOLLOW_REQUESTS
)
}
}
TootNotification.TYPE_POLL -> {
val colorBg = 0
if(n_account != null) showBoost(
n_accountRef,
n.time_created_at,
R.drawable.ic_vote,
R.string.end_of_polling_from
)
if(n_status != null) {
showNotificationStatus(n_status, colorBg)
}
}
else -> {
val colorBg = 0
if(n_account != null) showBoost(
n_accountRef,
n.time_created_at,
R.drawable.ic_question,
R.string.unknown_notification_from
)
if(n_status != null) {
showNotificationStatus(n_status, colorBg)
}
tvMessageHolder.visibility = View.VISIBLE
tvMessageHolder.text = "notification type is ${n.type}"
tvMessageHolder.gravity = Gravity.CENTER
}
}
}
private fun showList(list : TootList) {
llList.visibility = View.VISIBLE
btnListTL.text = list.title
btnListTL.textColor = content_color
btnListMore.imageTintList = content_color_csl
}
private fun showDomainBlock(domain_block : TootDomainBlock) {
llSearchTag.visibility = View.VISIBLE
btnSearchTag.text = domain_block.domain
}
private fun showFilter(filter : TootFilter) {
llFilter.visibility = View.VISIBLE
tvFilterPhrase.text = filter.phrase
val sb = StringBuffer()
//
sb.append(activity.getString(R.string.filter_context))
.append(": ")
.append(filter.getContextNames(activity).joinToString("/"))
//
val flags = ArrayList<String>()
if(filter.irreversible) flags.add(activity.getString(R.string.filter_irreversible))
if(filter.whole_word) flags.add(activity.getString(R.string.filter_word_match))
if(flags.isNotEmpty()) {
sb.append('\n')
.append(flags.joinToString(", "))
}
//
if(filter.time_expires_at != 0L) {
sb.append('\n')
.append(activity.getString(R.string.filter_expires_at))
.append(": ")
.append(TootStatus.formatTime(activity, filter.time_expires_at, false))
}
tvFilterDetail.text = sb.toString()
}
private fun showSearchTag(tag : TootTag) {
if(tag.history?.isNotEmpty() == true) {
llTrendTag.visibility = View.VISIBLE