Giter Site home page Giter Site logo

cedriclange / firestore-android-arch-components Goto Github PK

View Code? Open in Web Editor NEW

This project forked from amrro/firestore-android-arch-components

0.0 0.0 0.0 1.77 MB

Firestore sample with Android architecture component.

License: Apache License 2.0

Java 100.00%

firestore-android-arch-components's Introduction

Cloud Firestore Quickstart

Introduction

Fire Eats is a restaurant recommendation app built on Cloud Firestore alongside Android Architecture Component.

After reading about the new Android Architecture Component's guide to architect your app. I converted the orignal sample presented by firebase to use the component with respect due architecture recommendation in the guide.

For more information about Firestore visit the docs. For more information about Android Architecture Components visit the docs.

Getting Started

Security Rules

Add the following security rules to your project in the: rules tab:

service cloud.firestore {  
  match /databases/{database}/documents {
    // Anyone can read a restaurant, only authorized
    // users can create, update, or delete them.
  	 match /restaurants/{restaurantId} {
    	 allow read: if true;
    	 allow create, update, delete: if request.auth.uid != null;
    }
    
    // Anyone can read a rating. Only the user who made the rating
    // can delete it. Ratings can never be updated.
    match /restaurants/{restaurantId}/ratings/{ratingId} {
    	 allow read: if true;
      allow create: if request.auth.uid != null;
    	 allow delete: if request.resource.data.userId == request.auth.uid;
    	 allow update: if false;
    }
  }
}

Run the App

  • When you open the app you will be prompted to sign in, choose any email and password.
  • When you first open the app it will be empty, choose Add Random Items from the overflow menu to add some new entries.

Result

Indexes

As you use the app's filter functionality you may see warnings in logcat that look like this:

com.google.firebase.example.fireeats W/Firestore Adapter: onEvent:error
com.google.firebase.firestore.FirebaseFirestoreException: FAILED_PRECONDITION: The query requires an index. You can create it here: https://console.firebase.google.com/project/...

This is because indexes are required for most compound queries in Cloud Firestore. Clicking on the link from the error message will automatically open the index creation UI in the Firebase console with the correct paramters filled in:

This app also provides an index specification file in indexes.json which specifies all indexes required to run the application. You can add all of these indexes programatically using the Firebase CLI.

firestore-android-arch-components's People

Contributors

ahmed-abdelmeged avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.