rename MessagesAdapter to ThreadsAdapter, no other change

This commit is contained in:
tibbi 2020-04-11 10:50:47 +02:00
parent 8f6bd84773
commit f2c368e12e
4 changed files with 43 additions and 43 deletions

View File

@ -15,7 +15,7 @@ import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.smsmessenger.BuildConfig
import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.adapters.MessagesAdapter
import com.simplemobiletools.smsmessenger.adapters.ThreadsAdapter
import com.simplemobiletools.smsmessenger.extensions.config
import com.simplemobiletools.smsmessenger.extensions.getMessages
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
@ -71,7 +71,7 @@ class MainActivity : SimpleActivity() {
override fun onResume() {
super.onResume()
if (storedTextColor != config.textColor) {
(messages_list.adapter as? MessagesAdapter)?.updateTextColor(config.textColor)
(messages_list.adapter as? ThreadsAdapter)?.updateTextColor(config.textColor)
}
updateTextColors(main_coordinator)
@ -136,7 +136,7 @@ class MainActivity : SimpleActivity() {
ensureBackgroundThread {
val messages = getMessages()
runOnUiThread {
MessagesAdapter(this, messages, messages_list, messages_fastscroller) {
ThreadsAdapter(this, messages, messages_list, messages_fastscroller) {
Intent(this, ThreadActivity::class.java).apply {
putExtra(THREAD_ID, (it as Message).thread)
putExtra(THREAD_TITLE, it.getThreadTitle())

View File

@ -18,10 +18,10 @@ import com.simplemobiletools.smsmessenger.extensions.deleteThread
import com.simplemobiletools.smsmessenger.extensions.loadImage
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
import com.simplemobiletools.smsmessenger.models.Message
import kotlinx.android.synthetic.main.item_message.view.*
import kotlinx.android.synthetic.main.item_thread.view.*
class MessagesAdapter(
activity: SimpleActivity, var messages: ArrayList<Message>,
class ThreadsAdapter(
activity: SimpleActivity, var threads: ArrayList<Message>,
recyclerView: MyRecyclerView,
fastScroller: FastScroller,
itemClick: (Any) -> Unit
@ -31,7 +31,7 @@ class MessagesAdapter(
setupDragListener(true)
}
override fun getActionMenuId() = R.menu.cab_messages
override fun getActionMenuId() = R.menu.cab_threads
override fun prepareActionMode(menu: Menu) {}
@ -46,29 +46,29 @@ class MessagesAdapter(
}
}
override fun getSelectableItemCount() = messages.size
override fun getSelectableItemCount() = threads.size
override fun getIsItemSelectable(position: Int) = true
override fun getItemSelectionKey(position: Int) = messages.getOrNull(position)?.id
override fun getItemSelectionKey(position: Int) = threads.getOrNull(position)?.id
override fun getItemKeyPosition(key: Int) = messages.indexOfFirst { it.id == key }
override fun getItemKeyPosition(key: Int) = threads.indexOfFirst { it.id == key }
override fun onActionModeCreated() {}
override fun onActionModeDestroyed() {}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_message, parent)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_thread, parent)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val message = messages[position]
val message = threads[position]
holder.bindView(message, true, true) { itemView, layoutPosition ->
setupView(itemView, message)
}
bindViewHolder(holder)
}
override fun getItemCount() = messages.size
override fun getItemCount() = threads.size
private fun askConfirmDelete() {
val itemsCnt = selectedKeys.size
@ -89,15 +89,15 @@ class MessagesAdapter(
return
}
val messagesToRemove = messages.filter { selectedKeys.contains(it.id) } as ArrayList<Message>
val threadsToRemove = threads.filter { selectedKeys.contains(it.id) } as ArrayList<Message>
val positions = getSelectedItemPositions()
messagesToRemove.forEach {
threadsToRemove.forEach {
activity.deleteThread(it.thread)
}
messages.removeAll(messagesToRemove)
threads.removeAll(threadsToRemove)
activity.runOnUiThread {
if (messagesToRemove.isEmpty()) {
if (threadsToRemove.isEmpty()) {
refreshMessages()
finishActMode()
} else {
@ -109,34 +109,34 @@ class MessagesAdapter(
override fun onViewRecycled(holder: ViewHolder) {
super.onViewRecycled(holder)
if (!activity.isDestroyed && !activity.isFinishing) {
Glide.with(activity).clear(holder.itemView.message_image)
Glide.with(activity).clear(holder.itemView.thread_image)
}
}
private fun setupView(view: View, message: Message) {
view.apply {
message_frame.isSelected = selectedKeys.contains(message.id)
thread_frame.isSelected = selectedKeys.contains(message.id)
message_address.text = message.getThreadTitle()
message_body_short.text = message.body
message_date.text = message.date.formatDateOrTime(context, true)
thread_address.text = message.getThreadTitle()
thread_body_short.text = message.body
thread_date.text = message.date.formatDateOrTime(context, true)
if (message.read) {
message_address.setTypeface(null, Typeface.NORMAL)
message_body_short.setTypeface(null, Typeface.NORMAL)
message_body_short.alpha = 0.7f
thread_address.setTypeface(null, Typeface.NORMAL)
thread_body_short.setTypeface(null, Typeface.NORMAL)
thread_body_short.alpha = 0.7f
} else {
message_address.setTypeface(null, Typeface.BOLD)
message_body_short.setTypeface(null, Typeface.BOLD)
message_body_short.alpha = 1f
thread_address.setTypeface(null, Typeface.BOLD)
thread_body_short.setTypeface(null, Typeface.BOLD)
thread_body_short.alpha = 1f
}
arrayListOf<TextView>(message_address, message_body_short, message_date).forEach {
arrayListOf<TextView>(thread_address, thread_body_short, thread_date).forEach {
it.setTextColor(textColor)
}
val participant = message.participants.first()
context.loadImage(participant.photoUri, message_image, participant.name)
context.loadImage(participant.photoUri, thread_image, participant.name)
}
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/message_frame"
android:id="@+id/thread_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
@ -10,27 +10,27 @@
android:foreground="@drawable/selector">
<RelativeLayout
android:id="@+id/message_holder"
android:id="@+id/thread_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/activity_margin"
android:paddingBottom="@dimen/activity_margin">
<ImageView
android:id="@+id/message_image"
android:id="@+id/thread_image"
android:layout_width="@dimen/normal_icon_size"
android:layout_height="@dimen/normal_icon_size"
android:layout_alignTop="@+id/message_address"
android:layout_alignBottom="@+id/message_date"
android:layout_alignTop="@+id/thread_address"
android:layout_alignBottom="@+id/thread_date"
android:layout_centerVertical="true"
android:layout_marginStart="@dimen/normal_margin"
android:layout_marginEnd="@dimen/normal_margin" />
<TextView
android:id="@+id/message_address"
android:id="@+id/thread_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/message_image"
android:layout_toEndOf="@+id/thread_image"
android:ellipsize="end"
android:maxLines="1"
android:paddingEnd="@dimen/activity_margin"
@ -38,11 +38,11 @@
tools:text="John" />
<TextView
android:id="@+id/message_body_short"
android:id="@+id/thread_body_short"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/message_address"
android:layout_toEndOf="@+id/message_image"
android:layout_below="@+id/thread_address"
android:layout_toEndOf="@+id/thread_image"
android:ellipsize="end"
android:maxLines="1"
android:paddingEnd="@dimen/activity_margin"
@ -50,12 +50,12 @@
tools:text="Hey buddy!" />
<TextView
android:id="@+id/message_date"
android:id="@+id/thread_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/message_body_short"
android:layout_below="@+id/thread_body_short"
android:layout_marginTop="@dimen/tiny_margin"
android:layout_toEndOf="@+id/message_image"
android:layout_toEndOf="@+id/thread_image"
android:alpha="0.4"
android:textSize="@dimen/smaller_text_size"
tools:text="13:30" />