Add blocked dialog

This commit is contained in:
Niels Andriesse 2021-06-24 13:38:59 +10:00
parent 1dc7f7e9c0
commit 7373918d3d
19 changed files with 149 additions and 36 deletions

View File

@ -223,7 +223,7 @@
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/Theme.Session.DayNight.FlatActionBar" /> android:theme="@style/Theme.Session.DayNight.FlatActionBar" />
<activity <activity
android:name="org.thoughtcrime.securesms.conversation.v2.OpenGroupGuidelinesActivity" android:name="org.thoughtcrime.securesms.loki.activities.OpenGroupGuidelinesActivity"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@style/Theme.TextSecure.DayNight" /> android:theme="@style/Theme.TextSecure.DayNight" />
<activity <activity

View File

@ -8,7 +8,7 @@ import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import org.thoughtcrime.securesms.conversation.v2.TypingIndicatorView; import org.thoughtcrime.securesms.conversation.v2.components.TypingIndicatorView;
import org.thoughtcrime.securesms.mms.GlideRequests; import org.thoughtcrime.securesms.mms.GlideRequests;
import org.session.libsession.utilities.recipients.Recipient; import org.session.libsession.utilities.recipients.Recipient;
import org.session.libsession.utilities.ThemeUtil; import org.session.libsession.utilities.ThemeUtil;

View File

@ -32,6 +32,7 @@ import org.session.libsession.messaging.open_groups.OpenGroupAPIV2
import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.conversation.v2.dialogs.BlockedDialog
import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarButton 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.InputBarDelegate
import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarRecordingViewDelegate import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarRecordingViewDelegate
@ -45,6 +46,7 @@ import org.thoughtcrime.securesms.database.DraftDatabase
import org.thoughtcrime.securesms.database.DraftDatabase.Drafts import org.thoughtcrime.securesms.database.DraftDatabase.Drafts
import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.loki.api.PublicChatInfoUpdateWorker import org.thoughtcrime.securesms.loki.api.PublicChatInfoUpdateWorker
import org.thoughtcrime.securesms.loki.dialogs.SeedDialog
import org.thoughtcrime.securesms.loki.utilities.OpenGroupUtilities import org.thoughtcrime.securesms.loki.utilities.OpenGroupUtilities
import org.thoughtcrime.securesms.loki.utilities.toPx import org.thoughtcrime.securesms.loki.utilities.toPx
import org.thoughtcrime.securesms.mms.GlideApp import org.thoughtcrime.securesms.mms.GlideApp
@ -409,6 +411,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
// the view) so as to not interfere with all the other gestures. Do not add // the view) so as to not interfere with all the other gestures. Do not add
// onClickListeners directly to message content views. // onClickListeners directly to message content views.
view.onContentClick() view.onContentClick()
BlockedDialog(thread).show(supportFragmentManager, "Blocked Dialog")
} }
} }

View File

@ -1,4 +1,4 @@
package org.thoughtcrime.securesms.conversation.v2 package org.thoughtcrime.securesms.conversation.v2.components
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
@ -7,6 +7,8 @@ import android.view.LayoutInflater
import android.widget.FrameLayout import android.widget.FrameLayout
import kotlinx.android.synthetic.main.view_open_group_guidelines.view.* import kotlinx.android.synthetic.main.view_open_group_guidelines.view.*
import network.loki.messenger.R import network.loki.messenger.R
import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2
import org.thoughtcrime.securesms.loki.activities.OpenGroupGuidelinesActivity
import org.thoughtcrime.securesms.loki.utilities.push import org.thoughtcrime.securesms.loki.utilities.push
class OpenGroupGuidelinesView : FrameLayout { class OpenGroupGuidelinesView : FrameLayout {

View File

@ -1,4 +1,4 @@
package org.thoughtcrime.securesms.conversation.v2; package org.thoughtcrime.securesms.conversation.v2.components;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;

View File

@ -1,4 +1,4 @@
package org.thoughtcrime.securesms.conversation.v2 package org.thoughtcrime.securesms.conversation.v2.components
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet

View File

@ -0,0 +1,38 @@
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_blocked.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 BlockedDialog(private val recipient: Recipient) : BaseDialog() {
override fun setContentView(builder: AlertDialog.Builder) {
val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_blocked, 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_blocked_title, name)
contentView.blockedTitleTextView.text = title
val explanation = resources.getString(R.string.dialog_blocked_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.blockedExplanationTextView.text = spannable
contentView.unblockButton.setOnClickListener { unblock() }
builder.setView(contentView)
}
private fun unblock() {
}
}

View File

@ -0,0 +1,26 @@
package org.thoughtcrime.securesms.conversation.v2.utilities
import android.app.Dialog
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities
open class BaseDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val builder = AlertDialog.Builder(requireContext())
setContentView(builder)
val result = builder.create()
result.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val isLightMode = UiModeUtilities.isDayUiMode(requireContext())
result.window?.setDimAmount(if (isLightMode) 0.1f else 0.75f)
return result
}
open fun setContentView(builder: AlertDialog.Builder) {
// To be overridden by subclasses
}
}

View File

@ -1,4 +1,4 @@
package org.thoughtcrime.securesms.conversation.v2 package org.thoughtcrime.securesms.loki.activities
import android.os.Bundle import android.os.Bundle
import kotlinx.android.synthetic.main.activity_open_group_guidelines.* import kotlinx.android.synthetic.main.activity_open_group_guidelines.*

View File

@ -12,21 +12,16 @@ import network.loki.messenger.R
import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.loki.protocol.MultiDeviceProtocol import org.thoughtcrime.securesms.loki.protocol.MultiDeviceProtocol
import org.session.libsession.utilities.KeyPairUtilities import org.session.libsession.utilities.KeyPairUtilities
import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities
class ClearAllDataDialog : DialogFragment() { class ClearAllDataDialog : BaseDialog() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun setContentView(builder: AlertDialog.Builder) {
val builder = AlertDialog.Builder(requireContext())
val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_clear_all_data, null) val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_clear_all_data, null)
contentView.cancelButton.setOnClickListener { dismiss() } contentView.cancelButton.setOnClickListener { dismiss() }
contentView.clearAllDataButton.setOnClickListener { clearAllData() } contentView.clearAllDataButton.setOnClickListener { clearAllData() }
builder.setView(contentView) builder.setView(contentView)
val result = builder.create()
result.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val isLightMode = UiModeUtilities.isDayUiMode(requireContext())
result.window?.setDimAmount(if (isLightMode) 0.1f else 0.75f)
return result
} }
private fun clearAllData() { private fun clearAllData() {

View File

@ -1,25 +1,20 @@
package org.thoughtcrime.securesms.loki.dialogs package org.thoughtcrime.securesms.loki.dialogs
import android.app.Dialog
import android.content.ClipData import android.content.ClipData
import android.content.ClipboardManager import android.content.ClipboardManager
import android.content.Context import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import kotlinx.android.synthetic.main.dialog_seed.view.* import kotlinx.android.synthetic.main.dialog_seed.view.*
import network.loki.messenger.R import network.loki.messenger.R
import org.session.libsession.utilities.IdentityKeyUtil import org.session.libsession.utilities.IdentityKeyUtil
import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities import org.thoughtcrime.securesms.loki.utilities.MnemonicUtilities
import org.session.libsignal.crypto.MnemonicCodec import org.session.libsignal.crypto.MnemonicCodec
import org.session.libsignal.utilities.hexEncodedPrivateKey import org.session.libsignal.utilities.hexEncodedPrivateKey
import org.thoughtcrime.securesms.loki.utilities.UiModeUtilities import org.thoughtcrime.securesms.conversation.v2.utilities.BaseDialog
class SeedDialog : DialogFragment() { class SeedDialog : BaseDialog() {
private val seed by lazy { private val seed by lazy {
var hexEncodedSeed = IdentityKeyUtil.retrieve(requireContext(), IdentityKeyUtil.LOKI_SEED) var hexEncodedSeed = IdentityKeyUtil.retrieve(requireContext(), IdentityKeyUtil.LOKI_SEED)
@ -32,18 +27,12 @@ class SeedDialog : DialogFragment() {
MnemonicCodec(loadFileContents).encode(hexEncodedSeed!!, MnemonicCodec.Language.Configuration.english) MnemonicCodec(loadFileContents).encode(hexEncodedSeed!!, MnemonicCodec.Language.Configuration.english)
} }
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun setContentView(builder: AlertDialog.Builder) {
val builder = AlertDialog.Builder(requireContext())
val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_seed, null) val contentView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_seed, null)
contentView.seedTextView.text = seed contentView.seedTextView.text = seed
contentView.cancelButton.setOnClickListener { dismiss() } contentView.cancelButton.setOnClickListener { dismiss() }
contentView.copyButton.setOnClickListener { copySeed() } contentView.copyButton.setOnClickListener { copySeed() }
builder.setView(contentView) builder.setView(contentView)
val result = builder.create()
result.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val isLightMode = UiModeUtilities.isDayUiMode(requireContext())
result.window?.setDimAmount(if (isLightMode) 0.1f else 0.75f)
return result
} }
private fun copySeed() { private fun copySeed() {

View File

@ -6,7 +6,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<org.thoughtcrime.securesms.conversation.v2.OpenGroupGuidelinesView <org.thoughtcrime.securesms.conversation.v2.components.OpenGroupGuidelinesView
android:id="@+id/openGroupGuidelinesView" android:id="@+id/openGroupGuidelinesView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -18,7 +18,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginBottom="@dimen/input_bar_height" /> android:layout_marginBottom="@dimen/input_bar_height" />
<org.thoughtcrime.securesms.conversation.v2.TypingIndicatorViewContainer <org.thoughtcrime.securesms.conversation.v2.components.TypingIndicatorViewContainer
android:id="@+id/typingIndicatorViewContainer" android:id="@+id/typingIndicatorViewContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="36dp" android:layout_height="36dp"

View File

@ -135,7 +135,7 @@
android:background="?android:dividerHorizontal" android:background="?android:dividerHorizontal"
android:elevation="1dp" /> android:elevation="1dp" />
<org.thoughtcrime.securesms.conversation.v2.OpenGroupGuidelinesView <org.thoughtcrime.securesms.conversation.v2.components.OpenGroupGuidelinesView
android:id="@+id/open_group_guidelines_view" android:id="@+id/open_group_guidelines_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -24,7 +24,7 @@
android:padding="12dp" android:padding="12dp"
android:background="@drawable/message_bubble_background"> android:background="@drawable/message_bubble_background">
<org.thoughtcrime.securesms.conversation.v2.TypingIndicatorView <org.thoughtcrime.securesms.conversation.v2.components.TypingIndicatorView
android:id="@+id/typing_indicator" android:id="@+id/typing_indicator"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/default_dialog_background_inset"
android:gravity="center_horizontal"
android:orientation="vertical"
android:elevation="4dp"
android:padding="32dp">
<TextView
android:id="@+id/blockedTitleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dialog_blocked_title"
android:textColor="@color/text"
android:textStyle="bold"
android:textSize="@dimen/large_font_size" />
<TextView
android:id="@+id/blockedExplanationTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/large_spacing"
android:text="@string/dialog_blocked_explanation"
android:textColor="@color/text"
android:textSize="@dimen/small_font_size"
android:textAlignment="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/large_spacing"
android:orientation="horizontal">
<Button
style="@style/Widget.Session.Button.Dialog.Unimportant"
android:id="@+id/cancelButton"
android:layout_width="0dp"
android:layout_height="@dimen/small_button_height"
android:layout_weight="1"
android:text="@string/cancel" />
<Button
style="@style/Widget.Session.Button.Dialog.Unimportant"
android:id="@+id/unblockButton"
android:layout_width="0dp"
android:layout_height="@dimen/small_button_height"
android:layout_weight="1"
android:layout_marginStart="@dimen/medium_spacing"
android:text="@string/ConversationActivity_unblock" />
</LinearLayout>
</LinearLayout>

View File

@ -126,7 +126,7 @@
android:textColor="@color/text" android:textColor="@color/text"
tools:text="Sorry, gotta go fight crime again" /> tools:text="Sorry, gotta go fight crime again" />
<org.thoughtcrime.securesms.conversation.v2.TypingIndicatorView <org.thoughtcrime.securesms.conversation.v2.components.TypingIndicatorView
android:id="@+id/typingIndicatorView" android:id="@+id/typingIndicatorView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -17,7 +17,7 @@
android:background="@drawable/message_bubble_background_received_alone" android:background="@drawable/message_bubble_background_received_alone"
android:backgroundTint="?message_received_background_color"> android:backgroundTint="?message_received_background_color">
<org.thoughtcrime.securesms.conversation.v2.TypingIndicatorView <org.thoughtcrime.securesms.conversation.v2.components.TypingIndicatorView
android:id="@+id/typingIndicator" android:id="@+id/typingIndicator"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />

View File

@ -5,7 +5,7 @@
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="org.thoughtcrime.securesms.conversation.v2.TypingIndicatorView"> tools:context="org.thoughtcrime.securesms.conversation.v2.components.TypingIndicatorView">
<View <View
android:id="@+id/typing_dot1" android:id="@+id/typing_dot1"

View File

@ -309,7 +309,7 @@
<string name="MediaPreviewActivity_you">You</string> <string name="MediaPreviewActivity_you">You</string>
<string name="MediaPreviewActivity_unssuported_media_type">Unsupported media type</string> <string name="MediaPreviewActivity_unssuported_media_type">Unsupported media type</string>
<string name="MediaPreviewActivity_draft">Draft</string> <string name="MediaPreviewActivity_draft">Draft</string>
<string name="MediaPreviewActivity_signal_needs_the_storage_permission_in_order_to_write_to_external_storage_but_it_has_been_permanently_denied">Session needs the Storage permission in order to save to external storage, but it has been permanently denied. Please continue to app settings, select \"Permissions\", and enable \"Storage\".</string> <string name="MediaPreviewActivity_signal_needs_the_storage_permission_in_order_to_write_to_external_storage_but_it_has_been_permanently_denied">Session needs storage access in order to save to external storage, but it has been permanently denied. Please continue to app settings, select \"Permissions\", and enable \"Storage\".</string>
<string name="MediaPreviewActivity_unable_to_write_to_external_storage_without_permission">Unable to save to external storage without permissions</string> <string name="MediaPreviewActivity_unable_to_write_to_external_storage_without_permission">Unable to save to external storage without permissions</string>
<string name="MediaPreviewActivity_media_delete_confirmation_title">Delete message?</string> <string name="MediaPreviewActivity_media_delete_confirmation_title">Delete message?</string>
<string name="MediaPreviewActivity_media_delete_confirmation_message">This will permanently delete this message.</string> <string name="MediaPreviewActivity_media_delete_confirmation_message">This will permanently delete this message.</string>
@ -853,4 +853,8 @@
<string name="document">Document</string> <string name="document">Document</string>
<string name="dialog_blocked_title">Unblock %s?</string>
<string name="dialog_blocked_explanation">Are you sure you want to unblock %s?</string>
</resources> </resources>