Skip to content

Commit

Permalink
VIT-6624: Catch up with all API deprecations Pt.4 (#121)
Browse files Browse the repository at this point in the history
Remove:
* All deprecated SDK methods.

Move:
* VitalClient: instance method `checkUserId()` -> class method `checkUserId()`
  • Loading branch information
andersio authored Jun 12, 2024
1 parent 102cdf8 commit 553ca72
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 79 deletions.
45 changes: 7 additions & 38 deletions VitalClient/src/main/java/io/tryvital/client/VitalClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,6 @@ class VitalClient internal constructor(context: Context) {
val childSDKShouldReset: SharedFlow<Unit> get() = _childSDKShouldReset
private val _childSDKShouldReset = MutableSharedFlow<Unit>(extraBufferCapacity = Int.MAX_VALUE)


@Deprecated("Renamed to `signOut()` and is now a suspend function.", ReplaceWith("signOut()"))
fun cleanUp() {
@OptIn(DelicateCoroutinesApi::class)
GlobalScope.launch(start = CoroutineStart.UNDISPATCHED) {
signOut()
}
}

suspend fun signOut() {
sharedPreferences.edit().clear().apply()
encryptedSharedPreferences.edit().clear().apply()
Expand All @@ -122,16 +113,6 @@ class VitalClient internal constructor(context: Context) {
_childSDKShouldReset.emit(Unit)
}

@Deprecated(
message = "Use VitalClient.configure (API Key) or VitalClient.signIn (Vital Sign-In Token) instead.",
replaceWith = ReplaceWith("VitalClient.configure(context, region, environment, apiKey)"),
)
fun configure(region: Region, environment: Environment, apiKey: String) {
setConfiguration(
VitalClientAuthStrategy.APIKey(apiKey, environment, region)
)
}

private fun setConfiguration(strategy: VitalClientAuthStrategy) {
encryptedSharedPreferences.edit()
.putString(
Expand All @@ -142,11 +123,7 @@ class VitalClient internal constructor(context: Context) {
statusChanged.tryEmit(Unit)
}

@Deprecated(
message = "Use VitalClient.setUserId instead.",
replaceWith = ReplaceWith("VitalClient.setUserId(context, userId)"),
)
fun setUserId(userId: String) {
private fun setUserId(userId: String) {
// No-op if the SDK has been configured into JWT mode.
if (configurationReader.authStrategy is VitalClientAuthStrategy.JWT) {
return
Expand All @@ -160,20 +137,6 @@ class VitalClient internal constructor(context: Context) {
statusChanged.tryEmit(Unit)
}

@Deprecated(
message = "Use VitalClient.status instead.",
replaceWith = ReplaceWith("VitalClient.Status.SignedIn in VitalClient.status"),
)
fun hasUserId(): Boolean {
return encryptedSharedPreferences.getString(VITAL_ENCRYPTED_USER_ID_KEY, null) != null
}

fun checkUserId(): String {
return currentUserId ?: throw IllegalStateException(
"The SDK does not have a signed-in user, or is not configured with an API Key for evaluation."
)
}

companion object {
const val sdkVersion = "2.0.4"

Expand Down Expand Up @@ -238,6 +201,12 @@ class VitalClient internal constructor(context: Context) {
}
}

fun checkUserId(): String {
return currentUserId ?: throw IllegalStateException(
"The SDK does not have a signed-in user, or is not configured with an API Key for evaluation."
)
}

fun getOrCreate(context: Context): VitalClient = synchronized(VitalClient) {
val appContext = context.applicationContext
var instance = sharedInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fun VitalClient.hasUserConnectedTo(provider: ProviderSlug): Boolean {
}

suspend fun VitalClient.createConnectedSourceIfNotExist(provider: ManualProviderSlug) {
val userId = checkUserId()
val userId = VitalClient.checkUserId()
val slug = provider.toProviderSlug()
if (hasUserConnectedTo(slug)) {
// Local Hit: The client has witnessed a valid connected source for this provider before.
Expand Down Expand Up @@ -56,7 +56,7 @@ suspend fun VitalClient.createConnectedSourceIfNotExist(provider: ManualProvider
}

suspend fun VitalClient.userConnections(): List<UserConnection> {
val userId = checkUserId()
val userId = VitalClient.checkUserId()
resetCachedUserConnectedSourceRecordIfNeeded()

val response = userService.getUserConnections(userId = userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,30 +125,6 @@ class VitalHealthConnectManager private constructor(
setupSyncWorkerObservation()
}

/**
* Stop any running task, and close this VitalHealthConnectManager instance.
*
* Note that this is not [cleanUp], which erases all SDK settings and persistent state.
*/
@Suppress("unused")
fun close() {
taskScope.cancel()
}

/**
* Erase all SDK settings and persistent state for the current user.
*
* You typically only need to [cleanUp] when your application has logged out the current user.
*/
@Deprecated(
"Use [VitalClient.signOut]. It resets both the Vital Core and Health SDKs."
)
@Suppress("unused")
fun cleanUp() {
@Suppress("DEPRECATION")
vitalClient.cleanUp()
}

@OptIn(ExperimentalVitalApi::class)
private fun resetAutoSync() {
cancelSyncWorker()
Expand Down Expand Up @@ -508,18 +484,6 @@ class VitalHealthConnectManager private constructor(
}
}

@Suppress("unused")
@Deprecated(
message="Use `openHealthConnectIntent(context)`.",
replaceWith = ReplaceWith(
"openHealthConnectIntent(context)?.let { context.startActivity(it) }",
"io.tryvital.vitalhealthconnect.VitalHealthConnectManager.Companion.openHealthConnectIntent"
)
)
fun openHealthConnect(context: Context) {
openHealthConnectIntent(context)?.let { context.startActivity(it) }
}

@Suppress("unused")
fun openHealthConnectIntent(context: Context): Intent? {
return when (isAvailable(context)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ internal class ResourceSyncWorker(appContext: Context, workerParams: WorkerParam
timeZone: TimeZone
): UserSDKSyncStateResponse {
val backendState = vitalClient.vitalPrivateService.healthConnectSdkSyncState(
vitalClient.checkUserId(),
VitalClient.checkUserId(),
when (state) {
is ResourceSyncState.Historical -> UserSDKSyncStateBody(
stage = DataStage.Historical,
Expand Down Expand Up @@ -244,7 +244,7 @@ internal class ResourceSyncWorker(appContext: Context, workerParams: WorkerParam
state: ResourceSyncState.Incremental,
timeZone: TimeZone
) {
val userId = vitalClient.checkUserId()
val userId = VitalClient.checkUserId()
val client = healthConnectClientProvider.getHealthConnectClient(applicationContext)

val recordTypesToMonitor = recordTypesToMonitor().toSimpleNameSet()
Expand Down Expand Up @@ -323,7 +323,7 @@ internal class ResourceSyncWorker(appContext: Context, workerParams: WorkerParam
end: Instant,
timeZone: TimeZone
) {
val userId = vitalClient.checkUserId()
val userId = VitalClient.checkUserId()
val client = healthConnectClientProvider.getHealthConnectClient(applicationContext)

val recordTypesToMonitor = recordTypesToMonitor()
Expand Down

0 comments on commit 553ca72

Please sign in to comment.