mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 03:29:28 +01:00
fix jumping Note to self option in message action dialog.
Only get room for Note to Self after clicking on the option.. Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
82f63c0598
commit
c6d1f68442
@ -3295,37 +3295,61 @@ class ChatActivity :
|
||||
}
|
||||
}
|
||||
|
||||
fun shareToNotes(message: ChatMessage, roomToken: String) {
|
||||
var shareUri: Uri? = null
|
||||
val data: HashMap<String?, String?>?
|
||||
var metaData: String = ""
|
||||
var objectId: String = ""
|
||||
if (message.hasFileAttachment()) {
|
||||
val filename = message.selectedIndividualHashMap!!["name"]
|
||||
path = applicationContext.cacheDir.absolutePath + "/" + filename
|
||||
shareUri = FileProvider.getUriForFile(
|
||||
this,
|
||||
BuildConfig.APPLICATION_ID,
|
||||
File(path)
|
||||
)
|
||||
fun shareToNotes(message: ChatMessage) {
|
||||
val apiVersion = ApiUtils.getConversationApiVersion(
|
||||
conversationUser!!,
|
||||
intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1)
|
||||
)
|
||||
chatViewModel.checkForNoteToSelf(
|
||||
ApiUtils.getCredentials(conversationUser!!.username, conversationUser!!.token)!!,
|
||||
ApiUtils.getUrlForRooms(
|
||||
apiVersion,
|
||||
conversationUser!!.baseUrl
|
||||
),
|
||||
false
|
||||
)
|
||||
|
||||
this.grantUriPermission(
|
||||
applicationContext.packageName,
|
||||
shareUri,
|
||||
Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
)
|
||||
} else if (message.hasGeoLocation()) {
|
||||
data = message.messageParameters?.get("object")
|
||||
objectId = data?.get("id")!!
|
||||
val name = data["name"]!!
|
||||
val lat = data["latitude"]!!
|
||||
val lon = data["longitude"]!!
|
||||
metaData =
|
||||
"{\"type\":\"geo-location\",\"id\":\"geo:$lat,$lon\",\"latitude\":\"$lat\"," +
|
||||
"\"longitude\":\"$lon\",\"name\":\"$name\"}"
|
||||
chatViewModel.getNoteToSelfAvailability.observe(this) { state ->
|
||||
when (state) {
|
||||
is ChatViewModel.NoteToSelfAvailableState -> {
|
||||
this.lifecycleScope.launch {
|
||||
var shareUri: Uri? = null
|
||||
val data: HashMap<String?, String?>?
|
||||
var metaData: String = ""
|
||||
var objectId: String = ""
|
||||
if (message.hasFileAttachment()) {
|
||||
val filename = message.selectedIndividualHashMap!!["name"]
|
||||
path = applicationContext.cacheDir.absolutePath + "/" + filename
|
||||
shareUri = FileProvider.getUriForFile(
|
||||
context,
|
||||
BuildConfig.APPLICATION_ID,
|
||||
File(path)
|
||||
)
|
||||
|
||||
grantUriPermission(
|
||||
applicationContext.packageName,
|
||||
shareUri,
|
||||
Intent.FLAG_GRANT_WRITE_URI_PERMISSION or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
)
|
||||
} else if (message.hasGeoLocation()) {
|
||||
data = message.messageParameters?.get("object")
|
||||
objectId = data?.get("id")!!
|
||||
val name = data["name"]!!
|
||||
val lat = data["latitude"]!!
|
||||
val lon = data["longitude"]!!
|
||||
metaData =
|
||||
"{\"type\":\"geo-location\",\"id\":\"geo:$lat,$lon\",\"latitude\":\"$lat\"," +
|
||||
"\"longitude\":\"$lon\",\"name\":\"$name\"}"
|
||||
}
|
||||
|
||||
shareToNotes(shareUri, state.roomToken, message, objectId, metaData)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
Snackbar.make(binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shareToNotes(shareUri, roomToken, message, objectId, metaData)
|
||||
}
|
||||
|
||||
private fun shareToNotes(
|
||||
|
@ -25,7 +25,6 @@ import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.chat.ChatActivity
|
||||
import com.nextcloud.talk.chat.data.model.ChatMessage
|
||||
import com.nextcloud.talk.chat.viewmodels.ChatViewModel
|
||||
import com.nextcloud.talk.data.network.NetworkMonitor
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.databinding.DialogMessageActionsBinding
|
||||
@ -36,7 +35,6 @@ import com.nextcloud.talk.models.json.capabilities.SpreedCapability
|
||||
import com.nextcloud.talk.models.json.conversations.ConversationEnums
|
||||
import com.nextcloud.talk.repositories.reactions.ReactionsRepository
|
||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.CapabilitiesUtil
|
||||
import com.nextcloud.talk.utils.CapabilitiesUtil.hasSpreedFeatureCapability
|
||||
import com.nextcloud.talk.utils.ConversationUtils
|
||||
@ -123,35 +121,6 @@ class MessageActionsDialog(
|
||||
viewThemeUtils.material.colorBottomSheetDragHandle(dialogMessageActionsBinding.bottomSheetDragHandle)
|
||||
initEmojiBar(hasChatPermission)
|
||||
initMenuItemCopy(!message.isDeleted)
|
||||
val apiVersion = ApiUtils.getConversationApiVersion(user!!, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1))
|
||||
chatActivity.chatViewModel.checkForNoteToSelf(
|
||||
ApiUtils.getCredentials(user.username, user.token)!!,
|
||||
ApiUtils.getUrlForRooms(
|
||||
apiVersion,
|
||||
user.baseUrl
|
||||
),
|
||||
false
|
||||
)
|
||||
chatActivity.chatViewModel.getNoteToSelfAvailability.observe(this) { state ->
|
||||
when (state) {
|
||||
is ChatViewModel.NoteToSelfAvailableState -> {
|
||||
this.lifecycleScope.launch {
|
||||
initMenuAddToNote(
|
||||
!message.isDeleted &&
|
||||
!ConversationUtils.isNoteToSelfConversation(currentConversation) &&
|
||||
networkMonitor.isOnline.value,
|
||||
state.roomToken
|
||||
)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
initMenuAddToNote(
|
||||
false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
initMenuItems(networkMonitor.isOnline.value)
|
||||
}
|
||||
|
||||
@ -195,6 +164,11 @@ class MessageActionsDialog(
|
||||
isOnline
|
||||
)
|
||||
initMenuItemSave(message.getCalculateMessageType() == ChatMessage.MessageType.SINGLE_NC_ATTACHMENT_MESSAGE)
|
||||
initMenuAddToNote(
|
||||
!message.isDeleted &&
|
||||
!ConversationUtils.isNoteToSelfConversation(currentConversation) &&
|
||||
networkMonitor.isOnline.value
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -472,10 +446,10 @@ class MessageActionsDialog(
|
||||
dialogMessageActionsBinding.menuSaveMessage.visibility = getVisibility(visible)
|
||||
}
|
||||
|
||||
private fun initMenuAddToNote(visible: Boolean, roomToken: String = "") {
|
||||
private fun initMenuAddToNote(visible: Boolean) {
|
||||
if (visible) {
|
||||
dialogMessageActionsBinding.menuShareToNote.setOnClickListener {
|
||||
chatActivity.shareToNotes(message, roomToken)
|
||||
chatActivity.shareToNotes(message)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user