SurveyActivity -> jetpack
This commit is contained in:
parent
9409193935
commit
a6449a7578
2 changed files with 39 additions and 34 deletions
|
@ -6,6 +6,7 @@ import com.google.firebase.auth.FirebaseAuth
|
||||||
import com.google.firebase.database.FirebaseDatabase
|
import com.google.firebase.database.FirebaseDatabase
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.defaultProfile.DefaultProfile
|
import info.nightscout.androidaps.data.defaultProfile.DefaultProfile
|
||||||
|
import info.nightscout.androidaps.databinding.ActivitySurveyBinding
|
||||||
import info.nightscout.androidaps.dialogs.ProfileViewerDialog
|
import info.nightscout.androidaps.dialogs.ProfileViewerDialog
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
|
@ -18,10 +19,10 @@ import info.nightscout.androidaps.utils.SafeParse
|
||||||
import info.nightscout.androidaps.utils.ToastUtils
|
import info.nightscout.androidaps.utils.ToastUtils
|
||||||
import info.nightscout.androidaps.utils.stats.TddCalculator
|
import info.nightscout.androidaps.utils.stats.TddCalculator
|
||||||
import info.nightscout.androidaps.utils.stats.TirCalculator
|
import info.nightscout.androidaps.utils.stats.TirCalculator
|
||||||
import kotlinx.android.synthetic.main.activity_survey.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SurveyActivity : NoSplashAppCompatActivity() {
|
class SurveyActivity : NoSplashAppCompatActivity() {
|
||||||
|
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
@Inject lateinit var aapsLogger: AAPSLogger
|
||||||
@Inject lateinit var activePlugin: ActivePluginProvider
|
@Inject lateinit var activePlugin: ActivePluginProvider
|
||||||
@Inject lateinit var tddCalculator: TddCalculator
|
@Inject lateinit var tddCalculator: TddCalculator
|
||||||
|
@ -30,24 +31,27 @@ class SurveyActivity : NoSplashAppCompatActivity() {
|
||||||
@Inject lateinit var activityMonitor: ActivityMonitor
|
@Inject lateinit var activityMonitor: ActivityMonitor
|
||||||
@Inject lateinit var defaultProfile: DefaultProfile
|
@Inject lateinit var defaultProfile: DefaultProfile
|
||||||
|
|
||||||
|
private lateinit var binding: ActivitySurveyBinding
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_survey)
|
binding = ActivitySurveyBinding.inflate(layoutInflater)
|
||||||
|
setContentView(binding.root)
|
||||||
|
|
||||||
survey_id.text = InstanceId.instanceId()
|
binding.id.text = InstanceId.instanceId()
|
||||||
|
|
||||||
val profileStore = activePlugin.activeProfileInterface.profile
|
val profileStore = activePlugin.activeProfileInterface.profile
|
||||||
val profileList = profileStore?.getProfileList() ?: return
|
val profileList = profileStore?.getProfileList() ?: return
|
||||||
survey_spinner.adapter = ArrayAdapter(this, R.layout.spinner_centered, profileList)
|
binding.spinner.adapter = ArrayAdapter(this, R.layout.spinner_centered, profileList)
|
||||||
|
|
||||||
survey_tdds.text = tddCalculator.stats()
|
binding.tdds.text = tddCalculator.stats()
|
||||||
survey_tir.text = tirCalculator.stats()
|
binding.tir.text = tirCalculator.stats()
|
||||||
survey_activity.text = activityMonitor.stats()
|
binding.activity.text = activityMonitor.stats()
|
||||||
|
|
||||||
survey_profile.setOnClickListener {
|
binding.profile.setOnClickListener {
|
||||||
val age = SafeParse.stringToDouble(survey_age.text.toString())
|
val age = SafeParse.stringToDouble(binding.age.text.toString())
|
||||||
val weight = SafeParse.stringToDouble(survey_weight.text.toString())
|
val weight = SafeParse.stringToDouble(binding.weight.text.toString())
|
||||||
val tdd = SafeParse.stringToDouble(survey_tdd.text.toString())
|
val tdd = SafeParse.stringToDouble(binding.tdd.text.toString())
|
||||||
if (age < 1 || age > 120) {
|
if (age < 1 || age > 120) {
|
||||||
ToastUtils.showToastInUiThread(this, R.string.invalidage)
|
ToastUtils.showToastInUiThread(this, R.string.invalidage)
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
|
@ -76,11 +80,11 @@ class SurveyActivity : NoSplashAppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
survey_submit.setOnClickListener {
|
binding.submit.setOnClickListener {
|
||||||
val r = FirebaseRecord()
|
val r = FirebaseRecord()
|
||||||
r.id = InstanceId.instanceId()
|
r.id = InstanceId.instanceId()
|
||||||
r.age = SafeParse.stringToInt(survey_age.text.toString())
|
r.age = SafeParse.stringToInt(binding.age.text.toString())
|
||||||
r.weight = SafeParse.stringToInt(survey_weight.text.toString())
|
r.weight = SafeParse.stringToInt(binding.weight.text.toString())
|
||||||
if (r.age < 1 || r.age > 120) {
|
if (r.age < 1 || r.age > 120) {
|
||||||
ToastUtils.showToastInUiThread(this, R.string.invalidage)
|
ToastUtils.showToastInUiThread(this, R.string.invalidage)
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
|
@ -90,9 +94,9 @@ class SurveyActivity : NoSplashAppCompatActivity() {
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
if (survey_spinner.selectedItem == null)
|
if (binding.spinner.selectedItem == null)
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
val profileName = survey_spinner.selectedItem.toString()
|
val profileName = binding.spinner.selectedItem.toString()
|
||||||
val specificProfile = profileStore.getSpecificProfile(profileName)
|
val specificProfile = profileStore.getSpecificProfile(profileName)
|
||||||
|
|
||||||
r.profileJson = specificProfile.toString()
|
r.profileJson = specificProfile.toString()
|
||||||
|
@ -119,6 +123,7 @@ class SurveyActivity : NoSplashAppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class FirebaseRecord {
|
inner class FirebaseRecord {
|
||||||
|
|
||||||
var id = ""
|
var id = ""
|
||||||
var age: Int = 0
|
var age: Int = 0
|
||||||
var weight: Int = 0
|
var weight: Int = 0
|
||||||
|
|
|
@ -20,16 +20,16 @@
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/survey_id_label"
|
android:id="@+id/id_label"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:labelFor="@+id/survey_id"
|
android:labelFor="@+id/id"
|
||||||
android:text="@string/id"
|
android:text="@string/id"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/survey_id"
|
android:id="@+id/id"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
|
@ -43,16 +43,16 @@
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/survey_age_label"
|
android:id="@+id/age_label"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:labelFor="@+id/survey_age"
|
android:labelFor="@+id/age"
|
||||||
android:text="@string/age"
|
android:text="@string/age"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/survey_age"
|
android:id="@+id/age"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
|
@ -68,16 +68,16 @@
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/survey_weigth_label"
|
android:id="@+id/weigth_label"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:labelFor="@+id/survey_weight"
|
android:labelFor="@+id/weight"
|
||||||
android:text="@string/weight_label"
|
android:text="@string/weight_label"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/survey_weight"
|
android:id="@+id/weight"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
|
@ -93,16 +93,16 @@
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/survey_TDD_label"
|
android:id="@+id/TDD_label"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:labelFor="@+id/survey_weight"
|
android:labelFor="@+id/weight"
|
||||||
android:text="@string/tdd_total"
|
android:text="@string/tdd_total"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/survey_tdd"
|
android:id="@+id/tdd"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
|
@ -128,7 +128,7 @@
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/survey_spinner"
|
android:id="@+id/spinner"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
|
@ -137,34 +137,34 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/survey_tdds"
|
android:id="@+id/tdds"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/survey_tir"
|
android:id="@+id/tir"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/survey_activity"
|
android:id="@+id/activity"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/survey_submit"
|
android:id="@+id/submit"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/submit" />
|
android:text="@string/submit" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/survey_profile"
|
android:id="@+id/profile"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/profile" />
|
android:text="@string/profile" />
|
||||||
|
|
Loading…
Reference in a new issue