InsulinFragment -> jetpack

This commit is contained in:
Milos Kozak 2021-02-02 21:11:40 +01:00
parent 026d6039dc
commit 609c1dfad3
2 changed files with 48 additions and 41 deletions

View file

@ -6,25 +6,38 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.databinding.InsulinFragmentBinding
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import kotlinx.android.synthetic.main.insulin_fragment.*
import javax.inject.Inject import javax.inject.Inject
class InsulinFragment : DaggerFragment() { class InsulinFragment : DaggerFragment() {
@Inject lateinit var activePlugin: ActivePluginProvider @Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var resourceHelper: ResourceHelper @Inject lateinit var resourceHelper: ResourceHelper
private var _binding: InsulinFragmentBinding? = 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.insulin_fragment, container, false) _binding = InsulinFragmentBinding.inflate(inflater, container, false)
return binding.root
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
insulin_name?.text = activePlugin.activeInsulin.friendlyName binding.name.text = activePlugin.activeInsulin.friendlyName
insulin_comment?.text = activePlugin.activeInsulin.comment binding.comment.text = activePlugin.activeInsulin.comment
insulin_dia?.text = resourceHelper.gs(R.string.dia) + ": " + activePlugin.activeInsulin.dia + "h" binding.dia.text = resourceHelper.gs(R.string.dia) + ": " + resourceHelper.gs(R.string.format_hours, activePlugin.activeInsulin.dia)
insulin_graph?.show(activePlugin.activeInsulin) binding.graph.show(activePlugin.activeInsulin)
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
} }
} }

View file

@ -1,47 +1,41 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="info.nightscout.androidaps.plugins.insulin.InsulinFragment"> tools:context="info.nightscout.androidaps.plugins.insulin.InsulinFragment">
<ScrollView <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout <TextView
android:orientation="vertical" android:id="@+id/name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView <TextView
android:id="@+id/insulin_name" android:id="@+id/comment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="10dp" android:layout_margin="10dp"
android:textAppearance="?android:attr/textAppearanceLarge" /> android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView <TextView
android:id="@+id/insulin_comment" android:id="@+id/dia"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="10dp" android:layout_margin="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" /> android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView <info.nightscout.androidaps.plugins.insulin.ActivityGraph
android:id="@+id/insulin_dia" android:id="@+id/graph"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="200dip"
android:layout_margin="10dp" android:layout_margin="20dp" />
android:textAppearance="?android:attr/textAppearanceMedium" />
<info.nightscout.androidaps.plugins.insulin.ActivityGraph </LinearLayout>
android:id="@+id/insulin_graph"
android:layout_width="match_parent"
android:layout_margin="20dp"
android:layout_height="200dip" />
</LinearLayout> </ScrollView>
</ScrollView>
</FrameLayout>