mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-23 23:17:38 +01:00
remember the last used SIM card on a per-number basis
This commit is contained in:
parent
f5d3c2ab70
commit
cc2a4e596f
@ -1,5 +1,6 @@
|
|||||||
package com.simplemobiletools.smsmessenger.activities
|
package com.simplemobiletools.smsmessenger.activities
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
@ -146,6 +147,8 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||||
thread_type_message.requestFocus()
|
thread_type_message.requestFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupSIMSelector()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setupButtons()
|
setupButtons()
|
||||||
@ -265,7 +268,10 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
addAttachment(it)
|
addAttachment(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("MissingPermission")
|
||||||
|
private fun setupSIMSelector() {
|
||||||
val availableSIMs = SubscriptionManager.from(this).activeSubscriptionInfoList
|
val availableSIMs = SubscriptionManager.from(this).activeSubscriptionInfoList
|
||||||
if (availableSIMs.size > 1) {
|
if (availableSIMs.size > 1) {
|
||||||
availableSIMs.forEachIndexed { index, subscriptionInfo ->
|
availableSIMs.forEachIndexed { index, subscriptionInfo ->
|
||||||
@ -277,8 +283,10 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
availableSIMCards.add(SIMCard)
|
availableSIMCards.add(SIMCard)
|
||||||
}
|
}
|
||||||
|
|
||||||
currentSIMCardIndex = 0
|
val numbers = participants.map { it.phoneNumber }.toTypedArray()
|
||||||
thread_select_sim_icon.applyColorFilter(textColor)
|
currentSIMCardIndex = availableSIMs.indexOfFirstOrNull { it.subscriptionId == config.getUseSIMIdAtNumber(numbers.first()) } ?: 0
|
||||||
|
|
||||||
|
thread_select_sim_icon.applyColorFilter(config.textColor)
|
||||||
thread_select_sim_icon.beVisible()
|
thread_select_sim_icon.beVisible()
|
||||||
thread_select_sim_number.beVisible()
|
thread_select_sim_number.beVisible()
|
||||||
|
|
||||||
@ -291,8 +299,8 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_select_sim_number.setTextColor(textColor.getContrastColor())
|
thread_select_sim_number.setTextColor(config.textColor.getContrastColor())
|
||||||
thread_select_sim_number.text = "1"
|
thread_select_sim_number.text = (availableSIMCards[currentSIMCardIndex].id).toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,6 +477,9 @@ class ThreadActivity : SimpleActivity() {
|
|||||||
val SIMId = availableSIMCards.getOrNull(currentSIMCardIndex)?.subscriptionId
|
val SIMId = availableSIMCards.getOrNull(currentSIMCardIndex)?.subscriptionId
|
||||||
if (SIMId != null) {
|
if (SIMId != null) {
|
||||||
settings.subscriptionId = SIMId
|
settings.subscriptionId = SIMId
|
||||||
|
numbers.forEach {
|
||||||
|
config.saveUseSIMIdAtNumber(it, SIMId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val transaction = Transaction(this, settings)
|
val transaction = Transaction(this, settings)
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.simplemobiletools.smsmessenger.extensions
|
||||||
|
|
||||||
|
inline fun <T> List<T>.indexOfFirstOrNull(predicate: (T) -> Boolean): Int? {
|
||||||
|
var index = 0
|
||||||
|
for (item in this) {
|
||||||
|
if (predicate(item))
|
||||||
|
return index
|
||||||
|
index++
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
@ -7,4 +7,10 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
companion object {
|
companion object {
|
||||||
fun newInstance(context: Context) = Config(context)
|
fun newInstance(context: Context) = Config(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun saveUseSIMIdAtNumber(number: String, SIMId: Int) {
|
||||||
|
prefs.edit().putInt(USE_SIM_ID_PREFIX + number, SIMId).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getUseSIMIdAtNumber(number: String) = prefs.getInt(USE_SIM_ID_PREFIX + number, 0)
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ const val THREAD_TEXT = "thread_text"
|
|||||||
const val THREAD_NUMBER = "thread_number"
|
const val THREAD_NUMBER = "thread_number"
|
||||||
const val THREAD_ATTACHMENT_URI = "thread_attachment_uri"
|
const val THREAD_ATTACHMENT_URI = "thread_attachment_uri"
|
||||||
const val THREAD_ATTACHMENT_URIS = "thread_attachment_uris"
|
const val THREAD_ATTACHMENT_URIS = "thread_attachment_uris"
|
||||||
|
const val USE_SIM_ID_PREFIX = "use_sim_id_"
|
||||||
|
|
||||||
// view types for the thread list view
|
// view types for the thread list view
|
||||||
const val THREAD_DATE_TIME = 1
|
const val THREAD_DATE_TIME = 1
|
||||||
@ -16,10 +17,6 @@ const val THREAD_RECEIVED_MESSAGE = 2
|
|||||||
const val THREAD_SENT_MESSAGE = 3
|
const val THREAD_SENT_MESSAGE = 3
|
||||||
const val THREAD_SENT_MESSAGE_ERROR = 4
|
const val THREAD_SENT_MESSAGE_ERROR = 4
|
||||||
|
|
||||||
// constants used at passing info to SmsSentReceiver
|
|
||||||
const val MESSAGE_BODY = "message_body"
|
|
||||||
const val MESSAGE_ADDRESS = "message_address"
|
|
||||||
|
|
||||||
fun refreshMessages() {
|
fun refreshMessages() {
|
||||||
EventBus.getDefault().post(Events.RefreshMessages())
|
EventBus.getDefault().post(Events.RefreshMessages())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user