From 250fb50cc888477ca317e7e5bacb86a8ee5f9183 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 24 Jun 2021 13:54:34 +1000 Subject: [PATCH] Add open URL dialog --- .../conversation/v2/ConversationActivityV2.kt | 4 +- .../v2/dialogs/JoinOpenGroupDialog.kt | 2 - .../conversation/v2/dialogs/OpenURLDialog.kt | 30 ++++++++++ app/src/main/res/layout/dialog_open_url.xml | 57 +++++++++++++++++++ app/src/main/res/values/strings.xml | 4 ++ 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/OpenURLDialog.kt create mode 100644 app/src/main/res/layout/dialog_open_url.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 3e862e5357..55489e8416 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 @@ -34,6 +34,7 @@ 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.dialogs.OpenURLDialog 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 @@ -412,8 +413,7 @@ 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() - val openGroup = DatabaseFactory.getLokiThreadDatabase(this).getOpenGroupChat(threadID)!! - JoinOpenGroupDialog(openGroup).show(supportFragmentManager, "Blocked Dialog") + OpenURLDialog("http://iuasfiuhasf.oiasf").show(supportFragmentManager, "Blocked Dialog") } } 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 index 3b26fbce10..ae0cdd2f6f 100644 --- 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 @@ -8,10 +8,8 @@ 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() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/OpenURLDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/OpenURLDialog.kt new file mode 100644 index 0000000000..48d3e90c1e --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/OpenURLDialog.kt @@ -0,0 +1,30 @@ +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_open_url.view.* +import network.loki.messenger.R +import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog + +class OpenURLDialog(private val url: String) : BaseDialog() { + + override fun setContentView(builder: AlertDialog.Builder) { + val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_open_url, null) + val explanation = resources.getString(R.string.dialog_open_url_explanation, url) + val spannable = SpannableStringBuilder(explanation) + val startIndex = explanation.indexOf(url) + spannable.setSpan(StyleSpan(Typeface.BOLD), startIndex, startIndex + url.count(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) + contentView.openURLExplanationTextView.text = spannable + contentView.cancelButton.setOnClickListener { dismiss() } + contentView.openURLButton.setOnClickListener { open() } + builder.setView(contentView) + } + + private fun open() { + + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_open_url.xml b/app/src/main/res/layout/dialog_open_url.xml new file mode 100644 index 0000000000..05cd2b5f1c --- /dev/null +++ b/app/src/main/res/layout/dialog_open_url.xml @@ -0,0 +1,57 @@ + + + + + + + + + +