BrCobIobComplication -> kt

This commit is contained in:
Milos Kozak 2022-05-02 22:21:13 +02:00
parent 4e0a83ba85
commit 7de2c5a53a
2 changed files with 42 additions and 54 deletions

View file

@ -1,54 +0,0 @@
package info.nightscout.androidaps.complications;
import android.app.PendingIntent;
import android.support.wearable.complications.ComplicationData;
import android.support.wearable.complications.ComplicationText;
import javax.inject.Inject;
import dagger.android.AndroidInjection;
import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.interaction.utils.DisplayFormat;
import info.nightscout.androidaps.interaction.utils.SmallestDoubleString;
import info.nightscout.shared.logging.LTag;
/*
* Created by dlvoy on 2019-11-12
*/
@SuppressWarnings("deprecation")
public class BrCobIobComplication extends BaseComplicationProviderService {
@Inject DisplayFormat displayFormat;
// Not derived from DaggerService, do injection here
@Override
public void onCreate() {
AndroidInjection.inject(this);
super.onCreate();
}
public ComplicationData buildComplicationData(int dataType, RawDisplayData raw, PendingIntent complicationPendingIntent) {
ComplicationData complicationData = null;
if (dataType == ComplicationData.TYPE_SHORT_TEXT) {
final String cob = new SmallestDoubleString(raw.getStatus().getCob(), SmallestDoubleString.Units.USE).minimise(displayFormat.MIN_FIELD_LEN_COB);
final String iob = new SmallestDoubleString(raw.getStatus().getIobSum(), SmallestDoubleString.Units.USE).minimise(Math.max(displayFormat.MIN_FIELD_LEN_IOB, (displayFormat.MAX_FIELD_LEN_SHORT - 1) - cob.length()));
final ComplicationData.Builder builder = new ComplicationData.Builder(ComplicationData.TYPE_SHORT_TEXT)
.setShortText(ComplicationText.plainText(displayFormat.basalRateSymbol() + raw.getStatus().getCurrentBasal()))
.setShortTitle(ComplicationText.plainText(cob + " " + iob))
.setTapAction(complicationPendingIntent);
complicationData = builder.build();
} else {
aapsLogger.warn(LTag.WEAR, "Unexpected complication type " + dataType);
}
return complicationData;
}
@Override
public String getProviderCanonicalName() {
return BrCobIobComplication.class.getCanonicalName();
}
}

View file

@ -0,0 +1,42 @@
@file:Suppress("DEPRECATION")
package info.nightscout.androidaps.complications
import android.app.PendingIntent
import android.support.wearable.complications.ComplicationData
import android.support.wearable.complications.ComplicationText
import dagger.android.AndroidInjection
import info.nightscout.androidaps.data.RawDisplayData
import info.nightscout.androidaps.interaction.utils.SmallestDoubleString
import info.nightscout.shared.logging.LTag
import kotlin.math.max
/*
* Created by dlvoy on 2019-11-12
*/
class BrCobIobComplication : BaseComplicationProviderService() {
// Not derived from DaggerService, do injection here
override fun onCreate() {
AndroidInjection.inject(this)
super.onCreate()
}
override fun buildComplicationData(dataType: Int, raw: RawDisplayData, complicationPendingIntent: PendingIntent): ComplicationData? {
var complicationData: ComplicationData? = null
if (dataType == ComplicationData.TYPE_SHORT_TEXT) {
val cob = SmallestDoubleString(raw.status.cob, SmallestDoubleString.Units.USE).minimise(displayFormat.MIN_FIELD_LEN_COB)
val iob = SmallestDoubleString(raw.status.iobSum, SmallestDoubleString.Units.USE).minimise(max(displayFormat.MIN_FIELD_LEN_IOB, displayFormat.MAX_FIELD_LEN_SHORT - 1 - cob.length))
val builder = ComplicationData.Builder(ComplicationData.TYPE_SHORT_TEXT)
.setShortText(ComplicationText.plainText(displayFormat.basalRateSymbol() + raw.status.currentBasal))
.setShortTitle(ComplicationText.plainText("$cob $iob"))
.setTapAction(complicationPendingIntent)
complicationData = builder.build()
} else {
aapsLogger.warn(LTag.WEAR, "Unexpected complication type $dataType")
}
return complicationData
}
override fun getProviderCanonicalName(): String = BrCobIobComplication::class.java.canonicalName!!
}