Skip to content

Commit 469a0f4

Browse files
authored
Merge pull request #218 from appwrite/fix-android-examples
feat: android example fixes
2 parents ab56ba3 + 989acc8 commit 469a0f4

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed
Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
1+
import androidx.appcompat.app.AppCompatActivity
2+
import android.os.Bundle
3+
import kotlinx.coroutines.GlobalScope
4+
import kotlinx.coroutines.launch
15
import {{ sdk.namespace | caseDot }}.Client
26
import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }}
37

4-
val client = Client(context)
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)
514
{% if method.security|length > 0 %}
6-
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
15+
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
716
{% for node in method.security %}
817
{% for key,header in node|keys %}
9-
.set{{header | caseUcfirst}}("{{node[header]['x-appwrite']['demo']}}") // {{node[header].description}}
10-
{% endfor %}{% endfor %}{% endif %}
18+
.set{{header | caseUcfirst}}("{{node[header]['x-appwrite']['demo']}}") // {{node[header].description}}
19+
{% endfor %}
20+
{% endfor %}
21+
{% endif %}
22+
23+
val {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client)
24+
25+
GlobalScope.launch {
26+
val response = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | length == 0 %}){% endif %}
27+
28+
{% for parameter in method.parameters.all %}
29+
{% if parameter.required %}
30+
{{parameter.name}} = {{ parameter | paramExample }}{% if not loop.last %},{% endif %}
1131

12-
val {{ service.name | caseCamel }}Service = {{ service.name | caseUcfirst }}(client)
13-
val response = {{ service.name | caseCamel }}Service.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{{ parameter | paramExample }}{% endif %}{% endfor %})
14-
val json = response.body?.string()
32+
{% endif %}
33+
{% if loop.last %}
34+
)
35+
{% endif %}
36+
{% endfor %}
37+
val json = response.body?.string()
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)