From 06b9c30c27623f34ef26c01713bf18162d4dcdd2 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 24 Jun 2021 14:05:55 +1000 Subject: [PATCH] Add trust dialog --- .../conversation/v2/ConversationActivityV2.kt | 7 +-- .../conversation/v2/dialogs/DownloadDialog.kt | 39 +++++++++++++ app/src/main/res/layout/dialog_download.xml | 57 +++++++++++++++++++ app/src/main/res/values/strings.xml | 4 ++ 4 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/DownloadDialog.kt create mode 100644 app/src/main/res/layout/dialog_download.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 c3074b944f..9db5a10784 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 @@ -32,10 +32,7 @@ import org.session.libsession.messaging.open_groups.OpenGroupAPIV2 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.dialogs.LinkPreviewDialog -import org.thoughtcrime.securesms.conversation.v2.dialogs.OpenURLDialog +import org.thoughtcrime.securesms.conversation.v2.dialogs.* 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 @@ -414,7 +411,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() - LinkPreviewDialog().show(supportFragmentManager, "Blocked Dialog") + DownloadDialog(thread).show(supportFragmentManager, "Blocked Dialog") } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/DownloadDialog.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/DownloadDialog.kt new file mode 100644 index 0000000000..a5485c7c01 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/dialogs/DownloadDialog.kt @@ -0,0 +1,39 @@ +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_download.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 +import org.thoughtcrime.securesms.database.DatabaseFactory + +class DownloadDialog(private val recipient: Recipient) : BaseDialog() { + + override fun setContentView(builder: AlertDialog.Builder) { + val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_download, null) + val contactDB = DatabaseFactory.getSessionContactDatabase(requireContext()) + 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_download_title, name) + contentView.downloadTitleTextView.text = title + val explanation = resources.getString(R.string.dialog_download_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.downloadExplanationTextView.text = spannable + contentView.cancelButton.setOnClickListener { dismiss() } + contentView.downloadButton.setOnClickListener { trust() } + builder.setView(contentView) + } + + private fun trust() { + + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_download.xml b/app/src/main/res/layout/dialog_download.xml new file mode 100644 index 0000000000..f4279bf520 --- /dev/null +++ b/app/src/main/res/layout/dialog_download.xml @@ -0,0 +1,57 @@ + + + + + + + + + +