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 09bbf3c04d..52ec1fd95f 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 @@ -12,6 +12,7 @@ import dagger.android.support.DaggerFragment import info.nightscout.androidaps.Config import info.nightscout.androidaps.R import info.nightscout.androidaps.activities.PreferencesActivity +import info.nightscout.androidaps.databinding.ConfigbuilderFragmentBinding import info.nightscout.androidaps.events.EventRebuildTabs import info.nightscout.androidaps.interfaces.* import info.nightscout.androidaps.plugins.bus.RxBusWrapper @@ -23,11 +24,11 @@ import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.resources.ResourceHelper import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable -import kotlinx.android.synthetic.main.configbuilder_fragment.* import java.util.* import javax.inject.Inject class ConfigBuilderFragment : DaggerFragment() { + @Inject lateinit var rxBus: RxBusWrapper @Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin @@ -39,25 +40,32 @@ class ConfigBuilderFragment : DaggerFragment() { private var disposable: CompositeDisposable = CompositeDisposable() private val pluginViewHolders = ArrayList() + private var _binding: ConfigbuilderFragmentBinding? = null + + // This property is only valid between onCreateView and + // onDestroyView. + private val binding get() = _binding!! + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.configbuilder_fragment, container, false) + savedInstanceState: Bundle?): View { + _binding = ConfigbuilderFragmentBinding.inflate(inflater, container, false) + return binding.root } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) if (protectionCheck.isLocked(ProtectionCheck.Protection.PREFERENCES)) - configbuilder_main_layout.visibility = View.GONE + binding.mainLayout.visibility = View.GONE else - unlock.visibility = View.GONE + binding.unlock.visibility = View.GONE - unlock.setOnClickListener { + binding.unlock.setOnClickListener { activity?.let { activity -> - protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable { + protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, { activity.runOnUiThread { - configbuilder_main_layout.visibility = View.VISIBLE - unlock.visibility = View.GONE + binding.mainLayout.visibility = View.VISIBLE + binding.unlock.visibility = View.GONE } }) } @@ -82,9 +90,15 @@ class ConfigBuilderFragment : DaggerFragment() { disposable.clear() } + @Synchronized + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } + @Synchronized private fun updateGUI() { - configbuilder_categories.removeAllViews() + binding.categories.removeAllViews() if (!config.NSCLIENT) { createViewsForPlugins(R.string.configbuilder_profile, R.string.configbuilder_profile_description, PluginType.PROFILE, activePlugin.getSpecificPluginsVisibleInListByInterface(ProfileInterface::class.java, PluginType.PROFILE)) } @@ -115,7 +129,7 @@ class ConfigBuilderFragment : DaggerFragment() { pluginContainer.addView(pluginViewHolder.baseView) pluginViewHolders.add(pluginViewHolder) } - configbuilder_categories.addView(parent) + binding.categories.addView(parent) } inner class PluginViewHolder internal constructor(private val fragment: ConfigBuilderFragment, @@ -157,7 +171,7 @@ class ConfigBuilderFragment : DaggerFragment() { pluginPreferences.setOnClickListener { fragment.activity?.let { activity -> - protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable { + protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, { val i = Intent(fragment.context, PreferencesActivity::class.java) i.putExtra("id", plugin.preferencesId) fragment.startActivity(i) @@ -174,7 +188,7 @@ class ConfigBuilderFragment : DaggerFragment() { enabledInclusive.isChecked = plugin.isEnabled(pluginType) enabledInclusive.isEnabled = !plugin.pluginDescription.alwaysEnabled enabledExclusive.isEnabled = !plugin.pluginDescription.alwaysEnabled - if(plugin.menuIcon != -1) { + if (plugin.menuIcon != -1) { pluginIcon.visibility = View.VISIBLE pluginIcon.setImageDrawable(context?.let { ContextCompat.getDrawable(it, plugin.menuIcon) }) } else { @@ -196,7 +210,5 @@ class ConfigBuilderFragment : DaggerFragment() { private fun areMultipleSelectionsAllowed(type: PluginType): Boolean { return type == PluginType.GENERAL || type == PluginType.CONSTRAINTS || type == PluginType.LOOP } - } - } diff --git a/app/src/main/res/layout/configbuilder_fragment.xml b/app/src/main/res/layout/configbuilder_fragment.xml index 1073643100..719d680c63 100644 --- a/app/src/main/res/layout/configbuilder_fragment.xml +++ b/app/src/main/res/layout/configbuilder_fragment.xml @@ -1,7 +1,7 @@ @@ -13,13 +13,13 @@ android:text="@string/unlock_settings" />