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, ...@@ -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) { private suspend fun listenMessages(roomId: String) {
launch(CommonPool + strategy.jobs) { launch(CommonPool + strategy.jobs) {
for (message in client.messagesChannel) { for (message in client.messagesChannel) {
......
...@@ -50,6 +50,13 @@ interface ChatRoomView : LoadingView, MessageView { ...@@ -50,6 +50,13 @@ interface ChatRoomView : LoadingView, MessageView {
*/ */
fun showReplyStatus(replyMarkdown: String, quotedMessage: String) fun showReplyStatus(replyMarkdown: String, quotedMessage: String)
/**
* Copy message to clipboard.
*
* @param message The message to copy.
*/
fun copyToClipboard(message: String)
fun disableMessageInput() fun disableMessageInput()
fun enableMessageInput(clear: Boolean = false) fun enableMessageInput(clear: Boolean = false)
} }
\ No newline at end of file
...@@ -113,6 +113,7 @@ class ChatRoomAdapter(private val serverUrl: String, ...@@ -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_delete -> presenter.deleteMessage(roomId, id)
R.id.action_menu_msg_quote -> presenter.citeMessage(serverUrl, roomType, roomName, id, "", false) 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_reply -> presenter.citeMessage(serverUrl, roomType, roomName, id, "", true)
R.id.action_menu_msg_copy -> presenter.copyMessage(id)
else -> TODO("Not implemented") else -> TODO("Not implemented")
} }
} }
......
package chat.rocket.android.chatroom.ui package chat.rocket.android.chatroom.ui
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.support.v7.widget.DefaultItemAnimator import android.support.v7.widget.DefaultItemAnimator
...@@ -22,6 +25,7 @@ import kotlinx.android.synthetic.main.fragment_chat_room.* ...@@ -22,6 +25,7 @@ import kotlinx.android.synthetic.main.fragment_chat_room.*
import kotlinx.android.synthetic.main.message_composer.* import kotlinx.android.synthetic.main.message_composer.*
import javax.inject.Inject import javax.inject.Inject
fun newInstance(chatRoomId: String, chatRoomName: String, chatRoomType: String, isChatRoomReadOnly: Boolean): Fragment { fun newInstance(chatRoomId: String, chatRoomName: String, chatRoomType: String, isChatRoomReadOnly: Boolean): Fragment {
return ChatRoomFragment().apply { return ChatRoomFragment().apply {
arguments = Bundle(1).apply { arguments = Bundle(1).apply {
...@@ -145,6 +149,13 @@ class ChatRoomFragment : Fragment(), ChatRoomView { ...@@ -145,6 +149,13 @@ class ChatRoomFragment : Fragment(), ChatRoomView {
override fun showGenericErrorMessage() = showMessage(getString(R.string.msg_generic_error)) 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() { private fun setupComposer() {
if (isChatRoomReadOnly) { if (isChatRoomReadOnly) {
text_room_is_read_only.setVisible(true) text_room_is_read_only.setVisible(true)
......
...@@ -7,6 +7,11 @@ ...@@ -7,6 +7,11 @@
android:icon="@drawable/ic_reply_black_24px" android:icon="@drawable/ic_reply_black_24px"
android:title="@string/action_msg_reply" /> 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--> <!--<item-->
<!--android:id="@+id/action_menu_msg_edit"--> <!--android:id="@+id/action_menu_msg_edit"-->
<!--android:title="@string/action_msg_edit" />--> <!--android:title="@string/action_msg_edit" />-->
...@@ -16,11 +21,6 @@ ...@@ -16,11 +21,6 @@
android:icon="@drawable/ic_content_copy_black_24px" android:icon="@drawable/ic_content_copy_black_24px"
android:title="@string/action_msg_copy" /> 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--> <!--<item-->
<!--android:id="@+id/action_menu_msg_share"--> <!--android:id="@+id/action_menu_msg_share"-->
<!--android:icon="@drawable/ic_share_black_24px"--> <!--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