From 058319c9c760150242cc80085daad9fc3b215ad0 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 24 Jun 2021 13:47:24 +1000 Subject: [PATCH] Add join open group dialog --- .../conversation/v2/ConversationActivityV2.kt | 4 +- .../conversation/v2/dialogs/BlockedDialog.kt | 4 +- .../v2/dialogs/JoinOpenGroupDialog.kt | 36 ++++++++++++ app/src/main/res/layout/dialog_blocked.xml | 1 + .../res/layout/dialog_join_open_group.xml | 57 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 + 6 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/JoinOpenGroupDialog.kt create mode 100644 app/src/main/res/layout/dialog_join_open_group.xml diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 4d7a07318b..3e862e5357 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -33,6 +33,7 @@ import org.session.libsession.utilities.recipients.Recipient import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.conversation.v2.dialogs.BlockedDialog +import org.thoughtcrime.securesms.conversation.v2.dialogs.JoinOpenGroupDialog import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarButton import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarDelegate import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarRecordingViewDelegate @@ -411,7 +412,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe // the view) so as to not interfere with all the other gestures. Do not add // onClickListeners directly to message content views. view.onContentClick() - BlockedDialog(thread).show(supportFragmentManager, "Blocked Dialog") + val openGroup = DatabaseFactory.getLokiThreadDatabase(this).getOpenGroupChat(threadID)!! + JoinOpenGroupDialog(openGroup).show(supportFragmentManager, "Blocked Dialog") } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/BlockedDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/BlockedDialog.kt index aad7fc98f8..7c485b9207 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/BlockedDialog.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/BlockedDialog.kt @@ -7,6 +7,7 @@ import android.text.style.StyleSpan import android.view.LayoutInflater import androidx.appcompat.app.AlertDialog import kotlinx.android.synthetic.main.dialog_blocked.view.* +import kotlinx.android.synthetic.main.dialog_blocked.view.cancelButton import network.loki.messenger.R import org.session.libsession.messaging.contacts.Contact import org.session.libsession.utilities.recipients.Recipient @@ -28,11 +29,12 @@ class BlockedDialog(private val recipient: Recipient) : BaseDialog() { val startIndex = explanation.indexOf(name) spannable.setSpan(StyleSpan(Typeface.BOLD), startIndex, startIndex + name.count(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) contentView.blockedExplanationTextView.text = spannable + contentView.cancelButton.setOnClickListener { dismiss() } contentView.unblockButton.setOnClickListener { unblock() } builder.setView(contentView) } private fun unblock() { - + } } \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/JoinOpenGroupDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/JoinOpenGroupDialog.kt new file mode 100644 index 0000000000..3b26fbce10 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/JoinOpenGroupDialog.kt @@ -0,0 +1,36 @@ +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_join_open_group.view.* +import network.loki.messenger.R +import org.session.libsession.messaging.contacts.Contact +import org.session.libsession.messaging.open_groups.OpenGroupV2 +import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog +import org.thoughtcrime.securesms.database.DatabaseFactory + +class JoinOpenGroupDialog(private val openGroup: OpenGroupV2) : BaseDialog() { + + override fun setContentView(builder: AlertDialog.Builder) { + val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_join_open_group, null) + val name = openGroup.name + val title = resources.getString(R.string.dialog_join_open_group_title, name) + contentView.joinOpenGroupTitleTextView.text = title + val explanation = resources.getString(R.string.dialog_join_open_group_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.joinOpenGroupExplanationTextView.text = spannable + contentView.cancelButton.setOnClickListener { dismiss() } + contentView.joinButton.setOnClickListener { join() } + builder.setView(contentView) + } + + private fun join() { + + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_blocked.xml b/app/src/main/res/layout/dialog_blocked.xml index b66fa4fe98..38b13c3da5 100644 --- a/app/src/main/res/layout/dialog_blocked.xml +++ b/app/src/main/res/layout/dialog_blocked.xml @@ -24,6 +24,7 @@ android:layout_height="wrap_content" android:layout_marginTop="@dimen/large_spacing" android:text="@string/dialog_blocked_explanation" + android:paddingHorizontal="@dimen/medium_spacing" android:textColor="@color/text" android:textSize="@dimen/small_font_size" android:textAlignment="center" /> diff --git a/app/src/main/res/layout/dialog_join_open_group.xml b/app/src/main/res/layout/dialog_join_open_group.xml new file mode 100644 index 0000000000..a84a4101cd --- /dev/null +++ b/app/src/main/res/layout/dialog_join_open_group.xml @@ -0,0 +1,57 @@ + + + + + + + + + +