jamesonwilliams / simple-datastore

A sample Android application, showing a simple use of the AWS Amplify DataStore.

Home Page:https://github.com/aws-amplify/amplify-android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple DataStore Sample App

The purpose of this application is to test the Amplify DataStore.

Installation

To use, install, and evaluate this application, please do the following:

  1. Checkout and build Amplify Android @ main. Publish to your local repository:
./gradlew build publishToMavenLocal

Detailed instructions are in the Contributing Guide.

  1. Import this current project into Android studio. Try to build it.

  2. Using the schema.graphql as below, generate models and deploy an AppSync backend. Make sure that this step updates your local configuration.

enum PostStatus {
  ACTIVE
  INACTIVE
}

type Post @model {
  id: ID!
  title: String!
  rating: Int!
  status: PostStatus!
}

Use amplify init, amplify add api. Follow the guide to add a DataStore endpoint -- except choose "Cognito User Pools" as the auth type, instead of API key. Run amplify push when done, and wait.

  1. Create a valid Cognito user, in your the user pool you just created.
aws cognito-idp admin-create-user \
    --user-pool-id <pool_id_that_amplify_created> \
    --username <some_username>

aws cognito-idp admin-set-user-password \
    --user-pool-id <pool_id_that_amplify_created> \
    --username <some_username> \
    --password <some_password> \
    --permanent

Add the <some_username> and <some_password> values into app/src/main/res/values/sign_in.xml. For example, your sign_in.xml might look as below:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="username" type="id">koolusr44</string>
    <string name="password" type="id">koolpass99</string>
</resources>
  1. Re-build this current app and install it on an Android device.

Usage

For repeatable results, you should always swipe-kill the app, before running a manual test case:

adb shell am force-stop com.amplifyframework.datastore.sample
adb uninstall com.amplifyframework.datastore.sample

You may also manually update/clear your AppSync backend, while using this app. It can be useful to do this before opening this app, so that the app won't sync a bunch of old data. The script in clear-db.sh is useful for this.

The best way to understand the behavior of the different buttons is to read the MainActivity.java.

Portrait Mode

These are the behaviors of the buttons in the portrait mode of the UI:

  1. CREATE A POST: Create a single post, with some random data. Display this post on the screen.
  2. UPDATE ALL: Query all posts, and update them all. Display each update on the screen.
  3. LIST ALL POSTS: List all current posts, onto the screen.
  4. DELETE ALL POSTS: Query all posts, and delete each one. Display each deletion to the screen.
  5. SUBSCRIBE...: Start a new subscription. The subscription will emit information about its lifecycle onto the screen.
  6. STOP EVERYTHING: Stop/cancel any ongoing operation(s). This will cancel mutation, and it would also tear down a subscription.
  7. CLEAR LOG: This doesn't do anything to the DataStore. This just clears the log in the app window.
  8. SIGN IN: Sign in to Cognito using the username and password provided in your app/src/main/res/values/sign_in.xml

Landscape Mode

The left side shows client-side state, the right side shows AppSync side state. As of this time, the right side doesn't include _delete, _lastChangedAt, _version, so it is of limited utility.

About

A sample Android application, showing a simple use of the AWS Amplify DataStore.

https://github.com/aws-amplify/amplify-android


Languages

Language:Kotlin 73.3%Language:Java 21.9%Language:Shell 4.7%