Skip to content

Commit

Permalink
WIP file caption - Reverted Changes + Added Camera Implementation
Browse files Browse the repository at this point in the history
Signed-off-by: rapterjet2004 <[email protected]>
  • Loading branch information
rapterjet2004 committed Nov 3, 2023
1 parent 4326c7e commit 7f864ce
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.nextcloud.talk.databinding.ItemCustomIncomingPreviewMessageBinding;
import com.nextcloud.talk.databinding.ReactionsInsideMessageBinding;
import com.nextcloud.talk.models.json.chat.ChatMessage;
import com.nextcloud.talk.ui.ImageStackContainer;
import com.nextcloud.talk.utils.TextMatchers;

import java.util.HashMap;
Expand Down Expand Up @@ -140,10 +139,4 @@ public ProgressBar getPreviewContactProgressBar() {

@Override
public ReactionsInsideMessageBinding getReactionsBinding(){ return binding.reactions; }

@NonNull
@Override
public ImageStackContainer getImageStack() {
return binding.imageStack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@
import com.nextcloud.talk.databinding.ItemCustomOutcomingPreviewMessageBinding;
import com.nextcloud.talk.databinding.ReactionsInsideMessageBinding;
import com.nextcloud.talk.models.json.chat.ChatMessage;
import com.nextcloud.talk.ui.ImageStackContainer;
import com.nextcloud.talk.utils.TextMatchers;

import java.util.HashMap;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.emoji2.widget.EmojiTextView;

Expand Down Expand Up @@ -133,10 +131,4 @@ public ProgressBar getPreviewContactProgressBar() {

@Override
public EmojiTextView getMessageCaption() { return binding.messageCaption; }

@NonNull
@Override
public ImageStackContainer getImageStack() {
return binding.imageStack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.databinding.ReactionsInsideMessageBinding
import com.nextcloud.talk.extensions.loadChangelogBotAvatar
import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.ui.ImageStackContainer
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.DateUtils
Expand Down Expand Up @@ -121,7 +120,6 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
fileViewerUtils = FileViewerUtils(context!!, message.activeUser!!)
val fileName = message.selectedIndividualHashMap!![KEY_NAME]

imageStack.resetFilePaths(message.filePathList)
messageCaption.visibility = if (message.message != "{file}") {
View.VISIBLE
} else {
Expand Down Expand Up @@ -240,7 +238,6 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
image.setImageDrawable(ContextCompat.getDrawable(context!!, R.drawable.ic_mimetype_text_vcard))
}
} else if (message.displayImageStack()) {
imageStack.visibility = View.VISIBLE
previewContainer.visibility = View.GONE
previewContactContainer.visibility = View.GONE
}
Expand Down Expand Up @@ -335,7 +332,6 @@ abstract class PreviewMessageViewHolder(itemView: View?, payload: Any?) :
abstract val messageText: EmojiTextView
abstract val messageCaption: EmojiTextView
abstract val previewContainer: View
abstract val imageStack: ImageStackContainer
abstract val previewContactContainer: MaterialCardView
abstract val previewContactPhoto: ImageView
abstract val previewContactName: EmojiTextView
Expand Down
114 changes: 47 additions & 67 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,19 @@ class ChatActivity :
}

if (permissionUtil.isFilesPermissionGranted()) {
uploadFiles(filesToUpload)
val filenamesWithLineBreaks = StringBuilder("\n")

for (file in filesToUpload) {
val filename = FileUtils.getFileName(Uri.parse(file), context)
filenamesWithLineBreaks.append(filename).append("\n")
}

val newFragment: DialogFragment = FileAttachmentPreviewFragment.newInstance(
filenamesWithLineBreaks.toString(),
filesToUpload,
this::uploadFiles
)
newFragment.show(supportFragmentManager, FileAttachmentPreviewFragment.TAG)
} else {
UploadAndShareFilesWorker.requestStoragePermission(this)
}
Expand Down Expand Up @@ -2602,12 +2614,12 @@ class ChatActivity :
}

private fun uploadFiles(files: MutableList<String>, caption: String = "") {
// TODO for now all files are uploaded with a caption. In the future, set only one, and just don't render the
// rest, cuz it'll be a group message
val groupKey = SystemClock.elapsedRealtime().toString()
var newCaption = "$groupKey:" + "${files.size}:" + caption
for (file in files) {
uploadFile(file, false, newCaption)
for (i in 0 until files.size) {
if(i == files.size-1) {
uploadFile(files[i], false, caption)
} else {
uploadFile(files[i], false)
}
}
}

Expand Down Expand Up @@ -3168,8 +3180,6 @@ class ChatActivity :

handleExpandableSystemMessages(chatMessageList)

processGroupedFiles(chatMessageList)

processHeaderChatLastGiven(response, lookIntoFuture)

if (chatMessageList.isNotEmpty() &&
Expand All @@ -3191,30 +3201,7 @@ class ChatActivity :
Integer.parseInt(it)
}

try {
val mostRecentCallSystemMessage = adapter?.items?.first {
it.item is ChatMessage &&
(it.item as ChatMessage).systemMessageType in
listOf(
ChatMessage.SystemMessageType.CALL_STARTED,
ChatMessage.SystemMessageType.CALL_JOINED,
ChatMessage.SystemMessageType.CALL_LEFT,
ChatMessage.SystemMessageType.CALL_ENDED,
ChatMessage.SystemMessageType.CALL_TRIED,
ChatMessage.SystemMessageType.CALL_ENDED_EVERYONE,
ChatMessage.SystemMessageType.CALL_MISSED
)
}?.item

if (mostRecentCallSystemMessage != null) {
processMostRecentMessage(
mostRecentCallSystemMessage as ChatMessage,
chatMessageList
)
}
} catch (e: java.util.NoSuchElementException) {
Log.d(TAG, "No System messages found $e")
}
processCallStartedMessages(chatMessageList)

updateReadStatusOfAllMessages(newXChatLastCommonRead)
adapter?.notifyDataSetChanged()
Expand Down Expand Up @@ -3249,6 +3236,33 @@ class ChatActivity :
})
}

private fun processCallStartedMessages(chatMessageList: List<ChatMessage>) {
try {
val mostRecentCallSystemMessage = adapter?.items?.first {
it.item is ChatMessage &&
(it.item as ChatMessage).systemMessageType in
listOf(
ChatMessage.SystemMessageType.CALL_STARTED,
ChatMessage.SystemMessageType.CALL_JOINED,
ChatMessage.SystemMessageType.CALL_LEFT,
ChatMessage.SystemMessageType.CALL_ENDED,
ChatMessage.SystemMessageType.CALL_TRIED,
ChatMessage.SystemMessageType.CALL_ENDED_EVERYONE,
ChatMessage.SystemMessageType.CALL_MISSED
)
}?.item

if (mostRecentCallSystemMessage != null) {
processMostRecentMessage(
mostRecentCallSystemMessage as ChatMessage,
chatMessageList
)
}
} catch (e: NoSuchElementException) {
Log.d(TAG, "No System messages found $e")
}
}

private fun setupFieldsForPullChatMessages(
lookIntoFuture: Boolean,
xChatLastCommonRead: Int?,
Expand Down Expand Up @@ -3324,40 +3338,6 @@ class ChatActivity :
}
}

private fun processGroupedFiles(chatMessageList: List<ChatMessage>) {
val map = mutableMapOf<String, ChatMessage>()
for (message in chatMessageList) {
if (message.getCalculateMessageType() == ChatMessage.MessageType.SINGLE_NC_ATTACHMENT_MESSAGE &&
message.message!!.isNotBlank() && message.message != "{file}"
) {
val groupKey = message.message!!.substringBefore(':')
message.message = message.message!!.substringAfter(':')
val size = message.message!!.substringBefore(':').toInt()
message.message = message.message!!.substringAfter(':')
if (!map.contains(groupKey)) {
map.put(groupKey, message)
message.message = message.message!!.substringAfter(':')
val name = message.messageParameters?.get("file")?.get(PreviewMessageViewHolder.KEY_NAME)
if (name != null) {
val path = applicationContext.cacheDir.absolutePath + "/" + name
message.filePathList.add(path)
adapter?.notifyDataSetChanged()
}
} else {
message.displayedElseWhere = true
val name = message.messageParameters?.get("file")?.get(PreviewMessageViewHolder.KEY_NAME)
if (name != null) {
val path = applicationContext.cacheDir.absolutePath + "/" + name
map[groupKey]!!.filePathList.add(path)
adapter?.notifyDataSetChanged()
}
// TODO for now, both files will be displayed, but I just want to get this to work
// later on I can work on "hiding" the non rendered messages
}
}
}
}

private fun updateReadStatusOfAllMessages(xChatLastCommonRead: Int?) {
if (adapter != null) {
for (message in adapter!!.items) {
Expand Down
156 changes: 0 additions & 156 deletions app/src/main/java/com/nextcloud/talk/ui/ImageStackContainer.kt

This file was deleted.

Loading

0 comments on commit 7f864ce

Please sign in to comment.