Commit cb1aebab authored by divyanshu's avatar divyanshu

Merge branch 'develop-2.x' into send-msg-attachments

# Conflicts:
#	app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomFragment.kt
#	app/src/main/res/menu/chatroom_actions.xml
parents 2df5a82f 124b8519
......@@ -51,6 +51,7 @@ class ChatRoomNavigator(internal val activity: ChatRoomActivity) {
chatRoomLastSeen: Long,
isChatRoomSubscribed: Boolean,
isChatRoomCreator: Boolean,
isChatRoomFavorite: Boolean,
chatRoomMessage: String
) {
activity.startActivity(
......@@ -62,6 +63,7 @@ class ChatRoomNavigator(internal val activity: ChatRoomActivity) {
chatRoomLastSeen,
isChatRoomSubscribed,
isChatRoomCreator,
isChatRoomFavorite,
chatRoomMessage
)
)
......
......@@ -62,6 +62,7 @@ import chat.rocket.core.internal.rest.unpinMessage
import chat.rocket.core.internal.rest.unstarMessage
import chat.rocket.core.internal.rest.updateMessage
import chat.rocket.core.internal.rest.uploadFile
import chat.rocket.core.internal.rest.favorite
import chat.rocket.core.model.ChatRoomRole
import chat.rocket.core.model.Command
import chat.rocket.core.model.Message
......@@ -723,6 +724,25 @@ class ChatRoomPresenter @Inject constructor(
}
}
fun toggleFavoriteChatRoom(roomId: String, isFavorite: Boolean) {
launchUI(strategy) {
try {
// Note that if it is favorite then the user wants to unfavorite - and vice versa.
retryIO("favorite($roomId, $isFavorite)") {
client.favorite(roomId, !isFavorite)
}
view.showFavoriteIcon(!isFavorite)
} catch (e: RocketChatException) {
Timber.e(e, "Error while trying to favorite/unfavorite chat room.")
e.message?.let {
view.showMessage(it)
}.ifNull {
view.showGenericErrorMessage()
}
}
}
}
fun toMembersList(chatRoomId: String) =
navigator.toMembersList(chatRoomId)
......@@ -785,6 +805,7 @@ class ChatRoomPresenter @Inject constructor(
chatRoomLastSeen = it.lastSeen ?: -1,
chatRoomName = roomName,
isChatRoomCreator = false,
isChatRoomFavorite = false,
isChatRoomReadOnly = false,
isChatRoomSubscribed = it.open,
chatRoomMessage = message
......
......@@ -12,6 +12,13 @@ import chat.rocket.core.model.ChatRoom
interface ChatRoomView : LoadingView, MessageView {
/**
* Shows the Favorite/Unfavorite chat room icon.
*
* @param isFavorite Shows the favorite icon if true, otherwise shows the unfavorite icon.
*/
fun showFavoriteIcon(isFavorite: Boolean)
/**
* Shows the chat room messages.
*
......
......@@ -27,20 +27,22 @@ fun Context.chatRoomIntent(
chatRoomId: String,
chatRoomName: String,
chatRoomType: String,
isChatRoomReadOnly: Boolean,
isReadOnly: Boolean,
chatRoomLastSeen: Long,
isChatRoomSubscribed: Boolean = true,
isChatRoomCreator: Boolean = false,
isSubscribed: Boolean = true,
isCreator: Boolean = false,
isFavorite: Boolean = false,
chatRoomMessage: String? = null
): Intent {
return Intent(this, ChatRoomActivity::class.java).apply {
putExtra(INTENT_CHAT_ROOM_ID, chatRoomId)
putExtra(INTENT_CHAT_ROOM_NAME, chatRoomName)
putExtra(INTENT_CHAT_ROOM_TYPE, chatRoomType)
putExtra(INTENT_CHAT_ROOM_IS_READ_ONLY, isChatRoomReadOnly)
putExtra(INTENT_CHAT_ROOM_IS_READ_ONLY, isReadOnly)
putExtra(INTENT_CHAT_ROOM_LAST_SEEN, chatRoomLastSeen)
putExtra(INTENT_CHAT_IS_SUBSCRIBED, isChatRoomSubscribed)
putExtra(INTENT_CHAT_ROOM_IS_CREATOR, isChatRoomCreator)
putExtra(INTENT_CHAT_IS_SUBSCRIBED, isSubscribed)
putExtra(INTENT_CHAT_ROOM_IS_CREATOR, isCreator)
putExtra(INTENT_CHAT_ROOM_IS_FAVORITE, isFavorite)
putExtra(INTENT_CHAT_ROOM_MESSAGE, chatRoomMessage)
}
}
......@@ -50,6 +52,7 @@ private const val INTENT_CHAT_ROOM_NAME = "chat_room_name"
private const val INTENT_CHAT_ROOM_TYPE = "chat_room_type"
private const val INTENT_CHAT_ROOM_IS_READ_ONLY = "chat_room_is_read_only"
private const val INTENT_CHAT_ROOM_IS_CREATOR = "chat_room_is_creator"
private const val INTENT_CHAT_ROOM_IS_FAVORITE = "chat_room_is_favorite"
private const val INTENT_CHAT_ROOM_LAST_SEEN = "chat_room_last_seen"
private const val INTENT_CHAT_IS_SUBSCRIBED = "is_chat_room_subscribed"
private const val INTENT_CHAT_ROOM_MESSAGE = "chat_room_message"
......@@ -89,13 +92,15 @@ class ChatRoomActivity : AppCompatActivity(), HasSupportFragmentInjector {
val chatRoomType = intent.getStringExtra(INTENT_CHAT_ROOM_TYPE)
requireNotNull(chatRoomType) { "no chat_room_type provided in Intent extras" }
val isChatRoomReadOnly = intent.getBooleanExtra(INTENT_CHAT_ROOM_IS_READ_ONLY, true)
val isReadOnly = intent.getBooleanExtra(INTENT_CHAT_ROOM_IS_READ_ONLY, true)
val isChatRoomCreator = intent.getBooleanExtra(INTENT_CHAT_ROOM_IS_CREATOR, false)
val isCreator = intent.getBooleanExtra(INTENT_CHAT_ROOM_IS_CREATOR, false)
val isFavorite = intent.getBooleanExtra(INTENT_CHAT_ROOM_IS_FAVORITE, false)
val chatRoomLastSeen = intent.getLongExtra(INTENT_CHAT_ROOM_LAST_SEEN, -1)
val isChatRoomSubscribed = intent.getBooleanExtra(INTENT_CHAT_IS_SUBSCRIBED, true)
val isSubscribed = intent.getBooleanExtra(INTENT_CHAT_IS_SUBSCRIBED, true)
val chatRoomMessage = intent.getStringExtra(INTENT_CHAT_ROOM_MESSAGE)
......@@ -104,8 +109,15 @@ class ChatRoomActivity : AppCompatActivity(), HasSupportFragmentInjector {
if (supportFragmentManager.findFragmentByTag(TAG_CHAT_ROOM_FRAGMENT) == null) {
addFragment(TAG_CHAT_ROOM_FRAGMENT, R.id.fragment_container) {
newInstance(
chatRoomId, chatRoomName, chatRoomType, isChatRoomReadOnly, chatRoomLastSeen,
isChatRoomSubscribed, isChatRoomCreator, chatRoomMessage
chatRoomId,
chatRoomName,
chatRoomType,
isReadOnly,
chatRoomLastSeen,
isSubscribed,
isCreator,
isFavorite,
chatRoomMessage
)
}
}
......
package chat.rocket.android.chatroom.ui
import android.app.Activity
import android.app.AlertDialog
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
......@@ -17,11 +16,6 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.Button
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.DrawableRes
import androidx.core.text.bold
import androidx.core.view.isVisible
......@@ -61,8 +55,6 @@ import chat.rocket.android.util.extensions.inflate
import chat.rocket.android.util.extensions.rotateBy
import chat.rocket.android.util.extensions.showToast
import chat.rocket.android.util.extensions.textContent
import chat.rocket.android.util.extensions.getMimeType
import chat.rocket.android.util.extensions.getFileName
import chat.rocket.android.util.extensions.ui
import chat.rocket.common.model.RoomType
import chat.rocket.common.model.roomTypeOf
......@@ -224,53 +216,11 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
if (requestCode == REQUEST_CODE_FOR_PERFORM_SAF && resultCode == Activity.RESULT_OK) {
if (resultData != null) {
fileAttachmentDialog(resultData.data)
uploadFile(resultData.data)
}
}
}
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 onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.chatroom_actions, menu)
......@@ -465,8 +415,9 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
}
override fun uploadFile(uri: Uri, msg: String) {
presenter.uploadFile(chatRoomId, uri, msg)
override fun uploadFile(uri: Uri) {
// 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, "")
}
override fun showInvalidFileMessage() {
......
......@@ -60,9 +60,17 @@ class ChatRoomsPresenter @Inject constructor(
} else {
id
}
val isChatRoomOwner = ownerId == myself.id || isDirectMessage
navigator.toChatRoom(id, roomName, type, readonly ?: false,
lastSeen ?: -1, open, isChatRoomOwner)
navigator.toChatRoom(
chatRoomId = id,
chatRoomName = roomName,
chatRoomType = type,
isReadOnly = readonly ?: false,
chatRoomLastSeen = lastSeen ?: -1,
isSubscribed = open,
isCreator = ownerId == myself.id || isDirectMessage,
isFavorite = favorite ?: false
)
}
}
}
......
......@@ -41,20 +41,22 @@ class MainNavigator(internal val activity: MainActivity) {
chatRoomId: String,
chatRoomName: String,
chatRoomType: String,
isChatRoomReadOnly: Boolean,
isReadOnly: Boolean,
chatRoomLastSeen: Long,
isChatRoomSubscribed: Boolean,
isChatRoomCreator: Boolean
isSubscribed: Boolean,
isCreator: Boolean,
isFavorite: Boolean
) {
activity.startActivity(
activity.chatRoomIntent(
chatRoomId,
chatRoomName,
chatRoomType,
isChatRoomReadOnly,
isReadOnly,
chatRoomLastSeen,
isChatRoomSubscribed,
isChatRoomCreator
isSubscribed,
isCreator,
isFavorite
)
)
activity.overridePendingTransition(R.anim.open_enter, R.anim.open_exit)
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M22,9.24l-7.19,-0.62L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21 12,17.27 18.18,21l-1.63,-7.03L22,9.24zM12,15.4l-3.76,2.27 1,-4.28 -3.32,-2.88 4.38,-0.38L12,6.1l1.71,4.04 4.38,0.38 -3.32,2.88 1,4.28L12,15.4z" />
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFF59D"
android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z" />
</vector>
......@@ -9,7 +9,7 @@
<item
android:id="@+id/action_mentions"
android:title="@string/msg_mentions"
android:showAsAction="never" />
app:showAsAction="never" />
<item
android:id="@+id/action_pinned_messages"
......
......@@ -192,6 +192,11 @@
// TODO: Add proper translation.
<string name="permission_starring_not_allowed">Starring is not allowed</string>
<!-- Favorite/Unfavorite chat room -->
<!-- TODO Add proper translation-->
<string name="title_favorite_chat">Favorite chat</string>
<string name="title_unfavorite_chat">Unfavorite chat</string>
<!-- Members List -->
<string name="title_members_list">Miembros</string>
......@@ -214,7 +219,7 @@
<!-- Files -->
<!-- TODO Add proper translation-->
<string name="msg_files">Files</string>
<string name="title_files">Files</string>
<string name="title_files_total">Files (%d)</string>
<string name="msg_no_files">No files</string>
<string name="msg_all_files_appear_here">All the files appear here</string>
......
......@@ -192,6 +192,11 @@
// TODO: Add proper translation.
<string name="permission_starring_not_allowed">Starring is not allowed</string>
<!-- Favorite/Unfavorite chat room -->
<!-- TODO Add proper translation-->
<string name="title_favorite_chat">Favorite chat</string>
<string name="title_unfavorite_chat">Unfavorite chat</string>
<!-- Members List -->
<string name="title_members_list">Membres</string>
......@@ -214,7 +219,7 @@
<!-- Files -->
<!-- TODO Add proper translation-->
<string name="msg_files">Files</string>
<string name="title_files">Files</string>
<string name="title_files_total">Files (%d)</string>
<string name="msg_no_files">No files</string>
<string name="msg_all_files_appear_here">All the files appear here</string>
......
......@@ -178,6 +178,11 @@
<string name="permission_pinning_not_allowed">पिनि करने की अनुमति नहीं है</string>
<string name="permission_starring_not_allowed">तारांकित की अनुमति नहीं है</string>
<!-- Favorite/Unfavorite chat room -->
<!-- TODO Add proper translation-->
<string name="title_favorite_chat">Favorite chat</string>
<string name="title_unfavorite_chat">Unfavorite chat</string>
<!-- Members List -->
<string name="title_members_list">सदस्य</string>
......@@ -198,7 +203,7 @@
<string name="no_favorite_description">सभी पसंदीदा संदेश यहां\nदिखाई देते हैं</string>
<!-- Files -->
<string name="msg_files">फ़ाइलें</string>
<string name="title_files">फ़ाइलें</string>
<string name="title_files_total">फ़ाइलें (%d)</string>
<string name="msg_no_files">कोई फाइल नहीं है</string>
<string name="msg_all_files_appear_here">सभी फाइलें यहां दिखाई देती हैं</string>
......
......@@ -175,6 +175,10 @@
<string name="permission_pinning_not_allowed">Pinagem não permitida</string>
<string name="permission_starring_not_allowed">Favoritar não permitido</string>
<!-- Favorite/Unfavorite chat room -->
<string name="title_favorite_chat">Favoritar canal</string>
<string name="title_unfavorite_chat">Desfavoritar canal</string>
<!-- Members List -->
<string name="title_members_list">Membros</string>
......@@ -194,7 +198,7 @@
<string name="no_favorite_description">Todas mensagens favoritas\naparecerão aqui</string>
<!-- Files -->
<string name="msg_files">Arquivos</string>
<string name="title_files">Arquivos</string>
<string name="title_files_total">Arquivos (%d)</string>
<string name="msg_no_files">Nenhum arquivo</string>
<string name="msg_all_files_appear_here">Todos arquivos aparecerão aqui</string>
......
......@@ -171,6 +171,11 @@
<string name="permission_pinning_not_allowed">Прикрепление запрещено</string>
<string name="permission_starring_not_allowed">Отмечивание запрещено</string>
<!-- Favorite/Unfavorite chat room -->
<!-- TODO Add proper translation-->
<string name="title_favorite_chat">Favorite chat</string>
<string name="title_unfavorite_chat">Unfavorite chat</string>
<!-- Members List -->
<string name="title_members_list">Пользователи</string>
......@@ -190,7 +195,7 @@
<string name="no_favorite_description">Все избранные сообщения\nотображаются здесь</string>
<!-- Files -->
<string name="msg_files">Файлы</string>
<string name="title_files">Файлы</string>
<string name="title_files_total">Файлы (%d)</string>
<string name="msg_no_files">Нет файлов</string>
<string name="msg_all_files_appear_here">Все файлы отображаются здесь</string>
......
......@@ -173,6 +173,10 @@
<string name="permission_pinning_not_allowed">Pinning is not allowed</string>
<string name="permission_starring_not_allowed">Starring is not allowed</string>
<!-- Favorite/Unfavorite chat room -->
<string name="title_favorite_chat">Favorite chat</string>
<string name="title_unfavorite_chat">Unfavorite chat</string>
<!-- Members List -->
<string name="title_members_list">Members</string>
......@@ -192,7 +196,7 @@
<string name="no_favorite_description">All the favorite messages\nappear here</string>
<!-- Files -->
<string name="msg_files">Files</string>
<string name="title_files">Files</string>
<string name="title_files_total">Files (%d)</string>
<string name="msg_no_files">No files</string>
<string name="msg_all_files_appear_here">All the files appear here</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