Unverified Commit af2d382d authored by Filipe de Lima Brito's avatar Filipe de Lima Brito Committed by GitHub

Merge pull request #1387 from divyanshub024/send-msg-attachments

[NEW] Send message with attachments
parents 6d23badd 59c2ef88
...@@ -54,8 +54,9 @@ interface ChatRoomView : LoadingView, MessageView { ...@@ -54,8 +54,9 @@ interface ChatRoomView : LoadingView, MessageView {
* Uploads a file to a chat room. * Uploads a file to a chat room.
* *
* @param uri The file URI to send. * @param uri The file URI to send.
* @param msg Message to send with attachments
*/ */
fun uploadFile(uri: Uri) fun uploadFile(uri: Uri, msg: String)
/** /**
* Shows a invalid file message. * Shows a invalid file message.
......
package chat.rocket.android.chatroom.ui package chat.rocket.android.chatroom.ui
import android.app.Activity import android.app.Activity
import android.app.AlertDialog
import android.content.ClipData import android.content.ClipData
import android.content.ClipboardManager import android.content.ClipboardManager
import android.content.Context import android.content.Context
...@@ -15,6 +16,11 @@ import android.view.Menu ...@@ -15,6 +16,11 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.FrameLayout
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.core.text.bold import androidx.core.text.bold
import androidx.core.view.isVisible import androidx.core.view.isVisible
...@@ -57,6 +63,8 @@ import chat.rocket.android.util.extensions.rotateBy ...@@ -57,6 +63,8 @@ import chat.rocket.android.util.extensions.rotateBy
import chat.rocket.android.util.extensions.showToast import chat.rocket.android.util.extensions.showToast
import chat.rocket.android.util.extensions.textContent import chat.rocket.android.util.extensions.textContent
import chat.rocket.android.util.extensions.ui import chat.rocket.android.util.extensions.ui
import chat.rocket.android.util.extensions.getMimeType
import chat.rocket.android.util.extensions.getFileName
import chat.rocket.common.model.RoomType import chat.rocket.common.model.RoomType
import chat.rocket.common.model.roomTypeOf import chat.rocket.common.model.roomTypeOf
import chat.rocket.core.internal.realtime.socket.model.State import chat.rocket.core.internal.realtime.socket.model.State
...@@ -231,17 +239,59 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -231,17 +239,59 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
if (resultData != null && resultCode == Activity.RESULT_OK) { if (resultData != null && resultCode == Activity.RESULT_OK) {
when(requestCode){ when(requestCode){
REQUEST_CODE_FOR_PERFORM_SAF -> { REQUEST_CODE_FOR_PERFORM_SAF -> {
uploadFile(resultData.data) fileAttachmentDialog(resultData.data)
} }
REQUEST_CODE_FOR_DRAW -> { REQUEST_CODE_FOR_DRAW -> {
val result= resultData.getByteArrayExtra("bitmap") val result= resultData.getByteArrayExtra("bitmap")
val uri = presenter.getDrawingImageUri(result) val uri = presenter.getDrawingImageUri(result)
uploadFile(uri) fileAttachmentDialog(uri)
} }
} }
} }
} }
private fun fileAttachmentDialog(data: Uri) {
val builder = AlertDialog.Builder(activity)
val dialogView = View.inflate(context, R.layout.file_attachments_dialog, null)
builder.setView(dialogView)
val alertDialog = builder.create()
dialogView?.let {
val imagePreview = it.findViewById<ImageView>(R.id.image_preview)
val sendButton = it.findViewById<Button>(R.id.button_send)
val cancelButton: Button = it.findViewById(R.id.button_cancel)
val description = it.findViewById<EditText>(R.id.text_file_description)
val audioVideoAttachment = it.findViewById<FrameLayout>(R.id.audio_video_attachment)
val textFile = it.findViewById<TextView>(R.id.text_file_name)
activity?.let {
data.getMimeType(it).apply {
when {
this.startsWith("image") -> {
imagePreview.isVisible = true
imagePreview.setImageURI(data)
}
this.startsWith("video") -> {
audioVideoAttachment.isVisible = true
}
else -> {
textFile.isVisible = true
textFile.text = data.getFileName(it)
}
}
}
}
sendButton.setOnClickListener {
uploadFile(data, description.text.toString())
alertDialog.dismiss()
}
cancelButton.setOnClickListener {
alertDialog.dismiss()
}
}
alertDialog.show()
}
override fun onPrepareOptionsMenu(menu: Menu) { override fun onPrepareOptionsMenu(menu: Menu) {
menu.clear() menu.clear()
if (isFavorite) { if (isFavorite) {
...@@ -486,9 +536,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -486,9 +536,8 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
} }
} }
override fun uploadFile(uri: Uri) { override fun uploadFile(uri: Uri, msg: String) {
// TODO Just leaving a blank message that comes with the file for now. In the future lets add the possibility to add a message with the file to be uploaded. presenter.uploadFile(chatRoomId, uri, msg)
presenter.uploadFile(chatRoomId, uri, "")
} }
override fun showInvalidFileMessage() { override fun showInvalidFileMessage() {
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorAccent" />
<corners android:radius="4dp"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="16dp">
<TextView
android:id="@+id/text_dialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/msg_upload_file"
style="@style/Base.DialogWindowTitle.AppCompat"
android:layout_margin="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/text_file_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="@color/colorAccent"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:drawableStart="@drawable/ic_files_24dp"
android:drawablePadding="6dp"
app:layout_constraintTop_toBottomOf="@id/text_dialog_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_margin="16dp"
android:textDirection="locale"
android:visibility="gone"
tools:text="This is a very, very, very long filename, to test how the layout will work on very very very long filenames.pdf" />
<FrameLayout
android:id="@+id/audio_video_attachment"
android:layout_width="0dp"
android:layout_height="150dp"
android:background="@color/colorBlack"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/text_file_name"
android:layout_margin="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/exo_controls_play" />
</FrameLayout>
<ImageView
android:id="@+id/image_preview"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintHeight_max="240dp"
app:layout_constrainedHeight="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/audio_video_attachment"
android:layout_margin="16dp"
android:adjustViewBounds="true"
android:visibility="gone"
tools:visibility="visible" />
<EditText
android:id="@+id/text_file_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/image_preview"
android:layout_margin="16dp"
android:hint="@string/msg_file_description" />
<Button
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/text_file_description"
android:layout_margin="16dp"
android:background="@drawable/rounded_color_accent"
android:text="@string/msg_send"
android:textColor="@color/colorWhite" />
<Button
android:id="@+id/button_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/text_file_description"
app:layout_constraintEnd_toStartOf="@id/button_send"
android:layout_margin="16dp"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:text="@string/msg_cancel" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
\ No newline at end of file
...@@ -133,6 +133,9 @@ ...@@ -133,6 +133,9 @@
// TODO: Add proper translation. // TODO: Add proper translation.
<string name="msg_search">Search</string> <string name="msg_search">Search</string>
<string name="msg_message_copied">Mensaje copiado</string> <string name="msg_message_copied">Mensaje copiado</string>
<string name="msg_upload_file">Subir archivo</string>
<string name="msg_file_description">Descripción del archivo</string>
<string name="msg_send">enviar</string>
// TODO: Add proper translation. // TODO: Add proper translation.
<string name="msg_delete_message">Delete Message</string> <string name="msg_delete_message">Delete Message</string>
<string name="msg_delete_description">Are you sure you want to delete this message</string> <string name="msg_delete_description">Are you sure you want to delete this message</string>
...@@ -150,7 +153,6 @@ ...@@ -150,7 +153,6 @@
<string name="msg_member_not_found">Member not found</string> <string name="msg_member_not_found">Member not found</string>
<string name="msg_channel_created_successfully">Channel created successfully</string> <string name="msg_channel_created_successfully">Channel created successfully</string>
<!-- System messages --> <!-- System messages -->
<string name="message_room_name_changed">Nombre de la sala cambiado para: %1$s por %2$s</string> <string name="message_room_name_changed">Nombre de la sala cambiado para: %1$s por %2$s</string>
<string name="message_user_added_by">Usuario %1$s añadido por %2$s</string> <string name="message_user_added_by">Usuario %1$s añadido por %2$s</string>
......
...@@ -133,6 +133,9 @@ ...@@ -133,6 +133,9 @@
// TODO: Add proper translation. // TODO: Add proper translation.
<string name="msg_search">Search</string> <string name="msg_search">Search</string>
<string name="msg_message_copied">Message copié</string> <string name="msg_message_copied">Message copié</string>
<string name="msg_upload_file">Téléverser un fichier</string>
<string name="msg_file_description">Description du fichier</string>
<string name="msg_send">envoyer</string>
// TODO: Add proper translation. // TODO: Add proper translation.
<string name="msg_delete_message">Delete Message</string> <string name="msg_delete_message">Delete Message</string>
<string name="msg_delete_description">Are you sure you want to delete this message</string> <string name="msg_delete_description">Are you sure you want to delete this message</string>
......
...@@ -120,6 +120,9 @@ ...@@ -120,6 +120,9 @@
<string name="msg_channel_name">चैनल का नाम</string> <string name="msg_channel_name">चैनल का नाम</string>
<string name="msg_search">खोजें</string> <string name="msg_search">खोजें</string>
<string name="msg_message_copied">संदेश कॉपी किया गया</string> <string name="msg_message_copied">संदेश कॉपी किया गया</string>
<string name="msg_upload_file">फाइल अपलोड करें</string>
<string name="msg_file_description">फाइल विवरण</string>
<string name="msg_send">भेजें</string>
<string name="msg_delete_message">संदेश को हटाएं</string> <string name="msg_delete_message">संदेश को हटाएं</string>
<string name="msg_delete_description">क्या आप निश्चित रूप से यह संदेश हटाना चाहते हैं</string> <string name="msg_delete_description">क्या आप निश्चित रूप से यह संदेश हटाना चाहते हैं</string>
......
...@@ -120,6 +120,9 @@ ...@@ -120,6 +120,9 @@
<string name="msg_channel_name">Nome do chat</string> <string name="msg_channel_name">Nome do chat</string>
<string name="msg_search">Buscar</string> <string name="msg_search">Buscar</string>
<string name="msg_message_copied">Mensagem copiada</string> <string name="msg_message_copied">Mensagem copiada</string>
<string name="msg_upload_file">Subir arquivo</string>
<string name="msg_file_description">Descrição do arquivo</string>
<string name="msg_send">Enviar</string>
// TODO: Add proper translation. // TODO: Add proper translation.
<string name="msg_delete_message">Delete Message</string> <string name="msg_delete_message">Delete Message</string>
<string name="msg_delete_description">Are you sure you want to delete this message</string> <string name="msg_delete_description">Are you sure you want to delete this message</string>
......
...@@ -116,6 +116,9 @@ ...@@ -116,6 +116,9 @@
<string name="msg_several_users_are_typing">Несколько пользователей печатают…</string> <string name="msg_several_users_are_typing">Несколько пользователей печатают…</string>
<string name="msg_no_search_found">Результатов не найдено</string> <string name="msg_no_search_found">Результатов не найдено</string>
<string name="msg_message_copied">Сообщение скопировано</string> <string name="msg_message_copied">Сообщение скопировано</string>
<string name="msg_upload_file">Загрузить файл</string>
<string name="msg_file_description">Описание файла</string>
<string name="msg_send">послать</string>
<string name="msg_delete_message">Удалить сообщение</string> <string name="msg_delete_message">Удалить сообщение</string>
<string name="msg_delete_description">Вы уверены, что хотите удалить это сообщение?</string> <string name="msg_delete_description">Вы уверены, что хотите удалить это сообщение?</string>
<string name="msg_channel_name">Название канала</string> <string name="msg_channel_name">Название канала</string>
......
...@@ -120,6 +120,9 @@ ...@@ -120,6 +120,9 @@
<string name="msg_are_typing">\u0020are typing…</string> <string name="msg_are_typing">\u0020are typing…</string>
<string name="msg_several_users_are_typing">Several users are typing…</string> <string name="msg_several_users_are_typing">Several users are typing…</string>
<string name="msg_no_search_found">No result found</string> <string name="msg_no_search_found">No result found</string>
<string name="msg_upload_file">Upload file</string>
<string name="msg_file_description">File description</string>
<string name="msg_send">Send</string>
<!-- Create channel messages --> <!-- Create channel messages -->
<string name="msg_private_channel">Private</string> <string name="msg_private_channel">Private</string>
...@@ -132,7 +135,6 @@ ...@@ -132,7 +135,6 @@
<string name="msg_member_already_added">You have already selected this user</string> <string name="msg_member_already_added">You have already selected this user</string>
<string name="msg_member_not_found">Member not found</string> <string name="msg_member_not_found">Member not found</string>
<string name="msg_channel_created_successfully">Channel created successfully</string> <string name="msg_channel_created_successfully">Channel created successfully</string>
<string name="msg_message_copied">Message copied</string> <string name="msg_message_copied">Message copied</string>
<string name="msg_delete_message">Delete Message</string> <string name="msg_delete_message">Delete Message</string>
<string name="msg_delete_description">Are you sure you want to delete this message</string> <string name="msg_delete_description">Are you sure you want to delete this message</string>
......
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