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 Java tutorial #356

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
25 changes: 17 additions & 8 deletions src/routes/docs/tutorials/android/step-1/+page.markdoc
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
---
layout: tutorial
title: Coming soon
title: Build a recipe sharing app with Android
description: Learn to build an Android app with no backend code using an Appwrite backend.
framework: Android
step: 1
draft: true
difficulty: beginner
---

Improve the docs, add this guide.
**Recipewrite**: an Android app to share and find all the delicious recipes that left you licking your fingers.
In this tutorial, you will build Recipewrite with Appwrite and Java for 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. Database Queries
5. Pagination

# Prerequisites {% #prerequisites %}
1. Basic knowledge of Java.
2. Have [Java](https://www.java.com/en/) and [Android Studio](https://developer.android.com/studio) installed on your computer.

If you are stuck at any point, you can refer to the final code repository of this tutorial [here](https://github.com/letsintegreat/Recipewrite).
30 changes: 30 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,30 @@
---
layout: tutorial
title: Initialize project
description: Learn to build an Android app with no backend code using an Appwrite backend.
step: 2
difficulty: beginner
---

# Initialize Android Studio project {% #initialize-android-studio-project %}

Open Android Studio and click **New Project** to create a new project. Select **Empty Views Activity**, and click **Next**.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update screenshot, this is outdated version of AS

Copy link

@letsintegreat letsintegreat Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Here's the new screenshot. How am I supposed to make this change in this branch though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@letsintegreat Oh no you don't have to, I'll be making these changes :)


![Empty Activity](/images/docs/tutorials/recipewrite-empty-activity.png)

Name your project **Recipewrite**, under **Language** select Java, and minimum SDK would be **24**.

![New Project](/images/docs/tutorials/recipewrite-new-project.png)

# Add dependencies {% #add-dependencies %}

Open `app/build.gradle` file, update `compileSdk` and `targetSdk` to **34**, then find `dependencies` block, and add the Appwrite dependency along with existing ones.

```
dependencies {
implementation("io.appwrite:sdk-for-android:4.0.0")
... other dependencies
}
```

Click **Sync Now** to sync your dependencies.
85 changes: 85 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,85 @@
---
layout: tutorial
title: Setup Appwrite
description: Learn to build an Android app with no backend code using an Appwrite backend.
step: 3
difficulty: beginner
---

# 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 a **Android app**. **Package Name** can be found in app level gradle file.

{% 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 the optional steps.

# Connect your app with Appwrite {% #connect-your-app-with-appwrite %}

Create **Appwrite.java** in the same directory that contains **MainActivity.java**, this will handle our app's interaction with Appwrite server. Replace `<PROJECT_ID>` with your new project's id, which can be found beside your project's name in overview tab.

```java
package com.example.recipewrite;

import android.content.Context;

import io.appwrite.Client;
import io.appwrite.services.Account;
import io.appwrite.services.Databases;

public class Appwrite {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing imports

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just providing the entire classes and methods and not caring about package names, imports, etc. That is not an issue because of modern text editors, and I believe they would just add to the noise in our tutorial. LMK if you feel otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@letsintegreat I'll be taking this PR forward :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gewenyu99 oh okay. Is there anything else I need to do on my end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gewenyu99 oh okay. Is there anything else I need to do on my end?

Nope, we'll contact you soon about swag 😉

private static Client client;
private static Account account;
private static Databases databases;

private static final String projectID = "[project-id]";
private static final String endpoint = "https://cloud.appwrite.io/v1"; // Add local address if you are running Appwrite locally

public static void init(Context context) {
client = new Client(context);
client.setEndpoint(endpoint);
client.setProject(projectID);
client.setSelfSigned(true);

account = new Account(client);
databases = new Databases(client);
}
}
```

Finally, call this `init` method in `onCreate` method of **MainActivity.java**.

```java
package com.example.recipewrite;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Appwrite.init(this);
}
}
```
Loading