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" />
|
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
<data android:mimeType="image/*" />
|
<data android:mimeType="image/*" />
|
||||||
|
<data android:mimeType="audio/*" />
|
||||||
|
<data android:mimeType="video/*" />
|
||||||
|
<data android:mimeType="application/*" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|
|
@ -149,13 +149,17 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
|
||||||
private fun handleIntentParams(intent: Intent) {
|
private fun handleIntentParams(intent: Intent) {
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
Intent.ACTION_SEND, Intent.ACTION_SENDTO -> {
|
Intent.ACTION_SEND, Intent.ACTION_SENDTO -> {
|
||||||
lifecycleScope.launch {
|
if (intent.type?.startsWith("text/") == true) {
|
||||||
handleSendImage(intent)
|
handleSendText(intent)
|
||||||
|
} else {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
handleSendFile(intent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Intent.ACTION_SEND_MULTIPLE -> {
|
Intent.ACTION_SEND_MULTIPLE -> {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
handleSendMultipleImages(intent)
|
handleSendMultipleFiles(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Intent.ACTION_VIEW -> {
|
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 {
|
(intent.getParcelableExtra<Parcelable>(Intent.EXTRA_STREAM) as? Uri)?.let {
|
||||||
val list = arrayListOf<String>()
|
val list = arrayListOf<String>()
|
||||||
coroutineScope {
|
coroutineScope {
|
||||||
|
@ -243,7 +255,7 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
|
||||||
handleSendChatRoom(intent)
|
handleSendChatRoom(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun handleSendMultipleImages(intent: Intent) {
|
private suspend fun handleSendMultipleFiles(intent: Intent) {
|
||||||
intent.getParcelableArrayListExtra<Parcelable>(Intent.EXTRA_STREAM)?.let {
|
intent.getParcelableArrayListExtra<Parcelable>(Intent.EXTRA_STREAM)?.let {
|
||||||
val list = arrayListOf<String>()
|
val list = arrayListOf<String>()
|
||||||
coroutineScope {
|
coroutineScope {
|
||||||
|
@ -264,7 +276,7 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
|
||||||
handleSendChatRoom(intent)
|
handleSendChatRoom(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun handleSendChatRoom(intent: Intent) {
|
private fun handleSendChatRoom(intent: Intent) {
|
||||||
val uri = intent.data
|
val uri = intent.data
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
Log.i("[Main Activity] Found uri: $uri to send a message to")
|
Log.i("[Main Activity] Found uri: $uri to send a message to")
|
||||||
|
|
|
@ -238,6 +238,14 @@ class DetailChatRoomFragment : MasterFragment() {
|
||||||
coreContext.startCall(viewModel.addressToCall)
|
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 {
|
sharedViewModel.filesToShare.observe(viewLifecycleOwner, Observer {
|
||||||
if (it.isNotEmpty()) {
|
if (it.isNotEmpty()) {
|
||||||
for (path in it) {
|
for (path in it) {
|
||||||
|
|
|
@ -207,6 +207,13 @@ class MasterChatRoomsFragment : MasterFragment() {
|
||||||
adapter.selectedChatRoomEvent.value = Event(chatRoom)
|
adapter.selectedChatRoomEvent.value = Event(chatRoom)
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
sharedViewModel.filesToShare.observe(viewLifecycleOwner, Observer {
|
||||||
if (it.isNotEmpty()) {
|
if (it.isNotEmpty()) {
|
||||||
Log.i("[Chat] Found ${it.size} files to share")
|
Log.i("[Chat] Found ${it.size} files to share")
|
||||||
|
|
|
@ -40,6 +40,8 @@ class SharedMainViewModel : ViewModel() {
|
||||||
|
|
||||||
val filesToShare = MutableLiveData<ArrayList<String>>()
|
val filesToShare = MutableLiveData<ArrayList<String>>()
|
||||||
|
|
||||||
|
val textToShare = MutableLiveData<String>()
|
||||||
|
|
||||||
val messageToForwardEvent: MutableLiveData<Event<ChatMessage>> by lazy {
|
val messageToForwardEvent: MutableLiveData<Event<ChatMessage>> by lazy {
|
||||||
MutableLiveData<Event<ChatMessage>>()
|
MutableLiveData<Event<ChatMessage>>()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue