diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index e0e2a6b05b..861ee368ca 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
package="info.nightscout.androidaps">
+
+ /* + This method is triggered once autosens calculation has completed, so the LoopPlugin + has current data to work with. However, autosens calculation can be triggered by multiple + sources and currently only a new BG should trigger a loop run. Hence we return early if + the event causing the calculation is not EventNewBg. +
*/
disposable.add(rxBus
.toObservable(EventAutosensCalculationFinished.class)
@@ -212,15 +211,12 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
}
private void createNotificationChannel() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
-
- NotificationManager mNotificationManager =
- (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- @SuppressLint("WrongConstant") NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
- CHANNEL_ID,
- NotificationManager.IMPORTANCE_HIGH);
- mNotificationManager.createNotificationChannel(channel);
- }
+ NotificationManager mNotificationManager =
+ (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+ @SuppressLint("WrongConstant") NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
+ CHANNEL_ID,
+ NotificationManager.IMPORTANCE_HIGH);
+ mNotificationManager.createNotificationChannel(channel);
}
@Override
@@ -240,10 +236,6 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
}
}
- public long suspendedTo() {
- return loopSuspendedTill;
- }
-
public void suspendTo(long endTime) {
loopSuspendedTill = endTime;
isSuperBolus = false;
@@ -341,8 +333,9 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
}
return isDisconnected;
}
+
public boolean treatmentTimethreshold(int duartionMinutes) {
- long threshold = System.currentTimeMillis() + (duartionMinutes*60*1000);
+ long threshold = System.currentTimeMillis() + (duartionMinutes * 60 * 1000);
boolean bool = false;
if (treatmentsPlugin.getLastBolusTime() > threshold || treatmentsPlugin.getLastCarbTime() > threshold)
bool = true;
@@ -414,7 +407,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
// safety check for multiple SMBs
long lastBolusTime = treatmentsPlugin.getLastBolusTime();
if (lastBolusTime != 0 && lastBolusTime + T.mins(3).msecs() > System.currentTimeMillis()) {
- getAapsLogger().debug(LTag.APS, "SMB requsted but still in 3 min interval");
+ getAapsLogger().debug(LTag.APS, "SMB requested but still in 3 min interval");
resultAfterConstraints.smb = 0;
}
@@ -456,31 +449,31 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
&& resultAfterConstraints.carbsReq >= sp.getInt(R.string.key_smb_enable_carbs_suggestions_threshold, 0)
&& carbsSuggestionsSuspendedUntil < System.currentTimeMillis() && !treatmentTimethreshold(-15)) {
- if (sp.getBoolean(R.string.key_enable_carbs_required_alert_local,true) && !sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, false)) {
+ if (sp.getBoolean(R.string.key_enable_carbs_required_alert_local, true) && !sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, false)) {
Notification carbreqlocal = new Notification(Notification.CARBS_REQUIRED, resultAfterConstraints.getCarbsRequiredText(), Notification.NORMAL);
rxBus.send(new EventNewNotification(carbreqlocal));
}
if (sp.getBoolean(R.string.key_ns_create_announcements_from_carbs_req, false)) {
nsUpload.uploadError(resultAfterConstraints.getCarbsRequiredText());
}
- if (sp.getBoolean(R.string.key_enable_carbs_required_alert_local,true) && sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, false)){
+ if (sp.getBoolean(R.string.key_enable_carbs_required_alert_local, true) && sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, false)) {
Intent intentAction5m = new Intent(context, CarbSuggestionReceiver.class);
intentAction5m.putExtra("ignoreDuration", 5);
PendingIntent pendingIntent5m = PendingIntent.getBroadcast(context, 1, intentAction5m, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action actionIgnore5m = new
- NotificationCompat.Action(R.drawable.ic_notif_aaps, resourceHelper.gs(R.string.ignore5m,"Ignore 5m"), pendingIntent5m);
+ NotificationCompat.Action(R.drawable.ic_notif_aaps, resourceHelper.gs(R.string.ignore5m, "Ignore 5m"), pendingIntent5m);
Intent intentAction15m = new Intent(context, CarbSuggestionReceiver.class);
intentAction15m.putExtra("ignoreDuration", 15);
PendingIntent pendingIntent15m = PendingIntent.getBroadcast(context, 1, intentAction15m, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action actionIgnore15m = new
- NotificationCompat.Action(R.drawable.ic_notif_aaps, resourceHelper.gs(R.string.ignore15m,"Ignore 15m"), pendingIntent15m);
+ NotificationCompat.Action(R.drawable.ic_notif_aaps, resourceHelper.gs(R.string.ignore15m, "Ignore 15m"), pendingIntent15m);
Intent intentAction30m = new Intent(context, CarbSuggestionReceiver.class);
intentAction30m.putExtra("ignoreDuration", 30);
PendingIntent pendingIntent30m = PendingIntent.getBroadcast(context, 1, intentAction30m, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action actionIgnore30m = new
- NotificationCompat.Action(R.drawable.ic_notif_aaps, resourceHelper.gs(R.string.ignore30m,"Ignore 30m"), pendingIntent30m);
+ NotificationCompat.Action(R.drawable.ic_notif_aaps, resourceHelper.gs(R.string.ignore30m, "Ignore 30m"), pendingIntent30m);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID);
builder.setSmallIcon(R.drawable.notif_icon)
@@ -511,7 +504,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
} else {
//If carbs were required previously, but are no longer needed, dismiss notifications
- if ( prevCarbsreq > 0 ) {
+ if (prevCarbsreq > 0) {
dismissSuggestion();
rxBus.send(new EventDismissNotification(Notification.CARBS_REQUIRED));
}
@@ -591,8 +584,8 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
}
}
- public void disableCarbSuggestions(int duartionMinutes) {
- carbsSuggestionsSuspendedUntil = System.currentTimeMillis() + (duartionMinutes*60*1000);
+ public void disableCarbSuggestions(int durationMinutes) {
+ carbsSuggestionsSuspendedUntil = System.currentTimeMillis() + (durationMinutes * 60 * 1000);
dismissSuggestion();
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt
index af530665f0..eefaa2963e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/openhumans/OpenHumansUploader.kt
@@ -85,6 +85,7 @@ class OpenHumansUploader @Inject constructor(
}
private val openHumansAPI = OpenHumansAPI(OPEN_HUMANS_URL, CLIENT_ID, CLIENT_SECRET, REDIRECT_URL)
+ @Suppress("PrivatePropertyName")
private val FILE_NAME_DATE_FORMAT = SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.US).apply { timeZone = TimeZone.getTimeZone("UTC") }
private var isSetup
@@ -126,12 +127,12 @@ class OpenHumansUploader @Inject constructor(
private val appId: UUID
get() {
val id = sp.getStringOrNull("openhumans_appid", null)
- if (id == null) {
+ return if (id == null) {
val generated = UUID.randomUUID()
sp.putString("openhumans_appid", generated.toString())
- return generated
+ generated
} else {
- return UUID.fromString(id)
+ UUID.fromString(id)
}
}
@@ -140,7 +141,7 @@ class OpenHumansUploader @Inject constructor(
private val wakeLock = (context.getSystemService(Context.POWER_SERVICE) as PowerManager)
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS::OpenHumans")
- val preferenceChangeDisposable = CompositeDisposable()
+ private val preferenceChangeDisposable = CompositeDisposable()
override fun onStart() {
super.onStart()
@@ -453,7 +454,8 @@ class OpenHumansUploader @Inject constructor(
aapsLogger.error(LTag.OHUPLOADER, "Segmental upload exceptional", it)
}
- fun uploadData(maxEntries: Long?): Completable = gatherData(maxEntries)
+ @Suppress("SameParameterValue")
+ private fun uploadData(maxEntries: Long?): Completable = gatherData(maxEntries)
.flatMap { data -> refreshAccessTokensIfNeeded().map { accessToken -> accessToken to data } }
.flatMap { uploadFile(it.first, it.second).andThen(Single.just(it.second)) }
.flatMapCompletable {
@@ -616,14 +618,12 @@ class OpenHumansUploader @Inject constructor(
}
private fun setupNotificationChannel() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- val notificationManagerCompat = NotificationManagerCompat.from(context)
- notificationManagerCompat.createNotificationChannel(NotificationChannel(
- NOTIFICATION_CHANNEL,
- resourceHelper.gs(R.string.open_humans),
- NotificationManager.IMPORTANCE_DEFAULT
- ))
- }
+ val notificationManagerCompat = NotificationManagerCompat.from(context)
+ notificationManagerCompat.createNotificationChannel(NotificationChannel(
+ NOTIFICATION_CHANNEL,
+ resourceHelper.gs(R.string.open_humans),
+ NotificationManager.IMPORTANCE_DEFAULT
+ ))
}
private class UploadData(
@@ -633,6 +633,7 @@ class OpenHumansUploader @Inject constructor(
val highestQueueId: Long?
)
+ @Suppress("PrivatePropertyName")
private val HEX_DIGITS = "0123456789ABCDEF".toCharArray()
private fun ByteArray.toHexString(): String {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt
index 35fd71c6e8..9d23950e53 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationStore.kt
@@ -8,7 +8,6 @@ import android.content.Context
import android.content.Intent
import android.media.AudioManager
import android.media.RingtoneManager
-import android.os.Build
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -132,14 +131,12 @@ class NotificationStore @Inject constructor(
}
fun createNotificationChannel() {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- usesChannels = true
- val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
- @SuppressLint("WrongConstant") val channel = NotificationChannel(CHANNEL_ID,
- CHANNEL_ID,
- NotificationManager.IMPORTANCE_HIGH)
- mNotificationManager.createNotificationChannel(channel)
- }
+ usesChannels = true
+ val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+ @SuppressLint("WrongConstant") val channel = NotificationChannel(CHANNEL_ID,
+ CHANNEL_ID,
+ NotificationManager.IMPORTANCE_HIGH)
+ mNotificationManager.createNotificationChannel(channel)
}
@Synchronized
@@ -162,16 +159,6 @@ class NotificationStore @Inject constructor(
return clone
}
- /*
- private fun unSnooze() {
- if (sp.getBoolean(R.string.key_nsalarm_staledata, false)) {
- val notification = Notification(Notification.NSALARM, resourceHelper.gs(R.string.nsalarm_staledata), Notification.URGENT)
- sp.putLong(R.string.key_snoozedTo, System.currentTimeMillis())
- add(notification)
- aapsLogger.debug(LTag.NOTIFICATION, "Snoozed to current time and added back notification!")
- }
- }
- */
inner class NotificationRecyclerViewAdapter internal constructor(private val notificationsList: List