Merge pull request #1841 from MilosKozak/foreground-service-fix

Also show notification when no profile is set
This commit is contained in:
Tebbe Ubben 2019-06-20 23:25:17 +02:00 committed by GitHub
commit 412c06bd15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,6 +10,7 @@ import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.Build; 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;
@ -122,11 +123,13 @@ public class PersistentNotificationPlugin extends PluginBase {
return null; return null;
} }
String line1; String line1 = null;
String line1_aa; String line2 = null;
String line3 = null;
NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder = null;
if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() == null || !ProfileFunctions.getInstance().isProfileValid("Notificiation")) if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null && ProfileFunctions.getInstance().isProfileValid("Notification")) {
return null; String line1_aa;
String units = ProfileFunctions.getInstance().getProfileUnits(); String units = ProfileFunctions.getInstance().getProfileUnits();
@ -162,11 +165,11 @@ public class PersistentNotificationPlugin extends PluginBase {
IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round(); IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round();
String line2 = MainApp.gs(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U " + MainApp.gs(R.string.cob) + ": " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "PersistentNotificationPlugin").generateCOBString(); line2 = MainApp.gs(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U " + MainApp.gs(R.string.cob) + ": " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "PersistentNotificationPlugin").generateCOBString();
String line2_aa = MainApp.gs(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U. " + MainApp.gs(R.string.cob) + ": " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "PersistentNotificationPlugin").generateCOBString() + "."; String line2_aa = MainApp.gs(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U. " + MainApp.gs(R.string.cob) + ": " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "PersistentNotificationPlugin").generateCOBString() + ".";
String line3 = DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getPlugin().getActivePump().getBaseBasalRate()) + " U/h"; line3 = DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getPlugin().getActivePump().getBaseBasalRate()) + " U/h";
String line3_aa = DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getPlugin().getActivePump().getBaseBasalRate()) + " U/h."; String line3_aa = DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getPlugin().getActivePump().getBaseBasalRate()) + " U/h.";
@ -202,7 +205,7 @@ public class PersistentNotificationPlugin extends PluginBase {
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).build(); RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).build();
// Create the UnreadConversation // Create the UnreadConversation
NotificationCompat.CarExtender.UnreadConversation.Builder unreadConversationBuilder = unreadConversationBuilder =
new NotificationCompat.CarExtender.UnreadConversation.Builder(line1_aa + "\n" + line2_aa) new NotificationCompat.CarExtender.UnreadConversation.Builder(line1_aa + "\n" + line2_aa)
.setLatestTimestamp(System.currentTimeMillis()) .setLatestTimestamp(System.currentTimeMillis())
.setReadPendingIntent(msgReadPendingIntent) .setReadPendingIntent(msgReadPendingIntent)
@ -211,7 +214,7 @@ public class PersistentNotificationPlugin extends PluginBase {
/// Add dot to produce a "more natural sounding result" /// Add dot to produce a "more natural sounding result"
unreadConversationBuilder.addMessage(line3_aa); unreadConversationBuilder.addMessage(line3_aa);
/// End Android Auto /// End Android Auto
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, CHANNEL_ID); NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, CHANNEL_ID);
builder.setOngoing(true); builder.setOngoing(true);
@ -220,11 +223,11 @@ public class PersistentNotificationPlugin extends PluginBase {
builder.setSmallIcon(MainApp.getNotificationIcon()); builder.setSmallIcon(MainApp.getNotificationIcon());
Bitmap largeIcon = BitmapFactory.decodeResource(ctx.getResources(), MainApp.getIcon()); Bitmap largeIcon = BitmapFactory.decodeResource(ctx.getResources(), MainApp.getIcon());
builder.setLargeIcon(largeIcon); builder.setLargeIcon(largeIcon);
builder.setContentTitle(line1); builder.setContentTitle(line1 != null ? line1 : MainApp.gs(R.string.noprofileset));
builder.setContentText(line2); builder.setContentText(line2 != null ? line2 : MainApp.gs(R.string.noprofileset));
builder.setSubText(line3); builder.setSubText(line3 != null ? line3 : MainApp.gs(R.string.noprofileset));
/// Android Auto /// Android Auto
builder.extend(new NotificationCompat.CarExtender() if (unreadConversationBuilder != null) builder.extend(new NotificationCompat.CarExtender()
.setUnreadConversation(unreadConversationBuilder.build())); .setUnreadConversation(unreadConversationBuilder.build()));
/// End Android Auto /// End Android Auto