renaming SMS to Message in some cases for easier handling

This commit is contained in:
tibbi 2020-04-03 12:29:57 +02:00
parent 45e3d0b865
commit e6b8db6ad0
8 changed files with 87 additions and 84 deletions

View File

@ -11,8 +11,8 @@ import com.simplemobiletools.commons.helpers.PERMISSION_READ_SMS
import com.simplemobiletools.commons.models.FAQItem import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.smsmessenger.BuildConfig import com.simplemobiletools.smsmessenger.BuildConfig
import com.simplemobiletools.smsmessenger.R import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.adapters.SMSsAdapter import com.simplemobiletools.smsmessenger.adapters.MessagesAdapter
import com.simplemobiletools.smsmessenger.models.SMS import com.simplemobiletools.smsmessenger.models.Message
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : SimpleActivity() { class MainActivity : SimpleActivity() {
@ -50,16 +50,16 @@ class MainActivity : SimpleActivity() {
} }
private fun initMessenger() { private fun initMessenger() {
val smss = getSMSs() val messages = getMessages()
SMSsAdapter(this, smss, smss_list, smsss_fastscroller) { MessagesAdapter(this, messages, messages_list, messages_fastscroller) {
}.apply { }.apply {
smss_list.adapter = this messages_list.adapter = this
} }
} }
private fun getSMSs(): ArrayList<SMS> { private fun getMessages(): ArrayList<Message> {
val smss = ArrayList<SMS>() val messages = ArrayList<Message>()
val uri = Telephony.Sms.CONTENT_URI val uri = Telephony.Sms.CONTENT_URI
val projection = arrayOf( val projection = arrayOf(
Telephony.Sms._ID, Telephony.Sms._ID,
@ -83,8 +83,8 @@ class MainActivity : SimpleActivity() {
val address = cursor.getStringValue(Telephony.Sms.ADDRESS) val address = cursor.getStringValue(Telephony.Sms.ADDRESS)
val date = (cursor.getLongValue(Telephony.Sms.DATE) / 1000).toInt() val date = (cursor.getLongValue(Telephony.Sms.DATE) / 1000).toInt()
val read = cursor.getIntValue(Telephony.Sms.READ) == 1 val read = cursor.getIntValue(Telephony.Sms.READ) == 1
val sms = SMS(id, subject, body, type, address, date, read) val message = Message(id, subject, body, type, address, date, read)
smss.add(sms) messages.add(message)
} while (cursor.moveToNext()) } while (cursor.moveToNext())
} }
} catch (e: Exception) { } catch (e: Exception) {
@ -92,7 +92,7 @@ class MainActivity : SimpleActivity() {
} finally { } finally {
cursor?.close() cursor?.close()
} }
return smss return messages
} }
private fun launchSettings() { private fun launchSettings() {

View File

@ -0,0 +1,65 @@
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_message.view.*
class MessagesAdapter(
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) {}
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_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 {
view.message_address.text = message.address
view.message_body_short.text = message.body
}
}
}

View File

@ -1,62 +0,0 @@
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

@ -0,0 +1,3 @@
package com.simplemobiletools.smsmessenger.models
data class Message(val id: Int, val subject: String, val body: String, val type: Int, val address: String, val date: Int, val read: Boolean)

View File

@ -1,3 +0,0 @@
package com.simplemobiletools.smsmessenger.models
data class SMS(val id: Int, val subject: String, val body: String, val type: Int, val address: String, val date: Int, val read: Boolean)

View File

@ -6,7 +6,7 @@
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.simplemobiletools.commons.views.MyRecyclerView <com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/smss_list" android:id="@+id/messages_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:clipToPadding="false" android:clipToPadding="false"
@ -14,11 +14,11 @@
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" /> app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
<com.simplemobiletools.commons.views.FastScroller <com.simplemobiletools.commons.views.FastScroller
android:id="@+id/smsss_fastscroller" android:id="@+id/messages_fastscroller"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignTop="@+id/smss_list" android:layout_alignTop="@+id/messages_list"
android:layout_alignBottom="@+id/smss_list" android:layout_alignBottom="@+id/messages_list"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:paddingStart="@dimen/normal_margin"> android:paddingStart="@dimen/normal_margin">

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/sms_frame" android:id="@+id/message_frame"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
@ -10,13 +10,13 @@
android:foreground="@drawable/selector"> android:foreground="@drawable/selector">
<RelativeLayout <RelativeLayout
android:id="@+id/sms_holder" android:id="@+id/message_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="@dimen/activity_margin"> android:padding="@dimen/activity_margin">
<TextView <TextView
android:id="@+id/sms_address" android:id="@+id/message_address"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end" android:ellipsize="end"
@ -25,10 +25,10 @@
tools:text="John" /> tools:text="John" />
<TextView <TextView
android:id="@+id/sms_message_short" android:id="@+id/message_body_short"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/sms_address" android:layout_below="@+id/message_address"
android:alpha="0.6" android:alpha="0.6"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"