This commit is contained in:
Milos Kozak 2019-11-25 17:06:08 +01:00
parent 46270d87e2
commit 1ea25b68a8

View file

@ -39,7 +39,6 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorP
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.* import info.nightscout.androidaps.utils.*
import info.nightscout.androidaps.utils.DateUtil.now
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.StringUtils
@ -98,9 +97,10 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
override fun preprocessPreferences(preferenceFragment: PreferenceFragment) { override fun preprocessPreferences(preferenceFragment: PreferenceFragment) {
super.preprocessPreferences(preferenceFragment) super.preprocessPreferences(preferenceFragment)
val distance = preferenceFragment.findPreference(MainApp.gs(R.string.key_smscommunicator_remotebolusmindistance)) as ValidatingEditTextPreference val distance = preferenceFragment.findPreference(MainApp.gs(R.string.key_smscommunicator_remotebolusmindistance)) as ValidatingEditTextPreference?
val allowedNumbers = preferenceFragment.findPreference(MainApp.gs(R.string.key_smscommunicator_allowednumbers)) as EditTextPreference ?: return
if (distance != null && allowedNumbers != null) { val allowedNumbers = preferenceFragment.findPreference(MainApp.gs(R.string.key_smscommunicator_allowednumbers)) as EditTextPreference?
?: return
if (!areMoreNumbers(allowedNumbers.text)) { if (!areMoreNumbers(allowedNumbers.text)) {
distance.title = (MainApp.gs(R.string.smscommunicator_remotebolusmindistance) distance.title = (MainApp.gs(R.string.smscommunicator_remotebolusmindistance)
+ ".\n" + ".\n"
@ -124,7 +124,6 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
true true
} }
} }
}
override fun updatePreferenceSummary(pref: Preference) { override fun updatePreferenceSummary(pref: Preference) {
super.updatePreferenceSummary(pref) super.updatePreferenceSummary(pref)
@ -166,9 +165,10 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
fun handleNewData(intent: Intent) { fun handleNewData(intent: Intent) {
val bundle = intent.extras ?: return val bundle = intent.extras ?: return
val format = bundle.getString("format") ?: return
val pdus = bundle["pdus"] as Array<*> val pdus = bundle["pdus"] as Array<*>
for (pdu in pdus) { for (pdu in pdus) {
val message = SmsMessage.createFromPdu(pdu as ByteArray) val message = SmsMessage.createFromPdu(pdu as ByteArray, format)
processSms(Sms(message)) processSms(Sms(message))
} }
} }
@ -789,7 +789,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
if (currentProfile != null) { if (currentProfile != null) {
val tempTarget = TempTarget() val tempTarget = TempTarget()
.source(Source.USER) .source(Source.USER)
.date(now()) .date(DateUtil.now())
.duration(0) .duration(0)
.low(0.0) .low(0.0)
.high(0.0) .high(0.0)
@ -887,7 +887,6 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
private fun generatePasscode(): String { private fun generatePasscode(): String {
val startChar1 = 'A'.toInt() // on iphone 1st char is uppercase :) val startChar1 = 'A'.toInt() // on iphone 1st char is uppercase :)
var passCode = Character.toString((startChar1 + Math.random() * ('z' - 'a' + 1)).toChar()) var passCode = Character.toString((startChar1 + Math.random() * ('z' - 'a' + 1)).toChar())
//For Milos: may we have only 'a'.toInt() for the 2nd and 3rd chars? Upper letters are uncomfortable here
val startChar2: Int = if (Math.random() > 0.5) 'a'.toInt() else 'A'.toInt() val startChar2: Int = if (Math.random() > 0.5) 'a'.toInt() else 'A'.toInt()
passCode += Character.toString((startChar2 + Math.random() * ('z' - 'a' + 1)).toChar()) passCode += Character.toString((startChar2 + Math.random() * ('z' - 'a' + 1)).toChar())
val startChar3: Int = if (Math.random() > 0.5) 'a'.toInt() else 'A'.toInt() val startChar3: Int = if (Math.random() > 0.5) 'a'.toInt() else 'A'.toInt()