mirror of
https://github.com/oxen-io/session-android.git
synced 2023-12-14 02:53:01 +01:00
* refactor: Migrate home screen to data binding * Add view binding * Migrate ConversationView to view binding * Migrate ConversationActivityV2 to view binding * View model refactor * Move more functionality to the view model * Add ui state events flow * Update conversation item bindings * Update profile picture view bindings * Replace Kotlin synthetics with view bindings * Fix qr code fragment binding and optimize imports * View binding refactors * Make TextSecurePreferences an interface and add an implementation to improve testability * Add conversation repository * Migrate remaining TextSecurePreferences functions into the interface * Add unit conversation unit tests * Add unit test coverage for remaining view model functions
41 lines
2 KiB
Kotlin
41 lines
2 KiB
Kotlin
package org.thoughtcrime.securesms.conversation.v2.dialogs
|
|
|
|
import android.graphics.Typeface
|
|
import android.text.Spannable
|
|
import android.text.SpannableStringBuilder
|
|
import android.text.style.StyleSpan
|
|
import android.view.LayoutInflater
|
|
import androidx.appcompat.app.AlertDialog
|
|
import network.loki.messenger.R
|
|
import network.loki.messenger.databinding.DialogBlockedBinding
|
|
import org.session.libsession.messaging.contacts.Contact
|
|
import org.session.libsession.utilities.recipients.Recipient
|
|
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
|
|
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
|
|
|
|
/** Shown upon sending a message to a user that's blocked. */
|
|
class BlockedDialog(private val recipient: Recipient) : BaseDialog() {
|
|
|
|
override fun setContentView(builder: AlertDialog.Builder) {
|
|
val binding = DialogBlockedBinding.inflate(LayoutInflater.from(requireContext()))
|
|
val contactDB = DatabaseComponent.get(requireContext()).sessionContactDatabase()
|
|
val sessionID = recipient.address.toString()
|
|
val contact = contactDB.getContactWithSessionID(sessionID)
|
|
val name = contact?.displayName(Contact.ContactContext.REGULAR) ?: sessionID
|
|
val title = resources.getString(R.string.dialog_blocked_title, name)
|
|
binding.blockedTitleTextView.text = title
|
|
val explanation = resources.getString(R.string.dialog_blocked_explanation, name)
|
|
val spannable = SpannableStringBuilder(explanation)
|
|
val startIndex = explanation.indexOf(name)
|
|
spannable.setSpan(StyleSpan(Typeface.BOLD), startIndex, startIndex + name.count(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
binding.blockedExplanationTextView.text = spannable
|
|
binding.cancelButton.setOnClickListener { dismiss() }
|
|
binding.unblockButton.setOnClickListener { unblock() }
|
|
builder.setView(binding.root)
|
|
}
|
|
|
|
private fun unblock() {
|
|
DatabaseComponent.get(requireContext()).recipientDatabase().setBlocked(recipient, false)
|
|
dismiss()
|
|
}
|
|
} |