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