react-native-asleep 0.0.5 โ 0.0.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 +5 -4
- package/android/src/main/java/ai/asleep/reactnative/AsleepModule.kt +96 -158
- package/build/index.d.ts +2 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +20 -10
- package/build/index.js.map +1 -1
- package/ios/Asleep.podspec +1 -1
- package/ios/AsleepModule.swift +4 -5
- package/package.json +1 -1
- package/src/index.ts +27 -15
- package/android/src/main/aidl/ai/asleep/reactnative/IAsleepService.aidl +0 -9
- package/android/src/main/aidl/ai/asleep/reactnative/IListener.aidl +0 -12
- package/android/src/main/aidl/ai/asleep/reactnative/data/ErrorCode.aidl +0 -4
- package/android/src/main/java/ai/asleep/reactnative/data/ErrorCode.kt +0 -33
- package/android/src/main/java/ai/asleep/reactnative/service/AsleepService.kt +0 -179
- package/android/src/main/java/ai/asleep/reactnative/service/AsleepViewModel.kt +0 -246
- package/android/src/main/java/ai/asleep/reactnative/utils/PreferenceHelper.kt +0 -119
- package/android/src/main/java/ai/asleep/reactnative/utils/Utils.kt +0 -48
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
package ai.asleep.reactnative.utils
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import android.content.SharedPreferences
|
|
5
|
-
|
|
6
|
-
class PreferenceHelper private constructor() {
|
|
7
|
-
|
|
8
|
-
companion object {
|
|
9
|
-
private const val PREF_NAME = "time_prefs"
|
|
10
|
-
private const val START_TIME_HOUR_KEY = "start_time_hour"
|
|
11
|
-
private const val START_TIME_MINUTE_KEY = "start_time_minute"
|
|
12
|
-
private const val END_TIME_HOUR_KEY = "end_time_hour"
|
|
13
|
-
private const val END_TIME_MINUTE_KEY = "end_time_minute"
|
|
14
|
-
private const val ENABLE_TRACKING_KEY = "enable_tracking"
|
|
15
|
-
private const val USER_ID = "user_id"
|
|
16
|
-
private const val API_KEY = "api_key"
|
|
17
|
-
private const val START_TRACKING_TIME = "start_tracking_time"
|
|
18
|
-
private const val NOTIFICATION_TITLE = "notification_title"
|
|
19
|
-
private const val NOTIFICATION_TEXT = "notification_text"
|
|
20
|
-
private const val IS_TRACKING = "is_tracking"
|
|
21
|
-
|
|
22
|
-
private fun getSharedPreferences(context: Context): SharedPreferences {
|
|
23
|
-
return context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
fun putStartHour(context: Context, hour: Int) {
|
|
27
|
-
getSharedPreferences(context).edit().putInt(START_TIME_HOUR_KEY, hour).apply()
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
fun getStartHour(context: Context): Int {
|
|
31
|
-
return getSharedPreferences(context).getInt(START_TIME_HOUR_KEY, 23)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
fun putStartMinute(context: Context, minute: Int) {
|
|
35
|
-
getSharedPreferences(context).edit().putInt(START_TIME_MINUTE_KEY, minute).apply()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
fun getStartMinute(context: Context): Int {
|
|
39
|
-
return getSharedPreferences(context).getInt(START_TIME_MINUTE_KEY, 30)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
fun putEndHour(context: Context, hour: Int) {
|
|
43
|
-
getSharedPreferences(context).edit().putInt(END_TIME_HOUR_KEY, hour).apply()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
fun getEndHour(context: Context): Int {
|
|
47
|
-
return getSharedPreferences(context).getInt(END_TIME_HOUR_KEY, 7)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
fun putEndMinute(context: Context, minute: Int) {
|
|
51
|
-
getSharedPreferences(context).edit().putInt(END_TIME_MINUTE_KEY, minute).apply()
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
fun getEndMinute(context: Context): Int {
|
|
55
|
-
return getSharedPreferences(context).getInt(END_TIME_MINUTE_KEY, 0)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
fun putAutoTrackingEnabled(context: Context, isEnabled: Boolean) {
|
|
59
|
-
getSharedPreferences(context).edit().putBoolean(ENABLE_TRACKING_KEY, isEnabled).apply()
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
fun isAutoTrackingEnabled(context: Context): Boolean {
|
|
63
|
-
return getSharedPreferences(context).getBoolean(ENABLE_TRACKING_KEY, false)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
fun putUserId(context: Context, userId: String) {
|
|
68
|
-
getSharedPreferences(context).edit().putString(USER_ID, userId).apply()
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
fun getUserId(context: Context): String {
|
|
72
|
-
return getSharedPreferences(context).getString(USER_ID, "")?:""
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
fun putApiKey(context: Context?, apiKey: String?) {
|
|
76
|
-
if (context == null || apiKey == null) return
|
|
77
|
-
getSharedPreferences(context).edit().putString(API_KEY, apiKey).apply()
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
fun getApiKey(context: Context?): String {
|
|
81
|
-
if (context == null) return ""
|
|
82
|
-
return getSharedPreferences(context).getString(API_KEY, "") ?: ""
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
fun putStartTrackingTime(context: Context, startTrackingTime: String) {
|
|
86
|
-
getSharedPreferences(context).edit().putString(START_TRACKING_TIME, startTrackingTime).apply()
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
fun getStartTrackingTime(context: Context): String {
|
|
90
|
-
return getSharedPreferences(context).getString(START_TRACKING_TIME, "")?:""
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
fun putNotificationTitle(context: Context, title: String) {
|
|
94
|
-
getSharedPreferences(context).edit().putString(NOTIFICATION_TITLE, title).apply()
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
fun getNotificationTitle(context: Context): String {
|
|
98
|
-
return getSharedPreferences(context).getString(NOTIFICATION_TITLE, "Sleep Tracking") ?: "Sleep Tracking"
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
fun putNotificationText(context: Context, text: String) {
|
|
102
|
-
getSharedPreferences(context).edit().putString(NOTIFICATION_TEXT, text).apply()
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
fun getNotificationText(context: Context): String {
|
|
106
|
-
return getSharedPreferences(context).getString(NOTIFICATION_TEXT,
|
|
107
|
-
"We're measuring your sleep. Don't worry, the measurement continues even when your phone screen is off๐")
|
|
108
|
-
?: "We're measuring your sleep. Don't worry, the measurement continues even when your phone screen is off๐"
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
fun putIsTracking(context: Context, isTracking: Boolean) {
|
|
112
|
-
getSharedPreferences(context).edit().putBoolean(IS_TRACKING, isTracking).apply()
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
fun isTracking(context: Context): Boolean {
|
|
116
|
-
return getSharedPreferences(context).getBoolean(IS_TRACKING, false)
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
package ai.asleep.reactnative.utils
|
|
2
|
-
|
|
3
|
-
import android.os.Build
|
|
4
|
-
import java.text.SimpleDateFormat
|
|
5
|
-
import java.time.OffsetDateTime
|
|
6
|
-
import java.time.ZoneId
|
|
7
|
-
import java.time.ZonedDateTime
|
|
8
|
-
import java.time.format.DateTimeFormatter
|
|
9
|
-
import java.util.Date
|
|
10
|
-
import java.util.Locale
|
|
11
|
-
import java.util.TimeZone
|
|
12
|
-
|
|
13
|
-
internal fun changeTimeFormat(time: String?): String? {
|
|
14
|
-
if (time != null) {
|
|
15
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
16
|
-
val inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX")
|
|
17
|
-
val outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
|
|
18
|
-
|
|
19
|
-
val offsetDateTime = OffsetDateTime.parse(time, inputFormatter)
|
|
20
|
-
val systemZone = ZoneId.systemDefault()
|
|
21
|
-
val localDateTime = offsetDateTime.atZoneSameInstant(systemZone).toLocalDateTime()
|
|
22
|
-
|
|
23
|
-
return localDateTime.format(outputFormatter)
|
|
24
|
-
} else {
|
|
25
|
-
val inputFormatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.getDefault())
|
|
26
|
-
val date = inputFormatter.parse(time)
|
|
27
|
-
val outputFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
|
|
28
|
-
|
|
29
|
-
return outputFormatter.format(date)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return null
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
internal fun getCurrentTime(): String {
|
|
36
|
-
var time = ""
|
|
37
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
38
|
-
val systemZone = ZoneId.systemDefault()
|
|
39
|
-
val zonedDateTime = ZonedDateTime.now(systemZone)
|
|
40
|
-
time = zonedDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
|
|
41
|
-
} else {
|
|
42
|
-
val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
|
43
|
-
dateFormat.timeZone = TimeZone.getDefault()
|
|
44
|
-
val currentTime = Date(System.currentTimeMillis())
|
|
45
|
-
time = dateFormat.format(currentTime)
|
|
46
|
-
}
|
|
47
|
-
return time
|
|
48
|
-
}
|