react-native-mytatva-rn-sdk 1.2.20 → 1.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/mytatvarnsdk/activity/ConnectSensorActivity.kt +300 -247
- package/android/src/main/java/com/mytatvarnsdk/activity/SearchTransmitterActivity.kt +371 -427
- package/lib/commonjs/CGMConnect.js +9 -4
- package/lib/commonjs/CGMConnect.js.map +1 -1
- package/lib/module/CGMConnect.js +9 -4
- package/lib/module/CGMConnect.js.map +1 -1
- package/package.json +1 -1
- package/src/CGMConnect.ts +18 -12
|
@@ -33,11 +33,6 @@ import cgmblelib.custom.livedata.scan.PocDeviceAndRssi
|
|
|
33
33
|
import cgmblelib.database.entity.PocDevice
|
|
34
34
|
import cgmblelib.database.entity.PocGlucose
|
|
35
35
|
import com.bumptech.glide.Glide
|
|
36
|
-
import com.facebook.react.bridge.Arguments
|
|
37
|
-
import com.facebook.react.bridge.CatalystInstance
|
|
38
|
-
import com.facebook.react.bridge.WritableMap
|
|
39
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
40
|
-
import com.mytatvarnsdk.CgmTrackyLibModule
|
|
41
36
|
import com.mytatvarnsdk.R
|
|
42
37
|
import com.mytatvarnsdk.base.BaseBleActivity
|
|
43
38
|
import com.mytatvarnsdk.databinding.ActivitySearchTransmitterBinding
|
|
@@ -60,308 +55,317 @@ import java.util.Date
|
|
|
60
55
|
import java.util.Locale
|
|
61
56
|
|
|
62
57
|
class SearchTransmitterActivity : BaseBleActivity() {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
58
|
+
private lateinit var binding: ActivitySearchTransmitterBinding
|
|
59
|
+
private val handler = Handler(Looper.getMainLooper())
|
|
60
|
+
private var isSearching = true
|
|
61
|
+
private var isTransmitterConnected = false
|
|
62
|
+
private var transmitterDeviceInfo: PocDeviceAndRssi? = null
|
|
63
|
+
private lateinit var mModel: MainActivityModel
|
|
64
|
+
lateinit var authenticateSDKService: AuthenticateSDKService
|
|
65
|
+
private val job = Job()
|
|
66
|
+
private val scope = CoroutineScope(Dispatchers.IO + job)
|
|
67
|
+
private var isForReconnect: Boolean = false
|
|
68
|
+
|
|
69
|
+
override fun init() {
|
|
74
70
|
|
|
75
|
-
|
|
71
|
+
}
|
|
76
72
|
|
|
77
|
-
}
|
|
78
73
|
|
|
74
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
|
75
|
+
super.onCreate(savedInstanceState)
|
|
76
|
+
binding = ActivitySearchTransmitterBinding.inflate(layoutInflater)
|
|
77
|
+
enableEdgeToEdge()
|
|
78
|
+
setContentView(binding.root)
|
|
79
|
+
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
|
|
80
|
+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
|
81
|
+
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
|
82
|
+
insets
|
|
83
|
+
}
|
|
79
84
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
enableEdgeToEdge()
|
|
84
|
-
setContentView(binding.root)
|
|
85
|
-
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
|
|
86
|
-
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
|
87
|
-
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
|
|
88
|
-
insets
|
|
85
|
+
setupClickListeners()
|
|
86
|
+
setupInitialState()
|
|
87
|
+
startDeviceSearch()
|
|
89
88
|
}
|
|
90
89
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
90
|
+
override fun getPermission(): Array<out Array<out String?>?>? {
|
|
91
|
+
return arrayOfNulls<Array<String?>>(0)
|
|
92
|
+
}
|
|
95
93
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
94
|
+
override fun onPermissionRequestSuccess() {
|
|
95
|
+
}
|
|
99
96
|
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
override fun onPermissionRequestFail(vararg permission: String?) {
|
|
98
|
+
}
|
|
102
99
|
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
override fun onPermissionRequestFailForever(vararg permission: String?) {
|
|
101
|
+
}
|
|
105
102
|
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
private fun setupInitialState() {
|
|
104
|
+
isForReconnect = intent.getBooleanExtra("IsForReconnect", false)
|
|
108
105
|
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
// Set initial states
|
|
107
|
+
binding.searchingLayout.visibility = View.VISIBLE
|
|
108
|
+
binding.connectedLayout.visibility = View.GONE
|
|
111
109
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
binding.connectedLayout.visibility = View.GONE
|
|
110
|
+
binding.commonButton.btnProceed.isEnabled = false
|
|
111
|
+
binding.commonButton.btnProceed.alpha = 0.5f
|
|
115
112
|
|
|
116
|
-
|
|
117
|
-
|
|
113
|
+
Glide.with(this)
|
|
114
|
+
.asGif()
|
|
115
|
+
.load(R.drawable.success_anim)
|
|
116
|
+
.into(binding.ivSuccess)
|
|
117
|
+
}
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
fun manageErrorState(showError: Boolean, errorStatus: String) {
|
|
120
|
+
if (showError) {
|
|
121
|
+
binding.clFail.visibility = View.VISIBLE
|
|
122
|
+
binding.clMain.visibility = View.GONE
|
|
123
|
+
binding.commonButton.root.visibility = View.GONE
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
binding.commonButton.root.visibility = View.GONE
|
|
125
|
+
Glide.with(this)
|
|
126
|
+
.asGif()
|
|
127
|
+
.load(R.drawable.warning)
|
|
128
|
+
.into(binding.ivGif)
|
|
130
129
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
.load(R.drawable.warning)
|
|
134
|
-
.into(binding.ivGif)
|
|
130
|
+
binding.btnSupport.tvProceed.text = "Contact Support"
|
|
131
|
+
binding.btnRetry.tvProceed.text = "Retry"
|
|
135
132
|
|
|
136
|
-
|
|
137
|
-
binding.btnRetry.tvProceed.text = "Retry"
|
|
133
|
+
binding.btnWatchDemo.setOnClickListener {
|
|
138
134
|
|
|
139
|
-
|
|
135
|
+
}
|
|
140
136
|
|
|
141
|
-
|
|
137
|
+
binding.btnSupport.btnProceed.setOnClickListener {
|
|
138
|
+
startActivity(Intent(this, HelpActivity::class.java))
|
|
139
|
+
}
|
|
142
140
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
binding.btnRetry.btnProceed.setOnClickListener {
|
|
142
|
+
val intent = intent
|
|
143
|
+
finish()
|
|
144
|
+
startActivity(intent)
|
|
145
|
+
}
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
startActivity(Intent(this, HelpActivity::class.java))
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
binding.toolbar.btnClose.setOnClickListener {
|
|
344
|
-
openExitDialog()
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// Watch Demo button
|
|
348
|
-
binding.toolbar.btnWatchDemo.setOnClickListener {
|
|
349
|
-
// Implement demo video functionality
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// Connect button (visible when device is detected)
|
|
353
|
-
binding.btnConnect.setOnClickListener {
|
|
354
|
-
connectToTransmitter()
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
val callback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
|
|
358
|
-
override fun handleOnBackPressed() {
|
|
359
|
-
openExitDialog()
|
|
360
|
-
}
|
|
147
|
+
if (errorStatus.isNotEmpty()) {
|
|
148
|
+
binding.tvReason.visibility = View.VISIBLE
|
|
149
|
+
binding.tvReason.text = "Reason - ${errorStatus}"
|
|
150
|
+
} else {
|
|
151
|
+
binding.tvReason.visibility = View.GONE
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
binding.commonButton.root.visibility = View.VISIBLE
|
|
155
|
+
binding.clFail.visibility = View.GONE
|
|
156
|
+
binding.clMain.visibility = View.VISIBLE
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private fun openExitDialog() {
|
|
161
|
+
val binding = ExitDialogBottomsheetBinding.inflate(layoutInflater)
|
|
162
|
+
|
|
163
|
+
val dialog = Dialog(this)
|
|
164
|
+
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
|
|
165
|
+
dialog.setContentView(binding.root)
|
|
166
|
+
|
|
167
|
+
val window = dialog.window
|
|
168
|
+
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
|
169
|
+
window?.setGravity(Gravity.BOTTOM)
|
|
170
|
+
window?.setBackgroundDrawable(Color.TRANSPARENT.toDrawable())
|
|
171
|
+
|
|
172
|
+
binding.btnExit.tvProceed.text = "Exit"
|
|
173
|
+
|
|
174
|
+
binding.btnExit.root.setOnClickListener(View.OnClickListener { v: View? ->
|
|
175
|
+
finish()
|
|
176
|
+
dialog.dismiss()
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
binding.btnCancel.root.setOnClickListener(View.OnClickListener { v: View? ->
|
|
180
|
+
dialog.dismiss()
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
binding.closeButton.setOnClickListener(View.OnClickListener { v: View? ->
|
|
184
|
+
dialog.dismiss()
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
dialog.show()
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
public override fun scanStart() {
|
|
192
|
+
if (mPocDevice != null && mPocDevice.isBound) {
|
|
193
|
+
ProgressManagement.getInstance().showWait(this, ProgressType.PROGRESSDIALOG_SCAN, null)
|
|
194
|
+
}
|
|
195
|
+
manageErrorState(false, "")
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
public override fun scanIn(device: PocDeviceAndRssi) {
|
|
200
|
+
transmitterDeviceInfo = device
|
|
201
|
+
if (isSearching) {
|
|
202
|
+
deviceDetected(device)
|
|
203
|
+
}
|
|
204
|
+
manageErrorState(false, "")
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public override fun scanEnd() {
|
|
208
|
+
if (transmitterDeviceInfo != null && !binding.tvReason.isVisible) {
|
|
209
|
+
manageErrorState(false, "")
|
|
210
|
+
} else {
|
|
211
|
+
manageErrorState(true, "")
|
|
212
|
+
}
|
|
213
|
+
Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> scanEnd")
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
override fun bluetoothStateOFF() {
|
|
217
|
+
super.bluetoothStateOFF()
|
|
218
|
+
manageErrorState(true, "Bluetooth Off")
|
|
219
|
+
Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> bluetoothStateOFF")
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
override fun failGPS() {
|
|
223
|
+
super.failGPS()
|
|
224
|
+
manageErrorState(true, "GPS Off")
|
|
225
|
+
Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> failGPS")
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
override fun failLocal() {
|
|
229
|
+
super.failLocal()
|
|
230
|
+
manageErrorState(true, "Something went wrong")
|
|
231
|
+
Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> failLocal")
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
public override fun bindFail() {
|
|
235
|
+
ProgressManagement.getInstance().dismissWait(this)
|
|
236
|
+
manageErrorState(true, "Bind Failure")
|
|
237
|
+
Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> bindFail")
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public override fun bindSuccess() {
|
|
241
|
+
ProgressManagement.getInstance().dismissWait(this)
|
|
242
|
+
|
|
243
|
+
binding.tvTransName.text = "Sno: ${transmitterDeviceInfo!!.pocDevice.name}"
|
|
244
|
+
val formatter = SimpleDateFormat("hh:mm a", Locale.getDefault())
|
|
245
|
+
binding.tvDateTime.text = "Connected on ${formatter.format(Date()).uppercase()}"
|
|
246
|
+
binding.clSuccess.visibility = View.VISIBLE
|
|
247
|
+
binding.clMain.visibility = View.GONE
|
|
248
|
+
binding.commonButton.btnProceed.isEnabled = true
|
|
249
|
+
binding.commonButton.btnProceed.alpha = 1.0f
|
|
250
|
+
binding.view2.background = ContextCompat.getDrawable(this, R.drawable.bg_green_progress)
|
|
251
|
+
binding.tvDivide2.setTextColor("#299D6B".toColorInt())
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
fun mapToDto(glucose: PocGlucose): GlucoseLog {
|
|
255
|
+
val dto: GlucoseLog = GlucoseLog()
|
|
256
|
+
dto.timeInMillis = glucose.getTimeInMillis()
|
|
257
|
+
dto.countdownMinutes = glucose.getCountdownMinutes()
|
|
258
|
+
dto.countdownHours = glucose.getCountdownHours()
|
|
259
|
+
dto.countdownDays = glucose.getCountdownDays()
|
|
260
|
+
dto.hypoglycemiaEarlyWarnMinutes = glucose.getHypoglycemiaEarlyWarnMinutes()
|
|
261
|
+
dto.showGlucoseMG = glucose.getShowGlucoseMG()
|
|
262
|
+
dto.glucoseId = glucose.getGlucoseId()
|
|
263
|
+
dto.name = glucose.getName()
|
|
264
|
+
dto.showGlucose = glucose.getShowGlucose()
|
|
265
|
+
dto.Ib = glucose.getIb()
|
|
266
|
+
dto.Iw = glucose.getIw()
|
|
267
|
+
dto.T = glucose.getT()
|
|
268
|
+
dto.year = glucose.getYear()
|
|
269
|
+
dto.month = glucose.getMonth()
|
|
270
|
+
dto.day = glucose.getDay()
|
|
271
|
+
dto.hour = glucose.getHour()
|
|
272
|
+
dto.minute = glucose.getMinute()
|
|
273
|
+
|
|
274
|
+
// Convert byte[] to List<Integer>
|
|
275
|
+
dto.bytes = ArrayList()
|
|
276
|
+
for (b in glucose.getBytes()) {
|
|
277
|
+
dto.bytes?.add(b.toInt() and 0xFF) // Prevent negative values
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Trend
|
|
281
|
+
val trendObj: TrendObject = TrendObject()
|
|
282
|
+
trendObj.trendId = glucose.getTrend().getTrendId()
|
|
283
|
+
trendObj.drawableId = glucose.getTrend().getDrawableId()
|
|
284
|
+
trendObj.widgetImg = glucose.getTrend().getWidgetImg()
|
|
285
|
+
trendObj.apsChangeRate = glucose.getTrend().getApsChangeRate()
|
|
286
|
+
dto.trendObject = trendObj
|
|
287
|
+
|
|
288
|
+
// Status
|
|
289
|
+
val statusObj: GlucoseStatusObject = GlucoseStatusObject()
|
|
290
|
+
statusObj.statusId = glucose.getGlucoseStatus().getStatusId()
|
|
291
|
+
dto.glucoseStatusObject = statusObj
|
|
292
|
+
|
|
293
|
+
// Error
|
|
294
|
+
val errorObj: ErrorObject = ErrorObject()
|
|
295
|
+
errorObj.errorId = glucose.getErrorCode().getErrorId()
|
|
296
|
+
errorObj.sound = glucose.getErrorCode().getSound().toString()
|
|
297
|
+
dto.errorObject = errorObj
|
|
298
|
+
|
|
299
|
+
return dto
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
public override fun disconnect() {
|
|
304
|
+
ProgressManagement.getInstance().dismissWait(this)
|
|
305
|
+
showShortToast(R.string.bt_connect_fail)
|
|
306
|
+
manageErrorState(true, "Disconnected")
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
public override fun disconnectForTimeout() {
|
|
310
|
+
ProgressManagement.getInstance().dismissWait(this)
|
|
311
|
+
manageErrorState(true, "Disconnected")
|
|
312
|
+
Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> disconnectForTimeout")
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
public override fun checkFailForLowPower() {
|
|
316
|
+
ProgressManagement.getInstance().dismissWait(this)
|
|
317
|
+
WarnDialogUtils.getInstance().showWarnDialog(this, DialogType.TYPE_LOW_POWER)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
public override fun checkFailErrorTemperature() {
|
|
321
|
+
ProgressManagement.getInstance().dismissWait(this)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
public override fun onlineLost() {
|
|
325
|
+
showShortToast(R.string.online_lost)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
private fun bind(device: PocDevice) {
|
|
330
|
+
try {
|
|
331
|
+
if (device.address != null) {
|
|
332
|
+
ManageGattCallback.getInstance().ConnectViaAddress(device.address)
|
|
333
|
+
ManageScanCallback.getInstance().stopLeScan()
|
|
334
|
+
ProgressManagement.getInstance()
|
|
335
|
+
.showWait(this, ProgressType.PROGRESSDIALOG_CONNECT, null)
|
|
336
|
+
}
|
|
337
|
+
} catch (e: Exception) {
|
|
338
|
+
Log.d("bind::-> ", "bind: ${e.message}")
|
|
339
|
+
}
|
|
361
340
|
}
|
|
362
|
-
onBackPressedDispatcher.addCallback(this, callback)
|
|
363
341
|
|
|
364
|
-
|
|
342
|
+
private fun setupClickListeners() {
|
|
343
|
+
binding.toolbar.btnWhatsapp.setOnClickListener {
|
|
344
|
+
startActivity(Intent(this, HelpActivity::class.java))
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
binding.toolbar.btnClose.setOnClickListener {
|
|
348
|
+
openExitDialog()
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Watch Demo button
|
|
352
|
+
binding.toolbar.btnWatchDemo.setOnClickListener {
|
|
353
|
+
// Implement demo video functionality
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// Connect button (visible when device is detected)
|
|
357
|
+
binding.btnConnect.setOnClickListener {
|
|
358
|
+
connectToTransmitter()
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
val callback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
|
|
362
|
+
override fun handleOnBackPressed() {
|
|
363
|
+
openExitDialog()
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
onBackPressedDispatcher.addCallback(this, callback)
|
|
367
|
+
|
|
368
|
+
binding.commonButton.btnProceed.setOnClickListener {
|
|
365
369
|
// CoroutineScope(Dispatchers.IO).launch {
|
|
366
370
|
// // This block runs in IO thread
|
|
367
371
|
// val result = mModel.glucoseByTime
|
|
@@ -441,180 +445,120 @@ class SearchTransmitterActivity : BaseBleActivity() {
|
|
|
441
445
|
// }
|
|
442
446
|
// }
|
|
443
447
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
448
|
+
if (isTransmitterConnected) {
|
|
449
|
+
proceedToNextStep()
|
|
450
|
+
}
|
|
451
|
+
}
|
|
447
452
|
}
|
|
448
|
-
}
|
|
449
453
|
|
|
450
454
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
455
|
+
fun logLongJson(tag: String, message: String) {
|
|
456
|
+
val maxLogSize = 4000
|
|
457
|
+
for (i in 0..message.length / maxLogSize) {
|
|
458
|
+
val start = i * maxLogSize
|
|
459
|
+
val end = (i + 1) * maxLogSize
|
|
460
|
+
if (start < message.length) {
|
|
461
|
+
Log.d(tag, message.substring(start, minOf(end, message.length)))
|
|
462
|
+
}
|
|
463
|
+
}
|
|
459
464
|
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
private fun startDeviceSearch() {
|
|
463
|
-
mModel = ViewModelProviders.of(this)[MainActivityModel::class.java]
|
|
464
|
-
|
|
465
|
-
ReconnectManagement.getInstance()
|
|
466
|
-
.reconnect(ReconnectManagement.ReconnectState.STATE_SCAN_AGAIN)
|
|
467
|
-
|
|
468
|
-
authenticateSDKService = AuthenticateSDKService(scope = scope)
|
|
469
|
-
|
|
470
|
-
isSearching = true
|
|
471
|
-
isTransmitterConnected = false
|
|
472
465
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
binding.connectedLayout.visibility = View.GONE
|
|
466
|
+
private fun startDeviceSearch() {
|
|
467
|
+
mModel = ViewModelProviders.of(this)[MainActivityModel::class.java]
|
|
476
468
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
.load(R.drawable.searching)
|
|
480
|
-
.into(binding.progressSearch)
|
|
469
|
+
ReconnectManagement.getInstance()
|
|
470
|
+
.reconnect(ReconnectManagement.ReconnectState.STATE_SCAN_AGAIN)
|
|
481
471
|
|
|
482
|
-
|
|
483
|
-
binding.commonButton.btnProceed.alpha = 0.5f
|
|
484
|
-
}
|
|
472
|
+
authenticateSDKService = AuthenticateSDKService(scope = scope)
|
|
485
473
|
|
|
486
|
-
|
|
487
|
-
|
|
474
|
+
isSearching = true
|
|
475
|
+
isTransmitterConnected = false
|
|
488
476
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
fadeOut.setAnimationListener(object : Animation.AnimationListener {
|
|
493
|
-
override fun onAnimationStart(animation: Animation?) {}
|
|
477
|
+
// Show searching state
|
|
478
|
+
binding.searchingLayout.visibility = View.VISIBLE
|
|
479
|
+
binding.connectedLayout.visibility = View.GONE
|
|
494
480
|
|
|
495
|
-
|
|
496
|
-
|
|
481
|
+
Glide.with(this)
|
|
482
|
+
.asGif()
|
|
483
|
+
.load(R.drawable.searching)
|
|
484
|
+
.into(binding.progressSearch)
|
|
497
485
|
|
|
498
|
-
|
|
499
|
-
binding.
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
// Fade in the connected layout
|
|
503
|
-
val fadeIn = AlphaAnimation(0.0f, 1.0f)
|
|
504
|
-
fadeIn.duration = 300
|
|
505
|
-
binding.connectedLayout.startAnimation(fadeIn)
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
override fun onAnimationRepeat(animation: Animation?) {}
|
|
509
|
-
})
|
|
510
|
-
|
|
511
|
-
binding.searchingLayout.startAnimation(fadeOut)
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
private fun connectToTransmitter() {
|
|
515
|
-
isTransmitterConnected = true
|
|
486
|
+
binding.commonButton.btnProceed.isEnabled = false
|
|
487
|
+
binding.commonButton.btnProceed.alpha = 0.5f
|
|
488
|
+
}
|
|
516
489
|
|
|
490
|
+
private fun deviceDetected(device: PocDeviceAndRssi) {
|
|
491
|
+
isSearching = false
|
|
517
492
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
493
|
+
// Animate the transition
|
|
494
|
+
val fadeOut = AlphaAnimation(1.0f, 0.0f)
|
|
495
|
+
fadeOut.duration = 300
|
|
496
|
+
fadeOut.setAnimationListener(object : Animation.AnimationListener {
|
|
497
|
+
override fun onAnimationStart(animation: Animation?) {}
|
|
522
498
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
Log.d("onDeviceConnect--->", "isAbleScanQRCode")
|
|
526
|
-
} else {
|
|
527
|
-
bind(transmitterDeviceInfo!!.pocDevice)
|
|
528
|
-
}
|
|
499
|
+
override fun onAnimationEnd(animation: Animation?) {
|
|
500
|
+
binding.searchingLayout.visibility = View.GONE
|
|
529
501
|
|
|
530
|
-
|
|
502
|
+
// Show the connected layout
|
|
503
|
+
binding.connectedLayout.visibility = View.VISIBLE
|
|
504
|
+
binding.tvSerialNumber.text = device.pocDevice.name
|
|
531
505
|
|
|
532
|
-
|
|
506
|
+
// Fade in the connected layout
|
|
507
|
+
val fadeIn = AlphaAnimation(0.0f, 1.0f)
|
|
508
|
+
fadeIn.duration = 300
|
|
509
|
+
binding.connectedLayout.startAnimation(fadeIn)
|
|
510
|
+
}
|
|
533
511
|
|
|
534
|
-
|
|
512
|
+
override fun onAnimationRepeat(animation: Animation?) {}
|
|
513
|
+
})
|
|
535
514
|
|
|
536
|
-
|
|
537
|
-
binding.clMain.visibility = View.GONE
|
|
538
|
-
binding.commonButton.btnProceed.isEnabled = true
|
|
539
|
-
binding.commonButton.btnProceed.alpha = 1.0f
|
|
540
|
-
binding.view2.background = ContextCompat.getDrawable(this, R.drawable.bg_green_progress)
|
|
541
|
-
binding.tvDivide2.setTextColor("#299D6B".toColorInt())
|
|
515
|
+
binding.searchingLayout.startAnimation(fadeOut)
|
|
542
516
|
}
|
|
543
|
-
}
|
|
544
517
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
sendDataToRN("")
|
|
548
|
-
finish()
|
|
549
|
-
} else {
|
|
550
|
-
val intent = Intent(this, ConnectSensorActivity::class.java)
|
|
551
|
-
intent.putExtra("transmitterDeviceInfo", transmitterDeviceInfo) // Serializable
|
|
552
|
-
startActivity(intent)
|
|
553
|
-
finish()
|
|
554
|
-
// transmitterDeviceInfo?.let {
|
|
555
|
-
// QRActivity.startQR(
|
|
556
|
-
// this@SearchTransmitterActivity,
|
|
557
|
-
// it.pocDevice
|
|
558
|
-
// )
|
|
559
|
-
// }
|
|
560
|
-
}
|
|
561
|
-
}
|
|
518
|
+
private fun connectToTransmitter() {
|
|
519
|
+
isTransmitterConnected = true
|
|
562
520
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
val module = catalystInstance.getNativeModule(CgmTrackyLibModule::class.java)
|
|
521
|
+
if (transmitterDeviceInfo != null) {
|
|
522
|
+
if (isForReconnect) {
|
|
523
|
+
GattTool.unBindInDatabase(this, enumUnBind.UNBIND_FORCE)
|
|
524
|
+
}
|
|
568
525
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
526
|
+
Log.d("onDeviceConnect--->", "onDeviceConnect: " + transmitterDeviceInfo.toString())
|
|
527
|
+
if (enumDevice.getEnumDevice(transmitterDeviceInfo!!.pocDevice.name).isAbleScanQRCode) {
|
|
528
|
+
proceedToNextStep()
|
|
529
|
+
} else {
|
|
530
|
+
bind(transmitterDeviceInfo!!.pocDevice)
|
|
531
|
+
}
|
|
575
532
|
}
|
|
576
|
-
} catch (e: Exception) {
|
|
577
|
-
Log.e("sendDataToRN: Error ", e.message.toString())
|
|
578
|
-
}
|
|
579
|
-
} else {
|
|
580
|
-
Log.e("TrackyActivity", "ReactApplicationContext is null")
|
|
581
533
|
}
|
|
582
|
-
}
|
|
583
|
-
|
|
584
534
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
reactContext?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
593
|
-
?.emit("cgmDeviceEvent", map)
|
|
594
|
-
} catch (e: Exception) {
|
|
595
|
-
Log.e("sendDataToRNDirectly", "Error sending data to React", e)
|
|
535
|
+
private fun proceedToNextStep() {
|
|
536
|
+
val intent = Intent(this, ConnectSensorActivity::class.java)
|
|
537
|
+
intent.putExtra("transmitterDeviceInfo", transmitterDeviceInfo)
|
|
538
|
+
intent.putExtra("IsForReconnect", isForReconnect)
|
|
539
|
+
startActivity(intent)
|
|
540
|
+
finish()
|
|
596
541
|
}
|
|
597
|
-
}
|
|
598
542
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
543
|
+
override fun onDestroy() {
|
|
544
|
+
super.onDestroy()
|
|
545
|
+
handler.removeCallbacksAndMessages(null)
|
|
546
|
+
}
|
|
603
547
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
548
|
+
override fun onResume() {
|
|
549
|
+
super.onResume()
|
|
550
|
+
BleService.startService(this)
|
|
551
|
+
}
|
|
608
552
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
553
|
+
override fun setView(): Int {
|
|
554
|
+
return R.layout.activity_search_transmitter
|
|
555
|
+
}
|
|
612
556
|
|
|
613
|
-
|
|
614
|
-
|
|
557
|
+
override fun initViews() {
|
|
558
|
+
}
|
|
615
559
|
|
|
616
|
-
|
|
617
|
-
|
|
560
|
+
override fun onClick(p0: View?) {
|
|
561
|
+
}
|
|
618
562
|
|
|
619
563
|
|
|
620
564
|
}
|