From b346a85d5713fa54d7db4cd8dd7a7145769667d1 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Mon, 31 May 2021 14:06:02 +1000 Subject: [PATCH] Add basic conversation screen components --- .../conversation/v2/ConversationActivityV2.kt | 35 ++++++++++++++++++ .../conversation/v2/ConversationAdapter.kt | 35 ++++++++++++++++++ .../conversation/v2/messages/MessageView.kt | 37 +++++++++++++++++++ .../res/layout/activity_conversation_v2.xml | 14 +++++++ 4 files changed, 121 insertions(+) create mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt create mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt create mode 100644 app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/MessageView.kt create mode 100644 app/src/main/res/layout/activity_conversation_v2.xml diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt new file mode 100644 index 0000000000..0ae4adf548 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -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 +} \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt new file mode 100644 index 0000000000..8a08ac2678 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationAdapter.kt @@ -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(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 + } +} \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/MessageView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/MessageView.kt new file mode 100644 index 0000000000..6f239ed9a3 --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/MessageView.kt @@ -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 +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_conversation_v2.xml b/app/src/main/res/layout/activity_conversation_v2.xml new file mode 100644 index 0000000000..13dc9d7e4c --- /dev/null +++ b/app/src/main/res/layout/activity_conversation_v2.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file