1 package com.android.healthconnect.testapps.toolbox.ui
2 
3 import android.content.Context
4 import android.widget.CheckBox
5 import android.widget.EditText
6 import android.widget.LinearLayout
7 import com.android.healthconnect.testapps.toolbox.R
8 
9 class PerformanceTestingLinearLayout(context: Context) : LinearLayout(context) {
10 
11     private var spanOverTime: Boolean = false
12     private var numberOfMinutes: EditText
13 
14     init {
15         inflate(context, R.layout.fragment_performance_testing_dialog, this)
16         val checkbox = findViewById<CheckBox>(R.id.checkbox_insert_without_spanning)
17         numberOfMinutes = findViewById(R.id.number_of_minutes)
<lambda>null18         checkbox.setOnClickListener {
19             val isChecked = (it as CheckBox).isChecked
20             spanOverTime = isChecked
21             if (isChecked) {
22                 numberOfMinutes.visibility = VISIBLE
23             } else {
24                 numberOfMinutes.visibility = GONE
25             }
26         }
27     }
28 
getPerformanceDatanull29     fun getPerformanceData(): PerformanceData {
30         val numberOfRecordsPerBatch = getNumberOfRecordsPerBatch()
31         val numberOfMinutes = getNumberOfMinutes()
32         val numberOfBatches = getNumberOfBatches()
33         var isDataValid = true
34         if (numberOfBatches == -1L || numberOfMinutes == -1L || numberOfRecordsPerBatch == -1L) {
35             isDataValid = false
36         }
37         return PerformanceData(
38             spanOverTime,
39             getNumberOfMinutes(),
40             getNumberOfBatches(),
41             getNumberOfRecordsPerBatch(),
42             isDataValid)
43     }
44 
getNumberOfMinutesnull45     private fun getNumberOfMinutes(): Long {
46         if (spanOverTime) {
47             return returnIntIfNotEmpty(numberOfMinutes.text.toString())
48         }
49         return 0L
50     }
51 
getNumberOfBatchesnull52     private fun getNumberOfBatches(): Long {
53         return returnIntIfNotEmpty(findViewById<EditText>(R.id.number_of_batches).text.toString())
54     }
55 
getNumberOfRecordsPerBatchnull56     private fun getNumberOfRecordsPerBatch(): Long {
57         return returnIntIfNotEmpty(findViewById<EditText>(R.id.batch_size).text.toString())
58     }
59 
returnIntIfNotEmptynull60     private fun returnIntIfNotEmpty(dataString: String): Long {
61         if (dataString.isEmpty()) {
62             return -1L
63         }
64         return dataString.toLong()
65     }
66 }
67 
68 data class PerformanceData(
69     val spanOverTime: Boolean,
70     val numberOfMinutes: Long,
71     val numberOfBatches: Long,
72     val numberOfRecordsPerBatch: Long,
73     val isDataValid: Boolean,
74 )
75