adding an initial implementation of the messages adapter

This commit is contained in:
tibbi 2020-04-03 12:20:39 +02:00
parent b239227794
commit 45e3d0b865
5 changed files with 145 additions and 1 deletions

View File

@ -11,7 +11,9 @@ import com.simplemobiletools.commons.helpers.PERMISSION_READ_SMS
import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.smsmessenger.BuildConfig
import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.adapters.SMSsAdapter
import com.simplemobiletools.smsmessenger.models.SMS
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : SimpleActivity() {
@ -48,7 +50,12 @@ class MainActivity : SimpleActivity() {
}
private fun initMessenger() {
val sms = getSMSs()
val smss = getSMSs()
SMSsAdapter(this, smss, smss_list, smsss_fastscroller) {
}.apply {
smss_list.adapter = this
}
}
private fun getSMSs(): ArrayList<SMS> {

View File

@ -0,0 +1,62 @@
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.SMS
import kotlinx.android.synthetic.main.item_sms.view.*
class SMSsAdapter(
activity: SimpleActivity, var SMSs: ArrayList<SMS>, recyclerView: MyRecyclerView, fastScroller: FastScroller, itemClick: (Any) -> Unit
) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
init {
setupDragListener(true)
}
override fun getActionMenuId() = R.menu.cab_smss
override fun prepareActionMode(menu: Menu) {}
override fun actionItemPressed(id: Int) {}
override fun getSelectableItemCount() = SMSs.size
override fun getIsItemSelectable(position: Int) = true
override fun getItemSelectionKey(position: Int) = SMSs.getOrNull(position)?.id
override fun getItemKeyPosition(key: Int) = SMSs.indexOfFirst { it.id == key }
override fun onActionModeCreated() {}
override fun onActionModeDestroyed() {}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_sms, parent)
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val sms = SMSs[position]
holder.bindView(sms, true, true) { itemView, layoutPosition ->
setupView(itemView, sms)
}
bindViewHolder(holder)
}
override fun getItemCount() = SMSs.size
private fun getItemWithKey(key: Int): SMS? = SMSs.firstOrNull { it.id == key }
private fun getSelectedItems() = SMSs.filter { selectedKeys.contains(it.id) } as ArrayList<SMS>
private fun setupView(view: View, sms: SMS) {
view.apply {
view.sms_address.text = sms.address
view.sms_message_short.text = sms.body
}
}
}

View File

@ -1,6 +1,28 @@
<?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/main_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/smss_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="none"
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
<com.simplemobiletools.commons.views.FastScroller
android:id="@+id/smsss_fastscroller"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignTop="@+id/smss_list"
android:layout_alignBottom="@+id/smss_list"
android:layout_alignParentEnd="true"
android:paddingStart="@dimen/normal_margin">
<include layout="@layout/fastscroller_handle_vertical" />
</com.simplemobiletools.commons.views.FastScroller>
</RelativeLayout>

View File

@ -0,0 +1,39 @@
<?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/sms_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:foreground="@drawable/selector">
<RelativeLayout
android:id="@+id/sms_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_margin">
<TextView
android:id="@+id/sms_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textSize="@dimen/big_text_size"
tools:text="John" />
<TextView
android:id="@+id/sms_message_short"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/sms_address"
android:alpha="0.6"
android:ellipsize="end"
android:maxLines="1"
android:textSize="@dimen/normal_text_size"
tools:text="Hey buddy!" />
</RelativeLayout>
</FrameLayout>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/cab_select_all"
android:icon="@drawable/ic_select_all_vector"
android:title="@string/select_all"
app:showAsAction="ifRoom" />
<item
android:id="@+id/cab_delete"
android:icon="@drawable/ic_delete_vector"
android:title="@string/delete"
app:showAsAction="ifRoom" />
</menu>