simplify code
This commit is contained in:
parent
5f3fdca063
commit
22f9ccab32
10 changed files with 82 additions and 122 deletions
|
@ -3,6 +3,7 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="info.nightscout.androidaps">
|
package="info.nightscout.androidaps">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||||
|
|
|
@ -7,7 +7,6 @@ import android.app.PendingIntent;
|
||||||
import android.app.TaskStackBuilder;
|
import android.app.TaskStackBuilder;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
|
@ -185,12 +184,12 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe(event -> invoke("EventTempTargetChange", true), fabricPrivacy::logException)
|
.subscribe(event -> invoke("EventTempTargetChange", true), fabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
/**
|
/*
|
||||||
* This method is triggered once autosens calculation has completed, so the LoopPlugin
|
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
|
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
|
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.
|
the event causing the calculation is not EventNewBg.
|
||||||
* <p>
|
<p>
|
||||||
*/
|
*/
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventAutosensCalculationFinished.class)
|
.toObservable(EventAutosensCalculationFinished.class)
|
||||||
|
@ -212,15 +211,12 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNotificationChannel() {
|
private void createNotificationChannel() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
NotificationManager mNotificationManager =
|
||||||
|
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
NotificationManager mNotificationManager =
|
@SuppressLint("WrongConstant") NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
|
||||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
CHANNEL_ID,
|
||||||
@SuppressLint("WrongConstant") NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
|
NotificationManager.IMPORTANCE_HIGH);
|
||||||
CHANNEL_ID,
|
mNotificationManager.createNotificationChannel(channel);
|
||||||
NotificationManager.IMPORTANCE_HIGH);
|
|
||||||
mNotificationManager.createNotificationChannel(channel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -240,10 +236,6 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long suspendedTo() {
|
|
||||||
return loopSuspendedTill;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void suspendTo(long endTime) {
|
public void suspendTo(long endTime) {
|
||||||
loopSuspendedTill = endTime;
|
loopSuspendedTill = endTime;
|
||||||
isSuperBolus = false;
|
isSuperBolus = false;
|
||||||
|
@ -341,8 +333,9 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
|
||||||
}
|
}
|
||||||
return isDisconnected;
|
return isDisconnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean treatmentTimethreshold(int duartionMinutes) {
|
public boolean treatmentTimethreshold(int duartionMinutes) {
|
||||||
long threshold = System.currentTimeMillis() + (duartionMinutes*60*1000);
|
long threshold = System.currentTimeMillis() + (duartionMinutes * 60 * 1000);
|
||||||
boolean bool = false;
|
boolean bool = false;
|
||||||
if (treatmentsPlugin.getLastBolusTime() > threshold || treatmentsPlugin.getLastCarbTime() > threshold)
|
if (treatmentsPlugin.getLastBolusTime() > threshold || treatmentsPlugin.getLastCarbTime() > threshold)
|
||||||
bool = true;
|
bool = true;
|
||||||
|
@ -414,7 +407,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
|
||||||
// safety check for multiple SMBs
|
// safety check for multiple SMBs
|
||||||
long lastBolusTime = treatmentsPlugin.getLastBolusTime();
|
long lastBolusTime = treatmentsPlugin.getLastBolusTime();
|
||||||
if (lastBolusTime != 0 && lastBolusTime + T.mins(3).msecs() > System.currentTimeMillis()) {
|
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;
|
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)
|
&& resultAfterConstraints.carbsReq >= sp.getInt(R.string.key_smb_enable_carbs_suggestions_threshold, 0)
|
||||||
&& carbsSuggestionsSuspendedUntil < System.currentTimeMillis() && !treatmentTimethreshold(-15)) {
|
&& 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);
|
Notification carbreqlocal = new Notification(Notification.CARBS_REQUIRED, resultAfterConstraints.getCarbsRequiredText(), Notification.NORMAL);
|
||||||
rxBus.send(new EventNewNotification(carbreqlocal));
|
rxBus.send(new EventNewNotification(carbreqlocal));
|
||||||
}
|
}
|
||||||
if (sp.getBoolean(R.string.key_ns_create_announcements_from_carbs_req, false)) {
|
if (sp.getBoolean(R.string.key_ns_create_announcements_from_carbs_req, false)) {
|
||||||
nsUpload.uploadError(resultAfterConstraints.getCarbsRequiredText());
|
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);
|
Intent intentAction5m = new Intent(context, CarbSuggestionReceiver.class);
|
||||||
intentAction5m.putExtra("ignoreDuration", 5);
|
intentAction5m.putExtra("ignoreDuration", 5);
|
||||||
PendingIntent pendingIntent5m = PendingIntent.getBroadcast(context, 1, intentAction5m, PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent pendingIntent5m = PendingIntent.getBroadcast(context, 1, intentAction5m, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
NotificationCompat.Action actionIgnore5m = new
|
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);
|
Intent intentAction15m = new Intent(context, CarbSuggestionReceiver.class);
|
||||||
intentAction15m.putExtra("ignoreDuration", 15);
|
intentAction15m.putExtra("ignoreDuration", 15);
|
||||||
PendingIntent pendingIntent15m = PendingIntent.getBroadcast(context, 1, intentAction15m, PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent pendingIntent15m = PendingIntent.getBroadcast(context, 1, intentAction15m, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
NotificationCompat.Action actionIgnore15m = new
|
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);
|
Intent intentAction30m = new Intent(context, CarbSuggestionReceiver.class);
|
||||||
intentAction30m.putExtra("ignoreDuration", 30);
|
intentAction30m.putExtra("ignoreDuration", 30);
|
||||||
PendingIntent pendingIntent30m = PendingIntent.getBroadcast(context, 1, intentAction30m, PendingIntent.FLAG_UPDATE_CURRENT);
|
PendingIntent pendingIntent30m = PendingIntent.getBroadcast(context, 1, intentAction30m, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
NotificationCompat.Action actionIgnore30m = new
|
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);
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID);
|
||||||
builder.setSmallIcon(R.drawable.notif_icon)
|
builder.setSmallIcon(R.drawable.notif_icon)
|
||||||
|
@ -511,7 +504,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//If carbs were required previously, but are no longer needed, dismiss notifications
|
//If carbs were required previously, but are no longer needed, dismiss notifications
|
||||||
if ( prevCarbsreq > 0 ) {
|
if (prevCarbsreq > 0) {
|
||||||
dismissSuggestion();
|
dismissSuggestion();
|
||||||
rxBus.send(new EventDismissNotification(Notification.CARBS_REQUIRED));
|
rxBus.send(new EventDismissNotification(Notification.CARBS_REQUIRED));
|
||||||
}
|
}
|
||||||
|
@ -591,8 +584,8 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disableCarbSuggestions(int duartionMinutes) {
|
public void disableCarbSuggestions(int durationMinutes) {
|
||||||
carbsSuggestionsSuspendedUntil = System.currentTimeMillis() + (duartionMinutes*60*1000);
|
carbsSuggestionsSuspendedUntil = System.currentTimeMillis() + (durationMinutes * 60 * 1000);
|
||||||
dismissSuggestion();
|
dismissSuggestion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@ class OpenHumansUploader @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private val openHumansAPI = OpenHumansAPI(OPEN_HUMANS_URL, CLIENT_ID, CLIENT_SECRET, REDIRECT_URL)
|
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 val FILE_NAME_DATE_FORMAT = SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.US).apply { timeZone = TimeZone.getTimeZone("UTC") }
|
||||||
|
|
||||||
private var isSetup
|
private var isSetup
|
||||||
|
@ -126,12 +127,12 @@ class OpenHumansUploader @Inject constructor(
|
||||||
private val appId: UUID
|
private val appId: UUID
|
||||||
get() {
|
get() {
|
||||||
val id = sp.getStringOrNull("openhumans_appid", null)
|
val id = sp.getStringOrNull("openhumans_appid", null)
|
||||||
if (id == null) {
|
return if (id == null) {
|
||||||
val generated = UUID.randomUUID()
|
val generated = UUID.randomUUID()
|
||||||
sp.putString("openhumans_appid", generated.toString())
|
sp.putString("openhumans_appid", generated.toString())
|
||||||
return generated
|
generated
|
||||||
} else {
|
} 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)
|
private val wakeLock = (context.getSystemService(Context.POWER_SERVICE) as PowerManager)
|
||||||
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS::OpenHumans")
|
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AndroidAPS::OpenHumans")
|
||||||
|
|
||||||
val preferenceChangeDisposable = CompositeDisposable()
|
private val preferenceChangeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
@ -453,7 +454,8 @@ class OpenHumansUploader @Inject constructor(
|
||||||
aapsLogger.error(LTag.OHUPLOADER, "Segmental upload exceptional", it)
|
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 { data -> refreshAccessTokensIfNeeded().map { accessToken -> accessToken to data } }
|
||||||
.flatMap { uploadFile(it.first, it.second).andThen(Single.just(it.second)) }
|
.flatMap { uploadFile(it.first, it.second).andThen(Single.just(it.second)) }
|
||||||
.flatMapCompletable {
|
.flatMapCompletable {
|
||||||
|
@ -616,14 +618,12 @@ class OpenHumansUploader @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupNotificationChannel() {
|
private fun setupNotificationChannel() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
val notificationManagerCompat = NotificationManagerCompat.from(context)
|
||||||
val notificationManagerCompat = NotificationManagerCompat.from(context)
|
notificationManagerCompat.createNotificationChannel(NotificationChannel(
|
||||||
notificationManagerCompat.createNotificationChannel(NotificationChannel(
|
NOTIFICATION_CHANNEL,
|
||||||
NOTIFICATION_CHANNEL,
|
resourceHelper.gs(R.string.open_humans),
|
||||||
resourceHelper.gs(R.string.open_humans),
|
NotificationManager.IMPORTANCE_DEFAULT
|
||||||
NotificationManager.IMPORTANCE_DEFAULT
|
))
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class UploadData(
|
private class UploadData(
|
||||||
|
@ -633,6 +633,7 @@ class OpenHumansUploader @Inject constructor(
|
||||||
val highestQueueId: Long?
|
val highestQueueId: Long?
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Suppress("PrivatePropertyName")
|
||||||
private val HEX_DIGITS = "0123456789ABCDEF".toCharArray()
|
private val HEX_DIGITS = "0123456789ABCDEF".toCharArray()
|
||||||
|
|
||||||
private fun ByteArray.toHexString(): String {
|
private fun ByteArray.toHexString(): String {
|
||||||
|
|
|
@ -8,7 +8,6 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
import android.os.Build
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
@ -132,14 +131,12 @@ class NotificationStore @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createNotificationChannel() {
|
fun createNotificationChannel() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
usesChannels = true
|
||||||
usesChannels = true
|
val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
@SuppressLint("WrongConstant") val channel = NotificationChannel(CHANNEL_ID,
|
||||||
@SuppressLint("WrongConstant") val channel = NotificationChannel(CHANNEL_ID,
|
CHANNEL_ID,
|
||||||
CHANNEL_ID,
|
NotificationManager.IMPORTANCE_HIGH)
|
||||||
NotificationManager.IMPORTANCE_HIGH)
|
mNotificationManager.createNotificationChannel(channel)
|
||||||
mNotificationManager.createNotificationChannel(channel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
|
@ -162,16 +159,6 @@ class NotificationStore @Inject constructor(
|
||||||
return clone
|
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<Notification>) : RecyclerView.Adapter<NotificationRecyclerViewAdapter.NotificationsViewHolder>() {
|
inner class NotificationRecyclerViewAdapter internal constructor(private val notificationsList: List<Notification>) : RecyclerView.Adapter<NotificationRecyclerViewAdapter.NotificationsViewHolder>() {
|
||||||
|
|
||||||
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): NotificationsViewHolder {
|
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): NotificationsViewHolder {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.app.NotificationManager
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import androidx.core.app.RemoteInput
|
import androidx.core.app.RemoteInput
|
||||||
import androidx.core.app.TaskStackBuilder
|
import androidx.core.app.TaskStackBuilder
|
||||||
|
@ -106,11 +105,9 @@ class PersistentNotificationPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createNotificationChannel() {
|
private fun createNotificationChannel() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
val mNotificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
val channel = NotificationChannel(notificationHolder.channelID, notificationHolder.channelID as CharSequence, NotificationManager.IMPORTANCE_HIGH)
|
||||||
val channel = NotificationChannel(notificationHolder.channelID, notificationHolder.channelID as CharSequence, NotificationManager.IMPORTANCE_HIGH)
|
mNotificationManager.createNotificationChannel(channel)
|
||||||
mNotificationManager.createNotificationChannel(channel)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
|
@ -121,10 +118,7 @@ class PersistentNotificationPlugin @Inject constructor(
|
||||||
|
|
||||||
private fun triggerNotificationUpdate() {
|
private fun triggerNotificationUpdate() {
|
||||||
updateNotification()
|
updateNotification()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
context.startForegroundService(Intent(context, DummyService::class.java))
|
||||||
context.startForegroundService(Intent(context, DummyService::class.java))
|
|
||||||
else
|
|
||||||
context.startService(Intent(context, DummyService::class.java))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateNotification() {
|
private fun updateNotification() {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
|
@ -57,7 +56,6 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
||||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
|
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
|
||||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
||||||
import info.nightscout.androidaps.queue.commands.CustomCommand;
|
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
|
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||||
|
@ -135,6 +133,7 @@ import info.nightscout.androidaps.plugins.pump.insight.exceptions.app_layer_erro
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator;
|
import info.nightscout.androidaps.plugins.pump.insight.utils.ExceptionTranslator;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil;
|
import info.nightscout.androidaps.plugins.pump.insight.utils.ParameterBlockUtil;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
|
import info.nightscout.androidaps.queue.commands.CustomCommand;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.TimeChangeType;
|
import info.nightscout.androidaps.utils.TimeChangeType;
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
|
@ -294,12 +293,10 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNotificationChannel() {
|
private void createNotificationChannel() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationChannel channel = new NotificationChannel(ALERT_CHANNEL_ID, resourceHelper.gs(R.string.insight_alert_notification_channel), NotificationManager.IMPORTANCE_HIGH);
|
||||||
NotificationChannel channel = new NotificationChannel(ALERT_CHANNEL_ID, resourceHelper.gs(R.string.insight_alert_notification_channel), NotificationManager.IMPORTANCE_HIGH);
|
channel.setSound(null, null);
|
||||||
channel.setSound(null, null);
|
notificationManager.createNotificationChannel(channel);
|
||||||
notificationManager.createNotificationChannel(channel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -600,7 +597,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
bolusMessage.setDuration(0);
|
bolusMessage.setDuration(0);
|
||||||
bolusMessage.setExtendedAmount(0);
|
bolusMessage.setExtendedAmount(0);
|
||||||
bolusMessage.setImmediateAmount(insulin);
|
bolusMessage.setImmediateAmount(insulin);
|
||||||
bolusMessage.setVibration(sp.getBoolean(detailedBolusInfo.isSMB ? R.string.key_disable_vibration_auto : R.string.key_disable_vibration ,false));
|
bolusMessage.setVibration(sp.getBoolean(detailedBolusInfo.isSMB ? R.string.key_disable_vibration_auto : R.string.key_disable_vibration, false));
|
||||||
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
|
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
|
||||||
bolusCancelled = false;
|
bolusCancelled = false;
|
||||||
}
|
}
|
||||||
|
@ -724,8 +721,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
PumpEnactResult cancelTBRResult = cancelTempBasalOnly();
|
PumpEnactResult cancelTBRResult = cancelTempBasalOnly();
|
||||||
if (cancelTBRResult.success) {
|
if (cancelTBRResult.success) {
|
||||||
PumpEnactResult ebResult = setExtendedBolusOnly((absoluteRate - getBaseBasalRate()) / 60D
|
PumpEnactResult ebResult = setExtendedBolusOnly((absoluteRate - getBaseBasalRate()) / 60D
|
||||||
* ((double) durationInMinutes), durationInMinutes,
|
* ((double) durationInMinutes), durationInMinutes,
|
||||||
sp.getBoolean(R.string.key_disable_vibration_auto,false));
|
sp.getBoolean(R.string.key_disable_vibration_auto, false));
|
||||||
if (ebResult.success) {
|
if (ebResult.success) {
|
||||||
result.success = true;
|
result.success = true;
|
||||||
result.enacted = true;
|
result.enacted = true;
|
||||||
|
@ -803,7 +800,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
@NonNull @Override
|
@NonNull @Override
|
||||||
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||||
PumpEnactResult result = cancelExtendedBolusOnly();
|
PumpEnactResult result = cancelExtendedBolusOnly();
|
||||||
if (result.success) result = setExtendedBolusOnly(insulin, durationInMinutes, sp.getBoolean(R.string.key_disable_vibration,false));
|
if (result.success)
|
||||||
|
result = setExtendedBolusOnly(insulin, durationInMinutes, sp.getBoolean(R.string.key_disable_vibration, false));
|
||||||
try {
|
try {
|
||||||
fetchStatus();
|
fetchStatus();
|
||||||
readHistory();
|
readHistory();
|
||||||
|
|
|
@ -3,16 +3,12 @@ package info.nightscout.androidaps.receivers
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
|
||||||
import info.nightscout.androidaps.plugins.general.persistentNotification.DummyService
|
import info.nightscout.androidaps.plugins.general.persistentNotification.DummyService
|
||||||
|
|
||||||
class AutoStartReceiver : BroadcastReceiver() {
|
class AutoStartReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
|
if (intent.action == Intent.ACTION_BOOT_COMPLETED)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
context.startForegroundService(Intent(context, DummyService::class.java))
|
||||||
context.startForegroundService(Intent(context, DummyService::class.java))
|
|
||||||
else
|
|
||||||
context.startService(Intent(context, DummyService::class.java))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -35,6 +35,7 @@ class AndroidPermission @Inject constructor(
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
const val CASE_STORAGE = 0x1
|
const val CASE_STORAGE = 0x1
|
||||||
const val CASE_SMS = 0x2
|
const val CASE_SMS = 0x2
|
||||||
const val CASE_LOCATION = 0x3
|
const val CASE_LOCATION = 0x3
|
||||||
|
@ -103,13 +104,11 @@ class AndroidPermission @Inject constructor(
|
||||||
rxBus.send(EventNewNotification(notification))
|
rxBus.send(EventNewNotification(notification))
|
||||||
} else rxBus.send(EventDismissNotification(Notification.PERMISSION_SMS))
|
} else rxBus.send(EventDismissNotification(Notification.PERMISSION_SMS))
|
||||||
// Following is a bug in Android 8
|
// Following is a bug in Android 8
|
||||||
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
|
if (permissionNotGranted(activity, Manifest.permission.READ_PHONE_STATE)) {
|
||||||
if (permissionNotGranted(activity, Manifest.permission.READ_PHONE_STATE)) {
|
val notification = NotificationWithAction(injector, Notification.PERMISSION_PHONESTATE, resourceHelper.gs(R.string.smscommunicator_missingphonestatepermission), Notification.URGENT)
|
||||||
val notification = NotificationWithAction(injector, Notification.PERMISSION_PHONESTATE, resourceHelper.gs(R.string.smscommunicator_missingphonestatepermission), Notification.URGENT)
|
notification.action(R.string.request, Runnable { askForPermission(activity, arrayOf(Manifest.permission.READ_PHONE_STATE), CASE_PHONE_STATE) })
|
||||||
notification.action(R.string.request, Runnable { askForPermission(activity, arrayOf(Manifest.permission.READ_PHONE_STATE), CASE_PHONE_STATE) })
|
rxBus.send(EventNewNotification(notification))
|
||||||
rxBus.send(EventNewNotification(notification))
|
} else rxBus.send(EventDismissNotification(Notification.PERMISSION_PHONESTATE))
|
||||||
} else rxBus.send(EventDismissNotification(Notification.PERMISSION_PHONESTATE))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.content.Intent
|
||||||
import android.content.ServiceConnection
|
import android.content.ServiceConnection
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import info.nightscout.androidaps.interfaces.NotificationHolderInterface
|
import info.nightscout.androidaps.interfaces.NotificationHolderInterface
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
@ -20,6 +21,7 @@ import javax.inject.Singleton
|
||||||
Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{e317f7e u0 info.nightscout.nsclient/info.nightscout.androidaps.services.AlarmSoundService}
|
Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{e317f7e u0 info.nightscout.nsclient/info.nightscout.androidaps.services.AlarmSoundService}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
@Singleton
|
@Singleton
|
||||||
class AlarmSoundServiceHelper @Inject constructor(
|
class AlarmSoundServiceHelper @Inject constructor(
|
||||||
private val notificationHolder: NotificationHolderInterface
|
private val notificationHolder: NotificationHolderInterface
|
||||||
|
@ -33,10 +35,7 @@ class AlarmSoundServiceHelper @Inject constructor(
|
||||||
|
|
||||||
val alarmSoundService: AlarmSoundService = binder.getService()
|
val alarmSoundService: AlarmSoundService = binder.getService()
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
context.startForegroundService(getServiceIntent(context, sound))
|
||||||
context.startForegroundService(getServiceIntent(context, sound))
|
|
||||||
else
|
|
||||||
context.startService(getServiceIntent(context, sound))
|
|
||||||
|
|
||||||
// This is the key: Without waiting Android Framework to call this method
|
// This is the key: Without waiting Android Framework to call this method
|
||||||
// inside Service.onCreate(), immediately call here to post the notification.
|
// inside Service.onCreate(), immediately call here to post the notification.
|
||||||
|
@ -47,7 +46,6 @@ class AlarmSoundServiceHelper @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onServiceDisconnected(name: ComponentName?) {
|
override fun onServiceDisconnected(name: ComponentName?) {
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,10 +56,7 @@ class AlarmSoundServiceHelper @Inject constructor(
|
||||||
// Just call startForegroundService instead since we cannot bind a service to a
|
// Just call startForegroundService instead since we cannot bind a service to a
|
||||||
// broadcast receiver context. The service also have to call startForeground in
|
// broadcast receiver context. The service also have to call startForeground in
|
||||||
// this case.
|
// this case.
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
context.startForegroundService(getServiceIntent(context, sound))
|
||||||
context.startForegroundService(getServiceIntent(context, sound))
|
|
||||||
else
|
|
||||||
context.startService(getServiceIntent(context, sound))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import info.nightscout.androidaps.core.R
|
import info.nightscout.androidaps.core.R
|
||||||
import info.nightscout.androidaps.utils.CryptoUtil
|
import info.nightscout.androidaps.utils.CryptoUtil
|
||||||
|
@ -19,6 +20,7 @@ import javax.inject.Singleton
|
||||||
// since androidx.autofill.HintConstants are not available
|
// since androidx.autofill.HintConstants are not available
|
||||||
const val AUTOFILL_HINT_NEW_PASSWORD = "newPassword"
|
const val AUTOFILL_HINT_NEW_PASSWORD = "newPassword"
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
@Singleton
|
@Singleton
|
||||||
class PasswordCheck @Inject constructor(
|
class PasswordCheck @Inject constructor(
|
||||||
val sp: SP,
|
val sp: SP,
|
||||||
|
@ -45,11 +47,9 @@ class PasswordCheck @Inject constructor(
|
||||||
|
|
||||||
userInput2.visibility = View.GONE
|
userInput2.visibility = View.GONE
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
val autoFillHintPasswordKind = context.getString(preference)
|
||||||
val autoFillHintPasswordKind = context.getString(preference)
|
userInput.setAutofillHints(View.AUTOFILL_HINT_PASSWORD, "aaps_${autoFillHintPasswordKind}")
|
||||||
userInput.setAutofillHints(View.AUTOFILL_HINT_PASSWORD, "aaps_${autoFillHintPasswordKind}")
|
userInput.importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_YES
|
||||||
userInput.importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_YES
|
|
||||||
}
|
|
||||||
|
|
||||||
alertDialogBuilder
|
alertDialogBuilder
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
|
@ -80,11 +80,9 @@ class PasswordCheck @Inject constructor(
|
||||||
val userInput = promptsView.findViewById<View>(R.id.password_prompt_pass) as EditText
|
val userInput = promptsView.findViewById<View>(R.id.password_prompt_pass) as EditText
|
||||||
val userInput2 = promptsView.findViewById<View>(R.id.password_prompt_pass_confirm) as EditText
|
val userInput2 = promptsView.findViewById<View>(R.id.password_prompt_pass_confirm) as EditText
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
val autoFillHintPasswordKind = context.getString(preference)
|
||||||
val autoFillHintPasswordKind = context.getString(preference)
|
userInput.setAutofillHints(AUTOFILL_HINT_NEW_PASSWORD, "aaps_${autoFillHintPasswordKind}")
|
||||||
userInput.setAutofillHints(AUTOFILL_HINT_NEW_PASSWORD, "aaps_${autoFillHintPasswordKind}")
|
userInput.importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_YES
|
||||||
userInput.importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_YES
|
|
||||||
}
|
|
||||||
|
|
||||||
alertDialogBuilder
|
alertDialogBuilder
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
|
@ -145,11 +143,9 @@ class PasswordCheck @Inject constructor(
|
||||||
|
|
||||||
userInput2.visibility = View.GONE
|
userInput2.visibility = View.GONE
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
val autoFillHintPasswordKind = context.getString(preference)
|
||||||
val autoFillHintPasswordKind = context.getString(preference)
|
userInput.setAutofillHints(View.AUTOFILL_HINT_PASSWORD, "aaps_${autoFillHintPasswordKind}")
|
||||||
userInput.setAutofillHints(View.AUTOFILL_HINT_PASSWORD, "aaps_${autoFillHintPasswordKind}")
|
userInput.importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_YES
|
||||||
userInput.importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_YES
|
|
||||||
}
|
|
||||||
|
|
||||||
alertDialogBuilder
|
alertDialogBuilder
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
|
|
Loading…
Add table
Reference in a new issue