Aaps -> kt

This commit is contained in:
Milos Kozak 2021-12-10 15:27:09 +01:00
parent 17b4d6e7ed
commit bca7e433d4
2 changed files with 29 additions and 44 deletions

View file

@ -1,44 +0,0 @@
package info.nightscout.androidaps;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import dagger.android.AndroidInjector;
import dagger.android.DaggerApplication;
import info.nightscout.androidaps.di.DaggerAppComponent;
/**
* Created for xDrip+ by Emma Black on 3/21/15.
* Adapted for AAPS by dlvoy 2019-11-06.
*/
public class Aaps extends DaggerApplication implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
public void onCreate() {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
sharedPrefs.registerOnSharedPreferenceChangeListener(this);
super.onCreate();
}
@Override
protected AndroidInjector<? extends DaggerApplication> applicationInjector() {
return DaggerAppComponent
.builder()
.application(this)
.build();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
// we trigger update on Complications
Intent messageIntent = new Intent();
messageIntent.setAction(Intent.ACTION_SEND);
LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
}
}

View file

@ -0,0 +1,29 @@
package info.nightscout.androidaps
import android.content.Intent
import android.content.SharedPreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager
import dagger.android.AndroidInjector
import dagger.android.DaggerApplication
import info.nightscout.androidaps.di.DaggerAppComponent
class Aaps : DaggerApplication(), OnSharedPreferenceChangeListener {
override fun onCreate() {
super.onCreate()
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this)
}
override fun applicationInjector(): AndroidInjector<out DaggerApplication> =
DaggerAppComponent
.builder()
.application(this)
.build()
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
// we trigger update on Complications
LocalBroadcastManager.getInstance(this).sendBroadcast(Intent(Intent.ACTION_SEND))
}
}