2021-06-24 05:47:24 +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
|
2021-06-30 02:30:10 +02:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2021-06-24 05:47:24 +02:00
|
|
|
import network.loki.messenger.R
|
2022-01-14 06:56:15 +01:00
|
|
|
import network.loki.messenger.databinding.DialogJoinOpenGroupBinding
|
2021-06-29 06:23:36 +02:00
|
|
|
import org.session.libsession.utilities.OpenGroupUrlParser
|
2021-06-30 02:30:10 +02:00
|
|
|
import org.session.libsignal.utilities.ThreadUtils
|
2021-06-24 05:47:24 +02:00
|
|
|
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
|
2021-07-09 05:25:57 +02:00
|
|
|
import org.thoughtcrime.securesms.groups.OpenGroupManager
|
2021-07-09 05:01:16 +02:00
|
|
|
import org.thoughtcrime.securesms.util.ConfigurationMessageUtilities
|
2021-06-24 05:47:24 +02:00
|
|
|
|
2021-06-25 01:19:21 +02:00
|
|
|
/** Shown upon tapping an open group invitation. */
|
2021-06-29 06:23:36 +02:00
|
|
|
class JoinOpenGroupDialog(private val name: String, private val url: String) : BaseDialog() {
|
2021-06-24 05:47:24 +02:00
|
|
|
|
|
|
|
override fun setContentView(builder: AlertDialog.Builder) {
|
2022-01-14 06:56:15 +01:00
|
|
|
val binding = DialogJoinOpenGroupBinding.inflate(LayoutInflater.from(requireContext()))
|
2021-06-24 05:47:24 +02:00
|
|
|
val title = resources.getString(R.string.dialog_join_open_group_title, name)
|
2022-01-14 06:56:15 +01:00
|
|
|
binding.joinOpenGroupTitleTextView.text = title
|
2021-06-24 05:47:24 +02:00
|
|
|
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)
|
2022-01-14 06:56:15 +01:00
|
|
|
binding.joinOpenGroupExplanationTextView.text = spannable
|
|
|
|
binding.cancelButton.setOnClickListener { dismiss() }
|
|
|
|
binding.joinButton.setOnClickListener { join() }
|
|
|
|
builder.setView(binding.root)
|
2021-06-24 05:47:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun join() {
|
2021-06-29 06:23:36 +02:00
|
|
|
val openGroup = OpenGroupUrlParser.parseUrl(url)
|
2021-06-30 02:30:10 +02:00
|
|
|
val activity = requireContext() as AppCompatActivity
|
|
|
|
ThreadUtils.queue {
|
|
|
|
OpenGroupManager.add(openGroup.server, openGroup.room, openGroup.serverPublicKey, activity)
|
2021-07-09 05:01:16 +02:00
|
|
|
ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(activity)
|
2021-06-30 02:30:10 +02:00
|
|
|
}
|
2021-06-29 06:23:36 +02:00
|
|
|
dismiss()
|
2021-06-24 05:47:24 +02:00
|
|
|
}
|
|
|
|
}
|