StringUtils -> kt

This commit is contained in:
Milos Kozak 2021-12-13 17:31:48 +01:00
parent 78c3810226
commit 946081fb0e
5 changed files with 129 additions and 99 deletions

View file

@ -1,17 +1,16 @@
package info.nightscout.androidaps.plugins.general.tidepool.messages
import info.nightscout.androidaps.R
import info.nightscout.androidaps.utils.StringUtils
import info.nightscout.shared.sharedPreferences.SP
import okhttp3.Credentials
class AuthRequestMessage : BaseMessage() {
companion object {
object AuthRequestMessage : BaseMessage() {
fun getAuthRequestHeader(sp: SP): String? {
val username = sp.getStringOrNull(R.string.key_tidepool_username, null)
val password = sp.getStringOrNull(R.string.key_tidepool_password, null)
return if (StringUtils.emptyString(username) || StringUtils.emptyString(password)) null else Credentials.basic(username!!.trim { it <= ' ' }, password!!)
}
return if (username.isNullOrEmpty() || password.isNullOrEmpty()) null
else Credentials.basic(username.trim { it <= ' ' }, password)
}
}

View file

@ -1,20 +0,0 @@
package info.nightscout.androidaps.utils;
/**
* class contains useful String functions
*/
public class StringUtils {
public static String removeSurroundingQuotes(String string) {
if (string.length() >= 2 && string.charAt(0) == '"'
&& string.charAt(string.length() - 1) == '"') {
string = string.substring(1, string.length() - 1);
}
return string;
}
public static boolean emptyString(final String str) {
return str == null || str.length() == 0;
}
}

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.utils
/**
* class contains useful String functions
*/
object StringUtils {
fun removeSurroundingQuotes(input: String): String {
var string = input
if (string.length >= 2 && string[0] == '"' && string[string.length - 1] == '"') {
string = string.substring(1, string.length - 1)
}
return string
}
}

View file

@ -4,9 +4,8 @@ import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.diaconn.DiaconnG8Pump
import info.nightscout.androidaps.diaconn.R
import info.nightscout.androidaps.diaconn.pumplog.PumplogUtil
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.utils.StringUtils
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.shared.logging.LTag
import info.nightscout.shared.sharedPreferences.SP
import javax.inject.Inject
@ -40,7 +39,7 @@ class BasalLimitInquireResponsePacket(injector: HasAndroidInjector) : DiaconnG8P
}
diaconnG8Pump.maxBasalPerHours = getShortToInt(bufferData).toDouble() / 100.0 // not include tempbasal limit
val pumpFirmwareVersion = sp.getString(rh.gs(R.string.pumpversion), "")
if(!StringUtils.emptyString(pumpFirmwareVersion) && PumplogUtil.isPumpVersionGe(pumpFirmwareVersion, 3, 0)) {
if(pumpFirmwareVersion.isNotEmpty() && PumplogUtil.isPumpVersionGe(pumpFirmwareVersion, 3, 0)) {
diaconnG8Pump.maxBasal = diaconnG8Pump.maxBasalPerHours * 2.5 // include tempbasal
} else {
diaconnG8Pump.maxBasal = diaconnG8Pump.maxBasalPerHours * 2.0 // include tempbasal

View file

@ -27,8 +27,6 @@ import info.nightscout.androidaps.interfaces.CommandQueue
import info.nightscout.androidaps.interfaces.Profile
import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.interfaces.PumpSync
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
@ -40,8 +38,9 @@ import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.queue.commands.Command
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.StringUtils
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.shared.sharedPreferences.SP
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
@ -54,6 +53,7 @@ import kotlin.math.ceil
import kotlin.math.min
class DiaconnG8Service : DaggerService() {
@Inject lateinit var injector: HasAndroidInjector
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var rxBus: RxBus
@ -87,6 +87,7 @@ class DiaconnG8Service : DaggerService() {
}
inner class LocalBinder : Binder() {
val serviceInstance: DiaconnG8Service
get() = this@DiaconnG8Service
}
@ -137,7 +138,7 @@ class DiaconnG8Service : DaggerService() {
val pumpFirmwareVersion = sp.getString(rh.gs(R.string.pumpversion), "")
if(!StringUtils.emptyString(pumpFirmwareVersion) && PumplogUtil.isPumpVersionGe(pumpFirmwareVersion, 3, 0)) {
if (pumpFirmwareVersion.isNotEmpty() && PumplogUtil.isPumpVersionGe(pumpFirmwareVersion, 3, 0)) {
sendMessage(BigAPSMainInfoInquirePacket(injector)) // APS Pump Main Info
} else {
sendMessage(BasalLimitInquirePacket(injector)) // basal Limit
@ -182,7 +183,6 @@ class DiaconnG8Service : DaggerService() {
//If time-diff is very large, warn user until we can synchronize history readings properly
ErrorHelperActivity.runAlarm(context, rh.gs(R.string.largetimediff), rh.gs(R.string.largetimedifftitle), R.raw.error)
//de-initialize pump
diaconnG8Pump.reset()
rxBus.send(EventDiaconnG8NewStatus())
@ -215,7 +215,12 @@ class DiaconnG8Service : DaggerService() {
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
val reportFail = Notification(Notification.APPROACHING_DAILY_LIMIT, rh.gs(R.string.approachingdailylimit), Notification.URGENT)
rxBus.send(EventNewNotification(reportFail))
pumpSync.insertAnnouncement(rh.gs(R.string.approachingdailylimit) + ": " + diaconnG8Pump.dailyTotalUnits + "/" + diaconnG8Pump.maxDailyTotalUnits + "U", null, PumpType.DIACONN_G8, diaconnG8Pump.serialNo.toString())
pumpSync.insertAnnouncement(
rh.gs(R.string.approachingdailylimit) + ": " + diaconnG8Pump.dailyTotalUnits + "/" + diaconnG8Pump.maxDailyTotalUnits + "U",
null,
PumpType.DIACONN_G8,
diaconnG8Pump.serialNo.toString()
)
lastApproachingDailyLimit = System.currentTimeMillis()
}
}
@ -564,16 +569,48 @@ class DiaconnG8Service : DaggerService() {
val basalList = diaconnG8Pump.buildDiaconnG8ProfileRecord(profile)
val requestReqPacket1 = BasalSettingPacket(
injector, 1, 1, (basalList[0] * 100).toInt(), (basalList[1] * 100).toInt(), (basalList[2] * 100).toInt(), (basalList[3] * 100).toInt(), (basalList[4] * 100).toInt(), (basalList[5] * 100).toInt()
injector,
1,
1,
(basalList[0] * 100).toInt(),
(basalList[1] * 100).toInt(),
(basalList[2] * 100).toInt(),
(basalList[3] * 100).toInt(),
(basalList[4] * 100).toInt(),
(basalList[5] * 100).toInt()
)
val requestReqPacket2 = BasalSettingPacket(
injector, 1, 2, (basalList[6] * 100).toInt(), (basalList[7] * 100).toInt(), (basalList[8] * 100).toInt(), (basalList[9] * 100).toInt(), (basalList[10] * 100).toInt(), (basalList[11] * 100).toInt()
injector,
1,
2,
(basalList[6] * 100).toInt(),
(basalList[7] * 100).toInt(),
(basalList[8] * 100).toInt(),
(basalList[9] * 100).toInt(),
(basalList[10] * 100).toInt(),
(basalList[11] * 100).toInt()
)
val requestReqPacket3 = BasalSettingPacket(
injector, 1, 3, (basalList[12] * 100).toInt(), (basalList[13] * 100).toInt(), (basalList[14] * 100).toInt(), (basalList[15] * 100).toInt(), (basalList[16] * 100).toInt(), (basalList[17] * 100).toInt()
injector,
1,
3,
(basalList[12] * 100).toInt(),
(basalList[13] * 100).toInt(),
(basalList[14] * 100).toInt(),
(basalList[15] * 100).toInt(),
(basalList[16] * 100).toInt(),
(basalList[17] * 100).toInt()
)
val requestReqPacket4 = BasalSettingPacket(
injector, 1, 4, (basalList[18] * 100).toInt(), (basalList[19] * 100).toInt(), (basalList[20] * 100).toInt(), (basalList[21] * 100).toInt(), (basalList[22] * 100).toInt(), (basalList[23] * 100).toInt()
injector,
1,
4,
(basalList[18] * 100).toInt(),
(basalList[19] * 100).toInt(),
(basalList[20] * 100).toInt(),
(basalList[21] * 100).toInt(),
(basalList[22] * 100).toInt(),
(basalList[23] * 100).toInt()
)
// setting basal pattern 1,2,3,4
sendMessage(requestReqPacket1)