Commit 94e86c98 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Implement copy to clipboard action

parent b2db4bcc
......@@ -197,6 +197,23 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
}
}
/**
* Copy message to clipboard.
*
* @param messageId The id of the message to copy to clipboard.
*/
fun copyMessage(messageId: String) {
launchUI(strategy) {
try {
messagesRepository.getById(messageId)?.let { m ->
view.copyToClipboard(m.message)
}
} catch (e: RocketChatException) {
Timber.e(e)
}
}
}
private suspend fun listenMessages(roomId: String) {
launch(CommonPool + strategy.jobs) {
for (message in client.messagesChannel) {
......
......@@ -50,6 +50,13 @@ interface ChatRoomView : LoadingView, MessageView {
*/
fun showReplyStatus(replyMarkdown: String, quotedMessage: String)
/**
* Copy message to clipboard.
*
* @param message The message to copy.
*/
fun copyToClipboard(message: String)
fun disableMessageInput()
fun enableMessageInput(clear: Boolean = false)
}
\ No newline at end of file
......@@ -113,6 +113,7 @@ class ChatRoomAdapter(private val serverUrl: String,
R.id.action_menu_msg_delete -> presenter.deleteMessage(roomId, id)
R.id.action_menu_msg_quote -> presenter.citeMessage(serverUrl, roomType, roomName, id, "", false)
R.id.action_menu_msg_reply -> presenter.citeMessage(serverUrl, roomType, roomName, id, "", true)
R.id.action_menu_msg_copy -> presenter.copyMessage(id)
else -> TODO("Not implemented")
}
}
......
package chat.rocket.android.chatroom.ui
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.DefaultItemAnimator
......@@ -22,6 +25,7 @@ import kotlinx.android.synthetic.main.fragment_chat_room.*
import kotlinx.android.synthetic.main.message_composer.*
import javax.inject.Inject
fun newInstance(chatRoomId: String, chatRoomName: String, chatRoomType: String, isChatRoomReadOnly: Boolean): Fragment {
return ChatRoomFragment().apply {
arguments = Bundle(1).apply {
......@@ -145,6 +149,13 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
override fun showGenericErrorMessage() = showMessage(getString(R.string.msg_generic_error))
override fun copyToClipboard(message: String) {
activity?.apply {
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(ClipData.newPlainText("", message))
}
}
private fun setupComposer() {
if (isChatRoomReadOnly) {
text_room_is_read_only.setVisible(true)
......
......@@ -7,6 +7,11 @@
android:icon="@drawable/ic_reply_black_24px"
android:title="@string/action_msg_reply" />
<item
android:id="@+id/action_menu_msg_quote"
android:icon="@drawable/ic_quote_black_24px"
android:title="@string/action_msg_quote" />
<!--<item-->
<!--android:id="@+id/action_menu_msg_edit"-->
<!--android:title="@string/action_msg_edit" />-->
......@@ -16,11 +21,6 @@
android:icon="@drawable/ic_content_copy_black_24px"
android:title="@string/action_msg_copy" />
<item
android:id="@+id/action_menu_msg_quote"
android:icon="@drawable/ic_quote_black_24px"
android:title="@string/action_msg_quote" />
<!--<item-->
<!--android:id="@+id/action_menu_msg_share"-->
<!--android:icon="@drawable/ic_share_black_24px"-->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment