Fixed auto scroll when sending 2 or more files simultaneously
This commit is contained in:
parent
efd511c3f0
commit
df7f689501
4 changed files with 29 additions and 13 deletions
|
@ -53,7 +53,7 @@ class ChatMessageContentData(
|
|||
|
||||
val downloadable = MutableLiveData<Boolean>()
|
||||
val downloadEnabled = MutableLiveData<Boolean>()
|
||||
val downloadProgress = MutableLiveData<Int>()
|
||||
val downloadProgressInt = MutableLiveData<Int>()
|
||||
val downloadProgressString = MutableLiveData<String>()
|
||||
val downloadLabel = MutableLiveData<Spannable>()
|
||||
|
||||
|
@ -75,19 +75,23 @@ class ChatMessageContentData(
|
|||
offset: Int,
|
||||
total: Int
|
||||
) {
|
||||
if (message == chatMessage) {
|
||||
if (c.filePath == content.filePath) {
|
||||
val percent = offset * 100 / total
|
||||
Log.d("[Content] Download progress is: $offset / $total ($percent%)")
|
||||
downloadProgress.postValue(percent)
|
||||
downloadProgressInt.postValue(percent)
|
||||
downloadProgressString.postValue("$percent%")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMsgStateChanged(message: ChatMessage, state: ChatMessage.State) {
|
||||
if (state == ChatMessage.State.FileTransferDone || state == ChatMessage.State.FileTransferError) {
|
||||
message.removeListener(this)
|
||||
}
|
||||
downloadEnabled.postValue(chatMessage.state != ChatMessage.State.FileTransferInProgress)
|
||||
if (message == chatMessage) {
|
||||
if (state == ChatMessage.State.FileTransferDone || state == ChatMessage.State.FileTransferError) {
|
||||
downloadProgressInt.value = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,8 +106,10 @@ class ChatMessageContentData(
|
|||
} else {
|
||||
content.name
|
||||
}
|
||||
|
||||
// Display download size and underline text
|
||||
fileSize.value = AppUtils.bytesToDisplayableSize(content.fileSize.toLong())
|
||||
var spannable = SpannableString("${AppUtils.getString(R.string.chat_message_download_file)} (${fileSize.value})")
|
||||
val spannable = SpannableString("${AppUtils.getString(R.string.chat_message_download_file)} (${fileSize.value})")
|
||||
spannable.setSpan(UnderlineSpan(), 0, spannable.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
downloadLabel.value = spannable
|
||||
|
||||
|
@ -143,7 +149,7 @@ class ChatMessageContentData(
|
|||
|
||||
isGenericFile.value = !isPdf.value!! && !isAudio.value!! && !isVideo.value!! && !isImage.value!!
|
||||
downloadEnabled.value = !chatMessage.isFileTransferInProgress
|
||||
downloadProgress.value = 0
|
||||
downloadProgressInt.value = 0
|
||||
downloadProgressString.value = "0%"
|
||||
chatMessage.addListener(chatMessageListener)
|
||||
}
|
||||
|
@ -157,6 +163,8 @@ class ChatMessageContentData(
|
|||
FileUtils.deleteFile(path)
|
||||
filePath.value = ""
|
||||
}
|
||||
|
||||
chatMessage.removeListener(chatMessageListener)
|
||||
}
|
||||
|
||||
fun download() {
|
||||
|
|
|
@ -73,6 +73,8 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
|||
if (itemCount == 1 && positionStart > 0) {
|
||||
adapter.notifyItemChanged(positionStart - 1) // For grouping purposes
|
||||
scrollToBottom()
|
||||
} else if (positionStart > 0) {
|
||||
scrollToBottom()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="@{data.downloadProgress > 0 ? View.VISIBLE : View.GONE}"
|
||||
android:visibility="@{data.downloadProgressInt > 0 ? View.VISIBLE : View.GONE}"
|
||||
android:layout_centerInParent="true">
|
||||
|
||||
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||
|
@ -98,7 +98,7 @@
|
|||
android:max="100"
|
||||
android:layout_centerInParent="true"
|
||||
app:trackColor="?attr/backgroundColor"
|
||||
android:progress="@{data.downloadProgress, default=50}"
|
||||
android:progress="@{data.downloadProgressInt, default=50}"
|
||||
android:background="@drawable/background_round_secondary_color"/>
|
||||
|
||||
<TextView
|
||||
|
@ -106,6 +106,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:textColor="?attr/secondaryTextColor"
|
||||
style="@style/file_transfer_progress_font"
|
||||
android:text="@{data.downloadProgressString, default=`50%`}"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
|
@ -269,4 +269,9 @@
|
|||
<item name="android:textSize">10sp</item>
|
||||
</style>
|
||||
|
||||
<style name="file_transfer_progress_font" parent="@android:style/TextAppearance.Medium">
|
||||
<item name="android:textColor">?attr/secondaryTextColor</item>
|
||||
<item name="android:textSize">12sp</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue