Skip to content

Commit 4530c0e

Browse files
Merge pull request #10 from appwrite/dev
feat: Bug fixes and version bump
2 parents 29d85f7 + ab3029b commit 4530c0e

File tree

7 files changed

+77
-15
lines changed

7 files changed

+77
-15
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
![Maven Central](https://img.shields.io/maven-central/v/io.appwrite/sdk-for-android.svg?color=green&style=flat-square)
44
![License](https://img.shields.io/github/license/appwrite/sdk-for-android.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-0.8.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-0.9.0-blue.svg?style=flat-square)
66
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
77
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite_io?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite_io)
88
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
99

10-
**This SDK is compatible with Appwrite server version 0.8.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).**
10+
**This SDK is compatible with Appwrite server version 0.9.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-android/releases).**
1111

1212
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Android SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
1313

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import androidx.appcompat.app.AppCompatActivity
2+
import android.os.Bundle
3+
import kotlinx.coroutines.GlobalScope
4+
import kotlinx.coroutines.launch
5+
import io.appwrite.Client
6+
import io.appwrite.services.Account
7+
8+
class MainActivity : AppCompatActivity() {
9+
override fun onCreate(savedInstanceState: Bundle?) {
10+
super.onCreate(savedInstanceState)
11+
setContentView(R.layout.activity_main)
12+
13+
val client = Client(applicationContext)
14+
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
15+
.setProject("5df5acd0d48c2") // Your project ID
16+
17+
val account = Account(client)
18+
19+
GlobalScope.launch {
20+
val response = account.getSession(
21+
sessionId = "[SESSION_ID]"
22+
)
23+
val json = response.body?.string()
24+
}
25+
}
26+
}

example/src/main/java/io/appwrite/android/ui/accounts/AccountsFragment.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,22 @@ import android.widget.Toast
88
import androidx.activity.ComponentActivity
99
import androidx.databinding.DataBindingUtil
1010
import androidx.fragment.app.Fragment
11+
import androidx.fragment.app.viewModels
1112
import androidx.lifecycle.Observer
12-
import androidx.lifecycle.ViewModelProvider
1313
import io.appwrite.android.R
1414
import io.appwrite.android.databinding.FragmentAccountBinding
1515

1616

1717
class AccountsFragment : Fragment() {
1818

1919
private lateinit var binding: FragmentAccountBinding
20-
private lateinit var viewModel: AccountsViewModel
20+
private val viewModel: AccountsViewModel by viewModels()
2121

2222
override fun onCreateView(
2323
inflater: LayoutInflater ,
2424
container: ViewGroup? ,
2525
savedInstanceState: Bundle?
26-
): View? {
27-
viewModel = ViewModelProvider(this).get(AccountsViewModel::class.java)
26+
): View {
2827
binding = DataBindingUtil.inflate(
2928
inflater,
3029
R.layout.fragment_account,

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ android {
2828
targetSdkVersion(30)
2929
versionCode = 1
3030
versionName = "1.0"
31-
31+
buildConfigField "String", "SDK_VERSION", "\"${PUBLISH_VERSION}\""
3232
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3333
consumerProguardFiles("consumer-rules.pro")
3434
}
3535

3636
buildTypes {
37-
named("release") {
37+
release {
3838
minifyEnabled false
3939
proguardFiles(
4040
getDefaultProguardFile("proguard-android-optimize.txt"),

library/src/main/java/io/appwrite/Client.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.appwrite
33
import android.content.Context
44
import android.content.pm.PackageManager
55
import com.google.gson.Gson
6+
import io.appwrite.appwrite.BuildConfig
67
import io.appwrite.exceptions.AppwriteException
78
import io.appwrite.extensions.JsonExtensions.fromJson
89
import io.appwrite.models.Error
@@ -69,8 +70,8 @@ class Client @JvmOverloads constructor(
6970
"content-type" to "application/json",
7071
"origin" to "appwrite-android://${context.packageName}",
7172
"user-agent" to "${context.packageName}/${appVersion}, ${System.getProperty("http.agent")}",
72-
"x-sdk-version" to "appwrite:android:0.0.1",
73-
"x-appwrite-response-format" to "0.8.0"
73+
"x-sdk-version" to "appwrite:android:${BuildConfig.SDK_VERSION}",
74+
"x-appwrite-response-format" to "0.9.0"
7475
)
7576
config = mutableMapOf()
7677

@@ -227,7 +228,13 @@ class Client @JvmOverloads constructor(
227228
return@forEach
228229
}
229230
is List<*> -> {
230-
httpBuilder.addQueryParameter(it.key + "[]", it.value.toString())
231+
val list = it.value as List<*>
232+
for (index in list.indices) {
233+
httpBuilder.addQueryParameter(
234+
"${it.key}[]",
235+
list[index].toString()
236+
)
237+
}
231238
}
232239
else -> {
233240
httpBuilder.addQueryParameter(it.key, it.value.toString())

library/src/main/java/io/appwrite/services/Account.kt

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ class Account(private val client: Client) : BaseService(client) {
134134
* Use this endpoint to create a JSON Web Token. You can use the resulting JWT
135135
* to authenticate on behalf of the current user when working with the
136136
* Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes
137-
* from its creation and will be invalid if the user will logout.
137+
* from its creation and will be invalid if the user will logout in that time
138+
* frame.
138139
*
139140
* @return [Response]
140141
*/
@@ -431,9 +432,10 @@ class Account(private val client: Client) : BaseService(client) {
431432
*
432433
* Use this endpoint to allow a new user to register an anonymous account in
433434
* your project. This route will also create a new session for the user. To
434-
* allow the new user to convert an anonymous account to a normal account
435-
* account, you need to update its [email and
436-
* password](/docs/client/account#accountUpdateEmail).
435+
* allow the new user to convert an anonymous account to a normal account, you
436+
* need to update its [email and
437+
* password](/docs/client/account#accountUpdateEmail) or create an [OAuth2
438+
* session](/docs/client/account#accountCreateOAuth2Session).
437439
*
438440
* @return [Response]
439441
*/
@@ -527,6 +529,31 @@ class Account(private val client: Client) : BaseService(client) {
527529

528530
}
529531

532+
/**
533+
* Get Session By ID
534+
*
535+
* Use this endpoint to get a logged in user's session using a Session ID.
536+
* Inputting 'current' will return the current session being used.
537+
*
538+
* @param sessionId
539+
* @return [Response]
540+
*/
541+
@JvmOverloads
542+
@Throws(AppwriteException::class)
543+
suspend fun getSession(
544+
sessionId: String
545+
): Response {
546+
val path = "/account/sessions/{sessionId}".replace("{sessionId}", sessionId)
547+
val params = mapOf<String, Any?>(
548+
)
549+
550+
val headers = mapOf(
551+
"content-type" to "application/json"
552+
)
553+
554+
return client.call("GET", path, headers, params)
555+
}
556+
530557
/**
531558
* Delete Account Session
532559
*

library/src/main/java/io/appwrite/services/Storage.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class Storage(private val client: Client) : BaseService(client) {
195195
* @param fileId
196196
* @param width
197197
* @param height
198+
* @param gravity
198199
* @param quality
199200
* @param borderWidth
200201
* @param borderColor
@@ -211,6 +212,7 @@ class Storage(private val client: Client) : BaseService(client) {
211212
fileId: String,
212213
width: Int? = null,
213214
height: Int? = null,
215+
gravity: String? = null,
214216
quality: Int? = null,
215217
borderWidth: Int? = null,
216218
borderColor: String? = null,
@@ -224,6 +226,7 @@ class Storage(private val client: Client) : BaseService(client) {
224226
val params = mapOf<String, Any?>(
225227
"width" to width,
226228
"height" to height,
229+
"gravity" to gravity,
227230
"quality" to quality,
228231
"borderWidth" to borderWidth,
229232
"borderColor" to borderColor,

0 commit comments

Comments
 (0)