mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Fix adapter position vs layout position usage
This commit is contained in:
parent
b6134b42c4
commit
a554aa574e
@ -860,17 +860,13 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
conversationRecyclerView.scrollToPosition(lastSeenItemPosition)
|
conversationRecyclerView.scrollToPosition(lastSeenItemPosition)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun playNextAudioIfPossible(current: Int) {
|
override fun playVoiceMessageAtIndexIfPossible(indexInAdapter: Int) {
|
||||||
if (current > 0) {
|
if (indexInAdapter < 0 || indexInAdapter >= adapter.itemCount) { return }
|
||||||
val nextVisibleMessageView = conversationRecyclerView[current - 1] as? VisibleMessageView
|
val viewHolder = conversationRecyclerView.findViewHolderForAdapterPosition(indexInAdapter) as? ConversationAdapter.VisibleMessageViewHolder
|
||||||
nextVisibleMessageView?.let { visibleMessageView ->
|
val nextVisibleMessageView = viewHolder?.view ?: return
|
||||||
visibleMessageView.messageContentView.mainContainer.children.forEach { child ->
|
nextVisibleMessageView.messageContentView.mainContainer.children.forEach { view ->
|
||||||
val nextVoiceMessageView = child as? VoiceMessageView
|
if (view is VoiceMessageView) {
|
||||||
nextVoiceMessageView?.let { voiceMessageView ->
|
return@forEach view.togglePlayback()
|
||||||
voiceMessageView.togglePlayback()
|
|
||||||
return@forEach
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.conversation.v2
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.graphics.Rect
|
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
@ -72,7 +71,7 @@ class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPr
|
|||||||
view.snIsSelected = isSelected
|
view.snIsSelected = isSelected
|
||||||
view.messageTimestampTextView.isVisible = isSelected
|
view.messageTimestampTextView.isVisible = isSelected
|
||||||
val position = viewHolder.adapterPosition
|
val position = viewHolder.adapterPosition
|
||||||
view.viewHolderIndex = position
|
view.indexInAdapter = position
|
||||||
view.bind(message, getMessageBefore(position, cursor), getMessageAfter(position, cursor), glide, searchQuery)
|
view.bind(message, getMessageBefore(position, cursor), getMessageAfter(position, cursor), glide, searchQuery)
|
||||||
view.onPress = { event -> onItemPress(message, viewHolder.adapterPosition, view, event) }
|
view.onPress = { event -> onItemPress(message, viewHolder.adapterPosition, view, event) }
|
||||||
view.onSwipeToReply = { onItemSwipeToReply(message, viewHolder.adapterPosition) }
|
view.onSwipeToReply = { onItemSwipeToReply(message, viewHolder.adapterPosition) }
|
||||||
|
@ -22,7 +22,6 @@ import androidx.core.graphics.BlendModeColorFilterCompat
|
|||||||
import androidx.core.graphics.BlendModeCompat
|
import androidx.core.graphics.BlendModeCompat
|
||||||
import androidx.core.text.getSpans
|
import androidx.core.text.getSpans
|
||||||
import androidx.core.text.toSpannable
|
import androidx.core.text.toSpannable
|
||||||
import kotlinx.android.synthetic.main.view_link_preview.view.*
|
|
||||||
import kotlinx.android.synthetic.main.view_visible_message_content.view.*
|
import kotlinx.android.synthetic.main.view_visible_message_content.view.*
|
||||||
import network.loki.messenger.R
|
import network.loki.messenger.R
|
||||||
import org.session.libsession.utilities.ThemeUtil
|
import org.session.libsession.utilities.ThemeUtil
|
||||||
@ -49,7 +48,7 @@ class VisibleMessageContentView : LinearLayout {
|
|||||||
var onContentClick: ((event: MotionEvent) -> Unit)? = null
|
var onContentClick: ((event: MotionEvent) -> Unit)? = null
|
||||||
var onContentDoubleTap: (() -> Unit)? = null
|
var onContentDoubleTap: (() -> Unit)? = null
|
||||||
var delegate: VisibleMessageContentViewDelegate? = null
|
var delegate: VisibleMessageContentViewDelegate? = null
|
||||||
var viewHolderIndex: Int = -1
|
var indexInAdapter: Int = -1
|
||||||
|
|
||||||
// region Lifecycle
|
// region Lifecycle
|
||||||
constructor(context: Context) : super(context) { initialize() }
|
constructor(context: Context) : super(context) { initialize() }
|
||||||
@ -111,7 +110,7 @@ class VisibleMessageContentView : LinearLayout {
|
|||||||
// Audio attachment
|
// Audio attachment
|
||||||
if (contactIsTrusted || message.isOutgoing) {
|
if (contactIsTrusted || message.isOutgoing) {
|
||||||
val voiceMessageView = VoiceMessageView(context)
|
val voiceMessageView = VoiceMessageView(context)
|
||||||
voiceMessageView.index = viewHolderIndex
|
voiceMessageView.indexInAdapter = indexInAdapter
|
||||||
voiceMessageView.delegate = context as? ConversationActivityV2
|
voiceMessageView.delegate = context as? ConversationActivityV2
|
||||||
voiceMessageView.bind(message, isStartOfMessageCluster, isEndOfMessageCluster)
|
voiceMessageView.bind(message, isStartOfMessageCluster, isEndOfMessageCluster)
|
||||||
mainContainer.addView(voiceMessageView)
|
mainContainer.addView(voiceMessageView)
|
||||||
|
@ -43,7 +43,7 @@ class VisibleMessageView : LinearLayout {
|
|||||||
private var longPressCallback: Runnable? = null
|
private var longPressCallback: Runnable? = null
|
||||||
private var onDownTimestamp = 0L
|
private var onDownTimestamp = 0L
|
||||||
private var onDoubleTap: (() -> Unit)? = null
|
private var onDoubleTap: (() -> Unit)? = null
|
||||||
var viewHolderIndex: Int = -1
|
var indexInAdapter: Int = -1
|
||||||
var snIsSelected = false
|
var snIsSelected = false
|
||||||
set(value) { field = value; handleIsSelectedChanged()}
|
set(value) { field = value; handleIsSelectedChanged()}
|
||||||
var onPress: ((event: MotionEvent) -> Unit)? = null
|
var onPress: ((event: MotionEvent) -> Unit)? = null
|
||||||
@ -149,7 +149,7 @@ class VisibleMessageView : LinearLayout {
|
|||||||
var maxWidth = screenWidth - startPadding - endPadding
|
var maxWidth = screenWidth - startPadding - endPadding
|
||||||
if (profilePictureContainer.visibility != View.GONE) { maxWidth -= profilePictureContainer.width }
|
if (profilePictureContainer.visibility != View.GONE) { maxWidth -= profilePictureContainer.width }
|
||||||
// Populate content view
|
// Populate content view
|
||||||
messageContentView.viewHolderIndex = viewHolderIndex
|
messageContentView.indexInAdapter = indexInAdapter
|
||||||
messageContentView.bind(message, isStartOfMessageCluster, isEndOfMessageCluster, glide, maxWidth, thread, searchQuery, isGroupThread || (contact?.isTrusted ?: false))
|
messageContentView.bind(message, isStartOfMessageCluster, isEndOfMessageCluster, glide, maxWidth, thread, searchQuery, isGroupThread || (contact?.isTrusted ?: false))
|
||||||
messageContentView.delegate = contentViewDelegate
|
messageContentView.delegate = contentViewDelegate
|
||||||
onDoubleTap = { messageContentView.onContentDoubleTap?.invoke() }
|
onDoubleTap = { messageContentView.onContentDoubleTap?.invoke() }
|
||||||
|
@ -32,7 +32,7 @@ class VoiceMessageView : LinearLayout, AudioSlidePlayer.Listener {
|
|||||||
private var duration = 0L
|
private var duration = 0L
|
||||||
private var player: AudioSlidePlayer? = null
|
private var player: AudioSlidePlayer? = null
|
||||||
var delegate: VoiceMessageViewDelegate? = null
|
var delegate: VoiceMessageViewDelegate? = null
|
||||||
var index = -1
|
var indexInAdapter = -1
|
||||||
|
|
||||||
// region Lifecycle
|
// region Lifecycle
|
||||||
constructor(context: Context) : super(context) { initialize() }
|
constructor(context: Context) : super(context) { initialize() }
|
||||||
@ -85,7 +85,7 @@ class VoiceMessageView : LinearLayout, AudioSlidePlayer.Listener {
|
|||||||
if (progress == 1.0) {
|
if (progress == 1.0) {
|
||||||
togglePlayback()
|
togglePlayback()
|
||||||
handleProgressChanged(0.0)
|
handleProgressChanged(0.0)
|
||||||
delegate?.playNextAudioIfPossible(index)
|
delegate?.playVoiceMessageAtIndexIfPossible(indexInAdapter - 1)
|
||||||
} else {
|
} else {
|
||||||
handleProgressChanged(progress)
|
handleProgressChanged(progress)
|
||||||
}
|
}
|
||||||
@ -138,5 +138,5 @@ class VoiceMessageView : LinearLayout, AudioSlidePlayer.Listener {
|
|||||||
|
|
||||||
interface VoiceMessageViewDelegate {
|
interface VoiceMessageViewDelegate {
|
||||||
|
|
||||||
fun playNextAudioIfPossible(current: Int)
|
fun playVoiceMessageAtIndexIfPossible(indexInAdapter: Int)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user