Skip to content
Snippets Groups Projects
Commit 3384405a authored by Pierre Nicolas's avatar Pierre Nicolas :joy:
Browse files

details: connect block contact

Show `block contact` option for one to one conversation.
Connect the button to logic.

GitLab: #1723
Change-Id: I22792e004f284a9a3c07649a7af59f78e3ba507e
parent 2fdac232
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,6 @@ import androidx.annotation.StringRes ...@@ -24,7 +24,6 @@ import androidx.annotation.StringRes
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import cx.ring.R import cx.ring.R
import cx.ring.client.ColorChooserBottomSheet import cx.ring.client.ColorChooserBottomSheet
import cx.ring.client.EmojiChooserBottomSheet import cx.ring.client.EmojiChooserBottomSheet
...@@ -206,37 +205,16 @@ class ConversationActionsFragment : Fragment() { ...@@ -206,37 +205,16 @@ class ConversationActionsFragment : Fragment() {
descriptionPanel.isVisible = false // Disable description edit for 1-to-1 conversation descriptionPanel.isVisible = false // Disable description edit for 1-to-1 conversation
// Description being hidden, we put the rounded background on the secureP2pConnection. // Description being hidden, we put the rounded background on the secureP2pConnection.
secureP2pConnection.setBackgroundResource(R.drawable.background_rounded_16_top) secureP2pConnection.setBackgroundResource(R.drawable.background_rounded_16_top)
blockContact.setOnClickListener {
blockSwitch.isChecked = conversation.contact!!.isBanned ActionHelper.launchBlockContactAction(
blockSwitch.setOnClickListener { context = requireContext(),
val ctx = requireContext() accountId = mAccountService.currentAccount!!.accountId,
val builder = MaterialAlertDialogBuilder(ctx) contact = conversation.contact!!,
if (blockSwitch.isChecked) { // the contact is already blocked ) { accountId: String, contactUri: Uri ->
builder.setTitle(getString(R.string.unblock_contact_dialog_title, conversationUri)) mAccountService.removeContact(accountId, contactUri.uri, true)
builder.setMessage(getString(R.string.unblock_contact_dialog_message, conversationUri)) requireActivity().setResult(Activity.RESULT_OK)
builder.setPositiveButton(R.string.conversation_action_unblock_this) { _, _ -> requireActivity().finish()
// Unblock the contact and display a toast
mAccountService.addContact(conversation.accountId, conversation.contact!!.uri.rawRingId)
Snackbar.make(root,
getString(R.string.unblock_contact_completed, conversationUri),
Snackbar.LENGTH_LONG
).show()
blockSwitch.isChecked = false
}
} else {
builder.setTitle(getString(R.string.block_contact_dialog_title, conversationUri))
builder.setMessage(getString(R.string.block_contact_dialog_message, conversationUri))
builder.setPositiveButton(R.string.conversation_action_block_this) { _, _ ->
// Block the conversation and display a toast
mConversationFacade.banConversation(conversation.accountId, conversation.uri)
Snackbar.make(root,
getString(R.string.block_contact_completed, conversationUri),
Snackbar.LENGTH_LONG
).show()
blockSwitch.isChecked = true
}
} }
builder.setNegativeButton(android.R.string.cancel, null).show()
} }
} else { // If conversation mode is not one to one } else { // If conversation mode is not one to one
conversationDelete.text = resources.getString(R.string.leave_conversation) conversationDelete.text = resources.getString(R.string.leave_conversation)
...@@ -253,7 +231,7 @@ class ConversationActionsFragment : Fragment() { ...@@ -253,7 +231,7 @@ class ConversationActionsFragment : Fragment() {
requireActivity().finish() requireActivity().finish()
}) })
} }
blockSwitch.isVisible = false blockContact.isVisible = false
} }
@StringRes val infoString = @StringRes val infoString =
......
...@@ -142,6 +142,21 @@ object ActionHelper { ...@@ -142,6 +142,21 @@ object ActionHelper {
.setNegativeButton(android.R.string.cancel) { _, _ -> }.show() .setNegativeButton(android.R.string.cancel) { _, _ -> }.show()
} }
fun launchBlockContactAction(
context: Context,
accountId: String,
contact: Contact,
callback: (accountId: String, uri: Uri) -> Unit,
) {
val displayName =
contact.username?.blockingGet().takeIf { !it.isNullOrEmpty() } ?: contact.uri.uri
MaterialAlertDialogBuilder(context)
.setTitle(context.getString(R.string.block_contact_dialog_title, displayName))
.setMessage(context.getString(R.string.block_contact_dialog_message, displayName))
.setPositiveButton(android.R.string.ok) { _, _ -> callback(accountId, contact.uri) }
.setNegativeButton(android.R.string.cancel) { _, _ -> }.show()
}
fun getAddNumberIntentForContact(contact: Contact): Intent { fun getAddNumberIntentForContact(contact: Contact): Intent {
val intent = Intent(Intent.ACTION_INSERT_OR_EDIT) val intent = Intent(Intent.ACTION_INSERT_OR_EDIT)
intent.type = ContactsContract.Contacts.CONTENT_ITEM_TYPE intent.type = ContactsContract.Contacts.CONTENT_ITEM_TYPE
......
...@@ -409,22 +409,10 @@ along with this program; if not, write to the Free Software ...@@ -409,22 +409,10 @@ along with this program; if not, write to the Free Software
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="50dp"
android:layout_marginVertical="1dp" android:layout_marginVertical="1dp"
android:background="@color/background_secondary"
android:paddingHorizontal="12dp"
android:text="@string/mute_conversation"
android:textAlignment="textStart"
android:textColor="@color/colorOnSurface"
tools:checked="true" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/block_switch"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginVertical="1dp"
android:background="@drawable/background_rounded_16_bottom" android:background="@drawable/background_rounded_16_bottom"
android:backgroundTint="@color/background_secondary" android:backgroundTint="@color/background_secondary"
android:paddingHorizontal="12dp" android:paddingHorizontal="12dp"
android:text="@string/conversation_action_block_this" android:text="@string/mute_conversation"
android:textAlignment="textStart" android:textAlignment="textStart"
android:textColor="@color/colorOnSurface" android:textColor="@color/colorOnSurface"
tools:checked="true" /> tools:checked="true" />
...@@ -444,7 +432,22 @@ along with this program; if not, write to the Free Software ...@@ -444,7 +432,22 @@ along with this program; if not, write to the Free Software
android:paddingVertical="14dp" android:paddingVertical="14dp"
android:textColor="@color/red_600" android:textColor="@color/red_600"
android:textSize="14sp" android:textSize="14sp"
tools:text="Delete Conversation / Leave Swarm" /> tools:text="@string/delete_contact" />
<TextView
android:id="@+id/block_contact"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:background="@drawable/background_rounded_16"
android:backgroundTint="@color/background_secondary"
android:drawablePadding="12dp"
android:gravity="center_vertical"
android:paddingHorizontal="12dp"
android:paddingVertical="14dp"
android:text="@string/conversation_action_block_this"
android:textColor="@color/red_600"
android:textSize="14sp" />
</LinearLayout> </LinearLayout>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment