Skip to content

Commit

Permalink
Merge pull request #1118 from mpretty-cyro/feature/add-copy-to-long-p…
Browse files Browse the repository at this point in the history
…ress-menu

Add ‘Copy community URL’ to the long-press menu
  • Loading branch information
mpretty-cyro authored Feb 15, 2023
2 parents 5bd1883 + cc7a809 commit c8846bc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/layout/fragment_conversation_bottom_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
android:drawableTint="?attr/colorControlNormal"
android:text="@string/details" />

<TextView
android:id="@+id/copyConversationId"
style="@style/BottomSheetActionItem"
android:drawableStart="@drawable/ic_content_copy_white_24dp"
android:drawableTint="?attr/colorControlNormal"
android:visibility="gone"
android:text="@string/activity_conversation_menu_copy_session_id" />

<TextView
android:id="@+id/copyCommunityUrl"
style="@style/BottomSheetActionItem"
android:drawableStart="@drawable/ic_content_copy_white_24dp"
android:drawableTint="?attr/colorControlNormal"
android:visibility="gone"
android:text="@string/ConversationActivity_copy_open_group_url" />

<TextView
android:id="@+id/pinTextView"
style="@style/BottomSheetActionItem"
Expand Down

0 comments on commit c8846bc

Please sign in to comment.