Added ability to copy message to clipboard

This commit is contained in:
ChronosX88 2019-05-27 12:32:28 +04:00
parent 4839205cf4
commit b82c4d0447
5 changed files with 18 additions and 0 deletions

View File

@ -103,6 +103,7 @@ interface CoreContracts {
fun setAdapter(adapter: MessagesListAdapter<GenericMessage>)
fun setUserStatus(status: String)
fun getActivityObject(): Activity
fun showToast(text: String)
}
// -----SettingsFragment-----

View File

@ -16,6 +16,9 @@
package io.github.chronosx88.influence.presenters
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.view.MenuItem
import android.widget.Toast
import com.google.gson.Gson
@ -38,6 +41,7 @@ import java9.util.stream.StreamSupport
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.jetbrains.anko.toast
import org.jivesoftware.smackx.forward.packet.Forwarded
import java.util.*
import kotlin.Comparator
@ -62,6 +66,12 @@ class ChatPresenter(private val view: CoreContracts.IChatViewContract, private v
getUserStatus()
EventBus.getDefault().register(this)
AppHelper.setCurrentChatActivity(chatID)
chatAdapter.setOnMessageLongClickListener {
val clipboard = AppHelper.getContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText(it.text, it.text)
clipboard.primaryClip = clip
view.showToast(AppHelper.getContext().getString(R.string.copied_to_clipboard))
}
}
override fun sendMessage(text: String): Boolean {

View File

@ -37,6 +37,7 @@ import io.github.chronosx88.influence.contracts.CoreContracts
import io.github.chronosx88.influence.models.GenericMessage
import io.github.chronosx88.influence.presenters.ChatPresenter
import org.jetbrains.anko.find
import org.jetbrains.anko.toast
class ChatActivity : AppCompatActivity(), CoreContracts.IChatViewContract {
private var messageList: MessagesList? = null
@ -127,4 +128,8 @@ class ChatActivity : AppCompatActivity(), CoreContracts.IChatViewContract {
override fun getActivityObject(): Activity {
return this
}
override fun showToast(text: String) {
toast(text)
}
}

View File

@ -29,4 +29,5 @@
<string name="clear_chat">Очистить чат</string>
<string name="notification_channel_name">Уведомления Influence</string>
<string name="notification_channel_desc">Уведомления чатов Influence</string>
<string name="copied_to_clipboard">Сообщение скопировано в буфер обмена</string>
</resources>

View File

@ -28,4 +28,5 @@
<string name="clear_chat">Clear chat</string>
<string name="notification_channel_name">Influence Notifications</string>
<string name="notification_channel_desc">Influence chat notifications</string>
<string name="copied_to_clipboard">Message is copied to clipboard</string>
</resources>