Update Edit Message

Signed-off-by: Sowjanya Kota <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2024-02-01 13:08:18 +01:00
parent cc8719668d
commit 253c3fe024
7 changed files with 44 additions and 81 deletions

View file

@ -334,7 +334,8 @@ public interface NcApi {
@FormUrlEncoded
@PUT
Observable<ChatOCSSingleMessage> editChatMessage(@Header("Authorization") String authorization, @Url String url, @Field("message") String message);
Observable<ChatOverallSingleMessage> editChatMessage(@Header("Authorization") String authorization, @Url String url, @Field(
"message") String message);
@GET
Observable<Response<ChatShareOverall>> getSharedItems(@Header("Authorization") String authorization, @Url String url, @Query("objectType") String objectType, @Nullable @Query("lastKnownMessageId") Integer lastKnownMessageId, @Nullable @Query("limit") Integer limit);

View file

@ -84,7 +84,6 @@ import android.widget.RelativeLayout.BELOW
import android.widget.RelativeLayout.LayoutParams
import android.widget.SeekBar
import android.widget.TextView
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.content.ContextCompat
@ -168,7 +167,6 @@ import com.nextcloud.talk.models.domain.ObjectType
import com.nextcloud.talk.models.domain.ReactionAddedModel
import com.nextcloud.talk.models.domain.ReactionDeletedModel
import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.models.json.chat.ChatOCSSingleMessage
import com.nextcloud.talk.models.json.chat.ChatOverall
import com.nextcloud.talk.models.json.chat.ChatOverallSingleMessage
import com.nextcloud.talk.models.json.chat.ReadStatus
@ -762,12 +760,13 @@ class ChatActivity :
private fun initMessageInputView() {
val filters = arrayOfNulls<InputFilter>(1)
val lengthFilter = CapabilitiesUtilNew.getMessageMaxLength(conversationUser)
binding.editView.editMessageView.visibility = GONE
if (editableBehaviorSubject.value!!) {
val editableText = Editable.Factory.getInstance().newEditable(editMessage.message)
binding.messageInputView.inputEditText.text = editableText
binding.messageInputView.inputEditText.setSelection(editableText.length)
binding.editView.editMessage.setText(editMessage.message)
}
filters[0] = InputFilter.LengthFilter(lengthFilter)
@ -835,7 +834,7 @@ class ChatActivity :
binding.messageInputView.messageSendButton.visibility = View.GONE
binding.messageInputView.recordAudioButton.visibility = View.GONE
binding.messageInputView.editMessageButton.visibility = View.VISIBLE
binding.messageInputView.clearEditMessage.visibility = View.VISIBLE
binding.editView.editMessageView.visibility = View.VISIBLE
}
if (sharedText.isNotEmpty()) {
@ -851,13 +850,13 @@ class ChatActivity :
}
binding.messageInputView.editMessageButton.setOnClickListener {
if(editMessage.message == editedTextBehaviorSubject.value!!){
if (editMessage.message == editedTextBehaviorSubject.value!!) {
clearEditUI()
return@setOnClickListener
}
editMessageAPI(editMessage, editedMessageText = editedTextBehaviorSubject.value!!)
}
binding.messageInputView.clearEditMessage.setOnClickListener {
binding.editView.clearEdit.setOnClickListener {
clearEditUI()
}
@ -889,48 +888,33 @@ class ChatActivity :
), editedMessageText
)?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<ChatOCSSingleMessage> {
?.subscribe(object : Observer<ChatOverallSingleMessage> {
override fun onSubscribe(d: Disposable) {
// unused atm
}
override fun onNext(message: ChatOCSSingleMessage) {
//unused atm
when(message.meta!!.statusCode){
HTTP_BAD_REQUEST -> {
Toast.makeText(context,
getString(R.string.edit_error_24_hours_old_message),Toast.LENGTH_SHORT)
.show()
}
HTTP_FORBIDDEN -> {
Toast.makeText(context,
getString(R.string.conversation_is_read_only),
Toast.LENGTH_SHORT).show()
}
HTTP_NOT_FOUND -> {
Toast.makeText(context,
"Conversation Cannot be Found",
Toast.LENGTH_SHORT).show()
}
}
override fun onNext(messageEdited: ChatOverallSingleMessage) {
message.message = messageEdited.ocs?.data?.parentMessage?.text
adapter?.update(message)
adapter?.notifyDataSetChanged()
clearEditUI()
}
override fun onError(e: Throwable) {
}
override fun onComplete() {
clearEditUI()
}
})
}
private fun clearEditUI() {
binding.messageInputView.editMessageButton.visibility = GONE
binding.messageInputView.clearEditMessage.visibility = View.GONE
editableBehaviorSubject.onNext(false)
binding.messageInputView.inputEditText.setText("")
binding.editView.editMessageView.visibility = GONE
}
private fun themeMessageInputView() {
@ -1004,7 +988,7 @@ class ChatActivity :
)
adapter?.setLoadMoreListener(this)
adapter?.setDateHeadersFormatter { format(it) }
adapter?.setDateHeadersFormatter {format(it)}
adapter?.setOnMessageViewLongClickListener { view, message -> onMessageViewLongClick(view, message) }
adapter?.registerViewClickListener(
R.id.playPauseBtn
@ -3839,10 +3823,8 @@ class ChatActivity :
} else if (isPollVotedMessage(currentMessage)) {
// delete poll system messages
chatMessageIterator.remove()
}else if(isEditMessage(currentMessage)){
if (!chatMessageMap.containsKey(currentMessage.value.parentMessage!!.id)){
chatMessageIterator.remove()
}
} else if (isEditMessage(currentMessage)) {
chatMessageIterator.remove()
}
}
return chatMessageMap.values.toList()
@ -3883,7 +3865,7 @@ class ChatActivity :
currentMessage.value.systemMessageType == ChatMessage.SystemMessageType.REACTION_REVOKED
}
private fun isEditMessage(currentMessage:MutableMap.MutableEntry<String,ChatMessage>):Boolean{
private fun isEditMessage(currentMessage: MutableMap.MutableEntry<String, ChatMessage>): Boolean {
return currentMessage.value.parentMessage != null && currentMessage.value.systemMessageType == ChatMessage
.SystemMessageType.MESSAGE_EDITED
}

View file

@ -44,7 +44,6 @@ class MessageInput : MessageInput {
lateinit var micInputCloud: MicInputCloud
lateinit var playPauseBtn: MaterialButton
lateinit var editMessageButton:ImageButton
lateinit var clearEditMessage:ImageButton
lateinit var seekBar: SeekBar
constructor(context: Context?) : super(context) {
@ -72,7 +71,6 @@ class MessageInput : MessageInput {
playPauseBtn = findViewById(R.id.playPauseBtn)
seekBar = findViewById(R.id.seekbar)
editMessageButton = findViewById(R.id.editMessageButton)
clearEditMessage = findViewById(R.id.clearEditButton)
}
var messageInput: EmojiEditText

View file

@ -140,8 +140,8 @@
android:id="@+id/messagesListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp"
android:clipToPadding="false"
android:paddingBottom="20dp"
android:visibility="gone"
app:dateHeaderTextSize="13sp"
app:incomingBubblePaddingBottom="@dimen/message_bubble_corners_vertical_padding"
@ -170,11 +170,10 @@
app:outcomingTextSize="@dimen/chat_text_size"
app:outcomingTimeTextSize="12sp"
app:textAutoLink="all"
tools:visibility="visible"/>
tools:visibility="visible" />
<com.nextcloud.ui.popupbubble.PopupBubble
android:id="@+id/popupBubbleView"
android:theme="@style/Button.Primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/typing_indicator_wrapper"
@ -183,11 +182,12 @@
android:layout_marginTop="16dp"
android:layout_marginEnd="64dp"
android:layout_marginBottom="26dp"
android:minHeight="@dimen/min_size_clickable_area"
android:layout_toStartOf="@+id/scrollDownButton"
android:text="@string/nc_new_messages"
app:background="@color/colorPrimary"
android:ellipsize="middle"
android:minHeight="@dimen/min_size_clickable_area"
android:text="@string/nc_new_messages"
android:theme="@style/Button.Primary"
app:background="@color/colorPrimary"
app:cornerRadius="@dimen/button_corner_radius"
app:icon="@drawable/ic_baseline_arrow_downward_24px" />
@ -227,9 +227,9 @@
android:id="@+id/typing_indicator_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-19dp">
android:layout_marginBottom="-19dp"
android:orientation="vertical">
<View
android:id="@+id/separator_1"
@ -241,15 +241,14 @@
android:id="@+id/typing_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:ellipsize="end"
android:layout_marginStart="@dimen/side_margin"
android:layout_marginEnd="@dimen/side_margin"
android:background="@color/bg_default"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/low_emphasis_text"
tools:text="Marcel is typing"
tools:ignore="Overdraw">
</TextView>
tools:ignore="Overdraw"
tools:text="Marcel is typing"></TextView>
</LinearLayout>
@ -259,12 +258,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
layout = "@layout/edit_message_view"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_above = "@id/messageInputView">
</include>
<include
android:id="@+id/editView"
layout="@layout/edit_message_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"></include>
<com.nextcloud.talk.ui.MessageInput
android:id="@+id/messageInputView"

View file

@ -1,16 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id = "@+id/edit_message_view"
android:orientation = "horizontal">
<ImageView
@ -34,7 +31,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor = "@color/colorPrimaryDark"
android:text = "Edit Message">
android:text = "@string/nc_edit_message_text">
</TextView>
@ -61,4 +58,3 @@
</ImageView>
</LinearLayout>
</merge>

View file

@ -71,7 +71,7 @@
android:layout_height="wrap_content"
android:layout_below="@+id/quotedChatMessageView"
android:layout_centerHorizontal="true"
android:layout_toStartOf="@id/messageSendButton"
android:layout_marginEnd = "48dp"
android:layout_toEndOf="@id/smileyButton"
android:imeOptions="actionDone"
android:inputType="textAutoCorrect|textMultiLine|textCapSentences"
@ -253,20 +253,6 @@
tools:visibility = "visible"
android:contentDescription="@string/nc_send_edit_message" />
<ImageButton
android:id="@+id/clearEditButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_below="@id/quotedChatMessageView"
android:layout_alignParentEnd="true"
android:layout_marginEnd="48dp"
android:background="@color/transparent"
android:contentDescription="@string/nc_clear_edit_message"
android:src="@drawable/ic_clear_24"
android:visibility="gone"
tools:visibility = "visible"
app:layout_constraintEnd_toStartOf="@id/editMessageButton" />
<Space
android:id="@id/attachmentButtonSpace"
android:layout_width="0dp"

View file

@ -792,4 +792,5 @@ How to translate with transifex:
<string name="nc_clear_edit_message">Clear Edit Message</string>
<string name="edit_error_24_hours_old_message">Cannot Edit Messages older than 24 hours</string>
<string name="conversation_is_read_only">Conversation is read Only</string>
<string name="nc_edit_message_text">Edit Message Text</string>
</resources>