improve SetupWizard

This commit is contained in:
Milos Kozak 2020-12-06 13:19:53 +01:00
parent e1aa4acebe
commit f370def798
6 changed files with 131 additions and 193 deletions

View file

@ -28,9 +28,9 @@ import com.google.android.material.tabs.TabLayoutMediator
import com.joanzapata.iconify.Iconify import com.joanzapata.iconify.Iconify
import com.joanzapata.iconify.fonts.FontAwesomeModule import com.joanzapata.iconify.fonts.FontAwesomeModule
import dev.doubledot.doki.ui.DokiActivity import dev.doubledot.doki.ui.DokiActivity
import info.nightscout.androidaps.activities.ProfileHelperActivity
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.activities.PreferencesActivity import info.nightscout.androidaps.activities.PreferencesActivity
import info.nightscout.androidaps.activities.ProfileHelperActivity
import info.nightscout.androidaps.activities.SingleFragmentActivity import info.nightscout.androidaps.activities.SingleFragmentActivity
import info.nightscout.androidaps.activities.StatsActivity import info.nightscout.androidaps.activities.StatsActivity
import info.nightscout.androidaps.events.EventAppExit import info.nightscout.androidaps.events.EventAppExit
@ -71,6 +71,7 @@ import javax.inject.Inject
import kotlin.system.exitProcess import kotlin.system.exitProcess
class MainActivity : NoSplashAppCompatActivity() { class MainActivity : NoSplashAppCompatActivity() {
private val disposable = CompositeDisposable() private val disposable = CompositeDisposable()
@Inject lateinit var aapsLogger: AAPSLogger @Inject lateinit var aapsLogger: AAPSLogger
@ -136,16 +137,17 @@ class MainActivity : NoSplashAppCompatActivity() {
if (it.recreate) recreate() if (it.recreate) recreate()
else setupViews() else setupViews()
setWakeLock() setWakeLock()
}, fabricPrivacy::logException ) }, fabricPrivacy::logException)
) )
disposable.add(rxBus disposable.add(rxBus
.toObservable(EventPreferenceChange::class.java) .toObservable(EventPreferenceChange::class.java)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe({ processPreferenceChange(it) }, fabricPrivacy::logException ) .subscribe({ processPreferenceChange(it) }, fabricPrivacy::logException)
) )
if (!sp.getBoolean(R.string.key_setupwizard_processed, false) && !isRunningRealPumpTest()) { if (!sp.getBoolean(R.string.key_setupwizard_processed, false) && !isRunningRealPumpTest()) {
val intent = Intent(this, SetupWizardActivity::class.java) protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
startActivity(intent) startActivity(Intent(this, SetupWizardActivity::class.java))
})
} }
androidPermission.notifyForStoragePermission(this) androidPermission.notifyForStoragePermission(this)
androidPermission.notifyForBatteryOptimizationPermission(this) androidPermission.notifyForBatteryOptimizationPermission(this)
@ -288,7 +290,9 @@ class MainActivity : NoSplashAppCompatActivity() {
} }
R.id.nav_setupwizard -> { R.id.nav_setupwizard -> {
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
startActivity(Intent(this, SetupWizardActivity::class.java)) startActivity(Intent(this, SetupWizardActivity::class.java))
})
return true return true
} }

View file

@ -7,9 +7,6 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.os.Bundle import android.os.Bundle
import androidx.annotation.XmlRes import androidx.annotation.XmlRes
import androidx.preference.* import androidx.preference.*
import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasAndroidInjector
import dagger.android.support.AndroidSupportInjection import dagger.android.support.AndroidSupportInjection
import info.nightscout.androidaps.Config import info.nightscout.androidaps.Config
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
@ -58,7 +55,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Inject import javax.inject.Inject
class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeListener, HasAndroidInjector { class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeListener {
private var pluginId = -1 private var pluginId = -1
private var filter = "" private var filter = ""
@ -103,11 +100,6 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
@Inject lateinit var nsSettingStatus: NSSettingsStatus @Inject lateinit var nsSettingStatus: NSSettingsStatus
@Inject lateinit var openHumansUploader: OpenHumansUploader @Inject lateinit var openHumansUploader: OpenHumansUploader
// TODO why?
@Inject lateinit var androidInjector: DispatchingAndroidInjector<Any>
override fun androidInjector(): AndroidInjector<Any> = androidInjector
override fun onAttach(context: Context) { override fun onAttach(context: Context) {
AndroidSupportInjection.inject(this) AndroidSupportInjection.inject(this)
super.onAttach(context) 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) if (enabled) addPreferencesFromResource(preferencesResId, key)
} }
@ -426,7 +418,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)
} }
public fun setFilter(filter: String) { fun setFilter(filter: String) {
this.filter = filter this.filter = filter
updateFilterVisibility(filter, preferenceScreen) updateFilterVisibility(filter, preferenceScreen)
} }

View file

@ -10,7 +10,6 @@ import info.nightscout.androidaps.R
import info.nightscout.androidaps.utils.locale.LocaleHelper import info.nightscout.androidaps.utils.locale.LocaleHelper
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import kotlinx.android.synthetic.main.activity_preferences.* import kotlinx.android.synthetic.main.activity_preferences.*
import kotlinx.android.synthetic.main.local_insight_status_item.view.*
import javax.inject.Inject import javax.inject.Inject
class PreferencesActivity : NoSplashAppCompatActivity(), PreferenceFragmentCompat.OnPreferenceStartScreenCallback { class PreferencesActivity : NoSplashAppCompatActivity(), PreferenceFragmentCompat.OnPreferenceStartScreenCallback {
@ -33,8 +32,8 @@ class PreferencesActivity : NoSplashAppCompatActivity(), PreferenceFragmentCompa
override fun afterTextChanged(s: Editable) {} override fun afterTextChanged(s: Editable) {}
}) })
pref_filter_clear.setOnClickListener() { pref_filter_clear.setOnClickListener {
pref_filter.setText(""); pref_filter.setText("")
} }
title = resourceHelper.gs(R.string.nav_preferences) title = resourceHelper.gs(R.string.nav_preferences)

View file

@ -22,6 +22,7 @@ import javax.inject.Singleton;
import dagger.Lazy; import dagger.Lazy;
import dagger.android.HasAndroidInjector; import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp; 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.aps.loop.events.EventNewOpenLoopNotification;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker; 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.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; 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.general.wear.ActionStringHandler;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; 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 FabricPrivacy fabricPrivacy;
private final NSUpload nsUpload; private final NSUpload nsUpload;
private final HardLimits hardLimits; 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"; private static final String CHANNEL_ID = "AndroidAPS-Openloop";
@ -126,6 +126,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
AAPSLogger aapsLogger, AAPSLogger aapsLogger,
RxBusWrapper rxBus, RxBusWrapper rxBus,
SP sp, SP sp,
Config config,
ConstraintChecker constraintChecker, ConstraintChecker constraintChecker,
ResourceHelper resourceHelper, ResourceHelper resourceHelper,
ProfileFunction profileFunction, ProfileFunction profileFunction,
@ -147,6 +148,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
.pluginName(R.string.loop) .pluginName(R.string.loop)
.shortName(R.string.loop_shortname) .shortName(R.string.loop_shortname)
.preferencesId(R.xml.pref_loop) .preferencesId(R.xml.pref_loop)
.enableByDefault(config.getAPS())
.description(R.string.description_loop), .description(R.string.description_loop),
aapsLogger, resourceHelper, injector aapsLogger, resourceHelper, injector
); );
@ -415,7 +417,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
resultAfterConstraints.smb = 0; resultAfterConstraints.smb = 0;
} }
if (lastRun != null) { if (lastRun != null && lastRun.getConstraintsProcessed() != null) {
prevCarbsreq = lastRun.getConstraintsProcessed().carbsReq; prevCarbsreq = lastRun.getConstraintsProcessed().carbsReq;
} }

View file

@ -2,19 +2,15 @@ package info.nightscout.androidaps.setupwizard
import android.Manifest import android.Manifest
import android.content.Context import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config import info.nightscout.androidaps.Config
import info.nightscout.androidaps.Constants import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.PreferencesActivity
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog import info.nightscout.androidaps.dialogs.ProfileSwitchDialog
import info.nightscout.androidaps.events.EventConfigBuilderChange
import info.nightscout.androidaps.events.EventPumpStatusChanged import info.nightscout.androidaps.events.EventPumpStatusChanged
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.interfaces.ProfileFunction
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
@ -37,8 +33,6 @@ import info.nightscout.androidaps.setupwizard.events.EventSWUpdate
import info.nightscout.androidaps.utils.AndroidPermission import info.nightscout.androidaps.utils.AndroidPermission
import info.nightscout.androidaps.utils.CryptoUtil import info.nightscout.androidaps.utils.CryptoUtil
import info.nightscout.androidaps.utils.extensions.isRunningTest import info.nightscout.androidaps.utils.extensions.isRunningTest
import info.nightscout.androidaps.utils.locale.LocaleHelper.update
import info.nightscout.androidaps.utils.protection.ProtectionCheck
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import java.util.* import java.util.*
@ -61,7 +55,6 @@ class SWDefinition @Inject constructor(
private val loopPlugin: LoopPlugin, private val loopPlugin: LoopPlugin,
private val nsClientPlugin: NSClientPlugin, private val nsClientPlugin: NSClientPlugin,
private val nsProfilePlugin: NSProfilePlugin, private val nsProfilePlugin: NSProfilePlugin,
private val protectionCheck: ProtectionCheck,
private val importExportPrefs: ImportExportPrefs, private val importExportPrefs: ImportExportPrefs,
private val androidPermission: AndroidPermission, private val androidPermission: AndroidPermission,
private val cryptoUtil: CryptoUtil, private val cryptoUtil: CryptoUtil,
@ -83,16 +76,6 @@ class SWDefinition @Inject constructor(
private val screenSetupWizard = SWScreen(injector, R.string.nav_setupwizard) private val screenSetupWizard = SWScreen(injector, R.string.nav_setupwizard)
.add(SWInfotext(injector) .add(SWInfotext(injector)
.label(R.string.welcometosetupwizard)) .label(R.string.welcometosetupwizard))
private val screenLanguage = SWScreen(injector, R.string.language)
.skippable(false)
.add(SWRadioButton(injector)
.option(R.array.languagesArray, R.array.languagesValues)
.preferenceId(R.string.key_language).label(R.string.language)
.comment(R.string.setupwizard_language_prompt))
.validator(SWValidator {
update(context)
sp.contains(R.string.key_language)
})
private val screenEula = SWScreen(injector, R.string.end_user_license_agreement) private val screenEula = SWScreen(injector, R.string.end_user_license_agreement)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfotext(injector)
@ -100,20 +83,20 @@ class SWDefinition @Inject constructor(
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
.text(R.string.end_user_license_agreement_i_understand) .text(R.string.end_user_license_agreement_i_understand)
.visibility(SWValidator { !sp.getBoolean(R.string.key_i_understand, false) }) .visibility { !sp.getBoolean(R.string.key_i_understand, false) }
.action(Runnable { .action {
sp.putBoolean(R.string.key_i_understand, true) sp.putBoolean(R.string.key_i_understand, true)
rxBus.send(EventSWUpdate(false)) rxBus.send(EventSWUpdate(false))
})) })
.visibility(SWValidator { !sp.getBoolean(R.string.key_i_understand, false) }) .visibility { !sp.getBoolean(R.string.key_i_understand, false) }
.validator(SWValidator { sp.getBoolean(R.string.key_i_understand, false) }) .validator { sp.getBoolean(R.string.key_i_understand, false) }
private val screenUnits = SWScreen(injector, R.string.units) private val screenUnits = SWScreen(injector, R.string.units)
.skippable(false) .skippable(false)
.add(SWRadioButton(injector) .add(SWRadioButton(injector)
.option(R.array.unitsArray, R.array.unitsValues) .option(R.array.unitsArray, R.array.unitsValues)
.preferenceId(R.string.key_units).label(R.string.units) .preferenceId(R.string.key_units).label(R.string.units)
.comment(R.string.setupwizard_units_prompt)) .comment(R.string.setupwizard_units_prompt))
.validator(SWValidator { sp.contains(R.string.key_units) }) .validator { sp.contains(R.string.key_units) }
private val displaySettings = SWScreen(injector, R.string.wear_display_settings) private val displaySettings = SWScreen(injector, R.string.wear_display_settings)
.skippable(false) .skippable(false)
.add(SWEditNumberWithUnits(injector, Constants.LOWMARK * Constants.MGDL_TO_MMOLL, 3.0, 8.0) .add(SWEditNumberWithUnits(injector, Constants.LOWMARK * Constants.MGDL_TO_MMOLL, 3.0, 8.0)
@ -134,10 +117,10 @@ class SWDefinition @Inject constructor(
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
.text(R.string.askforpermission) .text(R.string.askforpermission)
.visibility(SWValidator { androidPermission.permissionNotGranted(context, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) }) .visibility { androidPermission.permissionNotGranted(context, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) }
.action(Runnable { androidPermission.askForPermission(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, AndroidPermission.CASE_BATTERY) })) .action { androidPermission.askForPermission(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, AndroidPermission.CASE_BATTERY) })
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) }) .visibility { androidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) }
.validator(SWValidator { !androidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) }) .validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) }
private val screenPermissionBt = SWScreen(injector, R.string.permission) private val screenPermissionBt = SWScreen(injector, R.string.permission)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfotext(injector)
@ -145,10 +128,10 @@ class SWDefinition @Inject constructor(
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
.text(R.string.askforpermission) .text(R.string.askforpermission)
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) }) .visibility { androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) }
.action(Runnable { androidPermission.askForPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION, AndroidPermission.CASE_LOCATION) })) .action { androidPermission.askForPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION, AndroidPermission.CASE_LOCATION) })
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) }) .visibility { androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) }
.validator(SWValidator { !androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) }) .validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) }
private val screenPermissionStore = SWScreen(injector, R.string.permission) private val screenPermissionStore = SWScreen(injector, R.string.permission)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfotext(injector)
@ -156,18 +139,18 @@ class SWDefinition @Inject constructor(
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
.text(R.string.askforpermission) .text(R.string.askforpermission)
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }) .visibility { androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }
.action(Runnable { androidPermission.askForPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, AndroidPermission.CASE_STORAGE) })) .action { androidPermission.askForPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, AndroidPermission.CASE_STORAGE) })
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }) .visibility { androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }
.validator(SWValidator { !androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }) .validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }
private val screenImport = SWScreen(injector, R.string.nav_import) private val screenImport = SWScreen(injector, R.string.nav_import)
.add(SWInfotext(injector) .add(SWInfotext(injector)
.label(R.string.storedsettingsfound)) .label(R.string.storedsettingsfound))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
.text(R.string.nav_import) .text(R.string.nav_import)
.action(Runnable { importExportPrefs.importSharedPreferences(activity) })) .action { importExportPrefs.importSharedPreferences(activity) })
.visibility(SWValidator { importExportPrefs.prefsFileExists() && !androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }) .visibility { importExportPrefs.prefsFileExists() && !androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }
private val screenNsClient = SWScreen(injector, R.string.nsclientinternal_title) private val screenNsClient = SWScreen(injector, R.string.nsclientinternal_title)
.skippable(true) .skippable(true)
.add(SWInfotext(injector) .add(SWInfotext(injector)
@ -175,22 +158,18 @@ class SWDefinition @Inject constructor(
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
.text(R.string.enable_nsclient) .text(R.string.enable_nsclient)
.action(Runnable { .action {
nsClientPlugin.setPluginEnabled(PluginType.GENERAL, true) configBuilderPlugin.performPluginSwitch(nsClientPlugin, true, PluginType.GENERAL)
nsClientPlugin.setFragmentVisible(PluginType.GENERAL, true)
configBuilderPlugin.processOnEnabledCategoryChanged(nsClientPlugin, PluginType.GENERAL)
configBuilderPlugin.storeSettings("SetupWizard")
rxBus.send(EventConfigBuilderChange())
rxBus.send(EventSWUpdate(true)) rxBus.send(EventSWUpdate(true))
}) }
.visibility(SWValidator { !nsClientPlugin.isEnabled(PluginType.GENERAL) })) .visibility { !nsClientPlugin.isEnabled(PluginType.GENERAL) })
.add(SWEditUrl(injector) .add(SWEditUrl(injector)
.preferenceId(R.string.key_nsclientinternal_url) .preferenceId(R.string.key_nsclientinternal_url)
.updateDelay(5) .updateDelay(5)
.label(R.string.nsclientinternal_url_title) .label(R.string.nsclientinternal_url_title)
.comment(R.string.nsclientinternal_url_dialogmessage)) .comment(R.string.nsclientinternal_url_dialogmessage))
.add(SWEditString(injector) .add(SWEditString(injector)
.validator(SWTextValidator { text: String -> text.length >= 12 }) .validator { text: String -> text.length >= 12 }
.preferenceId(R.string.key_nsclientinternal_api_secret) .preferenceId(R.string.key_nsclientinternal_api_secret)
.updateDelay(5) .updateDelay(5)
.label(R.string.nsclientinternal_secret_dialogtitle) .label(R.string.nsclientinternal_secret_dialogtitle)
@ -200,9 +179,8 @@ class SWDefinition @Inject constructor(
.label(R.string.status) .label(R.string.status)
.initialStatus(nsClientPlugin.status) .initialStatus(nsClientPlugin.status)
) )
.add(SWBreak(injector)) .validator { nsClientPlugin.nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth }
.validator(SWValidator { nsClientPlugin.nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth }) .visibility { !(nsClientPlugin.nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth) }
.visibility(SWValidator { !(nsClientPlugin.nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth) })
private val screenPatientName = SWScreen(injector, R.string.patient_name) private val screenPatientName = SWScreen(injector, R.string.patient_name)
.skippable(true) .skippable(true)
.add(SWInfotext(injector) .add(SWInfotext(injector)
@ -219,7 +197,7 @@ class SWDefinition @Inject constructor(
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWInfotext(injector) .add(SWInfotext(injector)
.label(R.string.master_password_summary)) .label(R.string.master_password_summary))
.validator(SWValidator { !cryptoUtil.checkPassword("", sp.getString(R.string.key_master_password, "")) }) .validator { !cryptoUtil.checkPassword("", sp.getString(R.string.key_master_password, "")) }
private val screenAge = SWScreen(injector, R.string.patientage) private val screenAge = SWScreen(injector, R.string.patientage)
.skippable(false) .skippable(false)
.add(SWBreak(injector)) .add(SWBreak(injector))
@ -228,51 +206,28 @@ class SWDefinition @Inject constructor(
.preferenceId(R.string.key_age) .preferenceId(R.string.key_age)
.label(R.string.patientage) .label(R.string.patientage)
.comment(R.string.patientage_summary)) .comment(R.string.patientage_summary))
.validator(SWValidator { sp.contains(R.string.key_age) }) .validator { sp.contains(R.string.key_age) }
private val screenInsulin = SWScreen(injector, R.string.configbuilder_insulin) private val screenInsulin = SWScreen(injector, R.string.configbuilder_insulin)
.skippable(false) .skippable(false)
.add(SWPlugin(injector) .add(SWPlugin(injector, this)
.option(PluginType.INSULIN, R.string.configbuilder_insulin_description) .option(PluginType.INSULIN, R.string.configbuilder_insulin_description)
.makeVisible(false) .makeVisible(false)
.label(R.string.configbuilder_insulin)) .label(R.string.configbuilder_insulin))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWInfotext(injector) .add(SWInfotext(injector)
.label(R.string.diawarning)) .label(R.string.diawarning))
.add(SWBreak(injector))
.add(SWButton(injector)
.text(R.string.insulinsourcesetup)
.action(Runnable {
val plugin = activePlugin.activeInsulin as PluginBase
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
val i = Intent(activity, PreferencesActivity::class.java)
i.putExtra("id", plugin.preferencesId)
activity.startActivity(i)
}, null)
})
.visibility(SWValidator { (activePlugin.activeInsulin as PluginBase).preferencesId > 0 }))
private val screenBgSource = SWScreen(injector, R.string.configbuilder_bgsource) private val screenBgSource = SWScreen(injector, R.string.configbuilder_bgsource)
.skippable(false) .skippable(false)
.add(SWPlugin(injector) .add(SWPlugin(injector, this)
.option(PluginType.BGSOURCE, R.string.configbuilder_bgsource_description) .option(PluginType.BGSOURCE, R.string.configbuilder_bgsource_description)
.label(R.string.configbuilder_bgsource)) .label(R.string.configbuilder_bgsource))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector)
.text(R.string.bgsourcesetup)
.action(Runnable {
val plugin = activePlugin.activeBgSource as PluginBase
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
val i = Intent(activity, PreferencesActivity::class.java)
i.putExtra("id", plugin.preferencesId)
activity.startActivity(i)
}, null)
})
.visibility(SWValidator { (activePlugin.activeBgSource as PluginBase).preferencesId > 0 }))
private val screenProfile = SWScreen(injector, R.string.configbuilder_profile) private val screenProfile = SWScreen(injector, R.string.configbuilder_profile)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfotext(injector)
.label(R.string.setupwizard_profile_description)) .label(R.string.setupwizard_profile_description))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWPlugin(injector) .add(SWPlugin(injector, this)
.option(PluginType.PROFILE, R.string.configbuilder_profile_description) .option(PluginType.PROFILE, R.string.configbuilder_profile_description)
.label(R.string.configbuilder_profile)) .label(R.string.configbuilder_profile))
private val screenNsProfile = SWScreen(injector, R.string.nsprofile) private val screenNsProfile = SWScreen(injector, R.string.nsprofile)
@ -281,69 +236,54 @@ class SWDefinition @Inject constructor(
.label(R.string.adjustprofileinns)) .label(R.string.adjustprofileinns))
.add(SWFragment(injector, this) .add(SWFragment(injector, this)
.add(NSProfileFragment())) .add(NSProfileFragment()))
.validator(SWValidator { nsProfilePlugin.profile != null && nsProfilePlugin.profile!!.getDefaultProfile() != null && nsProfilePlugin.profile!!.getDefaultProfile()!!.isValid("StartupWizard") }) .validator { nsProfilePlugin.profile != null && nsProfilePlugin.profile!!.getDefaultProfile() != null && nsProfilePlugin.profile!!.getDefaultProfile()!!.isValid("StartupWizard") }
.visibility(SWValidator { nsProfilePlugin.isEnabled(PluginType.PROFILE) }) .visibility { nsProfilePlugin.isEnabled(PluginType.PROFILE) }
private val screenLocalProfile = SWScreen(injector, R.string.localprofile) private val screenLocalProfile = SWScreen(injector, R.string.localprofile)
.skippable(false) .skippable(false)
.add(SWFragment(injector, this) .add(SWFragment(injector, this)
.add(LocalProfileFragment())) .add(LocalProfileFragment()))
.validator(SWValidator { localProfilePlugin.profile?.getDefaultProfile()?.isValid("StartupWizard") == true }) .validator { localProfilePlugin.profile?.getDefaultProfile()?.isValid("StartupWizard") == true }
.visibility(SWValidator { localProfilePlugin.isEnabled(PluginType.PROFILE) }) .visibility { localProfilePlugin.isEnabled(PluginType.PROFILE) }
private val screenProfileSwitch = SWScreen(injector, R.string.careportal_profileswitch) private val screenProfileSwitch = SWScreen(injector, R.string.careportal_profileswitch)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfotext(injector)
.label(R.string.profileswitch_ismissing)) .label(R.string.profileswitch_ismissing))
.add(SWButton(injector) .add(SWButton(injector)
.text(R.string.doprofileswitch) .text(R.string.doprofileswitch)
.action(Runnable { ProfileSwitchDialog().show(activity.supportFragmentManager, "SetupWizard") })) .action { ProfileSwitchDialog().show(activity.supportFragmentManager, "SetupWizard") })
.validator(SWValidator { profileFunction.getProfile() != null }) .validator { profileFunction.getProfile() != null }
.visibility(SWValidator { profileFunction.getProfile() == null }) .visibility { profileFunction.getProfile() == null }
private val screenPump = SWScreen(injector, R.string.configbuilder_pump) private val screenPump = SWScreen(injector, R.string.configbuilder_pump)
.skippable(false) .skippable(false)
.add(SWPlugin(injector) .add(SWPlugin(injector, this)
.option(PluginType.PUMP, R.string.configbuilder_pump_description) .option(PluginType.PUMP, R.string.configbuilder_pump_description)
.label(R.string.configbuilder_pump)) .label(R.string.configbuilder_pump))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector)
.text(R.string.pumpsetup)
.action(Runnable {
val plugin = activePlugin.activePump as PluginBase
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
val i = Intent(activity, PreferencesActivity::class.java)
i.putExtra("id", plugin.preferencesId)
activity.startActivity(i)
}, null)
})
.visibility(SWValidator { (activePlugin.activePump as PluginBase).preferencesId > 0 }))
.add(SWInfotext(injector) .add(SWInfotext(injector)
.label(R.string.setupwizard_pump_pump_not_initialized) .label(R.string.setupwizard_pump_pump_not_initialized)
.visibility(SWValidator { !isPumpInitialized() })) .visibility { !isPumpInitialized() })
.add( // Omnipod only .add( // Omnipod only
SWInfotext(injector) SWInfotext(injector)
.label(R.string.setupwizard_pump_waiting_for_riley_link_connection) .label(R.string.setupwizard_pump_waiting_for_riley_link_connection)
.visibility(SWValidator { .visibility {
val activePump = activePlugin.activePump val activePump = activePlugin.activePump
activePump is OmnipodPumpPlugin && !activePump.isRileyLinkReady activePump is OmnipodPumpPlugin && !activePump.isRileyLinkReady
})) })
.add( // Omnipod only .add( // Omnipod only
SWEventListener(injector, EventRileyLinkDeviceStatusChange::class.java) SWEventListener(injector, EventRileyLinkDeviceStatusChange::class.java)
.label(R.string.setupwizard_pump_riley_link_status) .label(R.string.setupwizard_pump_riley_link_status)
.visibility(SWValidator { .visibility { activePlugin.activePump is OmnipodPumpPlugin })
activePlugin.activePump is OmnipodPumpPlugin
}))
.add(SWButton(injector) .add(SWButton(injector)
.text(R.string.readstatus) .text(R.string.readstatus)
.action(Runnable { commandQueue.readStatus("Clicked connect to pump", null) }) .action { commandQueue.readStatus("Clicked connect to pump", null) }
.visibility(SWValidator { .visibility {
// Hide for Omnipod, because as we don't require a Pod to be paired in the setup wizard, // Hide for Omnipod, because as we don't require a Pod to be paired in the setup wizard,
// Getting the status might not be possible // Getting the status might not be possible
activePlugin.activePump !is OmnipodPumpPlugin activePlugin.activePump !is OmnipodPumpPlugin
}))
.add(SWEventListener(injector, EventPumpStatusChanged::class.java)
.visibility(SWValidator { activePlugin.activePump !is OmnipodPumpPlugin }))
.validator(SWValidator {
isPumpInitialized()
}) })
.add(SWEventListener(injector, EventPumpStatusChanged::class.java)
.visibility { activePlugin.activePump !is OmnipodPumpPlugin })
.validator { isPumpInitialized() }
private fun isPumpInitialized(): Boolean { private fun isPumpInitialized(): Boolean {
val activePump = activePlugin.activePump val activePump = activePlugin.activePump
@ -358,31 +298,20 @@ class SWDefinition @Inject constructor(
.add(SWInfotext(injector) .add(SWInfotext(injector)
.label(R.string.setupwizard_aps_description)) .label(R.string.setupwizard_aps_description))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWPlugin(injector, this)
.option(PluginType.APS, R.string.configbuilder_aps_description)
.label(R.string.configbuilder_aps))
.add(SWBreak(injector))
.add(SWHtmlLink(injector) .add(SWHtmlLink(injector)
.label("https://openaps.readthedocs.io/en/latest/")) .label("https://openaps.readthedocs.io/en/latest/"))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWPlugin(injector)
.option(PluginType.APS, R.string.configbuilder_aps_description)
.label(R.string.configbuilder_aps))
.add(SWButton(injector)
.text(R.string.apssetup)
.action(Runnable {
val plugin = activePlugin.activeAPS as PluginBase
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
val i = Intent(activity, PreferencesActivity::class.java)
i.putExtra("id", plugin.preferencesId)
activity.startActivity(i)
}, null)
})
.visibility(SWValidator { (activePlugin.activeAPS as PluginBase).preferencesId > 0 }))
.visibility(SWValidator { config.APS })
private val screenApsMode = SWScreen(injector, R.string.apsmode_title) private val screenApsMode = SWScreen(injector, R.string.apsmode_title)
.skippable(false) .skippable(false)
.add(SWRadioButton(injector) .add(SWRadioButton(injector)
.option(R.array.aps_modeArray, R.array.aps_modeValues) .option(R.array.aps_modeArray, R.array.aps_modeValues)
.preferenceId(R.string.key_aps_mode).label(R.string.apsmode_title) .preferenceId(R.string.key_aps_mode).label(R.string.apsmode_title)
.comment(R.string.setupwizard_preferred_aps_mode)) .comment(R.string.setupwizard_preferred_aps_mode))
.validator(SWValidator { sp.contains(R.string.key_aps_mode) }) .validator { sp.contains(R.string.key_aps_mode) }
private val screenLoop = SWScreen(injector, R.string.configbuilder_loop) private val screenLoop = SWScreen(injector, R.string.configbuilder_loop)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfotext(injector)
@ -390,17 +319,13 @@ class SWDefinition @Inject constructor(
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
.text(R.string.enableloop) .text(R.string.enableloop)
.action(Runnable { .action {
loopPlugin.setPluginEnabled(PluginType.LOOP, true) configBuilderPlugin.performPluginSwitch(loopPlugin, true, PluginType.LOOP)
loopPlugin.setFragmentVisible(PluginType.LOOP, true)
configBuilderPlugin.processOnEnabledCategoryChanged(loopPlugin, PluginType.LOOP)
configBuilderPlugin.storeSettings("SetupWizard")
rxBus.send(EventConfigBuilderChange())
rxBus.send(EventSWUpdate(true)) rxBus.send(EventSWUpdate(true))
}) }
.visibility(SWValidator { !loopPlugin.isEnabled(PluginType.LOOP) })) .visibility { !loopPlugin.isEnabled(PluginType.LOOP) })
.validator(SWValidator { loopPlugin.isEnabled(PluginType.LOOP) }) .validator { loopPlugin.isEnabled(PluginType.LOOP) }
.visibility(SWValidator { !loopPlugin.isEnabled(PluginType.LOOP) && config.APS }) .visibility { !loopPlugin.isEnabled(PluginType.LOOP) && config.APS }
private val screenSensitivity = SWScreen(injector, R.string.configbuilder_sensitivity) private val screenSensitivity = SWScreen(injector, R.string.configbuilder_sensitivity)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfotext(injector)
@ -408,21 +333,9 @@ class SWDefinition @Inject constructor(
.add(SWHtmlLink(injector) .add(SWHtmlLink(injector)
.label(R.string.setupwizard_sensitivity_url)) .label(R.string.setupwizard_sensitivity_url))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWPlugin(injector) .add(SWPlugin(injector, this)
.option(PluginType.SENSITIVITY, R.string.configbuilder_sensitivity_description) .option(PluginType.SENSITIVITY, R.string.configbuilder_sensitivity_description)
.label(R.string.configbuilder_sensitivity)) .label(R.string.configbuilder_sensitivity))
.add(SWBreak(injector))
.add(SWButton(injector)
.text(R.string.sensitivitysetup)
.action(Runnable {
val plugin = activePlugin.activeSensitivity as PluginBase
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
val i = Intent(activity, PreferencesActivity::class.java)
i.putExtra("id", plugin.preferencesId)
activity.startActivity(i)
}, null)
})
.visibility(SWValidator { (activePlugin.activeSensitivity as PluginBase).preferencesId > 0 }))
private val getScreenObjectives = SWScreen(injector, R.string.objectives) private val getScreenObjectives = SWScreen(injector, R.string.objectives)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfotext(injector)
@ -430,8 +343,8 @@ class SWDefinition @Inject constructor(
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWFragment(injector, this) .add(SWFragment(injector, this)
.add(ObjectivesFragment())) .add(ObjectivesFragment()))
.validator(SWValidator { objectivesPlugin.objectives[ObjectivesPlugin.FIRST_OBJECTIVE].isStarted }) .validator { objectivesPlugin.objectives[ObjectivesPlugin.FIRST_OBJECTIVE].isStarted }
.visibility(SWValidator { !objectivesPlugin.objectives[ObjectivesPlugin.FIRST_OBJECTIVE].isStarted && config.APS }) .visibility { !objectivesPlugin.objectives[ObjectivesPlugin.FIRST_OBJECTIVE].isStarted && config.APS }
private fun swDefinitionFull() { // List all the screens here private fun swDefinitionFull() { // List all the screens here
add(screenSetupWizard) add(screenSetupWizard)

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.setupwizard.elements package info.nightscout.androidaps.setupwizard.elements
import android.os.Bundle
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.LinearLayout import android.widget.LinearLayout
@ -7,15 +8,17 @@ import android.widget.RadioButton
import android.widget.RadioGroup import android.widget.RadioGroup
import android.widget.TextView import android.widget.TextView
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.activities.MyPreferenceFragment
import info.nightscout.androidaps.events.EventConfigBuilderChange import info.nightscout.androidaps.events.EventConfigBuilderChange
import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginType import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.PluginStore import info.nightscout.androidaps.plugins.configBuilder.PluginStore
import info.nightscout.androidaps.setupwizard.SWDefinition
import info.nightscout.androidaps.setupwizard.events.EventSWUpdate import info.nightscout.androidaps.setupwizard.events.EventSWUpdate
import javax.inject.Inject import javax.inject.Inject
class SWPlugin(injector: HasAndroidInjector) : SWItem(injector, Type.PLUGIN) { class SWPlugin(injector: HasAndroidInjector, val definition: SWDefinition) : SWItem(injector, Type.PLUGIN) {
@Inject lateinit var pluginStore: PluginStore @Inject lateinit var pluginStore: PluginStore
@Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin
@ -25,6 +28,8 @@ class SWPlugin(injector: HasAndroidInjector) : SWItem(injector, Type.PLUGIN) {
private var pluginDescription = 0 private var pluginDescription = 0
private var makeVisible = true private var makeVisible = true
private var fragment: MyPreferenceFragment? = null
fun option(pType: PluginType, pluginDescription: Int): SWPlugin { fun option(pType: PluginType, pluginDescription: Int): SWPlugin {
this.pType = pType this.pType = pType
this.pluginDescription = pluginDescription this.pluginDescription = pluginDescription
@ -37,26 +42,30 @@ class SWPlugin(injector: HasAndroidInjector) : SWItem(injector, Type.PLUGIN) {
} }
override fun generateDialog(layout: LinearLayout) { override fun generateDialog(layout: LinearLayout) {
var selectedPlugin: PluginBase? = null
val context = layout.context val context = layout.context
radioGroup = RadioGroup(context) radioGroup = RadioGroup(context)
radioGroup?.clearCheck() radioGroup?.clearCheck()
val pluginsInCategory = pluginStore.getSpecificPluginsList(pType!!) val pluginsInCategory = pluginStore.getSpecificPluginsList(pType!!)
radioGroup?.orientation = LinearLayout.VERTICAL radioGroup?.orientation = LinearLayout.VERTICAL
radioGroup?.visibility = View.VISIBLE radioGroup?.visibility = View.VISIBLE
val pdesc = TextView(context) val pDesc = TextView(context)
pdesc.setText(pluginDescription) pDesc.setText(pluginDescription)
var params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) var params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
params.setMargins(0, 0, 0, 40) params.setMargins(0, 0, 0, 40)
pdesc.layoutParams = params pDesc.layoutParams = params
layout.addView(pdesc) layout.addView(pDesc)
for (i in pluginsInCategory.indices) { for (i in pluginsInCategory.indices) {
val rdbtn = RadioButton(context) val rdBtn = RadioButton(context)
val p = pluginsInCategory[i] val p = pluginsInCategory[i]
rdbtn.id = View.generateViewId() rdBtn.id = View.generateViewId()
rdbtn.text = p.name rdBtn.text = p.name
if (p.isEnabled(pType!!)) rdbtn.isChecked = true if (p.isEnabled(pType!!)) {
rdbtn.tag = p rdBtn.isChecked = true
radioGroup?.addView(rdbtn) selectedPlugin = p
}
rdBtn.tag = p
radioGroup?.addView(rdBtn)
params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
params.setMargins(80, 0, 0, 0) params.setMargins(80, 0, 0, 0)
val desc = TextView(context) val desc = TextView(context)
@ -73,8 +82,27 @@ class SWPlugin(injector: HasAndroidInjector) : SWItem(injector, Type.PLUGIN) {
configBuilderPlugin.storeSettings("SetupWizard") configBuilderPlugin.storeSettings("SetupWizard")
rxBus.send(EventConfigBuilderChange()) rxBus.send(EventConfigBuilderChange())
rxBus.send(EventSWUpdate(false)) rxBus.send(EventSWUpdate(false))
addConfiguration(layout, plugin)
} }
layout.addView(radioGroup) layout.addView(radioGroup)
selectedPlugin?.let { addConfiguration(layout, it) }
super.generateDialog(layout) super.generateDialog(layout)
} }
fun addConfiguration(layout: LinearLayout, plugin: PluginBase) {
if (plugin.preferencesId != -1) {
fragment = MyPreferenceFragment()
fragment?.arguments = Bundle().also { it.putInt("id", plugin.preferencesId) }
definition.activity.supportFragmentManager.beginTransaction().run {
replace(layout.id, fragment!!)
commit()
}
} else {
definition.activity.supportFragmentManager.beginTransaction().run {
if (fragment != null) remove(fragment!!)
fragment = null
commit()
}
}
}
} }