2021-05-31 06:06:02 +02:00
|
|
|
package org.thoughtcrime.securesms.conversation.v2
|
|
|
|
|
2021-06-04 01:58:04 +02:00
|
|
|
import android.database.Cursor
|
2021-05-31 06:06:02 +02:00
|
|
|
import android.os.Bundle
|
2021-06-04 05:15:43 +02:00
|
|
|
import android.util.Log
|
2021-06-04 01:58:04 +02:00
|
|
|
import androidx.loader.app.LoaderManager
|
|
|
|
import androidx.loader.content.Loader
|
2021-06-04 05:15:43 +02:00
|
|
|
import androidx.recyclerview.widget.ItemTouchHelper
|
2021-05-31 06:06:02 +02:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
2021-05-31 06:29:11 +02:00
|
|
|
import kotlinx.android.synthetic.main.activity_conversation_v2.*
|
2021-06-04 06:55:53 +02:00
|
|
|
import kotlinx.android.synthetic.main.activity_conversation_v2_action_bar.*
|
2021-05-31 06:06:02 +02:00
|
|
|
import network.loki.messenger.R
|
|
|
|
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
2021-06-01 08:17:14 +02:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideApp
|
2021-05-31 06:06:02 +02:00
|
|
|
|
|
|
|
class ConversationActivityV2 : PassphraseRequiredActionBarActivity() {
|
|
|
|
private var threadID: Long = -1
|
|
|
|
|
2021-06-04 01:58:04 +02:00
|
|
|
private val adapter by lazy {
|
|
|
|
val cursor = DatabaseFactory.getMmsSmsDatabase(this).getConversation(threadID)
|
|
|
|
val adapter = ConversationAdapter(this, cursor)
|
|
|
|
adapter.setHasStableIds(true)
|
|
|
|
adapter
|
|
|
|
}
|
|
|
|
|
2021-06-01 08:17:14 +02:00
|
|
|
private val thread by lazy {
|
|
|
|
DatabaseFactory.getThreadDatabase(this).getRecipientForThreadId(threadID)!!
|
|
|
|
}
|
|
|
|
|
|
|
|
private val glide by lazy { GlideApp.with(this) }
|
|
|
|
|
2021-05-31 06:06:02 +02:00
|
|
|
// 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()
|
2021-06-01 08:17:14 +02:00
|
|
|
setUpToolbar()
|
2021-05-31 06:06:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2021-06-04 01:58:04 +02:00
|
|
|
layoutManager.stackFromEnd = true
|
2021-06-02 05:03:22 +02:00
|
|
|
conversationRecyclerView.layoutManager = layoutManager
|
2021-06-04 01:58:04 +02:00
|
|
|
// 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)
|
2021-05-31 06:06:02 +02:00
|
|
|
}
|
2021-06-01 08:17:14 +02:00
|
|
|
|
|
|
|
private fun setUpToolbar() {
|
2021-06-04 06:55:53 +02:00
|
|
|
val actionBar = supportActionBar!!
|
|
|
|
actionBar.setCustomView(R.layout.activity_conversation_v2_action_bar)
|
|
|
|
actionBar.setDisplayShowCustomEnabled(true)
|
2021-06-01 08:17:14 +02:00
|
|
|
conversationTitleView.text = thread.toShortString()
|
2021-06-02 05:28:02 +02:00
|
|
|
profilePictureView.glide = glide
|
|
|
|
profilePictureView.update(thread, threadID)
|
2021-06-01 08:17:14 +02:00
|
|
|
}
|
|
|
|
// 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.")
|
|
|
|
}
|
2021-05-31 06:06:02 +02:00
|
|
|
// endregion
|
|
|
|
}
|