code cleanup

This commit is contained in:
Milos Kozak 2022-03-30 20:54:06 +02:00
parent 0ec2a498c4
commit 0f67f74c96
18 changed files with 29 additions and 38 deletions

View file

@ -372,7 +372,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
if (sp.getString(pref.key, "").startsWith("hmac:")) { if (sp.getString(pref.key, "").startsWith("hmac:")) {
pref.summary = "******" pref.summary = "******"
} else { } else {
if (pref.getKey().contains("pin")) { if (pref.key.contains("pin")) {
pref.summary = rh.gs(R.string.pin_not_set) pref.summary = rh.gs(R.string.pin_not_set)
}else { }else {
pref.summary = rh.gs(R.string.password_not_set) pref.summary = rh.gs(R.string.password_not_set)

View file

@ -65,7 +65,7 @@ class PreferencesActivity : NoSplashAppCompatActivity(), PreferenceFragmentCompa
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.getItemId()) { when (item.itemId) {
android.R.id.home -> { android.R.id.home -> {
onBackPressed() onBackPressed()
return true return true

View file

@ -51,7 +51,7 @@ class DetermineBasalResultSMB private constructor(injector: HasAndroidInjector)
aapsLogger.error(LTag.APS, "Error parsing 'deliverAt' date: $date", e) aapsLogger.error(LTag.APS, "Error parsing 'deliverAt' date: $date", e)
} }
} }
if (result.has("variable_sens")) variableSens = result.getDouble("variable_sens"); if (result.has("variable_sens")) variableSens = result.getDouble("variable_sens")
} catch (e: JSONException) { } catch (e: JSONException) {
aapsLogger.error(LTag.APS, "Error parsing determine-basal result JSON", e) aapsLogger.error(LTag.APS, "Error parsing determine-basal result JSON", e)
} }

View file

@ -120,7 +120,7 @@ class SendToDataLayerThread extends AsyncTask<DataMap,Void,Void> {
} }
state = 0; state = 0;
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, logPrefix + "Got exception in sendToWear: " + e.toString()); Log.e(TAG, logPrefix + "Got exception in sendToWear: " + e);
} finally { } finally {
lastlock = 0; lastlock = 0;
lock.unlock(); lock.unlock();

View file

@ -574,17 +574,17 @@ class IobCobCalculatorPlugin @Inject constructor(
override fun getTempBasalIncludingConvertedExtended(timestamp: Long): TemporaryBasal? { override fun getTempBasalIncludingConvertedExtended(timestamp: Long): TemporaryBasal? {
val tb = repository.getTemporaryBasalActiveAt(timestamp).blockingGet() val tb = repository.getTemporaryBasalActiveAt(timestamp).blockingGet()
if (tb is ValueWrapper.Existing) return tb.value if (tb is ValueWrapper.Existing) return tb.value
return getConvertedExtended(timestamp); return getConvertedExtended(timestamp)
} }
override fun getTempBasalIncludingConvertedExtendedForRange(startTime: Long, endTime: Long, calculationStep: Long): Map<Long, TemporaryBasal?> { override fun getTempBasalIncludingConvertedExtendedForRange(startTime: Long, endTime: Long, calculationStep: Long): Map<Long, TemporaryBasal?> {
val tempBasals = HashMap<Long, TemporaryBasal?>(); val tempBasals = HashMap<Long, TemporaryBasal?>()
val tbs = repository.getTemporaryBasalsDataActiveBetweenTimeAndTime(startTime, endTime).blockingGet() val tbs = repository.getTemporaryBasalsDataActiveBetweenTimeAndTime(startTime, endTime).blockingGet()
for (t in startTime until endTime step calculationStep) { for (t in startTime until endTime step calculationStep) {
val tb = tbs.firstOrNull { basal -> basal.timestamp <= t && (basal.timestamp + basal.duration) > t } val tb = tbs.firstOrNull { basal -> basal.timestamp <= t && (basal.timestamp + basal.duration) > t }
tempBasals[t] = tb ?: getConvertedExtended(t) tempBasals[t] = tb ?: getConvertedExtended(t)
} }
return tempBasals; return tempBasals
} }
override fun calculateAbsoluteIobFromBaseBasals(toTime: Long): IobTotal { override fun calculateAbsoluteIobFromBaseBasals(toTime: Long): IobTotal {

View file

@ -52,10 +52,6 @@ class VirtualPumpFragment : DaggerFragment() {
return binding.root return binding.root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
@Synchronized @Synchronized
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()

View file

@ -109,25 +109,25 @@ public class ReadHistoryCommand extends BaseCommand {
if (!history.bolusHistory.isEmpty()) { if (!history.bolusHistory.isEmpty()) {
aapsLogger.debug(LTag.PUMP, "Read bolus history (" + history.bolusHistory.size() + "):"); aapsLogger.debug(LTag.PUMP, "Read bolus history (" + history.bolusHistory.size() + "):");
for (Bolus bolus : history.bolusHistory) { for (Bolus bolus : history.bolusHistory) {
aapsLogger.debug(LTag.PUMP, new Date(bolus.timestamp) + ": " + bolus.toString()); aapsLogger.debug(LTag.PUMP, new Date(bolus.timestamp) + ": " + bolus);
} }
} }
if (!history.pumpAlertHistory.isEmpty()) { if (!history.pumpAlertHistory.isEmpty()) {
aapsLogger.debug(LTag.PUMP, "Read error history (" + history.pumpAlertHistory.size() + "):"); aapsLogger.debug(LTag.PUMP, "Read error history (" + history.pumpAlertHistory.size() + "):");
for (PumpAlert pumpAlert : history.pumpAlertHistory) { for (PumpAlert pumpAlert : history.pumpAlertHistory) {
aapsLogger.debug(LTag.PUMP, new Date(pumpAlert.timestamp) + ": " + pumpAlert.toString()); aapsLogger.debug(LTag.PUMP, new Date(pumpAlert.timestamp) + ": " + pumpAlert);
} }
} }
if (!history.tddHistory.isEmpty()) { if (!history.tddHistory.isEmpty()) {
aapsLogger.debug(LTag.PUMP, "Read TDD history (" + history.tddHistory.size() + "):"); aapsLogger.debug(LTag.PUMP, "Read TDD history (" + history.tddHistory.size() + "):");
for (Tdd tdd : history.tddHistory) { for (Tdd tdd : history.tddHistory) {
aapsLogger.debug(LTag.PUMP, new Date(tdd.timestamp) + ": " + tdd.toString()); aapsLogger.debug(LTag.PUMP, new Date(tdd.timestamp) + ": " + tdd);
} }
} }
if (!history.tbrHistory.isEmpty()) { if (!history.tbrHistory.isEmpty()) {
aapsLogger.debug(LTag.PUMP, "Read TBR history (" + history.tbrHistory.size() + "):"); aapsLogger.debug(LTag.PUMP, "Read TBR history (" + history.tbrHistory.size() + "):");
for (Tbr tbr : history.tbrHistory) { for (Tbr tbr : history.tbrHistory) {
aapsLogger.debug(LTag.PUMP, new Date(tbr.timestamp) + ": " + tbr.toString()); aapsLogger.debug(LTag.PUMP, new Date(tbr.timestamp) + ": " + tbr);
} }
} }

View file

@ -163,10 +163,8 @@ public class PointsWithLabelGraphSeries<E extends DataPointWithLabelInterface> e
double x = graphWidth * ratX; double x = graphWidth * ratX;
// overdraw // overdraw
boolean overdraw = false; boolean overdraw = x > graphWidth;
if (x > graphWidth) { // end right // end right
overdraw = true;
}
if (y < 0) { // end bottom if (y < 0) { // end bottom
overdraw = true; overdraw = true;
} }

View file

@ -57,7 +57,7 @@ class MedtronicHistoryDataUTest : TestBase() {
val fileText = ClassLoader.getSystemResource("tbr_data.json").readText() val fileText = ClassLoader.getSystemResource("tbr_data.json").readText()
val listType: Type = object : TypeToken<MutableList<PumpHistoryEntry?>?>() {}.getType() val listType: Type = object : TypeToken<MutableList<PumpHistoryEntry?>?>() {}.type
val yourClassList: MutableList<PumpHistoryEntry> = gson.fromJson(fileText, listType) val yourClassList: MutableList<PumpHistoryEntry> = gson.fromJson(fileText, listType)
for (pumpHistoryEntry in yourClassList) { for (pumpHistoryEntry in yourClassList) {
@ -100,7 +100,7 @@ class MedtronicHistoryDataUTest : TestBase() {
val fileText = ClassLoader.getSystemResource("tbr_data_special.json").readText() val fileText = ClassLoader.getSystemResource("tbr_data_special.json").readText()
val listType: Type = object : TypeToken<MutableList<PumpHistoryEntry?>?>() {}.getType() val listType: Type = object : TypeToken<MutableList<PumpHistoryEntry?>?>() {}.type
val yourClassList: MutableList<PumpHistoryEntry> = gson.fromJson(fileText, listType) val yourClassList: MutableList<PumpHistoryEntry> = gson.fromJson(fileText, listType)
for (pumpHistoryEntry in yourClassList) { for (pumpHistoryEntry in yourClassList) {

View file

@ -34,7 +34,7 @@ class ErosHistoryTest {
@Test @Test
fun testInsertionAndRetrieval() { fun testInsertionAndRetrieval() {
var history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L); var history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L)
assert(history.isEmpty()) assert(history.isEmpty())
val type = PodHistoryEntryType.SET_BOLUS.code.toLong() val type = PodHistoryEntryType.SET_BOLUS.code.toLong()
@ -42,7 +42,7 @@ class ErosHistoryTest {
erosHistory.create(entity) erosHistory.create(entity)
erosHistory.create(ErosHistoryRecordEntity(3000L, PodHistoryEntryType.CANCEL_BOLUS.code.toLong())) erosHistory.create(ErosHistoryRecordEntity(3000L, PodHistoryEntryType.CANCEL_BOLUS.code.toLong()))
history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L); history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L)
assert(history.size == 2) assert(history.size == 2)
assert(type.equals(history.first().podEntryTypeCode)) assert(type.equals(history.first().podEntryTypeCode))

View file

@ -67,10 +67,7 @@ data class PumpDbEntryBolus(override var temporaryId: Long,
detailedBolusInfo: DetailedBolusInfo) : this(temporaryId, date, pumpType, serialNumber, null, detailedBolusInfo: DetailedBolusInfo) : this(temporaryId, date, pumpType, serialNumber, null,
detailedBolusInfo.insulin, detailedBolusInfo.insulin,
detailedBolusInfo.carbs, detailedBolusInfo.carbs,
detailedBolusInfo.bolusType) { detailedBolusInfo.bolusType)
}
} }

View file

@ -7,5 +7,4 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data;
public enum RLMessageType { public enum RLMessageType {
PowerOn, // for powering on the pump (wakeup) PowerOn, // for powering on the pump (wakeup)
ReadSimpleData, // for checking if pump is readable (for Medtronic we can use GetModel) ReadSimpleData, // for checking if pump is readable (for Medtronic we can use GetModel)
;
} }

View file

@ -7,5 +7,4 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs;
public enum RLMessageType { public enum RLMessageType {
PowerOn, // for powering on the pump (wakeup) PowerOn, // for powering on the pump (wakeup)
ReadSimpleData, // for checking if pump is readable (for Medtronic we can use GetModel) ReadSimpleData, // for checking if pump is readable (for Medtronic we can use GetModel)
;
} }

View file

@ -22,7 +22,7 @@ import info.nightscout.androidaps.interaction.utils.WearUtil;
*/ */
public class RawDisplayData { public class RawDisplayData {
private WearUtil wearUtil; private final WearUtil wearUtil;
public RawDisplayData(WearUtil wearUtil) { public RawDisplayData(WearUtil wearUtil) {
this.wearUtil = wearUtil; this.wearUtil = wearUtil;

View file

@ -26,10 +26,10 @@ import info.nightscout.shared.logging.LTag;
@Singleton @Singleton
public class Persistence { public class Persistence {
private Context context; private final Context context;
private AAPSLogger aapsLogger; private final AAPSLogger aapsLogger;
private WearUtil wearUtil; private final WearUtil wearUtil;
private SharedPreferences preferences; private final SharedPreferences preferences;
private final String COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY = private final String COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY =
"info.nightscout.androidaps.complications.COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY"; "info.nightscout.androidaps.complications.COMPLICATION_PROVIDER_PREFERENCES_FILE_KEY";

View file

@ -76,7 +76,7 @@ public class WearUtil {
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AAPS::" + name); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AAPS::" + name);
wl.acquire(millis); wl.acquire(millis);
if (debug_wakelocks) if (debug_wakelocks)
aapsLogger.debug(LTag.WEAR, "getWakeLock: " + name + " " + wl.toString()); aapsLogger.debug(LTag.WEAR, "getWakeLock: " + name + " " + wl);
return wl; return wl;
} }

View file

@ -3,6 +3,6 @@ package info.nightscout.androidaps.tile
class TempTargetTileService : TileBase() { class TempTargetTileService : TileBase() {
override val resourceVersion = "TempTargetTileService" override val resourceVersion = "TempTargetTileService"
override val source = TempTargetSource; override val source = TempTargetSource
} }

View file

@ -18,7 +18,6 @@ import android.os.Vibrator;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.wearable.view.WatchViewStub; import android.support.wearable.view.WatchViewStub;
import android.text.format.DateFormat; import android.text.format.DateFormat;
import android.util.Log;
import android.view.Display; import android.view.Display;
import android.view.View; import android.view.View;
import android.view.WindowInsets; import android.view.WindowInsets;
@ -49,6 +48,8 @@ import info.nightscout.androidaps.data.ListenerService;
import info.nightscout.androidaps.data.RawDisplayData; import info.nightscout.androidaps.data.RawDisplayData;
import info.nightscout.androidaps.interaction.utils.Persistence; import info.nightscout.androidaps.interaction.utils.Persistence;
import info.nightscout.androidaps.interaction.utils.WearUtil; import info.nightscout.androidaps.interaction.utils.WearUtil;
import info.nightscout.shared.logging.AAPSLogger;
import info.nightscout.shared.logging.LTag;
import lecho.lib.hellocharts.view.LineChartView; import lecho.lib.hellocharts.view.LineChartView;
/** /**
@ -61,6 +62,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
@Inject WearUtil wearUtil; @Inject WearUtil wearUtil;
@Inject Persistence persistence; @Inject Persistence persistence;
@Inject AAPSLogger aapsLogger;
public final static IntentFilter INTENT_FILTER; public final static IntentFilter INTENT_FILTER;
@ -382,7 +384,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
private void checkVibrateHourly(WatchFaceTime oldTime, WatchFaceTime newTime) { private void checkVibrateHourly(WatchFaceTime oldTime, WatchFaceTime newTime) {
boolean hourlyVibratePref = sharedPrefs.getBoolean("vibrate_Hourly", false); boolean hourlyVibratePref = sharedPrefs.getBoolean("vibrate_Hourly", false);
if (hourlyVibratePref && layoutSet && newTime.hasHourChanged(oldTime)) { if (hourlyVibratePref && layoutSet && newTime.hasHourChanged(oldTime)) {
Log.i("hourlyVibratePref", "true --> " + newTime.toString()); aapsLogger.info(LTag.WEAR, "hourlyVibratePref", "true --> " + newTime);
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
long[] vibrationPattern = {0, 150, 125, 100}; long[] vibrationPattern = {0, 150, 125, 100};
vibrator.vibrate(vibrationPattern, -1); vibrator.vibrate(vibrationPattern, -1);