diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/ConversationOptionsBottomSheet.kt b/app/src/main/java/org/thoughtcrime/securesms/home/ConversationOptionsBottomSheet.kt index 0b3c44a548..fc85f544fe 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/ConversationOptionsBottomSheet.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/ConversationOptionsBottomSheet.kt @@ -20,6 +20,7 @@ class ConversationOptionsBottomSheet(private val parentContext: Context) : Botto lateinit var thread: ThreadRecord var onViewDetailsTapped: (() -> Unit?)? = null + var onCopyConversationId: (() -> Unit?)? = null var onPinTapped: (() -> Unit)? = null var onUnpinTapped: (() -> Unit)? = null var onBlockTapped: (() -> Unit)? = null @@ -37,6 +38,8 @@ class ConversationOptionsBottomSheet(private val parentContext: Context) : Botto override fun onClick(v: View?) { when (v) { binding.detailsTextView -> onViewDetailsTapped?.invoke() + binding.copyConversationId -> onCopyConversationId?.invoke() + binding.copyCommunityUrl -> onCopyConversationId?.invoke() binding.pinTextView -> onPinTapped?.invoke() binding.unpinTextView -> onUnpinTapped?.invoke() binding.blockTextView -> onBlockTapped?.invoke() @@ -63,6 +66,10 @@ class ConversationOptionsBottomSheet(private val parentContext: Context) : Botto } else { binding.detailsTextView.visibility = View.GONE } + binding.copyConversationId.visibility = if (!recipient.isGroupRecipient && !recipient.isLocalNumber) View.VISIBLE else View.GONE + binding.copyConversationId.setOnClickListener(this) + binding.copyCommunityUrl.visibility = if (recipient.isOpenGroupRecipient) View.VISIBLE else View.GONE + binding.copyCommunityUrl.setOnClickListener(this) binding.unMuteNotificationsTextView.isVisible = recipient.isMuted && !recipient.isLocalNumber binding.muteNotificationsTextView.isVisible = !recipient.isMuted && !recipient.isLocalNumber binding.unMuteNotificationsTextView.setOnClickListener(this) diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index f1a9c8ed94..9b1e01a54a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -4,6 +4,8 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import android.content.ClipData +import android.content.ClipboardManager import android.os.Bundle import android.text.SpannableString import android.widget.Toast @@ -426,6 +428,24 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), userDetailsBottomSheet.arguments = bundle userDetailsBottomSheet.show(supportFragmentManager, userDetailsBottomSheet.tag) } + bottomSheet.onCopyConversationId = onCopyConversationId@{ + bottomSheet.dismiss() + if (!thread.recipient.isGroupRecipient && !thread.recipient.isLocalNumber) { + val clip = ClipData.newPlainText("Session ID", thread.recipient.address.toString()) + val manager = getSystemService(PassphraseRequiredActionBarActivity.CLIPBOARD_SERVICE) as ClipboardManager + manager.setPrimaryClip(clip) + Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show() + } + else if (thread.recipient.isOpenGroupRecipient) { + val threadId = threadDb.getThreadIdIfExistsFor(thread.recipient) ?: return@onCopyConversationId Unit + val openGroup = DatabaseComponent.get(this@HomeActivity).lokiThreadDatabase().getOpenGroupChat(threadId) ?: return@onCopyConversationId Unit + + val clip = ClipData.newPlainText("Community URL", openGroup.joinURL) + val manager = getSystemService(PassphraseRequiredActionBarActivity.CLIPBOARD_SERVICE) as ClipboardManager + manager.setPrimaryClip(clip) + Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show() + } + } bottomSheet.onBlockTapped = { bottomSheet.dismiss() if (!thread.recipient.isBlocked) { diff --git a/app/src/main/res/layout/fragment_conversation_bottom_sheet.xml b/app/src/main/res/layout/fragment_conversation_bottom_sheet.xml index 81f62c4a73..a4b93801bb 100644 --- a/app/src/main/res/layout/fragment_conversation_bottom_sheet.xml +++ b/app/src/main/res/layout/fragment_conversation_bottom_sheet.xml @@ -16,6 +16,22 @@ android:drawableTint="?attr/colorControlNormal" android:text="@string/details" /> + + + +