Remove `messageHolderBinding` variable

This commit is contained in:
Naveen 2023-08-22 14:09:04 +05:30
parent 8ebcaa3016
commit fead93ddf7
No known key found for this signature in database
GPG Key ID: 0E155DAD31671DA3
3 changed files with 42 additions and 44 deletions

View File

@ -113,7 +113,6 @@ class ThreadActivity : SimpleActivity() {
private var isAttachmentPickerVisible = false private var isAttachmentPickerVisible = false
private val binding by viewBinding(ActivityThreadBinding::inflate) private val binding by viewBinding(ActivityThreadBinding::inflate)
private lateinit var messageHolderBinding: LayoutThreadSendMessageHolderBinding
override fun onNewIntent(intent: Intent?) { override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent) super.onNewIntent(intent)
@ -124,7 +123,6 @@ class ThreadActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
isMaterialActivity = true isMaterialActivity = true
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
messageHolderBinding = binding.threadSendMessageHolder
setContentView(binding.root) setContentView(binding.root)
setupOptionsMenu() setupOptionsMenu()
refreshMenuItems() refreshMenuItems()
@ -177,7 +175,7 @@ class ThreadActivity : SimpleActivity() {
val smsDraft = getSmsDraft(threadId) val smsDraft = getSmsDraft(threadId)
if (smsDraft != null) { if (smsDraft != null) {
messageHolderBinding.threadTypeMessage.setText(smsDraft) binding.messageHolder.threadTypeMessage.setText(smsDraft)
} }
isActivityVisible = true isActivityVisible = true
@ -194,7 +192,7 @@ class ThreadActivity : SimpleActivity() {
} }
val bottomBarColor = getBottomBarColor() val bottomBarColor = getBottomBarColor()
messageHolderBinding.root.setBackgroundColor(bottomBarColor) binding.messageHolder.root.setBackgroundColor(bottomBarColor)
binding.shortCodeHolder.root.setBackgroundColor(bottomBarColor) binding.shortCodeHolder.root.setBackgroundColor(bottomBarColor)
updateNavigationBarColor(bottomBarColor) updateNavigationBarColor(bottomBarColor)
} }
@ -202,8 +200,8 @@ class ThreadActivity : SimpleActivity() {
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
if (messageHolderBinding.threadTypeMessage.value != "" && getAttachmentSelections().isEmpty()) { if (binding.messageHolder.threadTypeMessage.value != "" && getAttachmentSelections().isEmpty()) {
saveSmsDraft(messageHolderBinding.threadTypeMessage.value, threadId) saveSmsDraft(binding.messageHolder.threadTypeMessage.value, threadId)
} else { } else {
deleteSmsDraft(threadId) deleteSmsDraft(threadId)
} }
@ -214,7 +212,7 @@ class ThreadActivity : SimpleActivity() {
override fun onBackPressed() { override fun onBackPressed() {
isAttachmentPickerVisible = false isAttachmentPickerVisible = false
if (messageHolderBinding.attachmentPickerHolder.isVisible()) { if (binding.messageHolder.attachmentPickerHolder.isVisible()) {
hideAttachmentPicker() hideAttachmentPicker()
} else { } else {
super.onBackPressed() super.onBackPressed()
@ -341,7 +339,7 @@ class ThreadActivity : SimpleActivity() {
runOnUiThread { runOnUiThread {
if (messages.isEmpty()) { if (messages.isEmpty()) {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
messageHolderBinding.threadTypeMessage.requestFocus() binding.messageHolder.threadTypeMessage.requestFocus()
} }
setupThreadTitle() setupThreadTitle()
@ -519,7 +517,7 @@ class ThreadActivity : SimpleActivity() {
when { when {
any is Message && any.isScheduled -> showScheduledMessageInfo(any) any is Message && any.isScheduled -> showScheduledMessageInfo(any)
any is ThreadError -> { any is ThreadError -> {
messageHolderBinding.threadTypeMessage.setText(any.messageText) binding.messageHolder.threadTypeMessage.setText(any.messageText)
messageToResend = any.messageId messageToResend = any.messageId
} }
} }
@ -641,7 +639,7 @@ class ThreadActivity : SimpleActivity() {
updateTextColors(threadHolder) updateTextColors(threadHolder)
val textColor = getProperTextColor() val textColor = getProperTextColor()
messageHolderBinding.apply { binding.messageHolder.apply {
threadSendMessage.apply { threadSendMessage.apply {
setTextColor(textColor) setTextColor(textColor)
compoundDrawables.forEach { compoundDrawables.forEach {
@ -827,7 +825,7 @@ class ThreadActivity : SimpleActivity() {
private fun maybeDisableShortCodeReply() { private fun maybeDisableShortCodeReply() {
if (isSpecialNumber() && !isRecycleBin) { if (isSpecialNumber() && !isRecycleBin) {
messageHolderBinding.root.beGone() binding.messageHolder.root.beGone()
binding.shortCodeHolder.root.beVisible() binding.shortCodeHolder.root.beVisible()
val textColor = getProperTextColor() val textColor = getProperTextColor()
binding.shortCodeHolder.replyDisabledText.setTextColor(textColor) binding.shortCodeHolder.replyDisabledText.setTextColor(textColor)
@ -880,15 +878,15 @@ class ThreadActivity : SimpleActivity() {
} }
currentSIMCardIndex = getProperSimIndex(availableSIMs, numbers) currentSIMCardIndex = getProperSimIndex(availableSIMs, numbers)
messageHolderBinding.threadSelectSimIcon.applyColorFilter(getProperTextColor()) binding.messageHolder.threadSelectSimIcon.applyColorFilter(getProperTextColor())
messageHolderBinding.threadSelectSimIcon.beVisible() binding.messageHolder.threadSelectSimIcon.beVisible()
messageHolderBinding.threadSelectSimNumber.beVisible() binding.messageHolder.threadSelectSimNumber.beVisible()
if (availableSIMCards.isNotEmpty()) { if (availableSIMCards.isNotEmpty()) {
messageHolderBinding.threadSelectSimIcon.setOnClickListener { binding.messageHolder.threadSelectSimIcon.setOnClickListener {
currentSIMCardIndex = (currentSIMCardIndex + 1) % availableSIMCards.size currentSIMCardIndex = (currentSIMCardIndex + 1) % availableSIMCards.size
val currentSIMCard = availableSIMCards[currentSIMCardIndex] val currentSIMCard = availableSIMCards[currentSIMCardIndex]
messageHolderBinding.threadSelectSimNumber.text = currentSIMCard.id.toString() binding.messageHolder.threadSelectSimNumber.text = currentSIMCard.id.toString()
val currentSubscriptionId = currentSIMCard.subscriptionId val currentSubscriptionId = currentSIMCard.subscriptionId
numbers.forEach { numbers.forEach {
config.saveUseSIMIdAtNumber(it, currentSubscriptionId) config.saveUseSIMIdAtNumber(it, currentSubscriptionId)
@ -897,9 +895,9 @@ class ThreadActivity : SimpleActivity() {
} }
} }
messageHolderBinding.threadSelectSimNumber.setTextColor(getProperTextColor().getContrastColor()) binding.messageHolder.threadSelectSimNumber.setTextColor(getProperTextColor().getContrastColor())
try { try {
messageHolderBinding.threadSelectSimNumber.text = (availableSIMCards[currentSIMCardIndex].id).toString() binding.messageHolder.threadSelectSimNumber.text = (availableSIMCards[currentSIMCardIndex].id).toString()
} catch (e: Exception) { } catch (e: Exception) {
showErrorToast(e) showErrorToast(e)
} }
@ -1239,7 +1237,7 @@ class ThreadActivity : SimpleActivity() {
} }
private fun getAttachmentsAdapter(): AttachmentsAdapter? { private fun getAttachmentsAdapter(): AttachmentsAdapter? {
val adapter = messageHolderBinding.threadAttachmentsRecyclerview.adapter val adapter = binding.messageHolder.threadAttachmentsRecyclerview.adapter
return adapter as? AttachmentsAdapter return adapter as? AttachmentsAdapter
} }
@ -1273,17 +1271,17 @@ class ThreadActivity : SimpleActivity() {
if (adapter == null) { if (adapter == null) {
adapter = AttachmentsAdapter( adapter = AttachmentsAdapter(
activity = this, activity = this,
recyclerView = messageHolderBinding.threadAttachmentsRecyclerview, recyclerView = binding.messageHolder.threadAttachmentsRecyclerview,
onAttachmentsRemoved = { onAttachmentsRemoved = {
messageHolderBinding.threadAttachmentsRecyclerview.beGone() binding.messageHolder.threadAttachmentsRecyclerview.beGone()
checkSendMessageAvailability() checkSendMessageAvailability()
}, },
onReady = { checkSendMessageAvailability() } onReady = { checkSendMessageAvailability() }
) )
messageHolderBinding.threadAttachmentsRecyclerview.adapter = adapter binding.messageHolder.threadAttachmentsRecyclerview.adapter = adapter
} }
messageHolderBinding.threadAttachmentsRecyclerview.beVisible() binding.messageHolder.threadAttachmentsRecyclerview.beVisible()
val attachment = AttachmentSelection( val attachment = AttachmentSelection(
id = id, id = id,
uri = uri, uri = uri,
@ -1316,7 +1314,7 @@ class ThreadActivity : SimpleActivity() {
} }
private fun checkSendMessageAvailability() { private fun checkSendMessageAvailability() {
messageHolderBinding.apply { binding.messageHolder.apply {
if (threadTypeMessage.text!!.isNotEmpty() || (getAttachmentSelections().isNotEmpty() && !getAttachmentSelections().any { it.isPending })) { if (threadTypeMessage.text!!.isNotEmpty() || (getAttachmentSelections().isNotEmpty() && !getAttachmentSelections().any { it.isPending })) {
threadSendMessage.isEnabled = true threadSendMessage.isEnabled = true
threadSendMessage.isClickable = true threadSendMessage.isClickable = true
@ -1332,7 +1330,7 @@ class ThreadActivity : SimpleActivity() {
} }
private fun sendMessage() { private fun sendMessage() {
var text = messageHolderBinding.threadTypeMessage.value var text = binding.messageHolder.threadTypeMessage.value
if (text.isEmpty() && getAttachmentSelections().isEmpty()) { if (text.isEmpty() && getAttachmentSelections().isEmpty()) {
showErrorToast(getString(R.string.unknown_error_occurred)) showErrorToast(getString(R.string.unknown_error_occurred))
return return
@ -1411,7 +1409,7 @@ class ThreadActivity : SimpleActivity() {
} }
private fun clearCurrentMessage() { private fun clearCurrentMessage() {
messageHolderBinding.threadTypeMessage.setText("") binding.messageHolder.threadTypeMessage.setText("")
getAttachmentsAdapter()?.clear() getAttachmentsAdapter()?.clear()
checkSendMessageAvailability() checkSendMessageAvailability()
} }
@ -1587,13 +1585,13 @@ class ThreadActivity : SimpleActivity() {
} }
private fun updateMessageType() { private fun updateMessageType() {
val text = messageHolderBinding.threadTypeMessage.text.toString() val text = binding.messageHolder.threadTypeMessage.text.toString()
val stringId = if (isMmsMessage(text)) { val stringId = if (isMmsMessage(text)) {
R.string.mms R.string.mms
} else { } else {
R.string.sms R.string.sms
} }
messageHolderBinding.threadSendMessage.setText(stringId) binding.messageHolder.threadSendMessage.setText(stringId)
} }
private fun showScheduledMessageInfo(message: Message) { private fun showScheduledMessageInfo(message: Message) {
@ -1628,7 +1626,7 @@ class ThreadActivity : SimpleActivity() {
private fun editScheduledMessage(message: Message) { private fun editScheduledMessage(message: Message) {
scheduledMessage = message scheduledMessage = message
clearCurrentMessage() clearCurrentMessage()
messageHolderBinding.threadTypeMessage.setText(message.body) binding.messageHolder.threadTypeMessage.setText(message.body)
extractAttachments(message) extractAttachments(message)
scheduledDateTime = DateTime(message.millis()) scheduledDateTime = DateTime(message.millis())
showScheduleMessageDialog() showScheduleMessageDialog()
@ -1653,7 +1651,7 @@ class ThreadActivity : SimpleActivity() {
} }
} }
private fun setupScheduleSendUi() = messageHolderBinding.apply { private fun setupScheduleSendUi() = binding.messageHolder.apply {
val textColor = getProperTextColor() val textColor = getProperTextColor()
scheduledMessageHolder.background.applyColorFilter(getProperPrimaryColor().darkenColor()) scheduledMessageHolder.background.applyColorFilter(getProperPrimaryColor().darkenColor())
scheduledMessageIcon.applyColorFilter(textColor) scheduledMessageIcon.applyColorFilter(textColor)
@ -1679,11 +1677,11 @@ class ThreadActivity : SimpleActivity() {
private fun showScheduleMessageDialog() { private fun showScheduleMessageDialog() {
isScheduledMessage = true isScheduledMessage = true
updateSendButtonDrawable() updateSendButtonDrawable()
messageHolderBinding.scheduledMessageHolder.beVisible() binding.messageHolder.scheduledMessageHolder.beVisible()
val dateTime = scheduledDateTime val dateTime = scheduledDateTime
val millis = dateTime.millis val millis = dateTime.millis
messageHolderBinding.scheduledMessageButton.text = if (dateTime.yearOfCentury().get() > DateTime.now().yearOfCentury().get()) { binding.messageHolder.scheduledMessageButton.text = if (dateTime.yearOfCentury().get() > DateTime.now().yearOfCentury().get()) {
millis.formatDate(this) millis.formatDate(this)
} else { } else {
val flags = FORMAT_SHOW_TIME or FORMAT_SHOW_DATE or FORMAT_NO_YEAR val flags = FORMAT_SHOW_TIME or FORMAT_SHOW_DATE or FORMAT_NO_YEAR
@ -1693,7 +1691,7 @@ class ThreadActivity : SimpleActivity() {
private fun hideScheduleSendUi() { private fun hideScheduleSendUi() {
isScheduledMessage = false isScheduledMessage = false
messageHolderBinding.scheduledMessageHolder.beGone() binding.messageHolder.scheduledMessageHolder.beGone()
updateSendButtonDrawable() updateSendButtonDrawable()
} }
@ -1705,7 +1703,7 @@ class ThreadActivity : SimpleActivity() {
} }
ResourcesCompat.getDrawable(resources, drawableResId, theme)?.apply { ResourcesCompat.getDrawable(resources, drawableResId, theme)?.apply {
applyColorFilter(getProperTextColor()) applyColorFilter(getProperTextColor())
messageHolderBinding.threadSendMessage.setCompoundDrawablesWithIntrinsicBounds(null, this, null, null) binding.messageHolder.threadSendMessage.setCompoundDrawablesWithIntrinsicBounds(null, this, null, null)
} }
} }
@ -1734,7 +1732,7 @@ class ThreadActivity : SimpleActivity() {
.map { Attachment(null, messageId, it.uri.toString(), it.mimetype, 0, 0, it.filename) } .map { Attachment(null, messageId, it.uri.toString(), it.mimetype, 0, 0, it.filename) }
.toArrayList() .toArrayList()
private fun setupAttachmentPickerView() = messageHolderBinding.attachmentPicker.apply { private fun setupAttachmentPickerView() = binding.messageHolder.attachmentPicker.apply {
val buttonColors = arrayOf( val buttonColors = arrayOf(
R.color.md_red_500, R.color.md_red_500,
R.color.md_brown_500, R.color.md_brown_500,
@ -1803,20 +1801,20 @@ class ThreadActivity : SimpleActivity() {
} }
private fun showAttachmentPicker() { private fun showAttachmentPicker() {
messageHolderBinding.attachmentPickerDivider.showWithAnimation() binding.messageHolder.attachmentPickerDivider.showWithAnimation()
messageHolderBinding.attachmentPickerHolder.showWithAnimation() binding.messageHolder.attachmentPickerHolder.showWithAnimation()
animateAttachmentButton(rotation = -135f) animateAttachmentButton(rotation = -135f)
} }
private fun maybeSetupRecycleBinView() { private fun maybeSetupRecycleBinView() {
if (isRecycleBin) { if (isRecycleBin) {
messageHolderBinding.root.beGone() binding.messageHolder.root.beGone()
} }
} }
private fun hideAttachmentPicker() { private fun hideAttachmentPicker() {
messageHolderBinding.attachmentPickerDivider.beGone() binding.messageHolder.attachmentPickerDivider.beGone()
messageHolderBinding.attachmentPickerHolder.apply { binding.messageHolder.attachmentPickerHolder.apply {
beGone() beGone()
updateLayoutParams<ConstraintLayout.LayoutParams> { updateLayoutParams<ConstraintLayout.LayoutParams> {
height = config.keyboardHeight height = config.keyboardHeight
@ -1826,7 +1824,7 @@ class ThreadActivity : SimpleActivity() {
} }
private fun animateAttachmentButton(rotation: Float) { private fun animateAttachmentButton(rotation: Float) {
messageHolderBinding.threadAddAttachment.animate() binding.messageHolder.threadAddAttachment.animate()
.rotation(rotation) .rotation(rotation)
.setDuration(500L) .setDuration(500L)
.setInterpolator(OvershootInterpolator()) .setInterpolator(OvershootInterpolator())

View File

@ -139,14 +139,14 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="gone" android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/thread_send_message_holder" app:layout_constraintBottom_toTopOf="@id/message_holder"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/thread_messages_fastscroller" app:layout_constraintTop_toBottomOf="@id/thread_messages_fastscroller"
tools:visibility="visible" /> tools:visibility="visible" />
<include <include
android:id="@+id/thread_send_message_holder" android:id="@+id/message_holder"
layout="@layout/layout_thread_send_message_holder" layout="@layout/layout_thread_send_message_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -2,7 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/thread_send_message_holder" android:id="@+id/message_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">