ConfigBuilderFragment -> jetpack
This commit is contained in:
parent
c4eb6eae91
commit
fcf67cd014
2 changed files with 30 additions and 18 deletions
|
@ -12,6 +12,7 @@ import dagger.android.support.DaggerFragment
|
||||||
import info.nightscout.androidaps.Config
|
import info.nightscout.androidaps.Config
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.activities.PreferencesActivity
|
import info.nightscout.androidaps.activities.PreferencesActivity
|
||||||
|
import info.nightscout.androidaps.databinding.ConfigbuilderFragmentBinding
|
||||||
import info.nightscout.androidaps.events.EventRebuildTabs
|
import info.nightscout.androidaps.events.EventRebuildTabs
|
||||||
import info.nightscout.androidaps.interfaces.*
|
import info.nightscout.androidaps.interfaces.*
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
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 info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import kotlinx.android.synthetic.main.configbuilder_fragment.*
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ConfigBuilderFragment : DaggerFragment() {
|
class ConfigBuilderFragment : DaggerFragment() {
|
||||||
|
|
||||||
@Inject lateinit var rxBus: RxBusWrapper
|
@Inject lateinit var rxBus: RxBusWrapper
|
||||||
@Inject lateinit var resourceHelper: ResourceHelper
|
@Inject lateinit var resourceHelper: ResourceHelper
|
||||||
@Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
@Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||||
|
@ -39,25 +40,32 @@ class ConfigBuilderFragment : DaggerFragment() {
|
||||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||||
private val pluginViewHolders = ArrayList<PluginViewHolder>()
|
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?,
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?): View? {
|
savedInstanceState: Bundle?): View {
|
||||||
return inflater.inflate(R.layout.configbuilder_fragment, container, false)
|
_binding = ConfigbuilderFragmentBinding.inflate(inflater, container, false)
|
||||||
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
if (protectionCheck.isLocked(ProtectionCheck.Protection.PREFERENCES))
|
if (protectionCheck.isLocked(ProtectionCheck.Protection.PREFERENCES))
|
||||||
configbuilder_main_layout.visibility = View.GONE
|
binding.mainLayout.visibility = View.GONE
|
||||||
else
|
else
|
||||||
unlock.visibility = View.GONE
|
binding.unlock.visibility = View.GONE
|
||||||
|
|
||||||
unlock.setOnClickListener {
|
binding.unlock.setOnClickListener {
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, {
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
configbuilder_main_layout.visibility = View.VISIBLE
|
binding.mainLayout.visibility = View.VISIBLE
|
||||||
unlock.visibility = View.GONE
|
binding.unlock.visibility = View.GONE
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -82,9 +90,15 @@ class ConfigBuilderFragment : DaggerFragment() {
|
||||||
disposable.clear()
|
disposable.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun onDestroyView() {
|
||||||
|
super.onDestroyView()
|
||||||
|
_binding = null
|
||||||
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun updateGUI() {
|
private fun updateGUI() {
|
||||||
configbuilder_categories.removeAllViews()
|
binding.categories.removeAllViews()
|
||||||
if (!config.NSCLIENT) {
|
if (!config.NSCLIENT) {
|
||||||
createViewsForPlugins(R.string.configbuilder_profile, R.string.configbuilder_profile_description, PluginType.PROFILE, activePlugin.getSpecificPluginsVisibleInListByInterface(ProfileInterface::class.java, PluginType.PROFILE))
|
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)
|
pluginContainer.addView(pluginViewHolder.baseView)
|
||||||
pluginViewHolders.add(pluginViewHolder)
|
pluginViewHolders.add(pluginViewHolder)
|
||||||
}
|
}
|
||||||
configbuilder_categories.addView(parent)
|
binding.categories.addView(parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class PluginViewHolder internal constructor(private val fragment: ConfigBuilderFragment,
|
inner class PluginViewHolder internal constructor(private val fragment: ConfigBuilderFragment,
|
||||||
|
@ -157,7 +171,7 @@ class ConfigBuilderFragment : DaggerFragment() {
|
||||||
|
|
||||||
pluginPreferences.setOnClickListener {
|
pluginPreferences.setOnClickListener {
|
||||||
fragment.activity?.let { activity ->
|
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)
|
val i = Intent(fragment.context, PreferencesActivity::class.java)
|
||||||
i.putExtra("id", plugin.preferencesId)
|
i.putExtra("id", plugin.preferencesId)
|
||||||
fragment.startActivity(i)
|
fragment.startActivity(i)
|
||||||
|
@ -196,7 +210,5 @@ class ConfigBuilderFragment : DaggerFragment() {
|
||||||
private fun areMultipleSelectionsAllowed(type: PluginType): Boolean {
|
private fun areMultipleSelectionsAllowed(type: PluginType): Boolean {
|
||||||
return type == PluginType.GENERAL || type == PluginType.CONSTRAINTS || type == PluginType.LOOP
|
return type == PluginType.GENERAL || type == PluginType.CONSTRAINTS || type == PluginType.LOOP
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<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_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
@ -13,13 +13,13 @@
|
||||||
android:text="@string/unlock_settings" />
|
android:text="@string/unlock_settings" />
|
||||||
|
|
||||||
<androidx.core.widget.NestedScrollView
|
<androidx.core.widget.NestedScrollView
|
||||||
android:id="@+id/configbuilder_main_layout"
|
android:id="@+id/main_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/configbuilder_categories"
|
android:id="@+id/categories"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|
Loading…
Reference in a new issue