diff --git a/app/build.gradle b/app/build.gradle index 8d72d49d2e..2ba21b4d43 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -120,7 +120,7 @@ android { targetSdkVersion 28 multiDexEnabled true versionCode 1500 - version "2.7.1-dev" + version "2.7.2-dev" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' @@ -135,6 +135,9 @@ android { kotlinOptions { jvmTarget = '1.8' } + buildFeatures { + viewBinding true + } lintOptions { checkReleaseBuilds false disable 'MissingTranslation' diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index d550f3b247..709e290e8d 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -28,9 +28,9 @@ import com.google.android.material.tabs.TabLayoutMediator import com.joanzapata.iconify.Iconify import com.joanzapata.iconify.fonts.FontAwesomeModule import dev.doubledot.doki.ui.DokiActivity -import info.nightscout.androidaps.activities.ProfileHelperActivity 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 @@ -71,6 +71,7 @@ import javax.inject.Inject import kotlin.system.exitProcess class MainActivity : NoSplashAppCompatActivity() { + private val disposable = CompositeDisposable() @Inject lateinit var aapsLogger: AAPSLogger @@ -136,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) @@ -238,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 -> { @@ -273,7 +275,7 @@ class MainActivity : NoSplashAppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.nav_preferences -> { + R.id.nav_preferences -> { protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, { val i = Intent(this, PreferencesActivity::class.java) i.putExtra("id", -1) @@ -282,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}" @@ -313,7 +317,7 @@ class MainActivity : NoSplashAppCompatActivity() { return true } - R.id.nav_exit -> { + R.id.nav_exit -> { aapsLogger.debug(LTag.CORE, "Exiting") rxBus.send(EventAppExit()) finish() @@ -336,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 b3f3024de6..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,7 +55,7 @@ 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 = "" @@ -103,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) @@ -259,7 +251,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang } } - private fun addPreferencesFromResource(@XmlRes preferencesResId: Int, key: String?, enabled: Boolean) { + private fun addPreferencesFromResource(@Suppress("SameParameterValue") @XmlRes preferencesResId: Int, key: String?, enabled: Boolean) { if (enabled) addPreferencesFromResource(preferencesResId, key) } @@ -426,7 +418,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang return super.onPreferenceTreeClick(preference) } - public fun setFilter(filter: String) { + fun setFilter(filter: String) { this.filter = filter updateFilterVisibility(filter, preferenceScreen) } 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 42deb79742..3a2fda604b 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.kt @@ -10,7 +10,6 @@ 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 kotlinx.android.synthetic.main.local_insight_status_item.view.* import javax.inject.Inject class PreferencesActivity : NoSplashAppCompatActivity(), PreferenceFragmentCompat.OnPreferenceStartScreenCallback { @@ -33,10 +32,6 @@ class PreferencesActivity : NoSplashAppCompatActivity(), PreferenceFragmentCompa override fun afterTextChanged(s: Editable) {} }) - pref_filter_clear.setOnClickListener() { - pref_filter.setText(""); - } - title = resourceHelper.gs(R.string.nav_preferences) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayShowHomeEnabled(true) diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AutomationModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AutomationModule.kt index bf54732d93..04aacf5a84 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AutomationModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AutomationModule.kt @@ -39,6 +39,7 @@ abstract class AutomationModule { @ContributesAndroidInjector abstract fun actionLoopResumeInjector(): ActionLoopResume @ContributesAndroidInjector abstract fun actionLoopSuspendInjector(): ActionLoopSuspend @ContributesAndroidInjector abstract fun actionNotificationInjector(): ActionNotification + @ContributesAndroidInjector abstract fun actionAlarmInjector(): ActionAlarm @ContributesAndroidInjector abstract fun actionProfileSwitchInjector(): ActionProfileSwitch @ContributesAndroidInjector abstract fun actionProfileSwitchPercentInjector(): ActionProfileSwitchPercent @ContributesAndroidInjector abstract fun actionSendSMSInjector(): ActionSendSMS 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/ProfileSwitchDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/ProfileSwitchDialog.kt index 05f01297ae..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) 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 a4b96354fd..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; } 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/openAPSSMB/DetermineBasalAdapterSMBJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java index f25dfee9c0..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; 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/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/objectives/Objective.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java index 28efcf6f55..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 @@ -26,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<>(); @@ -116,7 +116,7 @@ public abstract class Objective { public abstract class Task { @StringRes - private int task; + private final int task; private Objective objective; ArrayList hints = new ArrayList<>(); @@ -138,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); } @@ -160,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); @@ -197,7 +195,7 @@ public abstract class Objective { @StringRes int question; ArrayList