mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-16 19:50:40 +01:00
show the appropriate messages at opening a thread
This commit is contained in:
parent
70c1e7d6b7
commit
f938c14cba
@ -2,8 +2,10 @@ package com.simplemobiletools.smsmessenger.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.adapters.ThreadAdapter
|
||||
import com.simplemobiletools.smsmessenger.extensions.getMessages
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
||||
import kotlinx.android.synthetic.main.activity_thread.*
|
||||
|
||||
class ThreadActivity : SimpleActivity() {
|
||||
|
||||
@ -12,5 +14,12 @@ class ThreadActivity : SimpleActivity() {
|
||||
setContentView(R.layout.activity_thread)
|
||||
val threadID = intent.getIntExtra(THREAD_ID, 0)
|
||||
val messages = getMessages(threadID)
|
||||
messages.sortBy { it.id }
|
||||
|
||||
ThreadAdapter(this, messages, thread_messages_list, thread_messages_fastscroller) {
|
||||
|
||||
}.apply {
|
||||
thread_messages_list.adapter = this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,73 @@
|
||||
package com.simplemobiletools.smsmessenger.adapters
|
||||
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.views.FastScroller
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
||||
import com.simplemobiletools.smsmessenger.models.Message
|
||||
import kotlinx.android.synthetic.main.item_thread_message.view.*
|
||||
|
||||
class ThreadAdapter(
|
||||
activity: SimpleActivity, var messages: ArrayList<Message>,
|
||||
recyclerView: MyRecyclerView,
|
||||
fastScroller: FastScroller,
|
||||
itemClick: (Any) -> Unit
|
||||
) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
|
||||
|
||||
init {
|
||||
setupDragListener(true)
|
||||
}
|
||||
|
||||
override fun getActionMenuId() = R.menu.cab_messages
|
||||
|
||||
override fun prepareActionMode(menu: Menu) {}
|
||||
|
||||
override fun actionItemPressed(id: Int) {
|
||||
if (selectedKeys.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
when (id) {
|
||||
R.id.cab_select_all -> selectAll()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getSelectableItemCount() = messages.size
|
||||
|
||||
override fun getIsItemSelectable(position: Int) = true
|
||||
|
||||
override fun getItemSelectionKey(position: Int) = messages.getOrNull(position)?.id
|
||||
|
||||
override fun getItemKeyPosition(key: Int) = messages.indexOfFirst { it.id == key }
|
||||
|
||||
override fun onActionModeCreated() {}
|
||||
|
||||
override fun onActionModeDestroyed() {}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_thread_message, parent)
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val message = messages[position]
|
||||
holder.bindView(message, true, true) { itemView, layoutPosition ->
|
||||
setupView(itemView, message)
|
||||
}
|
||||
bindViewHolder(holder)
|
||||
}
|
||||
|
||||
override fun getItemCount() = messages.size
|
||||
|
||||
private fun getItemWithKey(key: Int): Message? = messages.firstOrNull { it.id == key }
|
||||
|
||||
private fun getSelectedItems() = messages.filter { selectedKeys.contains(it.id) } as ArrayList<Message>
|
||||
|
||||
private fun setupView(view: View, message: Message) {
|
||||
view.apply {
|
||||
thread_message_body.text = message.body
|
||||
thread_message_body.setTextColor(textColor)
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:overScrollMode="ifContentScrolls"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
|
||||
|
||||
|
@ -1,7 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/thread_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.simplemobiletools.commons.views.MyRecyclerView
|
||||
android:id="@+id/thread_messages_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:overScrollMode="ifContentScrolls"
|
||||
android:scrollbars="none"
|
||||
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"
|
||||
app:stackFromEnd="true" />
|
||||
|
||||
<com.simplemobiletools.commons.views.FastScroller
|
||||
android:id="@+id/thread_messages_fastscroller"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignTop="@+id/thread_messages_list"
|
||||
android:layout_alignBottom="@+id/thread_messages_list"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:paddingStart="@dimen/normal_margin">
|
||||
|
||||
<include layout="@layout/fastscroller_handle_vertical" />
|
||||
|
||||
</com.simplemobiletools.commons.views.FastScroller>
|
||||
</RelativeLayout>
|
||||
|
16
app/src/main/res/layout/item_thread_message.xml
Normal file
16
app/src/main/res/layout/item_thread_message.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/thread_message_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/thread_message_body"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="@dimen/normal_text_size"
|
||||
tools:text="Hey buddy!" />
|
||||
|
||||
</RelativeLayout>
|
Loading…
x
Reference in New Issue
Block a user