This repository has been archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 553
[NEW][RFC] Support receiving shared content (audio/video/text) #874
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import android.content.Intent | |
import android.net.Uri | ||
import android.os.Bundle | ||
import android.os.Handler | ||
import android.os.Parcelable | ||
import android.support.annotation.DrawableRes | ||
import android.support.v4.app.Fragment | ||
import android.support.v7.widget.DefaultItemAnimator | ||
|
@@ -28,22 +29,33 @@ import chat.rocket.android.widget.emoji.Emoji | |
import chat.rocket.android.widget.emoji.EmojiKeyboardPopup | ||
import chat.rocket.android.widget.emoji.EmojiParser | ||
import chat.rocket.core.internal.realtime.State | ||
import chat.rocket.android.widget.share.ui.ShareBottomSheetDialog.Companion.ARGUMENT_SHARED_CONTENT | ||
import dagger.android.support.AndroidSupportInjection | ||
import io.reactivex.disposables.CompositeDisposable | ||
import kotlinx.android.synthetic.main.fragment_chat_room.* | ||
import kotlinx.android.synthetic.main.message_attachment_options.* | ||
import kotlinx.android.synthetic.main.message_composer.* | ||
import kotlinx.android.synthetic.main.message_list.* | ||
import timber.log.Timber | ||
import java.util.ArrayList | ||
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, shareableContent: Any?): Fragment { | ||
return ChatRoomFragment().apply { | ||
arguments = Bundle(1).apply { | ||
putString(BUNDLE_CHAT_ROOM_ID, chatRoomId) | ||
putString(BUNDLE_CHAT_ROOM_NAME, chatRoomName) | ||
putString(BUNDLE_CHAT_ROOM_TYPE, chatRoomType) | ||
putBoolean(BUNDLE_IS_CHAT_ROOM_READ_ONLY, isChatRoomReadOnly) | ||
shareableContent?.let { | ||
when (it) { | ||
is String -> putString(ARGUMENT_SHARED_CONTENT, it) | ||
is Uri -> putParcelable(ARGUMENT_SHARED_CONTENT, it) | ||
is ArrayList<*> -> if (it.size > 0 && it[0] is Uri) { | ||
putParcelableArrayList(ARGUMENT_SHARED_CONTENT, it as ArrayList<out Parcelable>) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -63,6 +75,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener { | |
private lateinit var chatRoomName: String | ||
private lateinit var chatRoomType: String | ||
private lateinit var emojiKeyboardPopup: EmojiKeyboardPopup | ||
private var contentToShare: Any? = null | ||
private var isChatRoomReadOnly: Boolean = false | ||
|
||
private lateinit var actionSnackbar: ActionSnackbar | ||
|
@@ -89,6 +102,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener { | |
chatRoomName = bundle.getString(BUNDLE_CHAT_ROOM_NAME) | ||
chatRoomType = bundle.getString(BUNDLE_CHAT_ROOM_TYPE) | ||
isChatRoomReadOnly = bundle.getBoolean(BUNDLE_IS_CHAT_ROOM_READ_ONLY) | ||
contentToShare = bundle.get(ARGUMENT_SHARED_CONTENT) | ||
} else { | ||
requireNotNull(bundle) { "no arguments supplied when the fragment was instantiated" } | ||
} | ||
|
@@ -174,6 +188,14 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener { | |
if (oldMessagesCount == 0 && dataSet.isNotEmpty()) { | ||
recycler_view.scrollToPosition(0) | ||
} | ||
contentToShare?.let { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't know if this is the right place to "plug" this... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know you are waiting the message list to be populated, but maybe we need a new callback on the View, to indicate the first messages are loaded. |
||
when (it) { | ||
is String -> sendMessage(it) | ||
is Uri -> uploadFile(uri = it) | ||
is ArrayList<*> -> it.forEach { uri -> uploadFile(uri as Uri) } | ||
} | ||
contentToShare = null | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/src/main/java/chat/rocket/android/main/presentation/ChatRoomsViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package chat.rocket.android.main.presentation | ||
|
||
import android.arch.lifecycle.LiveData | ||
import android.arch.lifecycle.MutableLiveData | ||
import android.arch.lifecycle.ViewModel | ||
import chat.rocket.core.model.ChatRoom | ||
|
||
class ChatRoomsViewModel : ViewModel() { | ||
private val chatRoomsLiveData = MutableLiveData<List<ChatRoom>>() | ||
private val selectedChatRoom = MutableLiveData<Pair<ChatRoom, Any>>() | ||
|
||
fun setChatRooms(chatRooms: List<ChatRoom>) { | ||
chatRoomsLiveData.setValue(chatRooms) | ||
} | ||
|
||
fun getChatRooms(): LiveData<List<ChatRoom>> = chatRoomsLiveData | ||
|
||
fun selectChatRoom(chatRoom: ChatRoom, content: Any?) { | ||
content?.let { | ||
selectedChatRoom.value = Pair(chatRoom, it) | ||
} | ||
} | ||
|
||
fun getSelectedChatRoom(): LiveData<Pair<ChatRoom, Any>> = selectedChatRoom | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it.isNotEmpty()