Fix conversation updating & stack messages from end

This commit is contained in:
nielsandriesse 2021-06-04 09:58:04 +10:00
parent f4ca2f2726
commit 10ec35bd74
4 changed files with 45 additions and 3 deletions

View File

@ -1,6 +1,9 @@
package org.thoughtcrime.securesms.conversation.v2
import android.database.Cursor
import android.os.Bundle
import androidx.loader.app.LoaderManager
import androidx.loader.content.Loader
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_conversation_v2.*
import network.loki.messenger.R
@ -11,6 +14,13 @@ import org.thoughtcrime.securesms.mms.GlideApp
class ConversationActivityV2 : PassphraseRequiredActionBarActivity() {
private var threadID: Long = -1
private val adapter by lazy {
val cursor = DatabaseFactory.getMmsSmsDatabase(this).getConversation(threadID)
val adapter = ConversationAdapter(this, cursor)
adapter.setHasStableIds(true)
adapter
}
private val thread by lazy {
DatabaseFactory.getThreadDatabase(this).getRecipientForThreadId(threadID)!!
}
@ -33,13 +43,26 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity() {
}
private fun setUpRecyclerView() {
val cursor = DatabaseFactory.getMmsSmsDatabase(this).getConversation(threadID)
val adapter = ConversationAdapter(this, cursor)
adapter.setHasStableIds(true)
conversationRecyclerView.adapter = adapter
val layoutManager = LinearLayoutManager(this)
layoutManager.reverseLayout = true
layoutManager.stackFromEnd = true
conversationRecyclerView.layoutManager = layoutManager
// Workaround for the fact that CursorRecyclerViewAdapter doesn't actually auto-update automatically (even though it says it will)
LoaderManager.getInstance(this).restartLoader(0, null, object : LoaderManager.LoaderCallbacks<Cursor> {
override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<Cursor> {
return ConversationLoader(threadID, this@ConversationActivityV2)
}
override fun onLoadFinished(loader: Loader<Cursor>, cursor: Cursor?) {
adapter.changeCursor(cursor)
}
override fun onLoaderReset(cursor: Loader<Cursor>) {
adapter.changeCursor(null)
}
})
}
private fun setUpToolbar() {

View File

@ -0,0 +1,13 @@
package org.thoughtcrime.securesms.conversation.v2
import android.content.Context
import android.database.Cursor
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.util.AbstractCursorLoader
class ConversationLoader(private val threadID: Long, context: Context) : AbstractCursorLoader(context) {
override fun getCursor(): Cursor {
return DatabaseFactory.getMmsSmsDatabase(context).getConversation(threadID)
}
}

View File

@ -52,6 +52,7 @@ class VisibleMessageContentView : LinearLayout {
background.colorFilter = filter
setBackground(background)
// Body
mainContainer.removeAllViews()
if (message is MmsMessageRecord && message.linkPreviews.isNotEmpty()) {
val linkPreviewView = LinkPreviewView(context)
linkPreviewView.bind(message)
@ -75,6 +76,10 @@ class VisibleMessageContentView : LinearLayout {
mainContainer.addView(bodyTextView)
}
}
fun recycle() {
mainContainer.removeAllViews()
}
// endregion
// region Convenience

View File

@ -81,6 +81,7 @@ class VisibleMessageView : LinearLayout {
fun recycle() {
profilePictureView.recycle()
messageContentView.recycle()
}
// endregion
}