@rentlydev/rently-tuya 0.1.0 → 0.1.2

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.
@@ -16,9 +16,14 @@ import com.rentlytuya.util.Util.strings
16
16
 
17
17
  @Composable
18
18
  fun FormatSDCardAlert(
19
+ id: String = "FormatSDCard",
20
+ title: String,
21
+ description: String,
22
+ confirmButtonText: String,
23
+ dismissButtonText: String,
19
24
  isFormatSDCardVisible: Boolean,
20
25
  onDismiss: () -> Unit,
21
- onFormat: () -> Unit
26
+ onConfirm: () -> Unit
22
27
  ) {
23
28
 
24
29
  Alert(
@@ -31,7 +36,7 @@ fun FormatSDCardAlert(
31
36
  Label(
32
37
  modifier = Modifier
33
38
  .padding(bottom = 5.dp),
34
- title = strings(id = R.string.formatSDCard),
39
+ title = title,
35
40
  bold = true,
36
41
  xl20 = true,
37
42
  black = true
@@ -40,7 +45,7 @@ fun FormatSDCardAlert(
40
45
  Label(
41
46
  modifier = Modifier
42
47
  .padding(vertical = 5.dp),
43
- title = strings(id = R.string.formatSDCardDescription),
48
+ title = description,
44
49
  medium = true,
45
50
  l = true,
46
51
  black = true,
@@ -56,8 +61,8 @@ fun FormatSDCardAlert(
56
61
  ) {
57
62
  AnchorButton(
58
63
  modifier = Modifier,
59
- id = "FormatSDCard_No",
60
- title = strings(id = R.string.no),
64
+ id = "${id}_${dismissButtonText}",
65
+ title = dismissButtonText,
61
66
  semiBold = true,
62
67
  black = true,
63
68
  m = true,
@@ -68,13 +73,13 @@ fun FormatSDCardAlert(
68
73
 
69
74
  AnchorButton(
70
75
  modifier = Modifier,
71
- id = "FormatSDCard_Yes",
72
- title = strings(id = R.string.yes),
76
+ id = "${id}_${confirmButtonText}",
77
+ title = confirmButtonText,
73
78
  semiBold = true,
74
79
  black = true,
75
80
  m = true,
76
81
  onClick = {
77
- onFormat()
82
+ onConfirm()
78
83
  }
79
84
  )
80
85
  }
@@ -123,9 +123,13 @@ fun StorageSettings(
123
123
  }
124
124
 
125
125
  FormatSDCardAlert(
126
+ title = strings(id = R.string.formatSDCard),
127
+ description = strings(id = R.string.formatSDCardDescription),
128
+ confirmButtonText = strings(id = R.string.yes),
129
+ dismissButtonText = strings(id = R.string.no),
126
130
  isFormatSDCardVisible = isFormatSDCardVisible.value,
127
131
  onDismiss = { isFormatSDCardVisible.value = false },
128
- onFormat = {
132
+ onConfirm = {
129
133
  isFormatSDCardVisible.value = false
130
134
  Settings.formatSDCard(
131
135
  isLoading = isLoading
@@ -36,6 +36,7 @@ import androidx.navigation.compose.NavHost
36
36
  import androidx.navigation.compose.composable
37
37
  import com.facebook.react.ReactApplication
38
38
  import com.rentlytuya.R
39
+ import com.rentlytuya.alerts.FormatSDCardAlert
39
40
  import com.rentlytuya.components.Label
40
41
  import com.rentlytuya.components.LoadingIndicator
41
42
  import com.rentlytuya.tuya.DefaultSettings
@@ -46,6 +47,7 @@ import com.rentlytuya.tuya.Tuya.TAG
46
47
  import com.rentlytuya.tuya.Tuya.isDefaultSettingsUpdated
47
48
  import com.rentlytuya.tuya.Tuya.isResident
48
49
  import com.rentlytuya.ui.theme.LocalColor
50
+ import com.rentlytuya.util.DPConstants
49
51
  import com.rentlytuya.util.DateUtil.isNotNull
50
52
  import com.rentlytuya.util.Heap
51
53
  import com.rentlytuya.util.Util.strings
@@ -95,6 +97,10 @@ fun NavController(
95
97
  val usedStorage = remember { mutableStateOf("0.0") }
96
98
  val remainingStorageCapacity = remember { mutableStateOf("0.0") }
97
99
 
100
+ // Format SD Card
101
+ val isFormatSDCardVisible = remember { mutableStateOf(false) }
102
+ val formatAttempts = remember { mutableIntStateOf(0) }
103
+
98
104
  val configuration = LocalConfiguration.current
99
105
 
100
106
  LaunchedEffect(Unit) {
@@ -177,7 +183,8 @@ fun NavController(
177
183
  batteryPercentage = batteryPercentage,
178
184
  totalStorageCapacity = totalStorageCapacity,
179
185
  usedStorage = usedStorage,
180
- remainingStorageCapacity = remainingStorageCapacity
186
+ remainingStorageCapacity = remainingStorageCapacity,
187
+ isFormatSDCardVisible = isFormatSDCardVisible
181
188
  )
182
189
  }
183
190
 
@@ -190,8 +197,42 @@ fun NavController(
190
197
  ) {
191
198
  composable("Dashboard") {
192
199
  if (isLoading.value) {
193
- LoadingIndicator(title = strings(id = R.string.closingConnection))
200
+ val loadingTitle = if (isFormatSDCardVisible.value) "Loading…" else strings(id = R.string.closingConnection)
201
+ LoadingIndicator(title = loadingTitle)
202
+ }
203
+
204
+ val (messageMain, messageNote) = when (formatAttempts.intValue) {
205
+ 0 -> R.string.sdCardStatusAbnormalMain to R.string.sdCardStatusAbnormalNote
206
+ 1 -> R.string.sdCardReformatFailedMain to null
207
+ else -> R.string.sdCardReformatFailedMain to R.string.sdCardReformatFailedNote
208
+ }
209
+
210
+ val confirmButtonText = if (formatAttempts.intValue == 0) {
211
+ strings(id = R.string.format)
212
+ } else {
213
+ strings(id = R.string.retryFormatting)
194
214
  }
215
+
216
+ FormatSDCardAlert(
217
+ id = "FormatSDCard_Abnormal",
218
+ isFormatSDCardVisible = isFormatSDCardVisible.value,
219
+ title = strings(id = R.string.doorbellSDCard),
220
+ description = strings(id = messageMain)
221
+ .plus(messageNote?.let { "\n\n${strings(id = it)}" } ?: ""),
222
+ confirmButtonText = confirmButtonText,
223
+ dismissButtonText = strings(id = R.string.cancel),
224
+ onDismiss = { isFormatSDCardVisible.value = false },
225
+ onConfirm = {
226
+ isFormatSDCardVisible.value = false
227
+ Settings.formatSDCard(
228
+ isLoading = isLoading,
229
+ onFailure = {
230
+ formatAttempts.intValue += 1
231
+ }
232
+ )
233
+ }
234
+ )
235
+
195
236
  Heap.trackEvent(eventName = "Dashboard Screen")
196
237
  Dashboard(
197
238
  modifier = Modifier.weight(if (!isSettings.value) 0.7f else 1f),
@@ -98,7 +98,8 @@ object Settings {
98
98
  batteryPercentage: MutableState<Int>,
99
99
  totalStorageCapacity: MutableState<String>,
100
100
  usedStorage: MutableState<String>,
101
- remainingStorageCapacity: MutableState<String>
101
+ remainingStorageCapacity: MutableState<String>,
102
+ isFormatSDCardVisible: MutableState<Boolean>
102
103
  ) {
103
104
  val deviceBean = ThingHomeSdk.getDataInstance().getDeviceBean(deviceId)
104
105
  if (deviceBean.isNotNull()) {
@@ -212,7 +213,8 @@ object Settings {
212
213
  batteryPercentage = batteryPercentage,
213
214
  totalStorageCapacity = totalStorageCapacity,
214
215
  usedStorage = usedStorage,
215
- remainingStorageCapacity = remainingStorageCapacity
216
+ remainingStorageCapacity = remainingStorageCapacity,
217
+ isFormatSDCardVisible = isFormatSDCardVisible
216
218
  )
217
219
  }
218
220
 
@@ -480,7 +482,9 @@ object Settings {
480
482
  }
481
483
 
482
484
  fun formatSDCard(
483
- isLoading: MutableState<Boolean>? = null
485
+ isLoading: MutableState<Boolean>? = null,
486
+ onSuccess: (() -> Unit)? = null,
487
+ onFailure: (() -> Unit)? = null,
484
488
  ) {
485
489
  isLoading?.value = true
486
490
  publishDps(
@@ -488,10 +492,12 @@ object Settings {
488
492
  value = true,
489
493
  onSuccess = {
490
494
  isLoading?.value = false
495
+ onSuccess?.invoke()
491
496
  Log.i(TAG, "SD Card Format started")
492
497
  },
493
498
  onError = { code, error ->
494
499
  isLoading?.value = false
500
+ onFailure?.invoke()
495
501
  Log.i(TAG, "Error in SD Card Format: Error Code: $code, Error: $error")
496
502
  }
497
503
  )
@@ -579,7 +585,8 @@ object Settings {
579
585
  batteryPercentage: MutableState<Int>,
580
586
  totalStorageCapacity: MutableState<String>,
581
587
  usedStorage: MutableState<String>,
582
- remainingStorageCapacity: MutableState<String>
588
+ remainingStorageCapacity: MutableState<String>,
589
+ isFormatSDCardVisible: MutableState<Boolean>
583
590
  ) {
584
591
  ThingHomeSdk.newDeviceInstance(deviceId).registerDevListener(object : IDevListener {
585
592
  override fun onDpUpdate(devId: String, dpStr: String) {
@@ -628,6 +635,9 @@ object Settings {
628
635
 
629
636
  DPConstants.SD_STATUS -> {
630
637
  storageFunctionType.value = obj.getInt(key)
638
+ if (storageFunctionType.value == 2) {
639
+ isFormatSDCardVisible.value = true
640
+ }
631
641
  }
632
642
 
633
643
  DPConstants.SD_RECORD_SWITCH -> {
@@ -113,6 +113,14 @@
113
113
  <string name="noMessages">No messages available at the moment.</string>
114
114
  <string name="unableToCaptureDetectedEvents">Unable to capture detected events because the doorbell\'s battery is too low. Please charge it to ensure events are detected and recorded.</string>
115
115
 
116
+ <!-- SD Card format -->
117
+ <string name="doorbellSDCard">Doorbell SD Card</string>
118
+ <string name="sdCardStatusAbnormalMain">The status of your doorbell’s SD card is abnormal, which may prevent new recordings from being stored. Would you like to format the SD card?</string>
119
+ <string name="sdCardStatusAbnormalNote">Important: Resetting will erase all previous recordings.</string>
120
+ <string name="sdCardReformatFailedMain">The SD card reformatting process has failed. Would you like to retry?</string>
121
+ <string name="sdCardReformatFailedNote">Note: If this issue persists, you may need to replace the SD card with a new one.</string>
122
+ <string name="retryFormatting">Retry Formatting</string>
123
+
116
124
  <!-- Additional -->
117
125
  <string name="closingConnection">Closing Connection…</string>
118
126
  <string name="ok">OK</string>
@@ -6,6 +6,7 @@ struct Dashboard: View {
6
6
  @Binding var currentScreen: ScreenState
7
7
  @State private var isDoorbellControlVisible = true
8
8
  @State private var isPermissionDisclaimerAlertVisible = false
9
+ @State private var isSDCardAlertVisible = false
9
10
  @EnvironmentObject var orientationManager: OrientationManager
10
11
 
11
12
  var body: some View {
@@ -48,8 +49,29 @@ struct Dashboard: View {
48
49
  }
49
50
  .background(LocalColor.Monochrome.black)
50
51
  .onAppear(perform: handleOnAppear)
52
+ .onChange(of: Tuya.shared.sdCardStatus) { newValue in
53
+ if newValue == 2 {
54
+ isSDCardAlertVisible = true
55
+ }
56
+ else if newValue == 4 {
57
+ Tuya.shared.previewLoader = true
58
+ }
59
+ }
51
60
  .onChange(of: orientationManager.isLandscape) { _ in handleOrientation() }
52
61
  .onChange(of: isDoorbellControlVisible) { _ in handleOrientation() }
62
+
63
+ .alert(isPresented: $isSDCardAlertVisible) {
64
+ getAlert(
65
+ title: "Doorbell SD Card",
66
+ message: sdcardReformatTitle(for: Tuya.shared.noOfRetrysSdCardFormat),
67
+ primaryButtonTitle: Tuya.shared.noOfRetrysSdCardFormat == 0 ? "Format" : "Retry Formatting",
68
+ withCancelButton: true,
69
+ secondaryButtonTitle: "Cancel",
70
+ primaryAction: {
71
+ SettingsManager.shared.formatSDCard()
72
+ }
73
+ )
74
+ }
53
75
 
54
76
  if tuya.dashboardLoader {
55
77
  ProgressView()
@@ -64,6 +86,14 @@ struct Dashboard: View {
64
86
  }
65
87
  }
66
88
 
89
+ private func sdcardReformatTitle(for noOfRetry: Int) -> String {
90
+ switch noOfRetry {
91
+ case 0: return "\nThe status of your doorbell’s SD card is abnormal, which may prevent new recordings from being stored. Would you like to format the SD card?\n\nImportant: Resetting will erase all previous recordings."
92
+ case 1: return "\nThe SD card reformatting process has failed.\nWould you like to retry?"
93
+ default: return "\nThe SD card reformatting process has failed. Would like to retry?\n\nNote: If this issue persists, you may need to replace the SD card with a new one."
94
+ }
95
+ }
96
+
67
97
  private func handleOrientation() {
68
98
  if orientationManager.isLandscape && isDoorbellControlVisible {
69
99
  DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
@@ -177,66 +177,69 @@ class SettingsManager: NSObject, ThingSmartCameraDPObserver {
177
177
  }
178
178
  }
179
179
 
180
- // Format SD Card
181
- func formatSDCard() {
182
- withDPManager { dpManager in
183
- guard self.isSupportedDP(dpKey: ThingSmartCameraDPKey.sdCardFormatDPName) else {
184
- return
185
- }
186
-
187
- Tuya.shared.settingsLoader = true
188
- dpManager.setValue(
189
- true,
190
- forDP: ThingSmartCameraDPKey.sdCardFormatDPName,
191
- success: { result in
192
- print("Tuya: Formatting started")
193
- Tuya.shared.settingsLoader = false
194
- },
195
- failure: { error in
196
- print("Tuya: Format failed")
197
- Tuya.shared.settingsLoader = false
198
- }
199
- )
200
- }
201
- }
202
-
203
- // Get Memory card Capaciry
204
- func getMemoryCardCapacity() {
205
- guard self.isSupportedDP(dpKey: ThingSmartCameraDPKey.sdCardStorageDPName) else {
206
- print("Tuya: Get SD card capacity is not supported.")
207
- return
208
- }
209
-
210
- Tuya.shared.settingsLoader = true
211
-
212
- if let result = getDPValue(dpKey: .sdCardStorageDPName) as? String {
213
- print("Tuya: Retrieve memory card status successfully. Result: \(result)")
214
- let components = result.split(separator: "|")
215
-
216
- guard components.count == 3 else {
217
- Tuya.shared.settingsLoader = false
218
- return
219
- }
220
-
221
- if let totalBytes = Double(components[0]) {
222
- Tuya.shared.totalCapacity = totalBytes / 1024 / 1024
223
- }
224
-
225
- if let usedBytes = Double(components[1]) {
226
- Tuya.shared.used = usedBytes / 1024 / 1024
227
- }
228
-
229
- if let remainingBytes = Double(components[2]) {
230
- Tuya.shared.remainingCapacity = remainingBytes / 1024 / 1024
231
- }
232
-
233
- Tuya.shared.settingsLoader = false
234
- } else {
235
- print("Tuya: No details available for the SD card.")
236
- Tuya.shared.settingsLoader = false
237
- }
238
- }
239
-
180
+ // Format SD Card
181
+ func formatSDCard() {
182
+ withDPManager { dpManager in
183
+ guard self.isSupportedDP(dpKey: ThingSmartCameraDPKey.sdCardFormatDPName) else {
184
+ return
185
+ }
186
+
187
+ Tuya.shared.settingsLoader = true
188
+ dpManager.setValue(
189
+ true,
190
+ forDP: ThingSmartCameraDPKey.sdCardFormatDPName,
191
+ success: { result in
192
+ print("Tuya: Formatting started")
193
+ Tuya.shared.settingsLoader = false
194
+ Tuya.shared.previewLoader = false
195
+ },
196
+ failure: { error in
197
+ print("Tuya: Format failed")
198
+ Tuya.shared.settingsLoader = false
199
+ Tuya.shared.previewLoader = false
200
+ Tuya.shared.noOfRetrysSdCardFormat += 1
201
+ }
202
+ )
203
+ }
204
+ }
205
+
206
+ // Get Memory card Capaciry
207
+ func getMemoryCardCapacity() {
208
+ guard self.isSupportedDP(dpKey: ThingSmartCameraDPKey.sdCardStorageDPName) else {
209
+ print("Tuya: Get SD card capacity is not supported.")
210
+ return
211
+ }
212
+
213
+ Tuya.shared.settingsLoader = true
214
+
215
+ if let result = getDPValue(dpKey: .sdCardStorageDPName) as? String {
216
+ print("Tuya: Retrieve memory card status successfully. Result: \(result)")
217
+ let components = result.split(separator: "|")
218
+
219
+ guard components.count == 3 else {
220
+ Tuya.shared.settingsLoader = false
221
+ return
222
+ }
223
+
224
+ if let totalBytes = Double(components[0]) {
225
+ Tuya.shared.totalCapacity = totalBytes / 1024 / 1024
226
+ }
227
+
228
+ if let usedBytes = Double(components[1]) {
229
+ Tuya.shared.used = usedBytes / 1024 / 1024
230
+ }
231
+
232
+ if let remainingBytes = Double(components[2]) {
233
+ Tuya.shared.remainingCapacity = remainingBytes / 1024 / 1024
234
+ }
235
+
236
+ Tuya.shared.settingsLoader = false
237
+ } else {
238
+ print("Tuya: No details available for the SD card.")
239
+ Tuya.shared.settingsLoader = false
240
+ }
241
+ }
242
+
240
243
  func getFirmwareVersion() {
241
244
  guard Tuya.shared.device.isSupportCheckFirmware() else {
242
245
  print("Tuya: Firmware upgrade check is not supported for this device.")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rentlydev/rently-tuya",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "rently-tuya",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",
@@ -52,14 +52,14 @@
52
52
  ],
53
53
  "repository": {
54
54
  "type": "git",
55
- "url": "git+https://github.com/harishkumar00/rently-tuya.git"
55
+ "url": "git+https://github.com/rently-com/rently-tuya.git"
56
56
  },
57
57
  "author": "harishkumar00 <harishkumar.h@rently.com> (https://github.com/harishkumar00)",
58
58
  "license": "MIT",
59
59
  "bugs": {
60
- "url": "https://github.com/harishkumar00/rently-tuya/issues"
60
+ "url": "https://github.com/rently-com/rently-tuya/issues"
61
61
  },
62
- "homepage": "https://github.com/harishkumar00/rently-tuya#readme",
62
+ "homepage": "https://github.com/rently-com/rently-tuya#readme",
63
63
  "publishConfig": {
64
64
  "registry": "https://registry.npmjs.org/"
65
65
  },
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
12
12
  s.authors = package["author"]
13
13
 
14
14
  s.platforms = { :ios => min_ios_version_supported }
15
- s.source = { :git => "https://github.com/harishkumar00/rently-tuya.git", :tag => "#{s.version}" }
15
+ s.source = { :git => "https://github.com/rently-com/rently-tuya.git", :tag => "#{s.version}" }
16
16
 
17
17
  s.source_files = "ios/**/*.{h,m,mm,swift}"
18
18
  s.resource_bundles = {