2021-06-24 05:38:59 +02:00
|
|
|
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 kotlinx.android.synthetic.main.dialog_blocked.view.*
|
|
|
|
import network.loki.messenger.R
|
|
|
|
import org.session.libsession.messaging.contacts.Contact
|
|
|
|
import org.session.libsession.utilities.recipients.Recipient
|
|
|
|
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
|
2021-10-04 09:51:19 +02:00
|
|
|
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
|
2021-06-24 05:38:59 +02:00
|
|
|
|
2021-06-25 01:19:21 +02:00
|
|
|
/** Shown upon sending a message to a user that's blocked. */
|
2021-06-24 05:38:59 +02:00
|
|
|
class BlockedDialog(private val recipient: Recipient) : BaseDialog() {
|
|
|
|
|
|
|
|
override fun setContentView(builder: AlertDialog.Builder) {
|
|
|
|
val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_blocked, null)
|
2021-10-04 09:51:19 +02:00
|
|
|
val contactDB = DatabaseComponent.get(requireContext()).sessionContactDatabase()
|
2021-06-24 05:38:59 +02:00
|
|
|
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)
|
|
|
|
contentView.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)
|
|
|
|
contentView.blockedExplanationTextView.text = spannable
|
2021-06-24 05:47:24 +02:00
|
|
|
contentView.cancelButton.setOnClickListener { dismiss() }
|
2021-06-24 05:38:59 +02:00
|
|
|
contentView.unblockButton.setOnClickListener { unblock() }
|
|
|
|
builder.setView(contentView)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun unblock() {
|
2021-10-04 09:51:19 +02:00
|
|
|
DatabaseComponent.get(requireContext()).recipientDatabase().setBlocked(recipient, false)
|
2021-06-28 05:36:15 +02:00
|
|
|
dismiss()
|
2021-06-24 05:38:59 +02:00
|
|
|
}
|
|
|
|
}
|