nsclient profile local

This commit is contained in:
AdrianLxM 2017-07-24 01:58:23 +02:00
parent 7a171bd949
commit 759154e578
3 changed files with 15 additions and 4 deletions

View file

@ -57,7 +57,6 @@
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<!-- Receiver from NSClient --> <!-- Receiver from NSClient -->
<action android:name="info.nightscout.client.NEW_PROFILE" />
<action android:name="info.nightscout.client.NEW_STATUS" /> <action android:name="info.nightscout.client.NEW_STATUS" />
<action android:name="info.nightscout.client.NEW_MBG" /> <action android:name="info.nightscout.client.NEW_MBG" />
<action android:name="info.nightscout.client.NEW_DEVICESTATUS" /> <action android:name="info.nightscout.client.NEW_DEVICESTATUS" />

View file

@ -173,6 +173,8 @@ public class MainApp extends Application {
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_TREATMENT)); lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_TREATMENT));
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_TREATMENT)); lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_TREATMENT));
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_SGV)); lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_SGV));
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_PROFILE));
} }

View file

@ -4,12 +4,14 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -23,15 +25,23 @@ public class BroadcastProfile {
public static void handleNewTreatment(ProfileStore profile, Context context, boolean isDelta) { public static void handleNewTreatment(ProfileStore profile, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("profile", profile.getData().toString()); bundle.putString("profile", profile.getData().toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_PROFILE); Intent intent = new Intent(Intents.ACTION_NEW_PROFILE);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean("nsclient_localbroadcasts", true)) {
bundle = new Bundle();
bundle.putString("profile", profile.getData().toString());
bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_NEW_PROFILE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
}
} }
} }