session-android/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt

93 lines
3.4 KiB
Kotlin
Raw Normal View History

package org.thoughtcrime.securesms.conversation.v2
import android.database.Cursor
import android.os.Bundle
2021-06-04 05:15:43 +02:00
import android.util.Log
import androidx.loader.app.LoaderManager
import androidx.loader.content.Loader
2021-06-04 05:15:43 +02:00
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
2021-05-31 06:29:11 +02:00
import kotlinx.android.synthetic.main.activity_conversation_v2.*
import kotlinx.android.synthetic.main.activity_conversation_v2_action_bar.*
import network.loki.messenger.R
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.database.DatabaseFactory
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)!!
}
private val glide by lazy { GlideApp.with(this) }
// region Settings
companion object {
const val THREAD_ID = "thread_id"
}
// endregion
// region Lifecycle
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
super.onCreate(savedInstanceState, isReady)
setContentView(R.layout.activity_conversation_v2)
threadID = intent.getLongExtra(THREAD_ID, -1)
setUpRecyclerView()
setUpToolbar()
}
private fun setUpRecyclerView() {
2021-05-31 06:29:11 +02:00
conversationRecyclerView.adapter = adapter
2021-06-02 05:03:22 +02:00
val layoutManager = LinearLayoutManager(this)
layoutManager.reverseLayout = true
layoutManager.stackFromEnd = true
2021-06-02 05:03:22 +02:00
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)
}
})
2021-06-04 05:15:43 +02:00
val touchHelperCallback = ConversationTouchHelperCallback(adapter, this) { reply(it) }
val touchHelper = ItemTouchHelper(touchHelperCallback)
touchHelper.attachToRecyclerView(conversationRecyclerView)
}
private fun setUpToolbar() {
val actionBar = supportActionBar!!
actionBar.setCustomView(R.layout.activity_conversation_v2_action_bar)
actionBar.setDisplayShowCustomEnabled(true)
conversationTitleView.text = thread.toShortString()
2021-06-02 05:28:02 +02:00
profilePictureView.glide = glide
profilePictureView.update(thread, threadID)
}
// endregion
// region Interaction
private fun showConversationSettings() {
// TODO: Implement
}
2021-06-04 05:15:43 +02:00
private fun reply(messagePosition: Int) {
Log.d("Loki", "Reply to message at position: $messagePosition.")
}
// endregion
}