show the SIM card ID at messages

This commit is contained in:
tibbi 2020-05-13 15:27:25 +02:00
parent 516aab0d5c
commit 64bb563ef6
4 changed files with 56 additions and 8 deletions

View File

@ -370,16 +370,24 @@ class ThreadActivity : SimpleActivity() {
showSelectedContacts()
}
@SuppressLint("MissingPermission")
private fun getThreadItems(): ArrayList<ThreadItem> {
messages.sortBy { it.date }
val subscriptionIdToSimId = HashMap<Int, String>()
subscriptionIdToSimId[-1] = "?"
SubscriptionManager.from(this).activeSubscriptionInfoList.forEachIndexed { index, subscriptionInfo ->
subscriptionIdToSimId[subscriptionInfo.subscriptionId] = "${index + 1}"
}
val items = ArrayList<ThreadItem>()
var prevDateTime = 0
var hadUnreadItems = false
messages.forEach {
// do not show the date/time above every message, only if the difference between the 2 messages is at least MIN_DATE_TIME_DIFF_SECS
if (it.date - prevDateTime > MIN_DATE_TIME_DIFF_SECS) {
items.add(ThreadDateTime(it.date))
val simCardID = subscriptionIdToSimId[it.subscriptionId] ?: "?"
items.add(ThreadDateTime(it.date, simCardID))
prevDateTime = it.date
}
items.add(it)

View File

@ -3,6 +3,7 @@ package com.simplemobiletools.smsmessenger.adapters
import android.content.Intent
import android.graphics.drawable.Drawable
import android.net.Uri
import android.telephony.SubscriptionManager
import android.view.Menu
import android.view.View
import android.view.ViewGroup
@ -42,6 +43,7 @@ class ThreadAdapter(activity: SimpleActivity, var messages: ArrayList<ThreadItem
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
private val roundedCornersRadius = resources.getDimension(R.dimen.normal_margin).toInt()
private val hasMultipleSIMCards = SubscriptionManager.from(activity).activeSubscriptionInfoList.size > 1
init {
setupDragListener(true)
@ -283,6 +285,14 @@ class ThreadAdapter(activity: SimpleActivity, var messages: ArrayList<ThreadItem
view.apply {
thread_date_time.text = dateTime.date.formatDateOrTime(context, false)
thread_date_time.setTextColor(textColor)
thread_sim_icon.beVisibleIf(hasMultipleSIMCards)
thread_sim_number.beVisibleIf(hasMultipleSIMCards)
if (hasMultipleSIMCards) {
thread_sim_number.text = dateTime.simID
thread_sim_number.setTextColor(textColor.getContrastColor())
thread_sim_icon.applyColorFilter(textColor)
}
}
}
}

View File

@ -1,3 +1,3 @@
package com.simplemobiletools.smsmessenger.models
open class ThreadDateTime(val date: Int) : ThreadItem()
open class ThreadDateTime(val date: Int, val simID: String) : ThreadItem()

View File

@ -1,10 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/thread_date_time"
android:id="@+id/thread_date_time_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/normal_margin"
android:gravity="center_horizontal"
android:textSize="@dimen/normal_text_size"
tools:text="13 March, 13:30" />
android:layout_marginTop="@dimen/medium_margin">
<TextView
android:id="@+id/thread_date_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="@dimen/normal_text_size"
tools:text="13 March, 13:30" />
<ImageView
android:id="@+id/thread_sim_icon"
android:layout_width="@dimen/activity_margin"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thread_date_time"
android:layout_alignBottom="@id/thread_date_time"
android:layout_marginEnd="@dimen/small_margin"
android:layout_toStartOf="@id/thread_date_time"
android:src="@drawable/ic_sim_vector" />
<TextView
android:id="@+id/thread_sim_number"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignStart="@+id/thread_sim_icon"
android:layout_alignTop="@+id/thread_sim_icon"
android:layout_alignEnd="@+id/thread_sim_icon"
android:layout_alignBottom="@+id/thread_sim_icon"
android:gravity="center"
android:textColor="@color/md_grey_black"
android:textSize="@dimen/smaller_text_size"
tools:text="1" />
</RelativeLayout>