mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-19 20:29:02 +00:00
Fix chat issues. Fixes #1738
This commit is contained in:
parent
ecfdce9107
commit
54cfa46d25
4 changed files with 22 additions and 17 deletions
|
|
@ -365,7 +365,9 @@ class FullProfileActivity : BaseActivity() {
|
|||
|
||||
binding.equipmentTableLayout.removeAllViews()
|
||||
for (index in 1 until binding.attributesTableLayout.childCount) {
|
||||
binding.attributesTableLayout.removeViewAt(index)
|
||||
if (binding.attributesTableLayout.getChildAt(index).isAttachedToWindow) {
|
||||
binding.attributesTableLayout.removeViewAt(index)
|
||||
}
|
||||
}
|
||||
|
||||
addLevelAttributes(user)
|
||||
|
|
|
|||
|
|
@ -68,11 +68,12 @@ class ChatRecyclerViewAdapter(user: User?, private val isTavern: Boolean) : Base
|
|||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
if (data[position].isSystemMessage) {
|
||||
val sysChatHolder = holder as? SystemChatMessageViewHolder ?: return
|
||||
val message = data[position]
|
||||
sysChatHolder.bind(
|
||||
data[position],
|
||||
message,
|
||||
expandedMessageId == data[position].id
|
||||
)
|
||||
sysChatHolder.onShouldExpand = { expandMessage(data[position].id, position) }
|
||||
sysChatHolder.onShouldExpand = { expandMessage(message) }
|
||||
} else {
|
||||
val chatHolder = holder as? ChatRecyclerMessageViewHolder ?: return
|
||||
val message = data[position]
|
||||
|
|
@ -82,7 +83,7 @@ class ChatRecyclerViewAdapter(user: User?, private val isTavern: Boolean) : Base
|
|||
user,
|
||||
expandedMessageId == message.id
|
||||
)
|
||||
chatHolder.onShouldExpand = { expandMessage(message.id, position) }
|
||||
chatHolder.onShouldExpand = { expandMessage(message) }
|
||||
chatHolder.onLikeMessage = { likeMessageEvents.onNext(it) }
|
||||
chatHolder.onOpenProfile = { userLabelClickEvents.onNext(it) }
|
||||
chatHolder.onReply = { replyMessageEvents.onNext(it) }
|
||||
|
|
@ -121,20 +122,20 @@ class ChatRecyclerViewAdapter(user: User?, private val isTavern: Boolean) : Base
|
|||
return copyMessageEvents.toFlowable(BackpressureStrategy.DROP)
|
||||
}
|
||||
|
||||
private fun expandMessage(id: String, position: Int) {
|
||||
expandedMessageId = if (expandedMessageId == id) {
|
||||
private fun expandMessage(message:ChatMessage) {
|
||||
expandedMessageId = if (expandedMessageId == message.id) {
|
||||
null
|
||||
} else {
|
||||
id
|
||||
message.id
|
||||
}
|
||||
notifyItemChanged(position)
|
||||
notifyItemChanged(data.indexOf(message))
|
||||
}
|
||||
}
|
||||
|
||||
class SystemChatMessageViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
private val textView: TextView = itemView.findViewById(R.id.text_view)
|
||||
private val timestamp: TextView = itemView.findViewById(R.id.system_message_timestamp)
|
||||
private val dateTime = java.text.SimpleDateFormat("MMM dd, hh:mm aaa")
|
||||
private val dateTime = java.text.SimpleDateFormat.getDateTimeInstance()
|
||||
val binding = SystemChatMessageBinding.bind(itemView)
|
||||
|
||||
var onShouldExpand: (() -> Unit)? = null
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.habitrpg.android.habitica.MainNavDirections
|
||||
import com.habitrpg.android.habitica.R
|
||||
|
|
@ -25,6 +24,7 @@ import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
|||
import com.habitrpg.android.habitica.ui.viewmodels.GroupViewModel
|
||||
import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar.Companion.showSnackbar
|
||||
import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar.SnackbarDisplayType
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
import io.reactivex.rxjava3.disposables.Disposable
|
||||
|
|
@ -199,12 +199,12 @@ class ChatFragment() : BaseFragment<FragmentChatBinding>() {
|
|||
private fun showDeleteConfirmationDialog(chatMessage: ChatMessage) {
|
||||
val context = context
|
||||
if (context != null) {
|
||||
AlertDialog.Builder(context)
|
||||
.setTitle(R.string.confirm_delete_tag_title)
|
||||
.setMessage(R.string.confirm_delete_tag_message)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setPositiveButton(R.string.yes) { _, _ -> viewModel?.deleteMessage(chatMessage) }
|
||||
.setNegativeButton(R.string.no, null).show()
|
||||
val dialog = HabiticaAlertDialog(context)
|
||||
dialog.setTitle(R.string.confirm_delete_tag_title)
|
||||
dialog.setMessage(R.string.confirm_delete_tag_message)
|
||||
dialog.addButton(R.string.yes, true, true) { _, _ ->
|
||||
viewModel?.deleteMessage(chatMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,9 @@ class AutocompleteAdapter(
|
|||
} else if (constraint[0] == '@') {
|
||||
lastAutocomplete = Date().time
|
||||
isAutocompletingUsers = true
|
||||
userResults = chatMessages.distinctBy {
|
||||
userResults = chatMessages
|
||||
.filter { it.isValid }
|
||||
.distinctBy {
|
||||
it.username
|
||||
}.filter { it.username?.startsWith(constraint.toString().drop(1)) ?: false }.map { message ->
|
||||
val result = FindUsernameResult()
|
||||
|
|
|
|||
Loading…
Reference in a new issue