mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Re-implement attachment sending
This commit is contained in:
parent
7f2ffcc114
commit
bf80f5c449
@ -7,6 +7,7 @@ import android.content.res.Resources
|
||||
import android.database.Cursor
|
||||
import android.graphics.Rect
|
||||
import android.graphics.Typeface
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.util.TypedValue
|
||||
@ -31,15 +32,16 @@ import nl.komponents.kovenant.ui.successUi
|
||||
import org.session.libsession.messaging.contacts.Contact
|
||||
import org.session.libsession.messaging.mentions.Mention
|
||||
import org.session.libsession.messaging.mentions.MentionsManager
|
||||
import org.session.libsession.messaging.messages.signal.OutgoingMediaMessage
|
||||
import org.session.libsession.messaging.messages.signal.OutgoingTextMessage
|
||||
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
||||
import org.session.libsession.messaging.open_groups.OpenGroupAPIV2
|
||||
import org.session.libsession.messaging.sending_receiving.MessageSender
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.Attachment
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.contactshare.SimpleTextWatcher
|
||||
import org.thoughtcrime.securesms.conversation.ConversationActivity
|
||||
import org.thoughtcrime.securesms.conversation.v2.dialogs.*
|
||||
import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarButton
|
||||
import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarDelegate
|
||||
@ -645,7 +647,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
this.previousText = newText
|
||||
}
|
||||
|
||||
override fun send() {
|
||||
override fun sendMessage() {
|
||||
// Create the message
|
||||
val message = VisibleMessage()
|
||||
message.sentTimestamp = System.currentTimeMillis()
|
||||
@ -665,6 +667,31 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
ApplicationContext.getInstance(this).typingStatusSender.onTypingStopped(threadID)
|
||||
}
|
||||
|
||||
private fun sendAttachments(attachments: List<Attachment>, body: String?) {
|
||||
// TODO: Quotes & link previews
|
||||
// Create the message
|
||||
val message = VisibleMessage()
|
||||
message.sentTimestamp = System.currentTimeMillis()
|
||||
message.text = body
|
||||
val outgoingTextMessage = OutgoingMediaMessage.from(message, thread, attachments, null, null)
|
||||
// Clear the input bar
|
||||
inputBar.text = ""
|
||||
// Clear mentions
|
||||
previousText = ""
|
||||
currentMentionStartIndex = -1
|
||||
mentions.clear()
|
||||
// Reset the attachment manager
|
||||
attachmentManager.clear(glide, false)
|
||||
//
|
||||
|
||||
// Put the message in the database
|
||||
message.id = DatabaseFactory.getMmsDatabase(this).insertMessageOutbox(outgoingTextMessage, threadID, false) { }
|
||||
// Send it
|
||||
MessageSender.send(message, thread.address, attachments, null, null)
|
||||
// Send a typing stopped message
|
||||
ApplicationContext.getInstance(this).typingStatusSender.onTypingStopped(threadID)
|
||||
}
|
||||
|
||||
private fun showGIFPicker() {
|
||||
AttachmentManager.selectGif(this, ConversationActivityV2.PICK_GIF)
|
||||
}
|
||||
@ -690,19 +717,22 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
intent ?: return
|
||||
when (requestCode) {
|
||||
PICK_DOCUMENT -> {
|
||||
val data = intent.data ?: return
|
||||
val uri = intent.data ?: return
|
||||
prepMediaForSending(uri, AttachmentManager.MediaType.DOCUMENT)
|
||||
}
|
||||
TAKE_PHOTO -> {
|
||||
val uri = attachmentManager.captureUri ?: return
|
||||
prepMediaForSending(uri, AttachmentManager.MediaType.IMAGE)
|
||||
}
|
||||
PICK_GIF -> {
|
||||
val data = intent.data ?: return
|
||||
val uri = intent.data ?: return
|
||||
val type = AttachmentManager.MediaType.GIF
|
||||
val width = intent.getIntExtra(GiphyActivity.EXTRA_WIDTH, 0)
|
||||
val height = intent.getIntExtra(GiphyActivity.EXTRA_HEIGHT, 0)
|
||||
prepMediaForSending(uri, type, width, height)
|
||||
}
|
||||
PICK_FROM_LIBRARY -> {
|
||||
val message = intent.getStringExtra(MediaSendActivity.EXTRA_MESSAGE)
|
||||
val body = intent.getStringExtra(MediaSendActivity.EXTRA_MESSAGE)
|
||||
val media = intent.getParcelableArrayListExtra<Media>(MediaSendActivity.EXTRA_MEDIA) ?: return
|
||||
val slideDeck = SlideDeck()
|
||||
for (item in media) {
|
||||
@ -721,9 +751,18 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
}
|
||||
}
|
||||
}
|
||||
sendAttachments(slideDeck.asAttachments(), body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun prepMediaForSending(uri: Uri, type: AttachmentManager.MediaType) {
|
||||
prepMediaForSending(uri, type, null, null)
|
||||
}
|
||||
|
||||
private fun prepMediaForSending(uri: Uri, type: AttachmentManager.MediaType, width: Int?, height: Int?) {
|
||||
attachmentManager.setMedia(glide, uri, type, MediaConstraints.getPushMediaConstraints(), width ?: 0, height ?: 0)
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region General
|
||||
|
@ -8,7 +8,6 @@ import android.view.MotionEvent
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.core.view.isVisible
|
||||
import kotlinx.android.synthetic.main.view_input_bar.view.*
|
||||
import kotlinx.android.synthetic.main.view_quote.view.*
|
||||
import network.loki.messenger.R
|
||||
import org.session.libsession.messaging.sending_receiving.link_preview.LinkPreview
|
||||
import org.thoughtcrime.securesms.conversation.v2.components.LinkPreviewDraftView
|
||||
@ -61,7 +60,7 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate, Li
|
||||
microphoneOrSendButtonContainer.addView(sendButton)
|
||||
sendButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
|
||||
sendButton.isVisible = false
|
||||
sendButton.onUp = { delegate?.send() }
|
||||
sendButton.onUp = { delegate?.sendMessage() }
|
||||
// Edit text
|
||||
inputBarEditText.imeOptions = inputBarEditText.imeOptions or 16777216 // Always use incognito keyboard
|
||||
inputBarEditText.delegate = this
|
||||
@ -163,5 +162,5 @@ interface InputBarDelegate {
|
||||
fun onMicrophoneButtonMove(event: MotionEvent)
|
||||
fun onMicrophoneButtonCancel(event: MotionEvent)
|
||||
fun onMicrophoneButtonUp(event: MotionEvent)
|
||||
fun send()
|
||||
fun sendMessage()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user