ConfigBuilderFragment -> jetpack
This commit is contained in:
parent
c4eb6eae91
commit
fcf67cd014
|
@ -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<PluginViewHolder>()
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
@ -13,13 +13,13 @@
|
|||
android:text="@string/unlock_settings" />
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/configbuilder_main_layout"
|
||||
android:id="@+id/main_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/configbuilder_categories"
|
||||
android:id="@+id/categories"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
|
|
Loading…
Reference in a new issue