Allow multiple file sharing (previously was picture only) & fixed text sharing
This commit is contained in:
parent
e2725f23ae
commit
6501cd5e9d
5 changed files with 38 additions and 6 deletions
|
@ -65,6 +65,9 @@
|
|||
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="image/*" />
|
||||
<data android:mimeType="audio/*" />
|
||||
<data android:mimeType="video/*" />
|
||||
<data android:mimeType="application/*" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
|
|
|
@ -149,13 +149,17 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
|
|||
private fun handleIntentParams(intent: Intent) {
|
||||
when (intent.action) {
|
||||
Intent.ACTION_SEND, Intent.ACTION_SENDTO -> {
|
||||
lifecycleScope.launch {
|
||||
handleSendImage(intent)
|
||||
if (intent.type?.startsWith("text/") == true) {
|
||||
handleSendText(intent)
|
||||
} else {
|
||||
lifecycleScope.launch {
|
||||
handleSendFile(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
Intent.ACTION_SEND_MULTIPLE -> {
|
||||
lifecycleScope.launch {
|
||||
handleSendMultipleImages(intent)
|
||||
handleSendMultipleFiles(intent)
|
||||
}
|
||||
}
|
||||
Intent.ACTION_VIEW -> {
|
||||
|
@ -224,7 +228,15 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun handleSendImage(intent: Intent) {
|
||||
private fun handleSendText(intent: Intent) {
|
||||
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
|
||||
sharedViewModel.textToShare.value = it
|
||||
}
|
||||
|
||||
handleSendChatRoom(intent)
|
||||
}
|
||||
|
||||
private suspend fun handleSendFile(intent: Intent) {
|
||||
(intent.getParcelableExtra<Parcelable>(Intent.EXTRA_STREAM) as? Uri)?.let {
|
||||
val list = arrayListOf<String>()
|
||||
coroutineScope {
|
||||
|
@ -243,7 +255,7 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
|
|||
handleSendChatRoom(intent)
|
||||
}
|
||||
|
||||
private suspend fun handleSendMultipleImages(intent: Intent) {
|
||||
private suspend fun handleSendMultipleFiles(intent: Intent) {
|
||||
intent.getParcelableArrayListExtra<Parcelable>(Intent.EXTRA_STREAM)?.let {
|
||||
val list = arrayListOf<String>()
|
||||
coroutineScope {
|
||||
|
@ -264,7 +276,7 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
|
|||
handleSendChatRoom(intent)
|
||||
}
|
||||
|
||||
private suspend fun handleSendChatRoom(intent: Intent) {
|
||||
private fun handleSendChatRoom(intent: Intent) {
|
||||
val uri = intent.data
|
||||
if (uri != null) {
|
||||
Log.i("[Main Activity] Found uri: $uri to send a message to")
|
||||
|
|
|
@ -238,6 +238,14 @@ class DetailChatRoomFragment : MasterFragment() {
|
|||
coreContext.startCall(viewModel.addressToCall)
|
||||
}
|
||||
|
||||
sharedViewModel.textToShare.observe(viewLifecycleOwner, Observer {
|
||||
if (it.isNotEmpty()) {
|
||||
Log.i("[Chat Room] Found text to share")
|
||||
chatSendingViewModel.textToSend.value = it
|
||||
sharedViewModel.textToShare.value = ""
|
||||
}
|
||||
})
|
||||
|
||||
sharedViewModel.filesToShare.observe(viewLifecycleOwner, Observer {
|
||||
if (it.isNotEmpty()) {
|
||||
for (path in it) {
|
||||
|
|
|
@ -207,6 +207,13 @@ class MasterChatRoomsFragment : MasterFragment() {
|
|||
adapter.selectedChatRoomEvent.value = Event(chatRoom)
|
||||
}
|
||||
} else {
|
||||
sharedViewModel.textToShare.observe(viewLifecycleOwner, Observer {
|
||||
if (it.isNotEmpty()) {
|
||||
Log.i("[Chat] Found text to share")
|
||||
val activity = requireActivity() as MainActivity
|
||||
activity.showSnackBar(R.string.chat_room_toast_choose_for_sharing)
|
||||
}
|
||||
})
|
||||
sharedViewModel.filesToShare.observe(viewLifecycleOwner, Observer {
|
||||
if (it.isNotEmpty()) {
|
||||
Log.i("[Chat] Found ${it.size} files to share")
|
||||
|
|
|
@ -40,6 +40,8 @@ class SharedMainViewModel : ViewModel() {
|
|||
|
||||
val filesToShare = MutableLiveData<ArrayList<String>>()
|
||||
|
||||
val textToShare = MutableLiveData<String>()
|
||||
|
||||
val messageToForwardEvent: MutableLiveData<Event<ChatMessage>> by lazy {
|
||||
MutableLiveData<Event<ChatMessage>>()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue