Skip to content

1.6.x #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ repositories {
Next, add the dependency to your project's `build.gradle(.kts)` file:

```groovy
implementation("io.appwrite:sdk-for-android:6.0.0")
implementation("io.appwrite:sdk-for-android:6.1.0")
```

### Maven
@@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file:
<dependency>
<groupId>io.appwrite</groupId>
<artifactId>sdk-for-android</artifactId>
<version>6.0.0</version>
<version>6.1.0</version>
</dependency>
</dependencies>
```
Original file line number Diff line number Diff line change
@@ -81,8 +81,8 @@ class AccountsViewModel : ViewModel() {
account.createOAuth2Session(
activity,
OAuthProvider.FACEBOOK,
"appwrite-callback-6070749e6acd4://demo.appwrite.io/auth/oauth2/success",
"appwrite-callback-6070749e6acd4://demo.appwrite.io/auth/oauth2/failure"
"appwrite-callback-6070749e6acd4://cloud.appwrite.io/auth/oauth2/success",
"appwrite-callback-6070749e6acd4://cloud.appwrite.io/auth/oauth2/failure"
)
} catch (e: Exception) {
_error.postValue(Event(e))
2 changes: 1 addition & 1 deletion library/src/main/java/io/appwrite/Client.kt
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ class Client @JvmOverloads constructor(
"x-sdk-name" to "Android",
"x-sdk-platform" to "client",
"x-sdk-language" to "android",
"x-sdk-version" to "6.0.0",
"x-sdk-version" to "6.1.0",
"x-appwrite-response-format" to "1.6.0"
)
config = mutableMapOf()
4 changes: 3 additions & 1 deletion library/src/main/java/io/appwrite/enums/ImageFormat.kt
Original file line number Diff line number Diff line change
@@ -12,7 +12,9 @@ enum class ImageFormat(val value: String) {
@SerializedName("png")
PNG("png"),
@SerializedName("webp")
WEBP("webp");
WEBP("webp"),
@SerializedName("avif")
AVIF("avif");

override fun toString() = value
}
6 changes: 3 additions & 3 deletions library/src/main/java/io/appwrite/models/Document.kt
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ data class Document<T>(
* Document permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).
*/
@SerializedName("\$permissions")
val permissions: List<Any>,
val permissions: List<String>,

/**
* Additional properties
@@ -66,7 +66,7 @@ data class Document<T>(
databaseId: String,
createdAt: String,
updatedAt: String,
permissions: List<Any>,
permissions: List<String>,
data: Map<String, Any>
) = Document<Map<String, Any>>(
id,
@@ -88,7 +88,7 @@ data class Document<T>(
databaseId = map["\$databaseId"] as String,
createdAt = map["\$createdAt"] as String,
updatedAt = map["\$updatedAt"] as String,
permissions = map["\$permissions"] as List<Any>,
permissions = map["\$permissions"] as List<String>,
data = map.jsonCast(to = nestedType)
)
}
4 changes: 2 additions & 2 deletions library/src/main/java/io/appwrite/models/Execution.kt
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ data class Execution(
* Execution roles.
*/
@SerializedName("\$permissions")
val permissions: List<Any>,
val permissions: List<String>,

/**
* Function ID.
@@ -139,7 +139,7 @@ data class Execution(
id = map["\$id"] as String,
createdAt = map["\$createdAt"] as String,
updatedAt = map["\$updatedAt"] as String,
permissions = map["\$permissions"] as List<Any>,
permissions = map["\$permissions"] as List<String>,
functionId = map["functionId"] as String,
trigger = map["trigger"] as String,
status = map["status"] as String,
4 changes: 2 additions & 2 deletions library/src/main/java/io/appwrite/models/File.kt
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ data class File(
* File permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).
*/
@SerializedName("\$permissions")
val permissions: List<Any>,
val permissions: List<String>,

/**
* File name.
@@ -98,7 +98,7 @@ data class File(
bucketId = map["bucketId"] as String,
createdAt = map["\$createdAt"] as String,
updatedAt = map["\$updatedAt"] as String,
permissions = map["\$permissions"] as List<Any>,
permissions = map["\$permissions"] as List<String>,
name = map["name"] as String,
signature = map["signature"] as String,
mimeType = map["mimeType"] as String,
10 changes: 5 additions & 5 deletions library/src/main/java/io/appwrite/models/Membership.kt
Original file line number Diff line number Diff line change
@@ -32,13 +32,13 @@ data class Membership(
val userId: String,

/**
* User name.
* User name. Hide this attribute by toggling membership privacy in the Console.
*/
@SerializedName("userName")
val userName: String,

/**
* User email address.
* User email address. Hide this attribute by toggling membership privacy in the Console.
*/
@SerializedName("userEmail")
val userEmail: String,
@@ -74,7 +74,7 @@ data class Membership(
val confirm: Boolean,

/**
* Multi factor authentication status, true if the user has MFA enabled or false otherwise.
* Multi factor authentication status, true if the user has MFA enabled or false otherwise. Hide this attribute by toggling membership privacy in the Console.
*/
@SerializedName("mfa")
val mfa: Boolean,
@@ -83,7 +83,7 @@ data class Membership(
* User list of roles
*/
@SerializedName("roles")
val roles: List<Any>,
val roles: List<String>,

) {
fun toMap(): Map<String, Any> = mapOf(
@@ -120,7 +120,7 @@ data class Membership(
joined = map["joined"] as String,
confirm = map["confirm"] as Boolean,
mfa = map["mfa"] as Boolean,
roles = map["roles"] as List<Any>,
roles = map["roles"] as List<String>,
)
}
}
4 changes: 2 additions & 2 deletions library/src/main/java/io/appwrite/models/MfaRecoveryCodes.kt
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ data class MfaRecoveryCodes(
* Recovery codes.
*/
@SerializedName("recoveryCodes")
val recoveryCodes: List<Any>,
val recoveryCodes: List<String>,

) {
fun toMap(): Map<String, Any> = mapOf(
@@ -24,7 +24,7 @@ data class MfaRecoveryCodes(
fun from(
map: Map<String, Any>,
) = MfaRecoveryCodes(
recoveryCodes = map["recoveryCodes"] as List<Any>,
recoveryCodes = map["recoveryCodes"] as List<String>,
)
}
}
4 changes: 2 additions & 2 deletions library/src/main/java/io/appwrite/models/Session.kt
Original file line number Diff line number Diff line change
@@ -167,7 +167,7 @@ data class Session(
* Returns a list of active session factors.
*/
@SerializedName("factors")
val factors: List<Any>,
val factors: List<String>,

/**
* Secret used to authenticate the user. Only included if the request was made with an API key
@@ -246,7 +246,7 @@ data class Session(
countryCode = map["countryCode"] as String,
countryName = map["countryName"] as String,
current = map["current"] as Boolean,
factors = map["factors"] as List<Any>,
factors = map["factors"] as List<String>,
secret = map["secret"] as String,
mfaUpdatedAt = map["mfaUpdatedAt"] as String,
)
8 changes: 8 additions & 0 deletions library/src/main/java/io/appwrite/models/Target.kt
Original file line number Diff line number Diff line change
@@ -55,6 +55,12 @@ data class Target(
@SerializedName("identifier")
val identifier: String,

/**
* Is the target expired.
*/
@SerializedName("expired")
val expired: Boolean,

) {
fun toMap(): Map<String, Any> = mapOf(
"\$id" to id as Any,
@@ -65,6 +71,7 @@ data class Target(
"providerId" to providerId as Any,
"providerType" to providerType as Any,
"identifier" to identifier as Any,
"expired" to expired as Any,
)

companion object {
@@ -81,6 +88,7 @@ data class Target(
providerId = map["providerId"] as? String?,
providerType = map["providerType"] as String,
identifier = map["identifier"] as String,
expired = map["expired"] as Boolean,
)
}
}
6 changes: 3 additions & 3 deletions library/src/main/java/io/appwrite/models/User.kt
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ data class User<T>(
* Labels for the user.
*/
@SerializedName("labels")
val labels: List<Any>,
val labels: List<String>,

/**
* Password update time in ISO 8601 format.
@@ -155,7 +155,7 @@ data class User<T>(
hashOptions: Any?,
registration: String,
status: Boolean,
labels: List<Any>,
labels: List<String>,
passwordUpdate: String,
email: String,
phone: String,
@@ -201,7 +201,7 @@ data class User<T>(
hashOptions = map["hashOptions"] as? Any?,
registration = map["registration"] as String,
status = map["status"] as Boolean,
labels = map["labels"] as List<Any>,
labels = map["labels"] as List<String>,
passwordUpdate = map["passwordUpdate"] as String,
email = map["email"] as String,
phone = map["phone"] as String,
30 changes: 17 additions & 13 deletions library/src/main/java/io/appwrite/services/Account.kt
Original file line number Diff line number Diff line change
@@ -190,7 +190,7 @@ class Account(client: Client) : Service(client) {
)

/**
* List Identities
* List identities
*
* Get the list of identities for the currently logged in user.
*
@@ -370,7 +370,7 @@ class Account(client: Client) : Service(client) {
)

/**
* Create Authenticator
* Create authenticator
*
* Add an authenticator app to be used as an MFA factor. Verify the authenticator using the [verify authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) method.
*
@@ -404,7 +404,7 @@ class Account(client: Client) : Service(client) {


/**
* Verify Authenticator
* Verify authenticator
*
* Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method.
*
@@ -441,7 +441,7 @@ class Account(client: Client) : Service(client) {
}

/**
* Verify Authenticator
* Verify authenticator
*
* Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method.
*
@@ -460,7 +460,7 @@ class Account(client: Client) : Service(client) {
)

/**
* Delete Authenticator
* Delete authenticator
*
* Delete an authenticator for a user by ID.
*
@@ -489,7 +489,7 @@ class Account(client: Client) : Service(client) {


/**
* Create MFA Challenge
* Create MFA challenge
*
* Begin the process of MFA verification after sign-in. Finish the flow with [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) method.
*
@@ -523,7 +523,7 @@ class Account(client: Client) : Service(client) {


/**
* Create MFA Challenge (confirmation)
* Create MFA challenge (confirmation)
*
* Complete the MFA challenge by providing the one-time password. Finish the process of MFA verification by providing the one-time password. To begin the flow, use [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.
*
@@ -555,7 +555,7 @@ class Account(client: Client) : Service(client) {


/**
* List Factors
* List factors
*
* List the factors available on the account to be used as a MFA challange.
*
@@ -586,7 +586,7 @@ class Account(client: Client) : Service(client) {


/**
* Get MFA Recovery Codes
* Get MFA recovery codes
*
* Get recovery codes that can be used as backup for MFA flow. Before getting codes, they must be generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method. An OTP challenge is required to read recovery codes.
*
@@ -617,7 +617,7 @@ class Account(client: Client) : Service(client) {


/**
* Create MFA Recovery Codes
* Create MFA recovery codes
*
* Generate recovery codes as backup for MFA flow. It&#039;s recommended to generate and show then immediately after user successfully adds their authehticator. Recovery codes can be used as a MFA verification type in [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.
*
@@ -648,7 +648,7 @@ class Account(client: Client) : Service(client) {


/**
* Regenerate MFA Recovery Codes
* Regenerate MFA recovery codes
*
* Regenerate recovery codes that can be used as backup for MFA flow. Before regenerating codes, they must be first generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method. An OTP challenge is required to regenreate recovery codes.
*
@@ -1209,7 +1209,9 @@ class Account(client: Client) : Service(client) {
return@forEach
}
is List<*> -> {
apiQuery.add("${it.key}[]=${it.value.toString()}")
(it.value as List<*>).forEach { v ->
apiQuery.add("${it.key}[]=${v.toString()}")
}
}
else -> {
apiQuery.add("${it.key}=${it.value.toString()}")
@@ -1688,7 +1690,9 @@ class Account(client: Client) : Service(client) {
return@forEach
}
is List<*> -> {
apiQuery.add("${it.key}[]=${it.value.toString()}")
(it.value as List<*>).forEach { v ->
apiQuery.add("${it.key}[]=${v.toString()}")
}
}
else -> {
apiQuery.add("${it.key}=${it.value.toString()}")
2 changes: 1 addition & 1 deletion library/src/main/java/io/appwrite/services/Locale.kt
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ class Locale(client: Client) : Service(client) {


/**
* List Locale Codes
* List locale codes
*
* List of all locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
*
22 changes: 22 additions & 0 deletions library/src/main/java/io/appwrite/services/Realtime.kt
Original file line number Diff line number Diff line change
@@ -29,6 +29,8 @@ class Realtime(client: Client) : Service(client), CoroutineScope {
private companion object {
private const val TYPE_ERROR = "error"
private const val TYPE_EVENT = "event"
private const val TYPE_PONG = "pong"
private const val HEARTBEAT_INTERVAL = 20_000L // 20 seconds

private const val DEBOUNCE_MILLIS = 1L

@@ -40,6 +42,7 @@ class Realtime(client: Client) : Service(client), CoroutineScope {
private var reconnectAttempts = 0
private var subscriptionsCounter = 0
private var reconnect = true
private var heartbeatJob: Job? = null
}

private fun createSocket() {
@@ -80,9 +83,25 @@ class Realtime(client: Client) : Service(client), CoroutineScope {
}

private fun closeSocket() {
stopHeartbeat()
socket?.close(RealtimeCode.POLICY_VIOLATION.value, null)
}

private fun startHeartbeat() {
stopHeartbeat()
heartbeatJob = launch {
while (isActive) {
delay(HEARTBEAT_INTERVAL)
socket?.send("""{"type":"ping"}""")
}
}
}

private fun stopHeartbeat() {
heartbeatJob?.cancel()
heartbeatJob = null
}

private fun getTimeout() = when {
reconnectAttempts < 5 -> 1000L
reconnectAttempts < 15 -> 5000L
@@ -145,6 +164,7 @@ class Realtime(client: Client) : Service(client), CoroutineScope {
override fun onOpen(webSocket: WebSocket, response: Response) {
super.onOpen(webSocket, response)
reconnectAttempts = 0
startHeartbeat()
}

override fun onMessage(webSocket: WebSocket, text: String) {
@@ -181,6 +201,7 @@ class Realtime(client: Client) : Service(client), CoroutineScope {

override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
super.onClosing(webSocket, code, reason)
stopHeartbeat()
if (!reconnect || code == RealtimeCode.POLICY_VIOLATION.value) {
reconnect = true
return
@@ -203,6 +224,7 @@ class Realtime(client: Client) : Service(client), CoroutineScope {

override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
super.onFailure(webSocket, t, response)
stopHeartbeat()
t.printStackTrace()
}
}
2 changes: 1 addition & 1 deletion library/src/main/java/io/appwrite/services/Storage.kt
Original file line number Diff line number Diff line change
@@ -189,7 +189,7 @@ class Storage(client: Client) : Service(client) {


/**
* Delete File
* Delete file
*
* Delete a file by its unique ID. Only users with write permissions have access to delete this resource.
*
4 changes: 2 additions & 2 deletions library/src/main/java/io/appwrite/services/Teams.kt
Original file line number Diff line number Diff line change
@@ -275,7 +275,7 @@ class Teams(client: Client) : Service(client) {
/**
* List team memberships
*
* Use this endpoint to list a team&#039;s members using the team&#039;s ID. All team members have read access to this endpoint.
* Use this endpoint to list a team&#039;s members using the team&#039;s ID. All team members have read access to this endpoint. Hide sensitive attributes from the response by toggling membership privacy in the Console.
*
* @param teamId Team ID.
* @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, teamId, invited, joined, confirm
@@ -369,7 +369,7 @@ class Teams(client: Client) : Service(client) {
/**
* Get team membership
*
* Get a team member by the membership unique id. All team members have read access for this resource.
* Get a team member by the membership unique id. All team members have read access for this resource. Hide sensitive attributes from the response by toggling membership privacy in the Console.
*
* @param teamId Team ID.
* @param membershipId Membership ID.