Skip to content
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

Feat android tutorial #529

Merged
merged 33 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
05e7ac4
feat: android tutorial
loks0n Oct 4, 2023
27af8fd
fix: missing groovy highlighting
loks0n Oct 4, 2023
94f6354
feat: add groovy highlighting
loks0n Oct 4, 2023
3d2ba86
chore: vincent review fixes
loks0n Oct 4, 2023
e490e85
fix: svelte -> android
loks0n Oct 4, 2023
366725b
Fix style and typos
Oct 5, 2023
f7adebd
chore: vincent feedback
loks0n Oct 6, 2023
0a60351
Merge branch 'main' of https://github.com/appwrite/website into feat-…
loks0n Oct 6, 2023
f7832de
chore: review feedback
loks0n Oct 9, 2023
6e9a41f
feat: error handling
loks0n Oct 9, 2023
6bae438
Add nuxt tutorial
evelinabe Oct 25, 2023
87e00fd
Update texts in Nuxt tutorial
evelinabe Oct 28, 2023
f58e0e2
Update src/routes/docs/tutorials/nuxt/step-7/+page.markdoc
evelinabe Oct 31, 2023
1cbd9eb
Add env variables, update texts
evelinabe Nov 13, 2023
5cf20e2
Merge pull request #243 from evelinabe/issue84-nuxt-tutorial
Nov 17, 2023
b88b0f0
Fixes minor format issues
Nov 17, 2023
7406592
Merge branch 'main' into feat-nuxt-tutorial
Nov 24, 2023
3538fa6
Add nuxt tutorial
Nov 24, 2023
4239f7d
Implement some of Thomas' comments
Jan 10, 2024
a786030
Fix alll suggestions
Jan 11, 2024
a7b9154
Apply suggestions from code review
Jan 12, 2024
3b1a0b9
Merge branch 'main' into feat-nuxt-tutorial
Jan 12, 2024
2f268d3
Refactor login form
Jan 12, 2024
06440e3
inverse script setup and template
Jan 12, 2024
4808e9e
Address all comments
Jan 12, 2024
1f81c8d
Add missing comma
Jan 15, 2024
de383d2
Merge branch 'main' into feat-android-tutorial
Jan 15, 2024
dd357ef
Fix more merge isues
Jan 15, 2024
6e32958
Updated Android tutorial, confirmed it works heehee
Jan 16, 2024
4741bb3
Merge branch 'feat-nuxt-tutorial' into feat-android-tutorial
Jan 16, 2024
bc653c5
Fix mistake in merge with main
Jan 16, 2024
2231e89
Apply suggestions from code review
Jan 17, 2024
eca713b
Clean up the rebased Nuxt tutorial
Jan 18, 2024
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
2 changes: 2 additions & 0 deletions src/lib/utils/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import plaintext from 'highlight.js/lib/languages/plaintext';
import graphql from 'highlight.js/lib/languages/graphql';
import http from 'highlight.js/lib/languages/http';
import css from 'highlight.js/lib/languages/css';
import groovy from 'highlight.js/lib/languages/groovy';
import { Platform } from './references';

const languages = {
Expand Down Expand Up @@ -58,6 +59,7 @@ const languages = {
rb: ruby,
cs: csharp,
css: css,
groovy: groovy,
svelte: xml
} as const satisfies Record<string, LanguageFn>;

Expand Down
7 changes: 4 additions & 3 deletions src/lib/utils/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export const platformMap: Record<Language | string, string> = {
[Platform.ServerRest]: 'REST',
sh: 'Shell',
js: 'JavaScript',
jsx: 'React',
tsx: 'React',
ts: 'TypeScript',
jsx: 'React',
tsx: 'React',
typescript: 'TypeScript',
dart: 'Dart',
java: 'Java',
Expand Down Expand Up @@ -97,7 +97,8 @@ export const platformMap: Record<Language | string, string> = {
yaml: 'YAML',
text: 'Text',
vue: 'Vue',
svelte: 'Svelte'
svelte: 'Svelte',
groovy: 'Groovy'
};

export const serviceMap: Record<Service, string> = {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/docs/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,4 @@
:global(.theme-dark) .bg-overlay {
background: linear-gradient(to right, #19191c00 0%, #19191c00 10%, #19191c);
}
</style>
</style>
6 changes: 3 additions & 3 deletions src/routes/docs/quick-starts/android/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Find your project's ID in the **Settings** page.
Create a new file `Appwrite.kt` and add the following code to it, replacing `[YOUR_PROJECT_ID]` with your project ID.

```kotlin
package com.example.myapplication
package <YOUR_ROOT_PACKAGE_HERE>

import android.content.Context
import io.appwrite.Client
Expand Down Expand Up @@ -139,7 +139,7 @@ object Appwrite {
Add the following code to `MainActivity.kt`.

```kotlin
package com.example.myapplication
package <YOUR_ROOT_PACKAGE_HERE>

import android.os.Bundle
import androidx.activity.ComponentActivity
Expand All @@ -151,7 +151,7 @@ import androidx.compose.runtime.*
import androidx.compose.ui.*
import androidx.compose.ui.text.input.*
import androidx.compose.ui.unit.*
import com.example.myapplication.ui.theme.MyApplicationTheme
import <YOUR_ROOT_PACKAGE_HERE>.ui.theme.MyApplicationTheme
import kotlinx.coroutines.launch

class MainActivity : ComponentActivity() {
Expand Down
42 changes: 21 additions & 21 deletions src/routes/docs/quick-starts/nuxt/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,6 @@ export { ID } from 'appwrite';
Add the following code to `app.vue`.

```html
<template>
<div>
<p>
{{ loggedInUser ? `Logged in as ${loggedInUser.name}` : 'Not logged in' }}
</p>

<form>
<input type="email" placeholder="Email" v-model="email" />
<input type="password" placeholder="Password" v-model="password" />
<input type="text" placeholder="Name" v-model="name" />
<button type="button" @click="login(email, password)">Login</button>
<button type="button" @click="register">
Register
</button>
<button type="button" @click="logout">
Logout
</button>
</form>
</div>
</template>

<script setup>
import { ref } from 'vue';
import { account, ID } from './utils/appwrite.js';
Expand All @@ -123,6 +102,27 @@ const logout = async () => {
loggedInUser.value = null;
};
</script>

<template>
<div>
<p>
{{ loggedInUser ? `Logged in as ${loggedInUser.name}` : 'Not logged in' }}
</p>

<form>
<input type="email" placeholder="Email" v-model="email" />
<input type="password" placeholder="Password" v-model="password" />
<input type="text" placeholder="Name" v-model="name" />
<button type="button" @click="login(email, password)">Login</button>
<button type="button" @click="register">
Register
</button>
<button type="button" @click="logout">
Logout
</button>
</form>
</div>
</template>
```
{% /section %}

Expand Down
1 change: 1 addition & 0 deletions src/routes/docs/tutorials/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
android: 'icon-android',
apple: 'icon-apple',
flutter: 'icon-flutter',
nuxt: 'icon-nuxt',
stripe: 'icon-stripe',
refine: 'aw-icon-refine'
};
Expand Down
22 changes: 14 additions & 8 deletions src/routes/docs/tutorials/android/step-1/+page.markdoc
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
---
layout: tutorial
title: Coming soon
title: Build an ideas tracker with Android
description: Learn to build an Android app with no backend code using an Appwrite backend.
framework: Android
category: Mobile and native
step: 1
draft: true
---

Improve the docs, add this guide.
**Idea tracker**: an app to track all the side project ideas that you'll start, but probably never finish.
In this tutorial, you will build Idea tracker with Appwrite and Android.

We still don't have this guide in place, but we do have some great news.
The Appwrite docs, just like Appwrite, is completely open sourced.
This means, anyone can help improve them and add new guides and tutorials.
# Concepts {% #concepts %}
This tutorial will introduce the following concepts:

If you see this page, **we're actively looking for contributions to this page**.
Follow our contribution guidelines, open a PR to [our Website repo](https://github.com/appwrite/website), and collaborate with our core team to improve this page.
1. Setting up your first project
2. Authentication
3. Databases and collections
4. Queries and pagination
5. Storage

# Prerequisites {% #prerequisites %}
1. Basic knowledge of Kotlin and Android development.
2. Have [Android Studio](https://developer.android.com/studio) installed on your computer.
48 changes: 48 additions & 0 deletions src/routes/docs/tutorials/android/step-2/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
layout: tutorial
title: Create app
description: Create a Android app project using Appwrite.
step: 2
---

# Create Android project {% #create-android-project %}

Create a Android app with the Android Studio **New Project** wizard. Select **Empty Activity** as the template.

# Add dependencies {% #add-dependencies %}

Install the Android Appwrite SDK.

Add the following to your dependencies in the `app/build.gradle` file:

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

In case you need to create OAuth 2 sessions in the future, the following activity needs to be added inside the `<application>` tag, along side the existing `<activity>` tags in your [AndroidManifest.xml](https://developer.android.com/guide/topics/manifest/manifest-intro).
Be sure to replace the **<PROJECT_ID>** string with your actual Appwrite project ID.
You can find your Appwrite project ID in you project settings screen in your Appwrite Console.

```xml
<manifest ...>
...
<application ...>
...
<!-- Add this inside the `<application>` tag, along side the existing `<activity>` tags -->
<activity android:name="io.appwrite.views.CallbackActivity" android:exported="true">
<intent-filter android:label="android_web_auth">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="appwrite-callback-[PROJECT_ID]" />
</intent-filter>
</activity>
</application>
</manifest>
```

# Using the emulator {% #using-the-emulator %}

Run your app on the [Android emulator](https://developer.android.com/studio/run/emulator).
You can use the emulator to test your app on different versions of the Android platform and different screen sizes without the need to use physical devices.
For now, you should see a blank screen.
65 changes: 65 additions & 0 deletions src/routes/docs/tutorials/android/step-3/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
layout: tutorial
title: Set up Appwrite
description: Initialize Appwrite in your Android project.
step: 3
---

# Create project {% #create-project %}

Head to the [Appwrite Console](https://cloud.appwrite.io/console).

{% only_dark %}
![Create project screen](/images/docs/quick-starts/dark/create-project.png)
{% /only_dark %}
{% only_light %}
![Create project screen](/images/docs/quick-starts/create-project.png)
{% /only_light %}

If this is your first time using Appwrite, create an account and create your first project.

Then, under **Add a platform**, add an **Android app**. The **Package Name** should be the same as the one you used when creating your app.

{% only_dark %}
![Add a platform](/images/docs/quick-starts/dark/add-platform.png)
{% /only_dark %}
{% only_light %}
![Add a platform](/images/docs/quick-starts/add-platform.png)
{% /only_light %}

You can skip optional steps.

# Initialize Appwrite SDK {% #init-sdk %}

To use Appwrite in our Android app, we'll need to find our project ID. Find your project's ID in the **Settings** page.

{% only_dark %}
![Project settings screen](/images/docs/quick-starts/dark/project-id.png)
{% /only_dark %}
{% only_light %}
![Project settings screen](/images/docs/quick-starts/project-id.png)
{% /only_light %}

Create a new file `services/Appwrite.kt` to hold our Appwrite related code.
Only one instance of the `Client` class should be created per app.
Add the following code to it, replacing `<YOUR_PROJECT_ID>` with your project ID.

```kotlin
package <YOUR_ROOT_PACKAGE_HERE>.services

import android.content.Context
import io.appwrite.Client

object Appwrite {
private const val ENDPOINT = "https://cloud.appwrite.io/v1"
private const val PROJECT_ID = "<YOUR_PROJECT_ID>"

private lateinit var client: Client

fun init(context: Context) {
client = Client(context)
.setEndpoint(ENDPOINT)
.setProject(PROJECT_ID)
}
}
```
Loading