That fuck shit the fascists are using
1package org.tm.archive.messagerequests
2
3import android.content.Context
4import android.content.res.ColorStateList
5import android.util.AttributeSet
6import android.view.View
7import androidx.constraintlayout.widget.ConstraintLayout
8import androidx.core.text.HtmlCompat
9import com.google.android.material.button.MaterialButton
10import org.tm.archive.R
11import org.tm.archive.messagerequests.MessageRequestBarColorTheme.Companion.resolveTheme
12import org.tm.archive.recipients.Recipient
13import org.tm.archive.util.CommunicationActions
14import org.tm.archive.util.Debouncer
15import org.tm.archive.util.HtmlUtil
16import org.tm.archive.util.views.LearnMoreTextView
17import org.tm.archive.util.visible
18
19/**
20 * View shown in a conversation during a message request state or related state (e.g., blocked).
21 */
22class MessageRequestsBottomView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : ConstraintLayout(context, attrs, defStyleAttr) {
23 private val showProgressDebouncer = Debouncer(250)
24
25 private val question: LearnMoreTextView
26 private val accept: MaterialButton
27 private val block: MaterialButton
28 private val unblock: MaterialButton
29 private val delete: MaterialButton
30 private val report: MaterialButton
31 private val busyIndicator: View
32 private val buttonBar: View
33
34 init {
35 inflate(context, R.layout.message_request_bottom_bar, this)
36
37 question = findViewById(R.id.message_request_question)
38 accept = findViewById(R.id.message_request_accept)
39 block = findViewById(R.id.message_request_block)
40 unblock = findViewById(R.id.message_request_unblock)
41 delete = findViewById(R.id.message_request_delete)
42 report = findViewById(R.id.message_request_report)
43 busyIndicator = findViewById(R.id.message_request_busy_indicator)
44 buttonBar = findViewById(R.id.message_request_button_layout)
45
46 setWallpaperEnabled(false)
47 }
48
49 fun setMessageRequestData(recipient: Recipient, messageRequestState: MessageRequestState) {
50 question.setLearnMoreVisible(false)
51 question.setOnLinkClickListener(null)
52
53 updateButtonVisibility(messageRequestState)
54
55 when (messageRequestState.state) {
56 MessageRequestState.State.INDIVIDUAL_BLOCKED -> {
57 val message = if (recipient.isReleaseNotes) R.string.MessageRequestBottomView_get_updates_and_news_from_s_you_wont_receive_any_updates_until_you_unblock_them else if (recipient.isRegistered) R.string.MessageRequestBottomView_do_you_want_to_let_s_message_you_wont_receive_any_messages_until_you_unblock_them else R.string.MessageRequestBottomView_do_you_want_to_let_s_message_you_wont_receive_any_messages_until_you_unblock_them_SMS
58 question.text = HtmlCompat.fromHtml(
59 context.getString(
60 message,
61 HtmlUtil.bold(recipient.getShortDisplayName(context))
62 ),
63 0
64 )
65 }
66
67 MessageRequestState.State.BLOCKED_GROUP -> question.setText(R.string.MessageRequestBottomView_unblock_this_group_and_share_your_name_and_photo_with_its_members)
68
69 MessageRequestState.State.LEGACY_INDIVIDUAL -> {
70 question.text = context.getString(R.string.MessageRequestBottomView_continue_your_conversation_with_s_and_share_your_name_and_photo, recipient.getShortDisplayName(context))
71 question.setLearnMoreVisible(true)
72 question.setOnLinkClickListener { CommunicationActions.openBrowserLink(context, context.getString(R.string.MessageRequestBottomView_legacy_learn_more_url)) }
73 accept.setText(R.string.MessageRequestBottomView_continue)
74 }
75
76 MessageRequestState.State.DEPRECATED_GROUP_V1 -> question.setText(R.string.MessageRequestBottomView_upgrade_this_group_to_activate_new_features)
77 MessageRequestState.State.GROUP_V2_INVITE -> {
78 question.setText(R.string.MessageRequestBottomView_do_you_want_to_join_this_group_you_wont_see_their_messages)
79 accept.setText(R.string.MessageRequestBottomView_accept)
80 }
81
82 MessageRequestState.State.GROUP_V2_ADD -> {
83 question.setText(R.string.MessageRequestBottomView_join_this_group_they_wont_know_youve_seen_their_messages_until_you_accept)
84 accept.setText(R.string.MessageRequestBottomView_accept)
85 }
86
87 MessageRequestState.State.INDIVIDUAL -> {
88 question.text = HtmlCompat.fromHtml(
89 context.getString(
90 R.string.MessageRequestBottomView_do_you_want_to_let_s_message_you_they_wont_know_youve_seen_their_messages_until_you_accept,
91 HtmlUtil.bold(recipient.getShortDisplayName(context))
92 ),
93 0
94 )
95 accept.setText(R.string.MessageRequestBottomView_accept)
96 }
97
98 MessageRequestState.State.INDIVIDUAL_HIDDEN -> {
99 question.text = HtmlCompat.fromHtml(
100 context.getString(
101 R.string.MessageRequestBottomView_do_you_want_to_let_s_message_you_you_removed_them_before,
102 HtmlUtil.bold(recipient.getShortDisplayName(context))
103 ),
104 0
105 )
106 accept.setText(R.string.MessageRequestBottomView_accept)
107 }
108
109 MessageRequestState.State.NONE -> Unit
110 MessageRequestState.State.NONE_HIDDEN -> Unit
111 }
112 }
113
114 private fun updateButtonVisibility(messageState: MessageRequestState) {
115 accept.visible = !messageState.isBlocked
116 block.visible = !messageState.isBlocked
117 unblock.visible = messageState.isBlocked
118 delete.visible = messageState.reportedAsSpam || messageState.isBlocked
119 report.visible = !messageState.reportedAsSpam
120 }
121
122 fun showBusy() {
123 showProgressDebouncer.publish { busyIndicator.visibility = VISIBLE }
124 buttonBar.visibility = INVISIBLE
125 }
126
127 fun hideBusy() {
128 showProgressDebouncer.clear()
129 busyIndicator.visibility = GONE
130 buttonBar.visibility = VISIBLE
131 }
132
133 fun setWallpaperEnabled(isEnabled: Boolean) {
134 val theme = resolveTheme(isEnabled)
135 listOf(delete, block, accept, unblock, report).forEach { it.backgroundTintList = ColorStateList.valueOf(theme.getButtonBackgroundColor(context)) }
136 listOf(delete, block, report).forEach { it.setTextColor(theme.getButtonForegroundDenyColor(context)) }
137 listOf(accept, unblock).forEach { it.setTextColor(theme.getButtonForegroundAcceptColor(context)) }
138
139 setBackgroundColor(theme.getContainerButtonBackgroundColor(context))
140 }
141
142 fun setAcceptOnClickListener(acceptOnClickListener: OnClickListener?) {
143 accept.setOnClickListener(acceptOnClickListener)
144 }
145
146 fun setDeleteOnClickListener(deleteOnClickListener: OnClickListener?) {
147 delete.setOnClickListener(deleteOnClickListener)
148 }
149
150 fun setBlockOnClickListener(blockOnClickListener: OnClickListener?) {
151 block.setOnClickListener(blockOnClickListener)
152 }
153
154 fun setUnblockOnClickListener(unblockOnClickListener: OnClickListener?) {
155 unblock.setOnClickListener(unblockOnClickListener)
156 }
157
158 fun setReportOnClickListener(reportOnClickListener: OnClickListener?) {
159 report.setOnClickListener(reportOnClickListener)
160 }
161}