diff --git a/app/build.gradle b/app/build.gradle index d875c460e8..8f19b7eedc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,14 +22,6 @@ jacoco { toolVersion = "0.8.3" } -ext { - powermockVersion = "1.7.3" - dexmakerVersion = "1.2" - retrofit2Version = '2.9.0' - okhttp3Version = '4.7.2' -} - - repositories { jcenter { url "https://jcenter.bintray.com/" } mavenCentral() @@ -128,7 +120,7 @@ android { targetSdkVersion 28 multiDexEnabled true versionCode 1500 - version "2.7.0" + version "2.7.2-dev" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' @@ -230,11 +222,9 @@ android { allprojects { repositories { - jcenter() flatDir { dirs 'libs' } - maven { url 'https://jitpack.io' } } } @@ -247,66 +237,11 @@ dependencies { implementation project(':danar') implementation project(':rileylink') implementation project(':medtronic') + implementation project(':omnipod') implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.google.android.gms:play-services-wearable:17.0.0' - implementation "com.google.android.gms:play-services-location:17.0.0" - implementation 'com.google.firebase:firebase-core:17.4.3' - implementation 'com.google.firebase:firebase-auth:19.3.1' - implementation 'com.google.firebase:firebase-database:19.3.1' - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.legacy:legacy-support-v13:1.0.0' - implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation 'androidx.cardview:cardview:1.0.0' - implementation 'androidx.biometric:biometric:1.0.1' - implementation 'androidx.recyclerview:recyclerview:1.1.0' - implementation 'androidx.gridlayout:gridlayout:1.0.0' - implementation 'androidx.percentlayout:percentlayout:1.0.0' - implementation "androidx.preference:preference-ktx:1.1.1" - implementation "androidx.activity:activity-ktx:${activityVersion}" - implementation "androidx.fragment:fragment:${fragmentVersion}" - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'com.google.android.material:material:1.1.0' - - implementation "io.reactivex.rxjava2:rxandroid:${rxandroid_version}" - - implementation "com.j256.ormlite:ormlite-core:${ormLiteVersion}" - implementation "com.j256.ormlite:ormlite-android:${ormLiteVersion}" - implementation("com.github.tony19:logback-android-classic:1.1.1-6") { - exclude group: "com.google.android", module: "android" - } - implementation 'org.apache.commons:commons-lang3:3.10' - implementation 'org.slf4j:slf4j-api:1.7.30' - // Graphview cannot be upgraded - implementation "com.jjoe64:graphview:4.0.1" - implementation "com.joanzapata.iconify:android-iconify-fontawesome:2.2.2" - implementation 'com.madgag.spongycastle:core:1.58.0.0' - // Omnipod wizard - implementation(name: "com.atech-software.android.library.wizardpager-1.1.4", ext: "aar") - implementation("com.google.android:flexbox:0.3.0") { - exclude group: "com.android.support" - } - implementation("io.socket:socket.io-client:1.0.0") { - // excluding org.json which is provided by Android - exclude group: "org.json", module: "json" - } - implementation "com.google.code.gson:gson:2.8.6" - implementation('com.google.guava:guava:29.0-jre') { - exclude group: "com.google.code.findbugs", module: "jsr305" - } - implementation 'com.google.code.findbugs:jsr305:3.0.2' - - implementation 'net.danlew:android.joda:2.10.6' - - implementation 'org.mozilla:rhino:1.7.12' - - implementation 'com.github.DavidProdinger:weekdays-selector:1.1.0' - - implementation 'com.github.kenglxn.QRGen:android:2.6.0' - implementation 'com.eatthepath:java-otp:0.2.0' - - testImplementation "junit:junit:4.13" + testImplementation "junit:junit:$junit_version" testImplementation 'org.json:json:20200518' testImplementation "org.mockito:mockito-core:2.8.47" testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}" @@ -321,31 +256,16 @@ dependencies { testImplementation "org.skyscreamer:jsonassert:1.5.0" testImplementation "org.hamcrest:hamcrest-all:1.3" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" - - // new for tidepool - implementation "com.squareup.okhttp3:okhttp:$okhttp3Version" - implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3Version" - implementation "com.squareup.retrofit2:retrofit:$retrofit2Version" - implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit2Version" - implementation "com.squareup.retrofit2:converter-gson:$retrofit2Version" - - // Phone checker - implementation 'com.scottyab:rootbeer-lib:0.0.8' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha03' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'androidx.test:rules:1.3.0-beta01' + androidTestImplementation "androidx.test.ext:junit:$androidx_junit" + androidTestImplementation "androidx.test:rules:$androidx_rules" androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.2' /* Dagger2 - We are going to use dagger.android which includes * support for Activity and fragment injection so we need to include * the following dependencies */ - implementation "com.google.dagger:dagger-android:$dagger_version" - implementation "com.google.dagger:dagger-android-support:$dagger_version" + + annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version" annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version" kapt "com.google.dagger:dagger-android-processor:$dagger_version" @@ -354,15 +274,6 @@ dependencies { kapt "com.google.dagger:dagger-compiler:$dagger_version" androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' - - //WorkManager - implementation 'androidx.work:work-runtime:2.3.4' - implementation 'androidx.work:work-runtime-ktx:2.3.4' - implementation 'androidx.work:work-rxjava2:2.3.4' - - implementation 'com.google.androidbrowserhelper:androidbrowserhelper:1.1.0' - - implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava' } /* diff --git a/app/libs/com.atech-software.android.library.wizardpager-1.1.4.aar b/app/libs/com.atech-software.android.library.wizardpager-1.1.4.aar deleted file mode 100644 index af0c6511cf..0000000000 Binary files a/app/libs/com.atech-software.android.library.wizardpager-1.1.4.aar and /dev/null differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 96763d8274..e0e2a6b05b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ @@ -71,6 +72,10 @@ + 60 && glucose_status.delta == 0 && glucose_status.short_avgdelta > -1 && glucose_status.short_avgdelta < 1 && glucose_status.long_avgdelta > -1 && glucose_status.long_avgdelta < 1 ) { + } else if ( bg > 60 && glucose_status.delta == 0 && glucose_status.short_avgdelta > -1 && glucose_status.short_avgdelta < 1 && glucose_status.long_avgdelta > -1 && glucose_status.long_avgdelta < 1 && !isSaveCgmSource) { if ( glucose_status.last_cal && glucose_status.last_cal < 3 ) { rT.reason = "CGM was just calibrated"; } else { diff --git a/app/src/main/assets/revoked_certs.txt b/app/src/main/assets/revoked_certs.txt index 41177d5667..e0d12d2a46 100644 --- a/app/src/main/assets/revoked_certs.txt +++ b/app/src/main/assets/revoked_certs.txt @@ -2,3 +2,5 @@ 51:6D:12:67:4C:27:F4:9B:9F:E5:42:9B:01:B3:98:E4:66:2B:85:B7:A8:DD:70:32:B7:6A:D7:97:9A:0D:97:10 #Leaked 55:5D:70:C9:BE:10:41:7E:4B:01:A9:C4:C6:44:4A:F8:69:71:35:25:ED:95:23:16:C7:15:E8:EB:C6:08:FC:B1 +E0:71:A3:6E:96:60:5A:FC:B3:77:DB:2F:C4:E0:92:F3:39:A6:27:24:91:F5:7E:BB:55:9B:60:C6:CC:A3:03:41 +32:99:61:C4:A0:92:E8:D2:C7:65:04:74:04:17:7E:2D:2A:16:2A:5A:63:48:69:6A:0A:C4:53:3C:7C:78:22:95 diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index ff35d585ee..709e290e8d 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -27,9 +27,10 @@ import androidx.viewpager2.widget.ViewPager2 import com.google.android.material.tabs.TabLayoutMediator import com.joanzapata.iconify.Iconify import com.joanzapata.iconify.fonts.FontAwesomeModule -import info.nightscout.androidaps.activities.ProfileHelperActivity +import dev.doubledot.doki.ui.DokiActivity import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.activities.PreferencesActivity +import info.nightscout.androidaps.activities.ProfileHelperActivity import info.nightscout.androidaps.activities.SingleFragmentActivity import info.nightscout.androidaps.activities.StatsActivity import info.nightscout.androidaps.events.EventAppExit @@ -45,6 +46,8 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtils +import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefs +import info.nightscout.androidaps.plugins.general.maintenance.PrefsFileContract import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin import info.nightscout.androidaps.setupwizard.SetupWizardActivity @@ -68,6 +71,7 @@ import javax.inject.Inject import kotlin.system.exitProcess class MainActivity : NoSplashAppCompatActivity() { + private val disposable = CompositeDisposable() @Inject lateinit var aapsLogger: AAPSLogger @@ -87,10 +91,17 @@ class MainActivity : NoSplashAppCompatActivity() { @Inject lateinit var constraintChecker: ConstraintChecker @Inject lateinit var signatureVerifierPlugin: SignatureVerifierPlugin @Inject lateinit var config: Config + @Inject lateinit var importExportPrefs: ImportExportPrefs private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle private var pluginPreferencesMenuItem: MenuItem? = null + val callForPrefFile = registerForActivityResult(PrefsFileContract()) { + it?.let { + importExportPrefs.importSharedPreferences(this, it) + } + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Iconify.with(FontAwesomeModule()) @@ -126,16 +137,17 @@ class MainActivity : NoSplashAppCompatActivity() { if (it.recreate) recreate() else setupViews() setWakeLock() - }) { fabricPrivacy::logException } + }, fabricPrivacy::logException) ) disposable.add(rxBus .toObservable(EventPreferenceChange::class.java) .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ processPreferenceChange(it) }) { fabricPrivacy::logException } + .subscribe({ processPreferenceChange(it) }, fabricPrivacy::logException) ) if (!sp.getBoolean(R.string.key_setupwizard_processed, false) && !isRunningRealPumpTest()) { - val intent = Intent(this, SetupWizardActivity::class.java) - startActivity(intent) + protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, { + startActivity(Intent(this, SetupWizardActivity::class.java)) + }) } androidPermission.notifyForStoragePermission(this) androidPermission.notifyForBatteryOptimizationPermission(this) @@ -163,8 +175,8 @@ class MainActivity : NoSplashAppCompatActivity() { override fun onResume() { super.onResume() protectionCheck.queryProtection(this, ProtectionCheck.Protection.APPLICATION, null, - UIRunnable(Runnable { OKDialog.show(this, "", resourceHelper.gs(R.string.authorizationfailed), Runnable { finish() }) }), - UIRunnable(Runnable { OKDialog.show(this, "", resourceHelper.gs(R.string.authorizationfailed), Runnable { finish() }) }) + UIRunnable { OKDialog.show(this, "", resourceHelper.gs(R.string.authorizationfailed)) { finish() } }, + UIRunnable { OKDialog.show(this, "", resourceHelper.gs(R.string.authorizationfailed)) { finish() } } ) } @@ -183,14 +195,14 @@ class MainActivity : NoSplashAppCompatActivity() { val pageAdapter = TabPageAdapter(this) main_navigation_view.setNavigationItemSelectedListener { true } val menu = main_navigation_view.menu.also { it.clear() } - for (p in activePlugin.pluginsList) { + for (p in activePlugin.getPluginsList()) { pageAdapter.registerNewFragment(p) if (p.isEnabled() && p.hasFragment() && !p.isFragmentVisible() && !p.pluginDescription.neverVisible) { val menuItem = menu.add(p.name) menuItem.isCheckable = true menuItem.setOnMenuItemClickListener { val intent = Intent(this, SingleFragmentActivity::class.java) - intent.putExtra("plugin", activePlugin.pluginsList.indexOf(p)) + intent.putExtra("plugin", activePlugin.getPluginsList().indexOf(p)) startActivity(intent) main_drawer_layout.closeDrawers() true @@ -228,7 +240,7 @@ class MainActivity : NoSplashAppCompatActivity() { if (permissions.isNotEmpty()) { if (ActivityCompat.checkSelfPermission(this, permissions[0]) == PackageManager.PERMISSION_GRANTED) { when (requestCode) { - AndroidPermission.CASE_STORAGE -> //show dialog after permission is granted + AndroidPermission.CASE_STORAGE -> //show dialog after permission is granted OKDialog.show(this, "", resourceHelper.gs(R.string.alert_dialog_storage_permission_text)) AndroidPermission.CASE_LOCATION, AndroidPermission.CASE_SMS, AndroidPermission.CASE_BATTERY, AndroidPermission.CASE_PHONE_STATE, AndroidPermission.CASE_SYSTEM_WINDOW -> { @@ -263,8 +275,8 @@ class MainActivity : NoSplashAppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.nav_preferences -> { - protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, Runnable { + R.id.nav_preferences -> { + protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, { val i = Intent(this, PreferencesActivity::class.java) i.putExtra("id", -1) startActivity(i) @@ -272,17 +284,19 @@ class MainActivity : NoSplashAppCompatActivity() { return true } - R.id.nav_historybrowser -> { + R.id.nav_historybrowser -> { startActivity(Intent(this, HistoryBrowseActivity::class.java)) return true } - R.id.nav_setupwizard -> { - startActivity(Intent(this, SetupWizardActivity::class.java)) + R.id.nav_setupwizard -> { + protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, { + startActivity(Intent(this, SetupWizardActivity::class.java)) + }) return true } - R.id.nav_about -> { + R.id.nav_about -> { var message = "Build: ${BuildConfig.BUILDVERSION}\n" message += "Flavor: ${BuildConfig.FLAVOR}${BuildConfig.BUILD_TYPE}\n" message += "${resourceHelper.gs(R.string.configbuilder_nightscoutversion_label)} ${nsSettingsStatus.nightscoutVersionName}" @@ -295,14 +309,15 @@ class MainActivity : NoSplashAppCompatActivity() { .setIcon(iconsProvider.getIcon()) .setMessage(messageSpanned) .setPositiveButton(resourceHelper.gs(R.string.ok), null) - .create().also { - it.show() - (it.findViewById(android.R.id.message) as TextView).movementMethod = LinkMovementMethod.getInstance() + .setNeutralButton(resourceHelper.gs(R.string.cta_dont_kill_my_app_info)) { _, _ -> DokiActivity.start(context = this@MainActivity) } + .create().apply { + show() + findViewById(android.R.id.message)?.movementMethod = LinkMovementMethod.getInstance() } return true } - R.id.nav_exit -> { + R.id.nav_exit -> { aapsLogger.debug(LTag.CORE, "Exiting") rxBus.send(EventAppExit()) finish() @@ -312,7 +327,7 @@ class MainActivity : NoSplashAppCompatActivity() { R.id.nav_plugin_preferences -> { val plugin = (main_pager.adapter as TabPageAdapter).getPluginAt(main_pager.currentItem) - protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, Runnable { + protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, { val i = Intent(this, PreferencesActivity::class.java) i.putExtra("id", plugin.preferencesId) startActivity(i) @@ -325,12 +340,12 @@ class MainActivity : NoSplashAppCompatActivity() { return true } */ - R.id.nav_defaultprofile -> { + R.id.nav_defaultprofile -> { startActivity(Intent(this, ProfileHelperActivity::class.java)) return true } - R.id.nav_stats -> { + R.id.nav_stats -> { startActivity(Intent(this, StatsActivity::class.java)) return true } diff --git a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt index d7ffdc5358..16a870ce61 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt @@ -7,9 +7,6 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener import android.os.Bundle import androidx.annotation.XmlRes import androidx.preference.* -import dagger.android.AndroidInjector -import dagger.android.DispatchingAndroidInjector -import dagger.android.HasAndroidInjector import dagger.android.support.AndroidSupportInjection import info.nightscout.androidaps.Config import info.nightscout.androidaps.R @@ -58,9 +55,10 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import javax.inject.Inject -class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeListener, HasAndroidInjector { +class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeListener { private var pluginId = -1 + private var filter = "" @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var resourceHelper: ResourceHelper @@ -102,11 +100,6 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang @Inject lateinit var nsSettingStatus: NSSettingsStatus @Inject lateinit var openHumansUploader: OpenHumansUploader - // TODO why? - @Inject lateinit var androidInjector: DispatchingAndroidInjector - - override fun androidInjector(): AndroidInjector = androidInjector - override fun onAttach(context: Context) { AndroidSupportInjection.inject(this) super.onAttach(context) @@ -115,11 +108,13 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang override fun setArguments(args: Bundle?) { super.setArguments(args) pluginId = args?.getInt("id") ?: -1 + filter = args?.getString("filter") ?: "" } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) outState.putInt("id", pluginId) + outState.putString("filter", filter) } override fun onDestroy() { @@ -150,6 +145,9 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang if (bundle.containsKey("id")) { pluginId = bundle.getInt("id") } + if (bundle.containsKey("filter")) { + filter = bundle.getString("filter") ?: "" + } } if (pluginId != -1) { addPreferencesFromResource(pluginId, rootKey) @@ -175,7 +173,8 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang addPreferencesFromResourceIfEnabled(localInsightPlugin, rootKey, config.PUMPDRIVERS) addPreferencesFromResourceIfEnabled(comboPlugin, rootKey, config.PUMPDRIVERS) addPreferencesFromResourceIfEnabled(medtronicPumpPlugin, rootKey, config.PUMPDRIVERS) - addPreferencesFromResourceIfEnabled(virtualPumpPlugin, rootKey, !config.NSCLIENT) + addPreferencesFromResource(R.xml.pref_pump, rootKey, config.PUMPDRIVERS) + addPreferencesFromResourceIfEnabled(virtualPumpPlugin, rootKey) addPreferencesFromResourceIfEnabled(insulinOrefFreePeakPlugin, rootKey) addPreferencesFromResourceIfEnabled(nsClientPlugin, rootKey) addPreferencesFromResourceIfEnabled(tidepoolPlugin, rootKey) @@ -190,6 +189,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang } initSummary(preferenceScreen, pluginId != -1) preprocessPreferences() + if (filter != "") updateFilterVisibility(filter, preferenceScreen) } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { @@ -251,6 +251,10 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang } } + private fun addPreferencesFromResource(@Suppress("SameParameterValue") @XmlRes preferencesResId: Int, key: String?, enabled: Boolean) { + if (enabled) addPreferencesFromResource(preferencesResId, key) + } + @SuppressLint("RestrictedApi") private fun addPreferencesFromResource(@XmlRes preferencesResId: Int, key: String?) { val xmlRoot = preferenceManager.inflateFromResource(context, @@ -283,6 +287,33 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang } } + private fun updateFilterVisibility(filter: String, p: Preference): Boolean { + + var visible = false + + if (p is PreferenceGroup) { + for (i in 0 until p.preferenceCount) { + visible = updateFilterVisibility(filter, p.getPreference(i)) || visible + } + if (visible && p is PreferenceCategory) { + p.initialExpandedChildrenCount = Int.MAX_VALUE + } + } else { + if (p.key != null) { + visible = visible || p.key.contains(filter, true) + } + if (p.title != null) { + visible = visible || p.title.contains(filter, true) + } + if (p.summary != null) { + visible = visible || p.summary.contains(filter, true) + } + } + + p.isVisible = visible + return visible + } + private fun updatePrefSummary(pref: Preference?) { if (pref is ListPreference) { pref.setSummary(pref.entry) @@ -386,4 +417,9 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang } return super.onPreferenceTreeClick(preference) } + + fun setFilter(filter: String) { + this.filter = filter + updateFilterVisibility(filter, preferenceScreen) + } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.kt index ea90f4b250..3a2fda604b 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.kt @@ -2,11 +2,14 @@ package info.nightscout.androidaps.activities import android.content.Context import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceScreen import info.nightscout.androidaps.R import info.nightscout.androidaps.utils.locale.LocaleHelper import info.nightscout.androidaps.utils.resources.ResourceHelper +import kotlinx.android.synthetic.main.activity_preferences.* import javax.inject.Inject class PreferencesActivity : NoSplashAppCompatActivity(), PreferenceFragmentCompat.OnPreferenceStartScreenCallback { @@ -14,18 +17,31 @@ class PreferencesActivity : NoSplashAppCompatActivity(), PreferenceFragmentCompa @Inject lateinit var resourceHelper: ResourceHelper var preferenceId = 0 + var myPreferenceFragment: MyPreferenceFragment? = null + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_single_fragment) + setContentView(R.layout.activity_preferences) + + pref_filter.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} + override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { + filterPreferences() + } + + override fun afterTextChanged(s: Editable) {} + }) + title = resourceHelper.gs(R.string.nav_preferences) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) - val myPreferenceFragment = MyPreferenceFragment() + myPreferenceFragment = MyPreferenceFragment() preferenceId = intent.getIntExtra("id", -1) val args = Bundle() args.putInt("id", preferenceId) - myPreferenceFragment.arguments = args - supportFragmentManager.beginTransaction().replace(R.id.frame_layout, myPreferenceFragment).commit() + args.putString("filter", pref_filter.text.toString()) + myPreferenceFragment?.arguments = args + supportFragmentManager.beginTransaction().replace(R.id.frame_layout, myPreferenceFragment!!).commit() } override fun onPreferenceStartScreen(caller: PreferenceFragmentCompat, pref: PreferenceScreen): Boolean { @@ -44,4 +60,8 @@ class PreferencesActivity : NoSplashAppCompatActivity(), PreferenceFragmentCompa override fun attachBaseContext(newBase: Context) { super.attachBaseContext(LocaleHelper.wrap(newBase)) } + + private fun filterPreferences() { + myPreferenceFragment?.setFilter(pref_filter.text.toString()) + } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.kt index 0193b690a6..862509249e 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.kt @@ -9,6 +9,8 @@ import dagger.android.support.DaggerAppCompatActivity import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.plugins.configBuilder.PluginStore +import info.nightscout.androidaps.plugins.general.maintenance.ImportExportPrefs +import info.nightscout.androidaps.plugins.general.maintenance.PrefsFileContract import info.nightscout.androidaps.utils.locale.LocaleHelper import info.nightscout.androidaps.utils.protection.ProtectionCheck import javax.inject.Inject @@ -16,9 +18,16 @@ import javax.inject.Inject class SingleFragmentActivity : DaggerAppCompatActivity() { @Inject lateinit var pluginStore: PluginStore @Inject lateinit var protectionCheck: ProtectionCheck + @Inject lateinit var importExportPrefs: ImportExportPrefs private var plugin: PluginBase? = null + val callForPrefFile = registerForActivityResult(PrefsFileContract()) { + it?.let { + importExportPrefs.importSharedPreferences(this, it) + } + } + public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_single_fragment) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index ef38b9e44e..679e119b21 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -417,6 +417,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { try { getDaoBgReadings().update(bgReading); openHumansUploader.enqueueBGReading(bgReading); + aapsLogger.debug(LTag.DATABASE, "BG: Updating record from: "+ bgReading.toString()); + scheduleBgHistoryChange(bgReading.date); // trigger cache invalidation } catch (SQLException e) { aapsLogger.error("Unhandled exception", e); } diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt index 1c0583f042..ef728a2193 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt @@ -10,6 +10,7 @@ import info.nightscout.androidaps.dana.di.DanaModule import info.nightscout.androidaps.danar.di.DanaRModule import info.nightscout.androidaps.danars.di.DanaRSModule import info.nightscout.androidaps.plugins.pump.common.dagger.RileyLinkModule +import info.nightscout.androidaps.plugins.pump.omnipod.dagger.OmnipodModule import javax.inject.Singleton @Singleton @@ -29,6 +30,7 @@ import javax.inject.Singleton WizardModule::class, RileyLinkModule::class, MedtronicModule::class, + OmnipodModule::class, APSModule::class, PreferencesModule::class, OverviewModule::class, diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/CommandQueueModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/CommandQueueModule.kt index e9339e187b..014a8de8e3 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/CommandQueueModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/CommandQueueModule.kt @@ -26,4 +26,5 @@ abstract class CommandQueueModule { @ContributesAndroidInjector abstract fun commandTempBasalAbsoluteInjector(): CommandTempBasalAbsolute @ContributesAndroidInjector abstract fun commandTempBasalPercentInjector(): CommandTempBasalPercent @ContributesAndroidInjector abstract fun commandSetUserSettingsInjector(): CommandSetUserSettings + @ContributesAndroidInjector abstract fun commandCustomCommandInjector(): CommandCustomCommand } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt index 0af077c632..42dd3e2972 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/FragmentsModule.kt @@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyL import info.nightscout.androidaps.plugins.pump.insight.LocalInsightFragment import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment import info.nightscout.androidaps.plugins.pump.medtronic.dialog.RileyLinkStatusDeviceMedtronic +import info.nightscout.androidaps.plugins.pump.omnipod.ui.OmnipodOverviewFragment import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpFragment import info.nightscout.androidaps.plugins.source.BGSourceFragment import info.nightscout.androidaps.plugins.treatments.TreatmentsFragment @@ -67,6 +68,7 @@ abstract class FragmentsModule { @ContributesAndroidInjector abstract fun contributesLoopFragment(): LoopFragment @ContributesAndroidInjector abstract fun contributesMaintenanceFragment(): MaintenanceFragment @ContributesAndroidInjector abstract fun contributesMedtronicFragment(): MedtronicFragment + @ContributesAndroidInjector abstract fun contributesOmnipodFragment(): OmnipodOverviewFragment @ContributesAndroidInjector abstract fun contributesNSProfileFragment(): NSProfileFragment @ContributesAndroidInjector abstract fun contributesNSClientFragment(): NSClientFragment @ContributesAndroidInjector diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt index 75c834977a..b28073a055 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt @@ -31,6 +31,7 @@ import info.nightscout.androidaps.plugins.general.persistentNotification.Persist import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin import info.nightscout.androidaps.plugins.general.wear.WearPlugin import info.nightscout.androidaps.plugins.general.xdripStatusline.StatusLinePlugin +import info.nightscout.androidaps.plugins.insulin.InsulinLyumjevPlugin import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin import info.nightscout.androidaps.plugins.insulin.InsulinOrefUltraRapidActingPlugin @@ -41,6 +42,7 @@ import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin import info.nightscout.androidaps.plugins.pump.mdi.MDIPlugin import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin +import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin @@ -82,6 +84,12 @@ abstract class PluginsModule { @IntKey(40) abstract fun bindInsulinOrefUltraRapidActingPlugin(plugin: InsulinOrefUltraRapidActingPlugin): PluginBase + @Binds + @AllConfigs + @IntoMap + @IntKey(42) + abstract fun bindInsulinLyumjevPlugin(plugin: InsulinLyumjevPlugin): PluginBase + @Binds @AllConfigs @IntoMap @@ -148,6 +156,12 @@ abstract class PluginsModule { @IntKey(150) abstract fun bindMedtronicPumpPlugin(plugin: MedtronicPumpPlugin): PluginBase + @Binds + @PumpDriver + @IntoMap + @IntKey(155) + abstract fun bindOmnipodPumpPlugin(plugin: OmnipodPumpPlugin): PluginBase + @Binds @NotNSClient @IntoMap diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ServicesModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ServicesModule.kt index ec71d8a4ad..6ba01130ae 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ServicesModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/ServicesModule.kt @@ -10,6 +10,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.Riley import info.nightscout.androidaps.plugins.pump.insight.InsightAlertService import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService +import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.service.RileyLinkOmnipodService import info.nightscout.androidaps.services.AlarmSoundService import info.nightscout.androidaps.services.DataService import info.nightscout.androidaps.services.LocationService @@ -29,4 +30,5 @@ abstract class ServicesModule { @ContributesAndroidInjector abstract fun contributesInsightConnectionService(): InsightConnectionService @ContributesAndroidInjector abstract fun contributesRileyLinkService(): RileyLinkService @ContributesAndroidInjector abstract fun contributesRileyLinkMedtronicService(): RileyLinkMedtronicService + @ContributesAndroidInjector abstract fun contributesRileyLinkOmnipodService(): RileyLinkOmnipodService } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/SkinsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/SkinsModule.kt index cd71cc8fd2..feb0b2f812 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/SkinsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/SkinsModule.kt @@ -9,6 +9,7 @@ import info.nightscout.androidaps.skins.SkinButtonsOn import info.nightscout.androidaps.skins.SkinClassic import info.nightscout.androidaps.skins.SkinInterface import info.nightscout.androidaps.skins.SkinLargeDisplay +import info.nightscout.androidaps.skins.SkinLowRes import javax.inject.Qualifier @Module @@ -32,6 +33,12 @@ open class SkinsModule { @IntKey(20) fun bindsSkinLargeDisplay(skinLargeDisplay: SkinLargeDisplay): SkinInterface = skinLargeDisplay + @Provides + @Skin + @IntoMap + @IntKey(30) + fun bindsSkinLowRes(skinLowRes: SkinLowRes): SkinInterface = skinLowRes + @Qualifier annotation class Skin } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CalibrationDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CalibrationDialog.kt index 10c10b27f5..894f017995 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CalibrationDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CalibrationDialog.kt @@ -58,7 +58,7 @@ class CalibrationDialog : DialogFragmentWithDate() { val units = profileFunction.getUnits() val unitLabel = if (units == Constants.MMOL) resourceHelper.gs(R.string.mmol) else resourceHelper.gs(R.string.mgdl) val actions: LinkedList = LinkedList() - val bg = overview_calibration_bg.value + val bg = overview_calibration_bg?.value ?: return false actions.add(resourceHelper.gs(R.string.treatments_wizard_bg_label) + ": " + Profile.toCurrentUnitsString(profileFunction, bg) + " " + unitLabel) if (bg > 0) { activity?.let { activity -> diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt index 22ed2bb688..f911c1ef66 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt @@ -150,7 +150,7 @@ class CarbsDialog : DialogFragmentWithDate() { } override fun submit(): Boolean { - val carbs = overview_carbs_carbs.value.toInt() + val carbs = overview_carbs_carbs?.value?.toInt() ?: return false val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(Constraint(carbs)).value() val units = profileFunction.getUnits() val activityTTDuration = defaultValueHelper.determineActivityTTDuration() diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt index bad46290aa..3dae80e53f 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt @@ -122,7 +122,7 @@ class CareDialog : DialogFragmentWithDate() { } } - val bg = Profile.fromMgdlToUnits(GlucoseStatus(injector).getGlucoseStatusData()?.glucose + val bg = Profile.fromMgdlToUnits(GlucoseStatus(injector).glucoseStatusData?.glucose ?: 0.0, profileFunction.getUnits()) val bgTextWatcher: TextWatcher = object : TextWatcher { override fun afterTextChanged(s: Editable) {} diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt index 78b436269a..dce221bf9a 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ExtendedBolusDialog.kt @@ -62,7 +62,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() { } override fun submit(): Boolean { - val insulin = SafeParse.stringToDouble(actions_extendedbolus_insulin.text) + val insulin = SafeParse.stringToDouble(actions_extendedbolus_insulin?.text ?: return false) val durationInMinutes = actions_extendedbolus_duration.value.toInt() val actions: LinkedList = LinkedList() val insulinAfterConstraint = constraintChecker.applyExtendedBolusConstraints(Constraint(insulin)).value() diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt index 24b2f798ea..167ee2cd84 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt @@ -85,7 +85,7 @@ class FillDialog : DialogFragmentWithDate() { } override fun submit(): Boolean { - val insulin = SafeParse.stringToDouble(fill_insulinamount.text) + val insulin = SafeParse.stringToDouble(fill_insulinamount?.text ?: return false) val actions: LinkedList = LinkedList() val insulinAfterConstraints = constraintChecker.applyBolusConstraints(Constraint(insulin)).value() diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt index f1c9c406db..881d5f8de0 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt @@ -129,7 +129,7 @@ class InsulinDialog : DialogFragmentWithDate() { override fun submit(): Boolean { val pumpDescription = activePlugin.activePump.pumpDescription - val insulin = SafeParse.stringToDouble(overview_insulin_amount.text) + val insulin = SafeParse.stringToDouble(overview_insulin_amount?.text ?: return false) val insulinAfterConstraints = constraintChecker.applyBolusConstraints(Constraint(insulin)).value() val actions: LinkedList = LinkedList() val units = profileFunction.getUnits() diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt index 5ea091fa28..31cc463bdc 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt @@ -52,7 +52,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() { overview_profileswitch_duration.setParams(savedInstanceState?.getDouble("overview_profileswitch_duration") ?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, ok) overview_profileswitch_percentage.setParams(savedInstanceState?.getDouble("overview_profileswitch_percentage") - ?: 100.0, Constants.CPP_MIN_PERCENTAGE.toDouble(), Constants.CPP_MAX_PERCENTAGE.toDouble(), 1.0, DecimalFormat("0"), false, ok) + ?: 100.0, Constants.CPP_MIN_PERCENTAGE.toDouble(), Constants.CPP_MAX_PERCENTAGE.toDouble(), 5.0, DecimalFormat("0"), false, ok) overview_profileswitch_timeshift.setParams(savedInstanceState?.getDouble("overview_profileswitch_timeshift") ?: 0.0, Constants.CPP_MIN_TIMESHIFT.toDouble(), Constants.CPP_MAX_TIMESHIFT.toDouble(), 1.0, DecimalFormat("0"), false, ok) @@ -91,7 +91,7 @@ class ProfileSwitchDialog : DialogFragmentWithDate() { ?: return false val actions: LinkedList = LinkedList() - val duration = overview_profileswitch_duration.value.toInt() + val duration = overview_profileswitch_duration?.value?.toInt() ?: return false if (duration > 0) actions.add(resourceHelper.gs(R.string.duration) + ": " + resourceHelper.gs(R.string.format_mins, duration)) val profile = overview_profileswitch_profile.selectedItem.toString() diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt index 68be68e060..cf8fad96b6 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempBasalDialog.kt @@ -84,7 +84,7 @@ class TempBasalDialog : DialogFragmentWithDate() { override fun submit(): Boolean { var percent = 0 var absolute = 0.0 - val durationInMinutes = actions_tempbasal_duration.value.toInt() + val durationInMinutes = actions_tempbasal_duration?.value?.toInt() ?: return false val profile = profileFunction.getProfile() ?: return false val actions: LinkedList = LinkedList() if (isPercentPump) { diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt index e4f5208471..9bdf58287f 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt @@ -116,7 +116,7 @@ class TempTargetDialog : DialogFragmentWithDate() { override fun submit(): Boolean { val actions: LinkedList = LinkedList() - val reason = overview_temptarget_reason.selectedItem.toString() + val reason = overview_temptarget_reason?.selectedItem?.toString() ?: return false val unitResId = if (profileFunction.getUnits() == Constants.MGDL) R.string.mgdl else R.string.mmol val target = overview_temptarget_temptarget.value val duration = overview_temptarget_duration.value.toInt() diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt index 429862ede9..c54f7b8378 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt @@ -94,7 +94,7 @@ class TreatmentDialog : DialogFragmentWithDate() { override fun submit(): Boolean { val pumpDescription = activePlugin.activePump.pumpDescription - val insulin = SafeParse.stringToDouble(overview_treatment_insulin.text) + val insulin = SafeParse.stringToDouble(overview_treatment_insulin?.text ?: return false) val carbs = SafeParse.stringToInt(overview_treatment_carbs.text) val recordOnlyChecked = overview_treatment_record_only.isChecked val actions: LinkedList = LinkedList() diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt index fb28182e33..17ed64b96f 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt @@ -108,7 +108,7 @@ class WizardDialog : DaggerDialogFragment() { if (profileFunction.getUnits() == Constants.MGDL) treatments_wizard_bg_input.setParams(savedInstanceState?.getDouble("treatments_wizard_bg_input") - ?: 0.0, 0.0, 500.0, 1.0, DecimalFormat("0.0"), false, ok, textWatcher) + ?: 0.0, 0.0, 500.0, 1.0, DecimalFormat("0"), false, ok, textWatcher) else treatments_wizard_bg_input.setParams(savedInstanceState?.getDouble("treatments_wizard_bg_input") ?: 0.0, 0.0, 30.0, 0.1, DecimalFormat("0.0"), false, ok, textWatcher) diff --git a/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt b/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt index df22cabde6..e72154ab1c 100644 --- a/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/historyBrowser/HistoryBrowseActivity.kt @@ -8,6 +8,7 @@ import android.view.ViewGroup import android.widget.LinearLayout import android.widget.RelativeLayout import android.widget.TextView +import androidx.lifecycle.lifecycleScope import com.jjoe64.graphview.GraphView import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R @@ -37,7 +38,6 @@ import io.reactivex.disposables.CompositeDisposable import io.reactivex.schedulers.Schedulers import kotlinx.android.synthetic.main.activity_historybrowse.* import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.util.* @@ -168,7 +168,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { if (it.cause is EventCustomCalculationFinished) { updateGUI("EventAutosensCalculationFinished", bgOnly = false) } - }) { fabricPrivacy::logException } + }, fabricPrivacy::logException ) ) disposable.add(rxBus .toObservable(EventAutosensBgLoaded::class.java) @@ -178,12 +178,12 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { if (it.cause is EventCustomCalculationFinished) { updateGUI("EventAutosensCalculationFinished", bgOnly = true) } - }) { fabricPrivacy::logException } + }, fabricPrivacy::logException ) ) disposable.add(rxBus .toObservable(EventIobCalculationProgress::class.java) .observeOn(AndroidSchedulers.mainThread()) - .subscribe({ overview_iobcalculationprogess?.text = it.progress }) { fabricPrivacy::logException } + .subscribe({ overview_iobcalculationprogess?.text = it.progress }, fabricPrivacy::logException ) ) disposable.add(rxBus .toObservable(EventRefreshOverview::class.java) @@ -193,7 +193,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { prepareGraphs() updateGUI("EventRefreshOverview", bgOnly = false) } - }) { fabricPrivacy::logException } + }, fabricPrivacy::logException ) ) if (start == 0L) { // set start of current day @@ -256,7 +256,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { } private fun runCalculation(from: String) { - GlobalScope.launch(Dispatchers.Default) { + lifecycleScope.launch(Dispatchers.Default) { treatmentsPluginHistory.initializeData(start - T.hours(8).msecs()) val end = start + T.hours(rangeToDisplay.toLong()).msecs() iobCobCalculatorPluginHistory.stopCalculation(from) @@ -273,7 +273,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() { val lowLine = defaultValueHelper.determineLowLine() val highLine = defaultValueHelper.determineHighLine() - GlobalScope.launch(Dispatchers.Main) { + lifecycleScope.launch(Dispatchers.Main) { historybrowse_noprofile?.visibility = (profile == null).toVisibility() profile ?: return@launch diff --git a/app/src/main/java/info/nightscout/androidaps/historyBrowser/TreatmentsPluginHistory.kt b/app/src/main/java/info/nightscout/androidaps/historyBrowser/TreatmentsPluginHistory.kt index caa0fb1b1a..f9d0a4019b 100644 --- a/app/src/main/java/info/nightscout/androidaps/historyBrowser/TreatmentsPluginHistory.kt +++ b/app/src/main/java/info/nightscout/androidaps/historyBrowser/TreatmentsPluginHistory.kt @@ -7,6 +7,7 @@ import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.nsclient.NSUpload +import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue import info.nightscout.androidaps.plugins.treatments.TreatmentService import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.utils.DateUtil @@ -27,8 +28,10 @@ class TreatmentsPluginHistory @Inject constructor( profileFunction: ProfileFunction, activePlugin: ActivePluginProvider, nsUpload: NSUpload, - fabricPrivacy: FabricPrivacy, dateUtil: DateUtil -) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, context, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil) { + fabricPrivacy: FabricPrivacy, + dateUtil: DateUtil, + uploadQueue: UploadQueue +) : TreatmentsPlugin(injector, aapsLogger, rxBus, resourceHelper, context, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil, uploadQueue) { init { onStart() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java index 0040dbc6fc..af8f4e3125 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java @@ -22,6 +22,7 @@ import javax.inject.Singleton; import dagger.Lazy; import dagger.android.HasAndroidInjector; import info.nightscout.androidaps.BuildConfig; +import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.MainApp; @@ -55,10 +56,10 @@ import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui; import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification; import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; -import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; @@ -95,9 +96,8 @@ public class LoopPlugin extends PluginBase implements LoopInterface { private final FabricPrivacy fabricPrivacy; private final NSUpload nsUpload; private final HardLimits hardLimits; - private Notification notification; - private CompositeDisposable disposable = new CompositeDisposable(); + private final CompositeDisposable disposable = new CompositeDisposable(); private static final String CHANNEL_ID = "AndroidAPS-Openloop"; @@ -126,6 +126,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface { AAPSLogger aapsLogger, RxBusWrapper rxBus, SP sp, + Config config, ConstraintChecker constraintChecker, ResourceHelper resourceHelper, ProfileFunction profileFunction, @@ -147,6 +148,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface { .pluginName(R.string.loop) .shortName(R.string.loop_shortname) .preferencesId(R.xml.pref_loop) + .enableByDefault(config.getAPS()) .description(R.string.description_loop), aapsLogger, resourceHelper, injector ); @@ -415,7 +417,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface { resultAfterConstraints.smb = 0; } - if (lastRun != null) { + if (lastRun != null && lastRun.getConstraintsProcessed() != null) { prevCarbsreq = lastRun.getConstraintsProcessed().carbsReq; } @@ -551,6 +553,9 @@ public class LoopPlugin extends PluginBase implements LoopInterface { rxBus.send(new EventLoopUpdateGui()); } }); + } else { + lastRun.setTbrSetByPump(result); + lastRun.setLastTBRRequest(lastRun.getLastAPSRun()); } rxBus.send(new EventLoopUpdateGui()); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java index a5b4fdff9b..a6876a3144 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java @@ -40,7 +40,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.sharedPreferences.SP; public class DetermineBasalAdapterAMAJS { - private HasAndroidInjector injector; + private final HasAndroidInjector injector; @Inject AAPSLogger aapsLogger; @Inject ConstraintChecker constraintChecker; @Inject SP sp; @@ -48,7 +48,7 @@ public class DetermineBasalAdapterAMAJS { @Inject TreatmentsPlugin treatmentsPlugin; @Inject OpenHumansUploader openHumansUploader; - private ScriptReader mScriptReader; + private final ScriptReader mScriptReader; private JSONObject mProfile; private JSONObject mGlucoseStatus; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java index 0cb082f368..25d3981c47 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java @@ -189,9 +189,9 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { } - if (!hardLimits.checkOnlyHardLimits(profile.getDia(), "dia", hardLimits.getMINDIA(), hardLimits.getMAXDIA())) + if (!hardLimits.checkOnlyHardLimits(profile.getDia(), "dia", hardLimits.minDia(), hardLimits.maxDia())) return; - if (!hardLimits.checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", hardLimits.getMINIC(), hardLimits.getMAXIC())) + if (!hardLimits.checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", hardLimits.minIC(), hardLimits.maxIC())) return; if (!hardLimits.checkOnlyHardLimits(profile.getIsfMgdl(), "sens", hardLimits.getMINISF(), hardLimits.getMAXISF())) return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java index 058ae596bd..1013434c95 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java @@ -55,7 +55,7 @@ public class DetermineBasalAdapterSMBJS { @Inject OpenHumansUploader openHumansUploader; - private ScriptReader mScriptReader; + private final ScriptReader mScriptReader; private JSONObject mProfile; private JSONObject mGlucoseStatus; private JSONArray mIobData; @@ -65,6 +65,7 @@ public class DetermineBasalAdapterSMBJS { private boolean mMicrobolusAllowed; private boolean mSMBAlwaysAllowed; private long mCurrentTime; + private boolean mIsSaveCgmSource; private String storedCurrentTemp = null; private String storedIobData = null; @@ -108,6 +109,7 @@ public class DetermineBasalAdapterSMBJS { aapsLogger.debug(LTag.APS, "MicroBolusAllowed: " + (storedMicroBolusAllowed = "" + mMicrobolusAllowed)); aapsLogger.debug(LTag.APS, "SMBAlwaysAllowed: " + (storedSMBAlwaysAllowed = "" + mSMBAlwaysAllowed)); aapsLogger.debug(LTag.APS, "CurrentTime: " + (storedCurrentTime = "" + mCurrentTime)); + aapsLogger.debug(LTag.APS, "isSaveCgmSource: " + mIsSaveCgmSource); DetermineBasalResultSMB determineBasalResultSMB = null; @@ -237,7 +239,8 @@ public class DetermineBasalAdapterSMBJS { boolean tempTargetSet, boolean microBolusAllowed, boolean uamAllowed, - boolean advancedFiltering + boolean advancedFiltering, + boolean isSaveCgmSource ) throws JSONException { String units = profile.getUnits(); @@ -282,7 +285,7 @@ public class DetermineBasalAdapterSMBJS { mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable); boolean smbEnabled = sp.getBoolean(resourceHelper.gs(R.string.key_use_smb), false); - mProfile.put("SMBInterval", sp.getInt("key_smbinterval", SMBDefaults.SMBInterval)); + mProfile.put("SMBInterval", sp.getInt(R.string.key_smbinterval, SMBDefaults.SMBInterval)); mProfile.put("enableSMB_with_COB", smbEnabled && sp.getBoolean(R.string.key_enableSMB_with_COB, false)); mProfile.put("enableSMB_with_temptarget", smbEnabled && sp.getBoolean(R.string.key_enableSMB_with_temptarget, false)); mProfile.put("allowSMB_with_high_temptarget", smbEnabled && sp.getBoolean(R.string.key_allowSMB_with_high_temptarget, false)); @@ -354,6 +357,7 @@ public class DetermineBasalAdapterSMBJS { mCurrentTime = now; + mIsSaveCgmSource = isSaveCgmSource; } private Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java index 3e54eb8a3a..e631a84955 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java @@ -220,9 +220,9 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr } - if (!hardLimits.checkOnlyHardLimits(profile.getDia(), "dia", hardLimits.getMINDIA(), hardLimits.getMAXDIA())) + if (!hardLimits.checkOnlyHardLimits(profile.getDia(), "dia", hardLimits.minDia(), hardLimits.maxDia())) return; - if (!hardLimits.checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", hardLimits.getMINIC(), hardLimits.getMAXIC())) + if (!hardLimits.checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", hardLimits.minIC(), hardLimits.maxIC())) return; if (!hardLimits.checkOnlyHardLimits(profile.getIsfMgdl(), "sens", hardLimits.getMINISF(), hardLimits.getMAXISF())) return; @@ -270,7 +270,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr isTempTarget, smbAllowed.value(), uam.value(), - advancedFiltering.value() + advancedFiltering.value(), + activePlugin.getActiveBgSource().getClass().getSimpleName().equals("DexcomPlugin") ); } catch (JSONException e) { fabricPrivacy.logException(e); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.kt index 3badb56824..09bbf3c04d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderFragment.kt @@ -5,12 +5,9 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.CheckBox -import android.widget.ImageButton -import android.widget.LinearLayout -import android.widget.RadioButton -import android.widget.TextView +import android.widget.* import androidx.annotation.StringRes +import androidx.core.content.ContextCompat import dagger.android.support.DaggerFragment import info.nightscout.androidaps.Config import info.nightscout.androidaps.R @@ -129,6 +126,7 @@ class ConfigBuilderFragment : DaggerFragment() { val baseView: LinearLayout = fragment.layoutInflater.inflate(R.layout.configbuilder_single_plugin, null) as LinearLayout private val enabledExclusive: RadioButton private val enabledInclusive: CheckBox + private val pluginIcon: ImageView private val pluginName: TextView private val pluginDescription: TextView private val pluginPreferences: ImageButton @@ -137,6 +135,7 @@ class ConfigBuilderFragment : DaggerFragment() { init { enabledExclusive = baseView.findViewById(R.id.plugin_enabled_exclusive) enabledInclusive = baseView.findViewById(R.id.plugin_enabled_inclusive) + pluginIcon = baseView.findViewById(R.id.plugin_icon) pluginName = baseView.findViewById(R.id.plugin_name) pluginDescription = baseView.findViewById(R.id.plugin_description) pluginPreferences = baseView.findViewById(R.id.plugin_preferences) @@ -175,6 +174,12 @@ class ConfigBuilderFragment : DaggerFragment() { enabledInclusive.isChecked = plugin.isEnabled(pluginType) enabledInclusive.isEnabled = !plugin.pluginDescription.alwaysEnabled enabledExclusive.isEnabled = !plugin.pluginDescription.alwaysEnabled + if(plugin.menuIcon != -1) { + pluginIcon.visibility = View.VISIBLE + pluginIcon.setImageDrawable(context?.let { ContextCompat.getDrawable(it, plugin.menuIcon) }) + } else { + pluginIcon.visibility = View.GONE + } pluginName.text = plugin.name if (plugin.description == null) pluginDescription.visibility = View.GONE diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.kt index 598ddf085f..58d31eb29b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConfigBuilderPlugin.kt @@ -46,17 +46,17 @@ class ConfigBuilderPlugin @Inject constructor( } private fun setAlwaysEnabledPluginsEnabled() { - for (plugin in activePlugin.pluginsList) { + for (plugin in activePlugin.getPluginsList()) { if (plugin.pluginDescription.alwaysEnabled) plugin.setPluginEnabled(plugin.getType(), true) } storeSettings("setAlwaysEnabledPluginsEnabled") } override fun storeSettings(from: String) { - activePlugin.pluginsList + activePlugin.getPluginsList() aapsLogger.debug(LTag.CONFIGBUILDER, "Storing settings from: $from") activePlugin.verifySelectionInCategories() - for (p in activePlugin.pluginsList) { + for (p in activePlugin.getPluginsList()) { val type = p.getType() if (p.pluginDescription.alwaysEnabled && p.pluginDescription.alwaysVisible) continue if (p.pluginDescription.alwaysEnabled && p.pluginDescription.neverVisible) continue @@ -82,7 +82,7 @@ class ConfigBuilderPlugin @Inject constructor( private fun loadSettings() { aapsLogger.debug(LTag.CONFIGBUILDER, "Loading stored settings") - for (p in activePlugin.pluginsList) { + for (p in activePlugin.getPluginsList()) { val type = p.getType() loadPref(p, type, true) if (p.getType() == PluginType.PUMP) { @@ -110,7 +110,7 @@ class ConfigBuilderPlugin @Inject constructor( } fun logPluginStatus() { - for (p in activePlugin.pluginsList) { + for (p in activePlugin.getPluginsList()) { aapsLogger.debug(LTag.CONFIGBUILDER, p.name + ":" + (if (p.isEnabled(PluginType.GENERAL)) " GENERAL" else "") + (if (p.isEnabled(PluginType.TREATMENT)) " TREATMENT" else "") + @@ -147,7 +147,7 @@ class ConfigBuilderPlugin @Inject constructor( } } - fun performPluginSwitch(changedPlugin: PluginBase, enabled: Boolean, type: PluginType) { + override fun performPluginSwitch(changedPlugin: PluginBase, enabled: Boolean, type: PluginType) { changedPlugin.setPluginEnabled(type, enabled) changedPlugin.setFragmentVisible(type, enabled) processOnEnabledCategoryChanged(changedPlugin, type) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginStore.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginStore.kt index 3958f17d78..05b020fac4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginStore.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginStore.kt @@ -15,13 +15,13 @@ class PluginStore @Inject constructor( lateinit var plugins: List<@JvmSuppressWildcards PluginBase> - private var activeBgSource: BgSourceInterface? = null - private var activePump: PumpInterface? = null + private var activeBgSourceStore: BgSourceInterface? = null + private var activePumpStore: PumpInterface? = null private var activeProfile: ProfileInterface? = null - private var activeAPS: APSInterface? = null - private var activeInsulin: InsulinInterface? = null - private var activeSensitivity: SensitivityInterface? = null - private var activeTreatments: TreatmentsInterface? = null + private var activeAPSStore: APSInterface? = null + private var activeInsulinStore: InsulinInterface? = null + private var activeSensitivityStore: SensitivityInterface? = null + private var activeTreatmentsStore: TreatmentsInterface? = null fun loadDefaults() { verifySelectionInCategories() @@ -71,34 +71,34 @@ class PluginStore @Inject constructor( // PluginType.APS if (!config.NSCLIENT && !config.PUMPCONTROL) { pluginsInCategory = getSpecificPluginsList(PluginType.APS) - activeAPS = getTheOneEnabledInArray(pluginsInCategory, PluginType.APS) as APSInterface? - if (activeAPS == null) { - activeAPS = getDefaultPlugin(PluginType.APS) as APSInterface - (activeAPS as PluginBase).setPluginEnabled(PluginType.APS, true) + activeAPSStore = getTheOneEnabledInArray(pluginsInCategory, PluginType.APS) as APSInterface? + if (activeAPSStore == null) { + activeAPSStore = getDefaultPlugin(PluginType.APS) as APSInterface + (activeAPSStore as PluginBase).setPluginEnabled(PluginType.APS, true) aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting APSInterface") } - setFragmentVisiblities((activeAPS as PluginBase).name, pluginsInCategory, PluginType.APS) + setFragmentVisiblities((activeAPSStore as PluginBase).name, pluginsInCategory, PluginType.APS) } // PluginType.INSULIN pluginsInCategory = getSpecificPluginsList(PluginType.INSULIN) - activeInsulin = getTheOneEnabledInArray(pluginsInCategory, PluginType.INSULIN) as InsulinInterface? - if (activeInsulin == null) { - activeInsulin = getDefaultPlugin(PluginType.INSULIN) as InsulinInterface - (activeInsulin as PluginBase).setPluginEnabled(PluginType.INSULIN, true) + activeInsulinStore = getTheOneEnabledInArray(pluginsInCategory, PluginType.INSULIN) as InsulinInterface? + if (activeInsulinStore == null) { + activeInsulinStore = getDefaultPlugin(PluginType.INSULIN) as InsulinInterface + (activeInsulinStore as PluginBase).setPluginEnabled(PluginType.INSULIN, true) aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting InsulinInterface") } - setFragmentVisiblities((activeInsulin as PluginBase).name, pluginsInCategory, PluginType.INSULIN) + setFragmentVisiblities((activeInsulinStore as PluginBase).name, pluginsInCategory, PluginType.INSULIN) // PluginType.SENSITIVITY pluginsInCategory = getSpecificPluginsList(PluginType.SENSITIVITY) - activeSensitivity = getTheOneEnabledInArray(pluginsInCategory, PluginType.SENSITIVITY) as SensitivityInterface? - if (activeSensitivity == null) { - activeSensitivity = getDefaultPlugin(PluginType.SENSITIVITY) as SensitivityInterface - (activeSensitivity as PluginBase).setPluginEnabled(PluginType.SENSITIVITY, true) + activeSensitivityStore = getTheOneEnabledInArray(pluginsInCategory, PluginType.SENSITIVITY) as SensitivityInterface? + if (activeSensitivityStore == null) { + activeSensitivityStore = getDefaultPlugin(PluginType.SENSITIVITY) as SensitivityInterface + (activeSensitivityStore as PluginBase).setPluginEnabled(PluginType.SENSITIVITY, true) aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting SensitivityInterface") } - setFragmentVisiblities((activeSensitivity as PluginBase).name, pluginsInCategory, PluginType.SENSITIVITY) + setFragmentVisiblities((activeSensitivityStore as PluginBase).name, pluginsInCategory, PluginType.SENSITIVITY) // PluginType.PROFILE pluginsInCategory = getSpecificPluginsList(PluginType.PROFILE) @@ -112,33 +112,33 @@ class PluginStore @Inject constructor( // PluginType.BGSOURCE pluginsInCategory = getSpecificPluginsList(PluginType.BGSOURCE) - activeBgSource = getTheOneEnabledInArray(pluginsInCategory, PluginType.BGSOURCE) as BgSourceInterface? - if (activeBgSource == null) { - activeBgSource = getDefaultPlugin(PluginType.BGSOURCE) as BgSourceInterface - (activeBgSource as PluginBase).setPluginEnabled(PluginType.BGSOURCE, true) + activeBgSourceStore = getTheOneEnabledInArray(pluginsInCategory, PluginType.BGSOURCE) as BgSourceInterface? + if (activeBgSourceStore == null) { + activeBgSourceStore = getDefaultPlugin(PluginType.BGSOURCE) as BgSourceInterface + (activeBgSourceStore as PluginBase).setPluginEnabled(PluginType.BGSOURCE, true) aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting BgInterface") } - setFragmentVisiblities((activeBgSource as PluginBase).name, pluginsInCategory, PluginType.PUMP) + setFragmentVisiblities((activeBgSourceStore as PluginBase).name, pluginsInCategory, PluginType.PUMP) // PluginType.PUMP pluginsInCategory = getSpecificPluginsList(PluginType.PUMP) - activePump = getTheOneEnabledInArray(pluginsInCategory, PluginType.PUMP) as PumpInterface? - if (activePump == null) { - activePump = getDefaultPlugin(PluginType.PUMP) as PumpInterface - (activePump as PluginBase).setPluginEnabled(PluginType.PUMP, true) + activePumpStore = getTheOneEnabledInArray(pluginsInCategory, PluginType.PUMP) as PumpInterface? + if (activePumpStore == null) { + activePumpStore = getDefaultPlugin(PluginType.PUMP) as PumpInterface + (activePumpStore as PluginBase).setPluginEnabled(PluginType.PUMP, true) aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting PumpInterface") } - setFragmentVisiblities((activePump as PluginBase).name, pluginsInCategory, PluginType.PUMP) + setFragmentVisiblities((activePumpStore as PluginBase).name, pluginsInCategory, PluginType.PUMP) // PluginType.TREATMENT pluginsInCategory = getSpecificPluginsList(PluginType.TREATMENT) - activeTreatments = getTheOneEnabledInArray(pluginsInCategory, PluginType.TREATMENT) as TreatmentsInterface? - if (activeTreatments == null) { - activeTreatments = getDefaultPlugin(PluginType.TREATMENT) as TreatmentsInterface - (activeTreatments as PluginBase).setPluginEnabled(PluginType.TREATMENT, true) + activeTreatmentsStore = getTheOneEnabledInArray(pluginsInCategory, PluginType.TREATMENT) as TreatmentsInterface? + if (activeTreatmentsStore == null) { + activeTreatmentsStore = getDefaultPlugin(PluginType.TREATMENT) as TreatmentsInterface + (activeTreatmentsStore as PluginBase).setPluginEnabled(PluginType.TREATMENT, true) aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting PumpInterface") } - setFragmentVisiblities((activeTreatments as PluginBase).name, pluginsInCategory, PluginType.TREATMENT) + setFragmentVisiblities((activeTreatmentsStore as PluginBase).name, pluginsInCategory, PluginType.TREATMENT) } /** @@ -203,27 +203,31 @@ class PluginStore @Inject constructor( // ***** Interface ***** - override fun getActiveBgSource(): BgSourceInterface { - return activeBgSource ?: checkNotNull(activeBgSource) { "No bg source selected" } - } + override val activeBgSource: BgSourceInterface + get() = activeBgSourceStore ?: checkNotNull(activeBgSourceStore) { "No bg source selected" } - override fun getActiveProfileInterface(): ProfileInterface = - activeProfile ?: checkNotNull(activeProfile) { "No profile selected" } + override val activeProfileInterface: ProfileInterface + get() = activeProfile ?: checkNotNull(activeProfile) { "No profile selected" } - override fun getActiveInsulin(): InsulinInterface = - activeInsulin ?: checkNotNull(activeInsulin) { "No insulin selected" } + override val activeInsulin: InsulinInterface + get() = activeInsulinStore ?: checkNotNull(activeInsulinStore) { "No insulin selected" } - override fun getActiveAPS(): APSInterface = - activeAPS ?: checkNotNull(activeAPS) { "No APS selected" } + override val activeAPS: APSInterface + get() = activeAPSStore ?: checkNotNull(activeAPSStore) { "No APS selected" } - override fun getActivePump(): PumpInterface = - activePump ?: checkNotNull(activePump) { "No pump selected" } + override val activePump: PumpInterface + get() = activePumpStore ?: checkNotNull(activePumpStore) { "No pump selected" } - override fun getActiveSensitivity(): SensitivityInterface = - activeSensitivity ?: checkNotNull(activeSensitivity) { "No sensitivity selected" } + override val activeSensitivity: SensitivityInterface + get() = activeSensitivityStore + ?: checkNotNull(activeSensitivityStore) { "No sensitivity selected" } - override fun getActiveTreatments(): TreatmentsInterface = - activeTreatments ?: checkNotNull(activeTreatments) { "No treatments selected" } + override val activeTreatments: TreatmentsInterface + get() = activeTreatmentsStore + ?: checkNotNull(activeTreatmentsStore) { "No treatments selected" } + + override val activeOverview: OverviewInterface + get() = getSpecificPluginsListByInterface(OverviewInterface::class.java).first() as OverviewInterface override fun getPluginsList(): ArrayList = ArrayList(plugins) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/events/EventConfigBuilderUpdateGui.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/events/EventConfigBuilderUpdateGui.kt index 26904127dd..8d24c912ad 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/events/EventConfigBuilderUpdateGui.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/events/EventConfigBuilderUpdateGui.kt @@ -2,5 +2,4 @@ package info.nightscout.androidaps.plugins.configBuilder.events import info.nightscout.androidaps.events.EventUpdateGui -class EventConfigBuilderUpdateGui : EventUpdateGui() { -} \ No newline at end of file +class EventConfigBuilderUpdateGui : EventUpdateGui() \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt index cc57908438..1c33eb7a2f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.plugins.constraints.objectives -import android.app.Activity +import androidx.fragment.app.FragmentActivity import com.google.common.base.Charsets import com.google.common.hash.Hashing import dagger.android.HasAndroidInjector @@ -116,7 +116,7 @@ class ObjectivesPlugin @Inject constructor( sp.putBoolean(R.string.key_objectiveusescale, false) } - fun completeObjectives(activity: Activity, request: String) { + fun completeObjectives(activity: FragmentActivity, request: String) { val requestCode = sp.getString(R.string.key_objectives_request_code, "") var url = sp.getString(R.string.key_nsclientinternal_url, "").toLowerCase(Locale.getDefault()) if (!url.endsWith("/")) url = "$url/" @@ -145,7 +145,7 @@ class ObjectivesPlugin @Inject constructor( } } - fun allPriorAccomplished(position: Int) : Boolean { + fun allPriorAccomplished(position: Int): Boolean { var accomplished = true for (i in 0 until position) { accomplished = accomplished && objectives[i].isAccomplished diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java index c15e1f8599..feef4a4222 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java @@ -8,6 +8,7 @@ import android.widget.CheckBox; import android.widget.TextView; import androidx.annotation.StringRes; +import androidx.fragment.app.FragmentActivity; import java.util.ArrayList; import java.util.List; @@ -25,9 +26,9 @@ public abstract class Objective { @Inject public SP sp; @Inject public ResourceHelper resourceHelper; - private String spName; - @StringRes private int objective; - @StringRes private int gate; + private final String spName; + @StringRes private final int objective; + @StringRes private final int gate; private long startedOn; private long accomplishedOn; List tasks = new ArrayList<>(); @@ -110,12 +111,12 @@ public abstract class Objective { return true; } - public void specialAction(Activity activity, String input) { + public void specialAction(FragmentActivity activity, String input) { } public abstract class Task { @StringRes - private int task; + private final int task; private Objective objective; ArrayList hints = new ArrayList<>(); @@ -137,8 +138,6 @@ public abstract class Objective { return isCompleted(); } - ; - public String getProgress() { return resourceHelper.gs(isCompleted() ? R.string.completed_well_done : R.string.not_completed_yet); } @@ -159,7 +158,7 @@ public abstract class Objective { public class MinimumDurationTask extends Task { - private long minimumDuration; + private final long minimumDuration; MinimumDurationTask(long minimumDuration) { super(R.string.time_elapsed); @@ -196,7 +195,7 @@ public abstract class Objective { @StringRes int question; ArrayList