Add basic conversation screen components

This commit is contained in:
nielsandriesse 2021-05-31 14:06:02 +10:00
parent 1e1e3bf0e8
commit b346a85d57
4 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,35 @@
package org.thoughtcrime.securesms.conversation.v2
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_home.*
import network.loki.messenger.R
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.database.DatabaseFactory
class ConversationActivityV2 : PassphraseRequiredActionBarActivity() {
private var threadID: Long = -1
// 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()
}
private fun setUpRecyclerView() {
val cursor = DatabaseFactory.getMmsSmsDatabase(this).getConversation(threadID)
val adapter = ConversationAdapter(this, cursor)
adapter.setHasStableIds(true)
recyclerView.adapter = adapter
recyclerView.layoutManager = LinearLayoutManager(this)
}
// endregion
}

View File

@ -0,0 +1,35 @@
package org.thoughtcrime.securesms.conversation.v2
import android.content.Context
import android.database.Cursor
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import org.thoughtcrime.securesms.conversation.v2.messages.MessageView
import org.thoughtcrime.securesms.database.CursorRecyclerViewAdapter
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.database.model.MessageRecord
class ConversationAdapter(context: Context, cursor: Cursor) : CursorRecyclerViewAdapter<ConversationAdapter.ViewHolder>(context, cursor) {
private val messageDB = DatabaseFactory.getMmsSmsDatabase(context)
class ViewHolder(val view: MessageView) : RecyclerView.ViewHolder(view)
override fun onCreateItemViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = MessageView(context)
return ViewHolder(view)
}
override fun onBindItemViewHolder(viewHolder: ViewHolder, cursor: Cursor) {
val message = getMessage(cursor)!!
viewHolder.view.bind(message)
}
override fun onItemViewRecycled(holder: ViewHolder?) {
holder?.view?.recycle()
super.onItemViewRecycled(holder)
}
private fun getMessage(cursor: Cursor): MessageRecord? {
return messageDB.readerFor(cursor).current
}
}

View File

@ -0,0 +1,37 @@
package org.thoughtcrime.securesms.conversation.v2.messages
import android.content.Context
import android.util.AttributeSet
import android.widget.LinearLayout
import org.thoughtcrime.securesms.database.model.MessageRecord
class MessageView : LinearLayout {
// region Lifecycle
constructor(context: Context) : super(context) {
setUpViewHierarchy()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
setUpViewHierarchy()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
setUpViewHierarchy()
}
private fun setUpViewHierarchy() {
// TODO: Implement
}
// endregion
// region Updating
fun bind(message: MessageRecord) {
}
fun recycle() {
// TODO: Implement
}
// endregion
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/conversationRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>