├── .github ├── ISSUE_TEMPLATE │ └── bug_report.md └── workflows │ └── android.yml ├── .gitignore ├── .vscode └── settings.json ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle.kts ├── lint.xml ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── google │ │ └── firebase │ │ └── example │ │ └── fireeats │ │ ├── FilterDialogFragment.kt │ │ ├── Filters.kt │ │ ├── MainActivity.kt │ │ ├── MainFragment.kt │ │ ├── RatingDialogFragment.kt │ │ ├── RestaurantDetailFragment.kt │ │ ├── adapter │ │ ├── FirestoreAdapter.kt │ │ ├── RatingAdapter.kt │ │ └── RestaurantAdapter.kt │ │ ├── model │ │ ├── Rating.kt │ │ └── Restaurant.kt │ │ ├── util │ │ ├── AuthInitializer.kt │ │ ├── FirestoreInitializer.kt │ │ ├── RatingUtil.kt │ │ └── RestaurantUtil.kt │ │ └── viewmodel │ │ └── MainActivityViewModel.kt │ └── res │ ├── drawable-hdpi │ └── pizza_monster.png │ ├── drawable-mdpi │ └── pizza_monster.png │ ├── drawable-nodpi │ └── food_1.png │ ├── drawable-xhdpi │ └── pizza_monster.png │ ├── drawable-xxhdpi │ └── pizza_monster.png │ ├── drawable │ ├── bg_shadow.xml │ ├── gradient_up.xml │ ├── ic_add_white_24px.xml │ ├── ic_arrow_back_white_24px.xml │ ├── ic_close_white_24px.xml │ ├── ic_fastfood_white_24dp.xml │ ├── ic_filter_list_white_24px.xml │ ├── ic_local_dining_white_24px.xml │ ├── ic_monetization_on_white_24px.xml │ ├── ic_place_white_24px.xml │ ├── ic_restaurant_white_24px.xml │ └── ic_sort_white_24px.xml │ ├── layout │ ├── activity_main.xml │ ├── activity_restaurant_detail.xml │ ├── dialog_filters.xml │ ├── dialog_rating.xml │ ├── fragment_main.xml │ ├── fragment_restaurant_detail.xml │ ├── item_rating.xml │ └── item_restaurant.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── navigation │ └── nav_graph.xml │ ├── values-v21 │ └── styles.xml │ ├── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ └── network_security_config.xml ├── build.gradle.kts ├── build.sh ├── docs └── home.png ├── firebase.json ├── firestore.indexes.json ├── firestore.rules ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── mock-google-services.json ├── settings.gradle.kts └── steps ├── img ├── 1129441c6ebb5eaf.png ├── 4c68c6654f4168ad.png ├── 67898572a35672a5.png ├── 73d151ed16016421.png ├── 78fa16cdf8ef435a.png ├── 7a67a8a400c80c50.png ├── 95691e9b71ba55e3.png ├── 9d2f625aebcab6af.png ├── 9e45f40faefce5d0.png ├── a670188398c3c59.png ├── de06424023ffb4b9.png ├── emulators-auth.png ├── emulators-firebase.png ├── f9e670f40bd615b0.png └── sign-in-providers.png └── index.lab.md /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Describe a bug you encountered in the codelab 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 18 | 19 | ### Step 1: Describe your environment 20 | 21 | * Android device: _____ 22 | * Android OS version: _____ 23 | 24 | ### Step 2: Describe the problem: 25 | 26 | #### Steps to reproduce: 27 | 28 | 1. _____ 29 | 2. _____ 30 | 3. _____ 31 | 32 | #### Observed Results: 33 | 34 | * What happened? This could be a description, `logcat` output, etc. 35 | 36 | #### Expected Results: 37 | 38 | * What did you expect to happen? 39 | 40 | #### Relevant Code: 41 | 42 | ``` 43 | // TODO(you): code here to reproduce the problem 44 | ``` 45 | -------------------------------------------------------------------------------- /.github/workflows/android.yml: -------------------------------------------------------------------------------- 1 | name: Android CI 2 | 3 | on: 4 | - pull_request 5 | - push 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: set up JDK 17 13 | uses: actions/setup-java@v1 14 | with: 15 | java-version: 17 16 | - name: Build with Gradle 17 | run: ./build.sh 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | local.properties 3 | .idea 4 | build/ 5 | .DS_Store 6 | *.iml 7 | *.apk 8 | *.aar 9 | *.zip 10 | google-services.json 11 | 12 | .project 13 | .settings 14 | .classpath 15 | 16 | .firebaserc 17 | *debug.log 18 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.configuration.updateBuildConfiguration": "disabled" 3 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to friendlyeats-android 2 | 3 | We'd love for you to contribute to our source code and to make this project even better than it is today! Here are the guidelines we'd like you to follow: 4 | 5 | - [Code of Conduct](#coc) 6 | - [Question or Problem?](#question) 7 | - [Issues and Bugs](#issue) 8 | - [Feature Requests](#feature) 9 | - [Submission Guidelines](#submit) 10 | - [Coding Rules](#rules) 11 | - [Signing the CLA](#cla) 12 | 13 | ## Code of Conduct 14 | 15 | As contributors and maintainers of the friendlyeats-android project, we pledge to respect everyone who contributes by posting issues, updating documentation, submitting pull requests, providing feedback in comments, and any other activities. 16 | 17 | Communication through any of Firebase's channels (GitHub, StackOverflow, Google+, Twitter, etc.) must be constructive and never resort to personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 18 | 19 | We promise to extend courtesy and respect to everyone involved in this project regardless of gender, gender identity, sexual orientation, disability, age, race, ethnicity, religion, or level of experience. We expect anyone contributing to the project to do the same. 20 | 21 | If any member of the community violates this code of conduct, the maintainers of the friendlyeats-android project may take action, removing issues, comments, and PRs or blocking accounts as deemed appropriate. 22 | 23 | If you are subject to or witness unacceptable behavior, or have any other concerns, please drop us a line at samstern@google.com. 24 | 25 | ## Got a Question or Problem? 26 | 27 | If you have questions about how to use the friendlyeats-android, please open a Github issue. If you need help debugging your own app, please please direct these to [StackOverflow][stackoverflow] and use the `firebase` tag. 28 | 29 | If you feel that we're missing an important bit of documentation, feel free to 30 | file an issue so we can help. Here's an example to get you started: 31 | 32 | ``` 33 | What are you trying to do or find out more about? 34 | 35 | Where have you looked? 36 | 37 | Where did you expect to find this information? 38 | ``` 39 | 40 | ## Found an Issue? 41 | If you find a bug in the source code or a mistake in the documentation, you can help us by 42 | submitting an issue. Even better you can submit a Pull Request with a fix. 43 | 44 | See [below](#submit) for some guidelines. 45 | 46 | ## Submission Guidelines 47 | 48 | ### Submitting an Issue 49 | Before you submit your issue search the archive, maybe your question was already answered. 50 | 51 | If your issue appears to be a bug, and hasn't been reported, open a new issue. 52 | Help us to maximize the effort we can spend fixing issues and adding new 53 | features, by not reporting duplicate issues. Providing the following information will increase the 54 | chances of your issue being dealt with quickly: 55 | 56 | * **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps 57 | * **Motivation for or Use Case** - explain why this is a bug for you 58 | * **Environment** - is this a problem with all devices or only some? 59 | * **Reproduce the Error** - provide a live example or a unambiguous set of steps. 60 | * **Related Issues** - has a similar issue been reported before? 61 | * **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be 62 | causing the problem (line of code or commit) 63 | 64 | **If you get help, help others. Good karma rulez!** 65 | 66 | Here's a template to get you started: 67 | 68 | ``` 69 | Device: 70 | Operating system version: 71 | Firebase SDK version: 72 | 73 | What steps will reproduce the problem: 74 | 1. 75 | 2. 76 | 3. 77 | 78 | What is the expected result? 79 | 80 | What happens instead of that? 81 | 82 | Please provide any other information below, and attach a screenshot if possible. 83 | ``` 84 | 85 | ### Submitting a Pull Request 86 | Before you submit your pull request consider the following guidelines: 87 | 88 | * Search [GitHub](https://github.com/firebase/friendlyeats-android/pulls) for an open or closed Pull Request 89 | that relates to your submission. You don't want to duplicate effort. 90 | * Please sign our [Contributor License Agreement (CLA)](#cla) before sending pull 91 | requests. We cannot accept code without this. 92 | * Make your changes in a new git branch: 93 | 94 | ```shell 95 | git checkout -b my-fix-branch master 96 | ``` 97 | 98 | * Create your patch, **including appropriate test cases**. 99 | * Avoid checking in files that shouldn't be tracked (e.g `.tmp`, `.idea`). We recommend using a [global](#global-gitignore) gitignore for this. 100 | * Commit your changes using a descriptive commit message. 101 | 102 | ```shell 103 | git commit -a 104 | ``` 105 | Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files. 106 | 107 | * Build your changes locally to ensure all the tests pass: 108 | 109 | ```shell 110 | gulp 111 | ``` 112 | 113 | * Push your branch to GitHub: 114 | 115 | ```shell 116 | git push origin my-fix-branch 117 | ``` 118 | 119 | * In GitHub, send a pull request to `friendlyeats-android:master`. 120 | * If we suggest changes then: 121 | * Make the required updates. 122 | * Rebase your branch and force push to your GitHub repository (this will update your Pull Request): 123 | 124 | ```shell 125 | git rebase master -i 126 | git push origin my-fix-branch -f 127 | ``` 128 | 129 | That's it! Thank you for your contribution! 130 | 131 | #### After your pull request is merged 132 | 133 | After your pull request is merged, you can safely delete your branch and pull the changes 134 | from the main (upstream) repository: 135 | 136 | * Delete the remote branch on GitHub either through the GitHub UI or your local shell as follows: 137 | 138 | ```shell 139 | git push origin --delete my-fix-branch 140 | ``` 141 | 142 | * Check out the master branch: 143 | 144 | ```shell 145 | git checkout master -f 146 | ``` 147 | 148 | * Delete the local branch: 149 | 150 | ```shell 151 | git branch -D my-fix-branch 152 | ``` 153 | 154 | * Update your master with the latest upstream version: 155 | 156 | ```shell 157 | git pull --ff upstream master 158 | ``` 159 | 160 | ## Signing the CLA 161 | 162 | Please sign our [Contributor License Agreement][google-cla] (CLA) before sending pull requests. For any code 163 | changes to be accepted, the CLA must be signed. It's a quick process, we promise! 164 | 165 | [github]: https://github.com/firebase/friendyeats-android 166 | [google-cla]: https://cla.developers.google.com 167 | [stackoverflow]: http://stackoverflow.com/questions/tagged/firebase 168 | [global-gitignore]: https://help.github.com/articles/ignoring-files/#create-a-global-gitignore 169 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2017 Google Inc 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | All code in any directories or sub-directories that end with *.html or 205 | *.css is licensed under the Creative Commons Attribution International 206 | 4.0 License, which full text can be found here: 207 | https://creativecommons.org/licenses/by/4.0/legalcode. 208 | 209 | As an exception to this license, all html or css that is generated by 210 | the software at the direction of the user is copyright the user. The 211 | user has full ownership and control over such content, including 212 | whether and how they wish to license it. 213 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Friendly Eats 2 | 3 | 4 | 5 | This is the source code that accompanies the Firestore Android Codelab: 6 | https://codelabs.developers.google.com/codelabs/firestore-android 7 | 8 | The codelab will walk you through developing an Android restaurant recommendation 9 | app powered by Cloud Firestore. 10 | 11 | 12 | 13 | If you don't want to do the codelab and would rather view the completed 14 | sample code, see the Firebase Android Quickstart repository: 15 | https://github.com/firebase/quickstart-android 16 | 17 | ## Build Status 18 | 19 | [![Actions Status][gh-actions-badge]][gh-actions] 20 | 21 | [gh-actions]: https://github.com/firebase/friendlyeats-android/actions 22 | [gh-actions-badge]: https://github.com/firebase/friendlyeats-android/workflows/Android%20CI/badge.svg 23 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | id("kotlin-android") 4 | id("com.google.gms.google-services") 5 | id("androidx.navigation.safeargs") 6 | } 7 | 8 | android { 9 | namespace = "com.google.firebase.example.fireeats" 10 | compileSdk = 36 11 | defaultConfig { 12 | applicationId = "com.google.firebase.example.fireeats" 13 | minSdk = 23 14 | targetSdk = 36 15 | versionCode = 1 16 | versionName = "1.0" 17 | 18 | multiDexEnabled = true 19 | vectorDrawables.useSupportLibrary = true 20 | } 21 | buildTypes { 22 | getByName("release") { 23 | isMinifyEnabled = false 24 | proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") 25 | } 26 | } 27 | buildFeatures { 28 | viewBinding = true 29 | } 30 | lint { 31 | // TODO(thatfiredev): Remove this once 32 | // https://github.com/bumptech/glide/issues/4940 is fixed 33 | disable.add("NotificationPermission") 34 | } 35 | compileOptions { 36 | sourceCompatibility = JavaVersion.VERSION_17 37 | targetCompatibility = JavaVersion.VERSION_17 38 | } 39 | kotlinOptions { 40 | jvmTarget = "17" 41 | } 42 | } 43 | 44 | dependencies { 45 | // Import the Firebase BoM (see: https://firebase.google.com/docs/android/learn-more#bom) 46 | implementation(platform("com.google.firebase:firebase-bom:33.14.0")) 47 | 48 | // Firestore 49 | implementation("com.google.firebase:firebase-firestore-ktx") 50 | 51 | // Other Firebase/Play services deps 52 | implementation("com.google.firebase:firebase-auth-ktx") 53 | 54 | // Pinned to 20.7.0 as a workaround for issue https://github.com/firebase/quickstart-android/issues/1647 55 | implementation("com.google.android.gms:play-services-auth:20.7.0") 56 | 57 | // FirebaseUI (for authentication) 58 | implementation("com.firebaseui:firebase-ui-auth:9.0.0") 59 | 60 | // Support Libs 61 | implementation("androidx.appcompat:appcompat:1.7.1") 62 | implementation("androidx.vectordrawable:vectordrawable-animated:1.2.0") 63 | implementation("androidx.cardview:cardview:1.0.0") 64 | implementation("androidx.browser:browser:1.5.0") 65 | implementation("com.google.android.material:material:1.12.0") 66 | implementation("androidx.multidex:multidex:2.0.1") 67 | implementation("androidx.recyclerview:recyclerview:1.4.0") 68 | implementation("androidx.navigation:navigation-fragment-ktx:2.9.0") 69 | implementation("androidx.navigation:navigation-ui-ktx:2.9.0") 70 | implementation("androidx.startup:startup-runtime:1.2.0") 71 | 72 | // Android architecture components 73 | implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.9.1") 74 | implementation("androidx.lifecycle:lifecycle-extensions:2.2.0") 75 | annotationProcessor("androidx.lifecycle:lifecycle-compiler:2.9.1") 76 | 77 | // Third-party libraries 78 | implementation("me.zhanghai.android.materialratingbar:library:1.4.0") 79 | implementation("com.github.bumptech.glide:glide:4.16.0") 80 | } 81 | -------------------------------------------------------------------------------- /app/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/google/home/samstern/android-sdk-linux/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle.kts. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 27 | 29 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/FilterDialogFragment.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats 2 | 3 | import android.content.Context 4 | import android.os.Bundle 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import androidx.fragment.app.DialogFragment 9 | import com.google.firebase.example.fireeats.databinding.DialogFiltersBinding 10 | import com.google.firebase.example.fireeats.model.Restaurant 11 | import com.google.firebase.firestore.Query 12 | 13 | /** 14 | * Dialog Fragment containing filter form. 15 | */ 16 | class FilterDialogFragment : DialogFragment() { 17 | 18 | private var _binding: DialogFiltersBinding? = null 19 | private val binding get() = _binding!! 20 | private var filterListener: FilterListener? = null 21 | 22 | private val selectedCategory: String? 23 | get() { 24 | val selected = binding.spinnerCategory.selectedItem as String 25 | return if (getString(R.string.value_any_category) == selected) { 26 | null 27 | } else { 28 | selected 29 | } 30 | } 31 | 32 | private val selectedCity: String? 33 | get() { 34 | val selected = binding.spinnerCity.selectedItem as String 35 | return if (getString(R.string.value_any_city) == selected) { 36 | null 37 | } else { 38 | selected 39 | } 40 | } 41 | 42 | private val selectedPrice: Int 43 | get() { 44 | val selected = binding.spinnerPrice.selectedItem as String 45 | return when (selected) { 46 | getString(R.string.price_1) -> 1 47 | getString(R.string.price_2) -> 2 48 | getString(R.string.price_3) -> 3 49 | else -> -1 50 | } 51 | } 52 | 53 | private val selectedSortBy: String? 54 | get() { 55 | val selected = binding.spinnerSort.selectedItem as String 56 | if (getString(R.string.sort_by_rating) == selected) { 57 | return Restaurant.FIELD_AVG_RATING 58 | } 59 | if (getString(R.string.sort_by_price) == selected) { 60 | return Restaurant.FIELD_PRICE 61 | } 62 | return if (getString(R.string.sort_by_popularity) == selected) { 63 | Restaurant.FIELD_POPULARITY 64 | } else { 65 | null 66 | } 67 | } 68 | 69 | private val sortDirection: Query.Direction 70 | get() { 71 | val selected = binding.spinnerSort.selectedItem as String 72 | if (getString(R.string.sort_by_rating) == selected) { 73 | return Query.Direction.DESCENDING 74 | } 75 | if (getString(R.string.sort_by_price) == selected) { 76 | return Query.Direction.ASCENDING 77 | } 78 | return if (getString(R.string.sort_by_popularity) == selected) { 79 | Query.Direction.DESCENDING 80 | } else { 81 | Query.Direction.DESCENDING 82 | } 83 | } 84 | 85 | val filters: Filters 86 | get() { 87 | val filters = Filters() 88 | 89 | filters.category = selectedCategory 90 | filters.city = selectedCity 91 | filters.price = selectedPrice 92 | filters.sortBy = selectedSortBy 93 | filters.sortDirection = sortDirection 94 | 95 | return filters 96 | } 97 | 98 | interface FilterListener { 99 | 100 | fun onFilter(filters: Filters) 101 | } 102 | 103 | override fun onCreateView( 104 | inflater: LayoutInflater, 105 | container: ViewGroup?, 106 | savedInstanceState: Bundle? 107 | ): View? { 108 | _binding = DialogFiltersBinding.inflate(inflater, container, false) 109 | 110 | binding.buttonSearch.setOnClickListener { onSearchClicked() } 111 | binding.buttonCancel.setOnClickListener { onCancelClicked() } 112 | 113 | return binding.root 114 | } 115 | 116 | override fun onDestroyView() { 117 | super.onDestroyView() 118 | _binding = null 119 | } 120 | 121 | override fun onAttach(context: Context) { 122 | super.onAttach(context) 123 | 124 | if (parentFragment is FilterListener) { 125 | filterListener = parentFragment as FilterListener 126 | } 127 | } 128 | 129 | override fun onResume() { 130 | super.onResume() 131 | dialog?.window?.setLayout( 132 | ViewGroup.LayoutParams.MATCH_PARENT, 133 | ViewGroup.LayoutParams.WRAP_CONTENT) 134 | } 135 | 136 | private fun onSearchClicked() { 137 | filterListener?.onFilter(filters) 138 | dismiss() 139 | } 140 | 141 | private fun onCancelClicked() { 142 | dismiss() 143 | } 144 | 145 | fun resetFilters() { 146 | _binding?.let { 147 | it.spinnerCategory.setSelection(0) 148 | it.spinnerCity.setSelection(0) 149 | it.spinnerPrice.setSelection(0) 150 | it.spinnerSort.setSelection(0) 151 | } 152 | } 153 | 154 | companion object { 155 | 156 | const val TAG = "FilterDialog" 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/Filters.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats 2 | 3 | import android.content.Context 4 | import android.text.TextUtils 5 | import com.google.firebase.example.fireeats.model.Restaurant 6 | import com.google.firebase.example.fireeats.util.RestaurantUtil 7 | import com.google.firebase.firestore.Query 8 | 9 | /** 10 | * Object for passing filters around. 11 | */ 12 | class Filters { 13 | 14 | var category: String? = null 15 | var city: String? = null 16 | var price = -1 17 | var sortBy: String? = null 18 | var sortDirection: Query.Direction = Query.Direction.DESCENDING 19 | 20 | fun hasCategory(): Boolean { 21 | return !TextUtils.isEmpty(category) 22 | } 23 | 24 | fun hasCity(): Boolean { 25 | return !TextUtils.isEmpty(city) 26 | } 27 | 28 | fun hasPrice(): Boolean { 29 | return price > 0 30 | } 31 | 32 | fun hasSortBy(): Boolean { 33 | return !TextUtils.isEmpty(sortBy) 34 | } 35 | 36 | fun getSearchDescription(context: Context): String { 37 | val desc = StringBuilder() 38 | 39 | if (category == null && city == null) { 40 | desc.append("") 41 | desc.append(context.getString(R.string.all_restaurants)) 42 | desc.append("") 43 | } 44 | 45 | if (category != null) { 46 | desc.append("") 47 | desc.append(category) 48 | desc.append("") 49 | } 50 | 51 | if (category != null && city != null) { 52 | desc.append(" in ") 53 | } 54 | 55 | if (city != null) { 56 | desc.append("") 57 | desc.append(city) 58 | desc.append("") 59 | } 60 | 61 | if (price > 0) { 62 | desc.append(" for ") 63 | desc.append("") 64 | desc.append(RestaurantUtil.getPriceString(price)) 65 | desc.append("") 66 | } 67 | 68 | return desc.toString() 69 | } 70 | 71 | fun getOrderDescription(context: Context): String { 72 | return when (sortBy) { 73 | Restaurant.FIELD_PRICE -> context.getString(R.string.sorted_by_price) 74 | Restaurant.FIELD_POPULARITY -> context.getString(R.string.sorted_by_popularity) 75 | else -> context.getString(R.string.sorted_by_rating) 76 | } 77 | } 78 | 79 | companion object { 80 | 81 | val default: Filters 82 | get() { 83 | val filters = Filters() 84 | filters.sortBy = Restaurant.FIELD_AVG_RATING 85 | filters.sortDirection = Query.Direction.DESCENDING 86 | 87 | return filters 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import androidx.navigation.Navigation 6 | 7 | class MainActivity : AppCompatActivity() { 8 | override fun onCreate(savedInstanceState: Bundle?) { 9 | super.onCreate(savedInstanceState) 10 | setContentView(R.layout.activity_main) 11 | setSupportActionBar(findViewById(R.id.toolbar)) 12 | Navigation.findNavController(this, R.id.nav_host_fragment) 13 | .setGraph(R.navigation.nav_graph) 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/MainFragment.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats 2 | 3 | import android.app.Activity 4 | import android.os.Bundle 5 | import android.view.LayoutInflater 6 | import android.view.Menu 7 | import android.view.MenuInflater 8 | import android.view.MenuItem 9 | import android.view.View 10 | import android.view.ViewGroup 11 | import android.widget.Toast 12 | import androidx.annotation.StringRes 13 | import androidx.appcompat.app.AlertDialog 14 | import androidx.core.text.HtmlCompat 15 | import androidx.fragment.app.Fragment 16 | import androidx.lifecycle.ViewModelProvider 17 | import androidx.navigation.fragment.findNavController 18 | import androidx.recyclerview.widget.LinearLayoutManager 19 | import com.firebase.ui.auth.AuthUI 20 | import com.firebase.ui.auth.ErrorCodes 21 | import com.firebase.ui.auth.FirebaseAuthUIActivityResultContract 22 | import com.firebase.ui.auth.data.model.FirebaseAuthUIAuthenticationResult 23 | import com.google.android.material.snackbar.Snackbar 24 | import com.google.firebase.auth.ktx.auth 25 | import com.google.firebase.example.fireeats.databinding.FragmentMainBinding 26 | import com.google.firebase.example.fireeats.adapter.RestaurantAdapter 27 | import com.google.firebase.example.fireeats.model.Restaurant 28 | import com.google.firebase.example.fireeats.viewmodel.MainActivityViewModel 29 | import com.google.firebase.firestore.DocumentSnapshot 30 | import com.google.firebase.firestore.FirebaseFirestore 31 | import com.google.firebase.firestore.FirebaseFirestoreException 32 | import com.google.firebase.firestore.Query 33 | import com.google.firebase.firestore.ktx.firestore 34 | import com.google.firebase.ktx.Firebase 35 | 36 | class MainFragment : Fragment(), 37 | FilterDialogFragment.FilterListener, 38 | RestaurantAdapter.OnRestaurantSelectedListener { 39 | 40 | lateinit var firestore: FirebaseFirestore 41 | private var query: Query? = null 42 | 43 | private lateinit var binding: FragmentMainBinding 44 | private lateinit var filterDialog: FilterDialogFragment 45 | private var adapter: RestaurantAdapter? = null 46 | 47 | private lateinit var viewModel: MainActivityViewModel 48 | private val signInLauncher = registerForActivityResult( 49 | FirebaseAuthUIActivityResultContract() 50 | ) { result -> this.onSignInResult(result) } 51 | 52 | override fun onCreateView( 53 | inflater: LayoutInflater, 54 | container: ViewGroup?, 55 | savedInstanceState: Bundle? 56 | ): View { 57 | setHasOptionsMenu(true) 58 | binding = FragmentMainBinding.inflate(inflater, container, false); 59 | return binding.root; 60 | } 61 | 62 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 63 | super.onViewCreated(view, savedInstanceState) 64 | 65 | // View model 66 | viewModel = ViewModelProvider(this).get(MainActivityViewModel::class.java) 67 | 68 | // Enable Firestore logging 69 | FirebaseFirestore.setLoggingEnabled(true) 70 | 71 | // Firestore 72 | firestore = Firebase.firestore 73 | 74 | // RecyclerView 75 | query?.let { 76 | adapter = object : RestaurantAdapter(it, this@MainFragment) { 77 | override fun onDataChanged() { 78 | // Show/hide content if the query returns empty. 79 | if (itemCount == 0) { 80 | binding.recyclerRestaurants.visibility = View.GONE 81 | binding.viewEmpty.visibility = View.VISIBLE 82 | } else { 83 | binding.recyclerRestaurants.visibility = View.VISIBLE 84 | binding.viewEmpty.visibility = View.GONE 85 | } 86 | } 87 | 88 | override fun onError(e: FirebaseFirestoreException) { 89 | // Show a snackbar on errors 90 | Snackbar.make( 91 | binding.root, 92 | "Error: check logs for info.", Snackbar.LENGTH_LONG 93 | ).show() 94 | } 95 | } 96 | binding.recyclerRestaurants.adapter = adapter 97 | } 98 | 99 | binding.recyclerRestaurants.layoutManager = LinearLayoutManager(context) 100 | 101 | // Filter Dialog 102 | filterDialog = FilterDialogFragment() 103 | 104 | binding.filterBar.setOnClickListener { onFilterClicked() } 105 | binding.buttonClearFilter.setOnClickListener { onClearFilterClicked() } 106 | } 107 | 108 | override fun onStart() { 109 | super.onStart() 110 | 111 | // Start sign in if necessary 112 | if (shouldStartSignIn()) { 113 | startSignIn() 114 | return 115 | } 116 | 117 | // Apply filters 118 | onFilter(viewModel.filters) 119 | 120 | // Start listening for Firestore updates 121 | adapter?.startListening() 122 | } 123 | 124 | override fun onStop() { 125 | super.onStop() 126 | adapter?.stopListening() 127 | } 128 | 129 | override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { 130 | inflater.inflate(R.menu.menu_main, menu) 131 | return super.onCreateOptionsMenu(menu, inflater) 132 | } 133 | 134 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 135 | when (item.itemId) { 136 | R.id.menu_add_items -> onAddItemsClicked() 137 | R.id.menu_sign_out -> { 138 | AuthUI.getInstance().signOut(requireContext()) 139 | startSignIn() 140 | } 141 | } 142 | return super.onOptionsItemSelected(item) 143 | } 144 | 145 | private fun onSignInResult(result: FirebaseAuthUIAuthenticationResult) { 146 | val response = result.idpResponse 147 | viewModel.isSigningIn = false 148 | 149 | if (result.resultCode != Activity.RESULT_OK) { 150 | if (response == null) { 151 | // User pressed the back button. 152 | requireActivity().finish() 153 | } else if (response.error != null && response.error!!.errorCode == ErrorCodes.NO_NETWORK) { 154 | showSignInErrorDialog(R.string.message_no_network) 155 | } else { 156 | showSignInErrorDialog(R.string.message_unknown) 157 | } 158 | } 159 | } 160 | 161 | private fun onFilterClicked() { 162 | // Show the dialog containing filter options 163 | filterDialog.show(childFragmentManager, FilterDialogFragment.TAG) 164 | } 165 | 166 | private fun onClearFilterClicked() { 167 | filterDialog.resetFilters() 168 | 169 | onFilter(Filters.default) 170 | } 171 | 172 | override fun onRestaurantSelected(restaurant: DocumentSnapshot) { 173 | // Go to the details page for the selected restaurant 174 | val action = MainFragmentDirections 175 | .actionMainFragmentToRestaurantDetailFragment(restaurant.id) 176 | 177 | findNavController().navigate(action) 178 | } 179 | 180 | override fun onFilter(filters: Filters) { 181 | // TODO(developer): Construct new query 182 | 183 | // Set header 184 | binding.textCurrentSearch.text = HtmlCompat.fromHtml( 185 | filters.getSearchDescription(requireContext()), 186 | HtmlCompat.FROM_HTML_MODE_LEGACY 187 | ) 188 | binding.textCurrentSortBy.text = filters.getOrderDescription(requireContext()) 189 | 190 | // Save filters 191 | viewModel.filters = filters 192 | } 193 | 194 | private fun shouldStartSignIn(): Boolean { 195 | return !viewModel.isSigningIn && Firebase.auth.currentUser == null 196 | } 197 | 198 | private fun startSignIn() { 199 | // Sign in with FirebaseUI 200 | val intent = AuthUI.getInstance().createSignInIntentBuilder() 201 | .setAvailableProviders(listOf(AuthUI.IdpConfig.EmailBuilder().build())) 202 | .setCredentialManagerEnabled(false) 203 | .build() 204 | 205 | signInLauncher.launch(intent) 206 | viewModel.isSigningIn = true 207 | } 208 | 209 | private fun onAddItemsClicked() { 210 | // TODO(developer): Add random restaurants 211 | showTodoToast() 212 | } 213 | 214 | private fun showSignInErrorDialog(@StringRes message: Int) { 215 | val dialog = AlertDialog.Builder(requireContext()) 216 | .setTitle(R.string.title_sign_in_error) 217 | .setMessage(message) 218 | .setCancelable(false) 219 | .setPositiveButton(R.string.option_retry) { _, _ -> startSignIn() } 220 | .setNegativeButton(R.string.option_exit) { _, _ -> requireActivity().finish() }.create() 221 | 222 | dialog.show() 223 | } 224 | 225 | private fun showTodoToast() { 226 | Toast.makeText(context, "TODO: Implement", Toast.LENGTH_SHORT).show() 227 | } 228 | 229 | companion object { 230 | 231 | private const val TAG = "MainActivity" 232 | 233 | private const val LIMIT = 50 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/RatingDialogFragment.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats 2 | 3 | import android.content.Context 4 | import android.os.Bundle 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import androidx.fragment.app.DialogFragment 9 | import com.google.firebase.auth.ktx.auth 10 | import com.google.firebase.example.fireeats.databinding.DialogRatingBinding 11 | import com.google.firebase.example.fireeats.model.Rating 12 | import com.google.firebase.ktx.Firebase 13 | 14 | /** 15 | * Dialog Fragment containing rating form. 16 | */ 17 | class RatingDialogFragment : DialogFragment() { 18 | 19 | private var _binding: DialogRatingBinding? = null 20 | private val binding get() = _binding!! 21 | private var ratingListener: RatingListener? = null 22 | 23 | internal interface RatingListener { 24 | 25 | fun onRating(rating: Rating) 26 | } 27 | 28 | override fun onCreateView( 29 | inflater: LayoutInflater, 30 | container: ViewGroup?, 31 | savedInstanceState: Bundle? 32 | ): View? { 33 | _binding = DialogRatingBinding.inflate(inflater, container, false) 34 | 35 | binding.restaurantFormButton.setOnClickListener { onSubmitClicked() } 36 | binding.restaurantFormCancel.setOnClickListener { onCancelClicked() } 37 | 38 | return binding.root 39 | } 40 | 41 | override fun onDestroyView() { 42 | super.onDestroyView() 43 | _binding = null 44 | } 45 | 46 | override fun onAttach(context: Context) { 47 | super.onAttach(context) 48 | 49 | if (parentFragment is RatingListener) { 50 | ratingListener = parentFragment as RatingListener 51 | } 52 | } 53 | 54 | override fun onResume() { 55 | super.onResume() 56 | dialog?.window?.setLayout( 57 | ViewGroup.LayoutParams.MATCH_PARENT, 58 | ViewGroup.LayoutParams.WRAP_CONTENT) 59 | } 60 | 61 | private fun onSubmitClicked() { 62 | val user = Firebase.auth.currentUser 63 | user?.let { 64 | val rating = Rating( 65 | it, 66 | binding.restaurantFormRating.rating.toDouble(), 67 | binding.restaurantFormText.text.toString()) 68 | 69 | ratingListener?.onRating(rating) 70 | } 71 | 72 | dismiss() 73 | } 74 | 75 | private fun onCancelClicked() { 76 | dismiss() 77 | } 78 | 79 | companion object { 80 | 81 | const val TAG = "RatingDialog" 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/RestaurantDetailFragment.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats 2 | 3 | import android.content.Context 4 | import android.os.Bundle 5 | import android.util.Log 6 | import android.view.LayoutInflater 7 | import android.view.View 8 | import android.view.ViewGroup 9 | import android.view.inputmethod.InputMethodManager 10 | import androidx.fragment.app.Fragment 11 | import androidx.recyclerview.widget.LinearLayoutManager 12 | import com.bumptech.glide.Glide 13 | import com.google.android.gms.tasks.Task 14 | import com.google.android.gms.tasks.Tasks 15 | import com.google.android.material.snackbar.Snackbar 16 | import com.google.firebase.example.fireeats.databinding.FragmentRestaurantDetailBinding 17 | import com.google.firebase.example.fireeats.adapter.RatingAdapter 18 | import com.google.firebase.example.fireeats.model.Rating 19 | import com.google.firebase.example.fireeats.model.Restaurant 20 | import com.google.firebase.example.fireeats.util.RestaurantUtil 21 | import com.google.firebase.firestore.DocumentReference 22 | import com.google.firebase.firestore.DocumentSnapshot 23 | import com.google.firebase.firestore.EventListener 24 | import com.google.firebase.firestore.FirebaseFirestore 25 | import com.google.firebase.firestore.FirebaseFirestoreException 26 | import com.google.firebase.firestore.ListenerRegistration 27 | import com.google.firebase.firestore.Query 28 | import com.google.firebase.firestore.ktx.firestore 29 | import com.google.firebase.firestore.ktx.toObject 30 | import com.google.firebase.ktx.Firebase 31 | 32 | class RestaurantDetailFragment : Fragment(), 33 | EventListener, 34 | RatingDialogFragment.RatingListener { 35 | 36 | private var ratingDialog: RatingDialogFragment? = null 37 | 38 | private lateinit var binding: FragmentRestaurantDetailBinding 39 | private lateinit var firestore: FirebaseFirestore 40 | private lateinit var restaurantRef: DocumentReference 41 | private lateinit var ratingAdapter: RatingAdapter 42 | 43 | private var restaurantRegistration: ListenerRegistration? = null 44 | 45 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 46 | binding = FragmentRestaurantDetailBinding.inflate(inflater, container, false) 47 | return binding.root 48 | } 49 | 50 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 51 | super.onViewCreated(view, savedInstanceState) 52 | 53 | // Get restaurant ID from extras 54 | val restaurantId = RestaurantDetailFragmentArgs.fromBundle(requireArguments()).keyRestaurantId 55 | 56 | // Initialize Firestore 57 | firestore = Firebase.firestore 58 | 59 | // Get reference to the restaurant 60 | restaurantRef = firestore.collection("restaurants").document(restaurantId) 61 | 62 | // Get ratings 63 | val ratingsQuery = restaurantRef 64 | .collection("ratings") 65 | .orderBy("timestamp", Query.Direction.DESCENDING) 66 | .limit(50) 67 | 68 | // RecyclerView 69 | ratingAdapter = object : RatingAdapter(ratingsQuery) { 70 | override fun onDataChanged() { 71 | if (itemCount == 0) { 72 | binding.recyclerRatings.visibility = View.GONE 73 | binding.viewEmptyRatings.visibility = View.VISIBLE 74 | } else { 75 | binding.recyclerRatings.visibility = View.VISIBLE 76 | binding.viewEmptyRatings.visibility = View.GONE 77 | } 78 | } 79 | } 80 | binding.recyclerRatings.layoutManager = LinearLayoutManager(context) 81 | binding.recyclerRatings.adapter = ratingAdapter 82 | 83 | ratingDialog = RatingDialogFragment() 84 | 85 | binding.restaurantButtonBack.setOnClickListener { onBackArrowClicked() } 86 | binding.fabShowRatingDialog.setOnClickListener { onAddRatingClicked() } 87 | } 88 | 89 | public override fun onStart() { 90 | super.onStart() 91 | 92 | ratingAdapter.startListening() 93 | restaurantRegistration = restaurantRef.addSnapshotListener(this) 94 | } 95 | 96 | public override fun onStop() { 97 | super.onStop() 98 | 99 | ratingAdapter.stopListening() 100 | 101 | restaurantRegistration?.remove() 102 | restaurantRegistration = null 103 | } 104 | 105 | /** 106 | * Listener for the Restaurant document ([.restaurantRef]). 107 | */ 108 | override fun onEvent(snapshot: DocumentSnapshot?, e: FirebaseFirestoreException?) { 109 | if (e != null) { 110 | Log.w(TAG, "restaurant:onEvent", e) 111 | return 112 | } 113 | 114 | snapshot?.let { 115 | val restaurant = snapshot.toObject() 116 | if (restaurant != null) { 117 | onRestaurantLoaded(restaurant) 118 | } 119 | } 120 | } 121 | 122 | private fun onRestaurantLoaded(restaurant: Restaurant) { 123 | binding.restaurantName.text = restaurant.name 124 | binding.restaurantRating.rating = restaurant.avgRating.toFloat() 125 | binding.restaurantNumRatings.text = getString(R.string.fmt_num_ratings, restaurant.numRatings) 126 | binding.restaurantCity.text = restaurant.city 127 | binding.restaurantCategory.text = restaurant.category 128 | binding.restaurantPrice.text = RestaurantUtil.getPriceString(restaurant) 129 | 130 | // Background image 131 | Glide.with(binding.restaurantImage.context) 132 | .load(restaurant.photo) 133 | .into(binding.restaurantImage) 134 | } 135 | 136 | private fun onBackArrowClicked() { 137 | requireActivity().onBackPressed() 138 | } 139 | 140 | private fun onAddRatingClicked() { 141 | ratingDialog?.show(childFragmentManager, RatingDialogFragment.TAG) 142 | } 143 | 144 | override fun onRating(rating: Rating) { 145 | // In a transaction, add the new rating and update the aggregate totals 146 | addRating(restaurantRef, rating) 147 | .addOnSuccessListener(requireActivity()) { 148 | Log.d(TAG, "Rating added") 149 | 150 | // Hide keyboard and scroll to top 151 | hideKeyboard() 152 | binding.recyclerRatings.smoothScrollToPosition(0) 153 | } 154 | .addOnFailureListener(requireActivity()) { e -> 155 | Log.w(TAG, "Add rating failed", e) 156 | 157 | // Show failure message and hide keyboard 158 | hideKeyboard() 159 | Snackbar.make( 160 | requireView().findViewById(android.R.id.content), "Failed to add rating", 161 | Snackbar.LENGTH_SHORT).show() 162 | } 163 | } 164 | 165 | private fun addRating(restaurantRef: DocumentReference, rating: Rating): Task { 166 | // TODO(developer): Implement 167 | return Tasks.forException(Exception("not yet implemented")) 168 | } 169 | 170 | private fun hideKeyboard() { 171 | val view = requireActivity().currentFocus 172 | if (view != null) { 173 | (requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager) 174 | .hideSoftInputFromWindow(view.windowToken, 0) 175 | } 176 | } 177 | 178 | companion object { 179 | 180 | private const val TAG = "RestaurantDetail" 181 | 182 | const val KEY_RESTAURANT_ID = "key_restaurant_id" 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/adapter/FirestoreAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats.adapter 2 | 3 | import androidx.recyclerview.widget.RecyclerView 4 | import android.util.Log 5 | import com.google.firebase.firestore.DocumentSnapshot 6 | import com.google.firebase.firestore.FirebaseFirestoreException 7 | import com.google.firebase.firestore.ListenerRegistration 8 | import com.google.firebase.firestore.Query 9 | import java.util.ArrayList 10 | 11 | /** 12 | * RecyclerView adapter for displaying the results of a Firestore [Query]. 13 | * 14 | * Note that this class forgoes some efficiency to gain simplicity. For example, the result of 15 | * [DocumentSnapshot.toObject] is not cached so the same object may be deserialized 16 | * many times as the user scrolls. 17 | */ 18 | abstract class FirestoreAdapter(private var query: Query) : 19 | RecyclerView.Adapter() { 20 | 21 | private var registration: ListenerRegistration? = null 22 | 23 | private val snapshots = ArrayList() 24 | 25 | fun startListening() { 26 | // TODO(developer): Implement 27 | } 28 | 29 | fun stopListening() { 30 | registration?.remove() 31 | registration = null 32 | 33 | snapshots.clear() 34 | notifyDataSetChanged() 35 | } 36 | 37 | fun setQuery(query: Query) { 38 | // Stop listening 39 | stopListening() 40 | 41 | // Clear existing data 42 | snapshots.clear() 43 | notifyDataSetChanged() 44 | 45 | // Listen to new query 46 | this.query = query 47 | startListening() 48 | } 49 | 50 | open fun onError(e: FirebaseFirestoreException) { 51 | Log.w(TAG, "onError", e) 52 | } 53 | 54 | open fun onDataChanged() {} 55 | 56 | override fun getItemCount(): Int { 57 | return snapshots.size 58 | } 59 | 60 | protected fun getSnapshot(index: Int): DocumentSnapshot { 61 | return snapshots[index] 62 | } 63 | 64 | companion object { 65 | 66 | private const val TAG = "FirestoreAdapter" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/adapter/RatingAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats.adapter 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import androidx.recyclerview.widget.RecyclerView 6 | import com.google.firebase.example.fireeats.databinding.ItemRatingBinding 7 | import com.google.firebase.example.fireeats.model.Rating 8 | import com.google.firebase.firestore.Query 9 | import com.google.firebase.firestore.ktx.toObject 10 | import java.text.SimpleDateFormat 11 | import java.util.Locale 12 | 13 | /** 14 | * RecyclerView adapter for a list of [Rating]. 15 | */ 16 | open class RatingAdapter(query: Query) : FirestoreAdapter(query) { 17 | 18 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 19 | return ViewHolder(ItemRatingBinding.inflate(LayoutInflater.from(parent.context), parent, false)) 20 | } 21 | 22 | override fun onBindViewHolder(holder: ViewHolder, position: Int) { 23 | holder.bind(getSnapshot(position).toObject()) 24 | } 25 | 26 | class ViewHolder(val binding: ItemRatingBinding) : RecyclerView.ViewHolder(binding.root) { 27 | 28 | fun bind(rating: Rating?) { 29 | if (rating == null) { 30 | return 31 | } 32 | 33 | binding.ratingItemName.text = rating.userName 34 | binding.ratingItemRating.rating = rating.rating.toFloat() 35 | binding.ratingItemText.text = rating.text 36 | 37 | if (rating.timestamp != null) { 38 | binding.ratingItemDate.text = FORMAT.format(rating.timestamp) 39 | } 40 | } 41 | 42 | companion object { 43 | 44 | private val FORMAT = SimpleDateFormat( 45 | "MM/dd/yyyy", Locale.US) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/adapter/RestaurantAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats.adapter 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import androidx.recyclerview.widget.RecyclerView 6 | import com.bumptech.glide.Glide 7 | import com.google.firebase.example.fireeats.R 8 | import com.google.firebase.example.fireeats.databinding.ItemRestaurantBinding 9 | import com.google.firebase.example.fireeats.model.Restaurant 10 | import com.google.firebase.example.fireeats.util.RestaurantUtil 11 | import com.google.firebase.firestore.DocumentSnapshot 12 | import com.google.firebase.firestore.Query 13 | import com.google.firebase.firestore.ktx.toObject 14 | 15 | /** 16 | * RecyclerView adapter for a list of Restaurants. 17 | */ 18 | open class RestaurantAdapter(query: Query, private val listener: OnRestaurantSelectedListener) : 19 | FirestoreAdapter(query) { 20 | 21 | interface OnRestaurantSelectedListener { 22 | 23 | fun onRestaurantSelected(restaurant: DocumentSnapshot) 24 | } 25 | 26 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 27 | return ViewHolder(ItemRestaurantBinding.inflate( 28 | LayoutInflater.from(parent.context), parent, false)) 29 | } 30 | 31 | override fun onBindViewHolder(holder: ViewHolder, position: Int) { 32 | holder.bind(getSnapshot(position), listener) 33 | } 34 | 35 | class ViewHolder(val binding: ItemRestaurantBinding) : RecyclerView.ViewHolder(binding.root) { 36 | 37 | fun bind( 38 | snapshot: DocumentSnapshot, 39 | listener: OnRestaurantSelectedListener? 40 | ) { 41 | 42 | val restaurant = snapshot.toObject() 43 | if (restaurant == null) { 44 | return 45 | } 46 | 47 | val resources = binding.root.resources 48 | 49 | // Load image 50 | Glide.with(binding.restaurantItemImage.context) 51 | .load(restaurant.photo) 52 | .into(binding.restaurantItemImage) 53 | 54 | val numRatings: Int = restaurant.numRatings 55 | 56 | binding.restaurantItemName.text = restaurant.name 57 | binding.restaurantItemRating.rating = restaurant.avgRating.toFloat() 58 | binding.restaurantItemCity.text = restaurant.city 59 | binding.restaurantItemCategory.text = restaurant.category 60 | binding.restaurantItemNumRatings.text = resources.getString( 61 | R.string.fmt_num_ratings, 62 | numRatings) 63 | binding.restaurantItemPrice.text = RestaurantUtil.getPriceString(restaurant) 64 | 65 | // Click listener 66 | binding.root.setOnClickListener { 67 | listener?.onRestaurantSelected(snapshot) 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/model/Rating.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats.model 2 | 3 | import android.text.TextUtils 4 | import com.google.firebase.auth.FirebaseUser 5 | import com.google.firebase.firestore.ServerTimestamp 6 | import java.util.Date 7 | 8 | /** 9 | * Model POJO for a rating. 10 | */ 11 | data class Rating( 12 | var userId: String? = null, 13 | var userName: String? = null, 14 | var rating: Double = 0.toDouble(), 15 | var text: String? = null, 16 | @ServerTimestamp var timestamp: Date? = null 17 | ) { 18 | 19 | constructor(user: FirebaseUser, rating: Double, text: String) : this() { 20 | this.userId = user.uid 21 | this.userName = user.displayName 22 | if (TextUtils.isEmpty(this.userName)) { 23 | this.userName = user.email 24 | } 25 | 26 | this.rating = rating 27 | this.text = text 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/model/Restaurant.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats.model 2 | 3 | import com.google.firebase.firestore.IgnoreExtraProperties 4 | 5 | /** 6 | * Restaurant POJO. 7 | */ 8 | @IgnoreExtraProperties 9 | data class Restaurant( 10 | var name: String? = null, 11 | var city: String? = null, 12 | var category: String? = null, 13 | var photo: String? = null, 14 | var price: Int = 0, 15 | var numRatings: Int = 0, 16 | var avgRating: Double = 0.toDouble() 17 | ) { 18 | 19 | companion object { 20 | 21 | const val FIELD_CITY = "city" 22 | const val FIELD_CATEGORY = "category" 23 | const val FIELD_PRICE = "price" 24 | const val FIELD_POPULARITY = "numRatings" 25 | const val FIELD_AVG_RATING = "avgRating" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/util/AuthInitializer.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats.util 2 | 3 | import android.content.Context 4 | import androidx.startup.Initializer 5 | import com.google.firebase.auth.FirebaseAuth 6 | import com.google.firebase.auth.ktx.auth 7 | import com.google.firebase.example.fireeats.BuildConfig 8 | import com.google.firebase.ktx.Firebase 9 | 10 | class AuthInitializer : Initializer { 11 | // The host '10.0.2.2' is a special IP address to let the 12 | // Android emulator connect to 'localhost'. 13 | private val AUTH_EMULATOR_HOST = "10.0.2.2" 14 | private val AUTH_EMULATOR_PORT = 9099 15 | 16 | override fun create(context: Context): FirebaseAuth { 17 | val firebaseAuth = Firebase.auth 18 | // Use emulators only in debug builds 19 | if (BuildConfig.DEBUG) { 20 | firebaseAuth.useEmulator(AUTH_EMULATOR_HOST, AUTH_EMULATOR_PORT) 21 | } 22 | return firebaseAuth 23 | } 24 | 25 | // No dependencies on other libraries 26 | override fun dependencies(): MutableList>> = mutableListOf() 27 | } -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/util/FirestoreInitializer.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats.util 2 | 3 | import android.content.Context 4 | import androidx.startup.Initializer 5 | import com.google.firebase.example.fireeats.BuildConfig 6 | import com.google.firebase.firestore.FirebaseFirestore 7 | import com.google.firebase.firestore.ktx.firestore 8 | import com.google.firebase.ktx.Firebase 9 | 10 | class FirestoreInitializer : Initializer { 11 | 12 | // The host '10.0.2.2' is a special IP address to let the 13 | // Android emulator connect to 'localhost'. 14 | private val FIRESTORE_EMULATOR_HOST = "10.0.2.2" 15 | private val FIRESTORE_EMULATOR_PORT = 8080 16 | 17 | override fun create(context: Context): FirebaseFirestore { 18 | val firestore = Firebase.firestore 19 | // Use emulators only in debug builds 20 | if (BuildConfig.DEBUG) { 21 | firestore.useEmulator(FIRESTORE_EMULATOR_HOST, FIRESTORE_EMULATOR_PORT) 22 | } 23 | return firestore 24 | } 25 | 26 | // No dependencies on other libraries 27 | override fun dependencies(): MutableList>> = mutableListOf() 28 | } -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/util/RatingUtil.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats.util 2 | 3 | import com.google.firebase.example.fireeats.model.Rating 4 | import java.util.ArrayList 5 | import java.util.Random 6 | import java.util.UUID 7 | 8 | /** 9 | * Utilities for Ratings. 10 | */ 11 | object RatingUtil { 12 | 13 | private val REVIEW_CONTENTS = arrayOf( 14 | // 0 - 1 stars 15 | "This was awful! Totally inedible.", 16 | 17 | // 1 - 2 stars 18 | "This was pretty bad, would not go back.", 19 | 20 | // 2 - 3 stars 21 | "I was fed, so that's something.", 22 | 23 | // 3 - 4 stars 24 | "This was a nice meal, I'd go back.", 25 | 26 | // 4 - 5 stars 27 | "This was fantastic! Best ever!") 28 | 29 | /** 30 | * Create a random Rating POJO. 31 | */ 32 | private val random: Rating 33 | get() { 34 | val rating = Rating() 35 | 36 | val random = Random() 37 | 38 | val score = random.nextDouble() * 5.0 39 | val text = REVIEW_CONTENTS[Math.floor(score).toInt()] 40 | 41 | rating.userId = UUID.randomUUID().toString() 42 | rating.userName = "Random User" 43 | rating.rating = score 44 | rating.text = text 45 | 46 | return rating 47 | } 48 | 49 | /** 50 | * Get a list of random Rating POJOs. 51 | */ 52 | fun getRandomList(length: Int): List { 53 | val result = ArrayList() 54 | 55 | for (i in 0 until length) { 56 | result.add(random) 57 | } 58 | 59 | return result 60 | } 61 | 62 | /** 63 | * Get the average rating of a List. 64 | */ 65 | fun getAverageRating(ratings: List): Double { 66 | var sum = 0.0 67 | 68 | for (rating in ratings) { 69 | sum += rating.rating 70 | } 71 | 72 | return sum / ratings.size 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/util/RestaurantUtil.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats.util 2 | 3 | import android.content.Context 4 | import com.google.firebase.example.fireeats.R 5 | import com.google.firebase.example.fireeats.model.Restaurant 6 | import java.util.Arrays 7 | import java.util.Locale 8 | import java.util.Random 9 | 10 | /** 11 | * Utilities for Restaurants. 12 | */ 13 | object RestaurantUtil { 14 | 15 | private const val RESTAURANT_URL_FMT = "https://storage.googleapis.com/firestorequickstarts.appspot.com/food_%d.png" 16 | private const val MAX_IMAGE_NUM = 22 17 | 18 | private val NAME_FIRST_WORDS = arrayOf( 19 | "Foo", "Bar", "Baz", "Qux", "Fire", "Sam's", "World Famous", "Google", "The Best") 20 | 21 | private val NAME_SECOND_WORDS = arrayOf( 22 | "Restaurant", "Cafe", "Spot", "Eatin' Place", "Eatery", "Drive Thru", "Diner") 23 | 24 | /** 25 | * Create a random Restaurant POJO. 26 | */ 27 | fun getRandom(context: Context): Restaurant { 28 | val restaurant = Restaurant() 29 | val random = Random() 30 | 31 | // Cities (first elemnt is 'Any') 32 | var cities = context.resources.getStringArray(R.array.cities) 33 | cities = Arrays.copyOfRange(cities, 1, cities.size) 34 | 35 | // Categories (first element is 'Any') 36 | var categories = context.resources.getStringArray(R.array.categories) 37 | categories = Arrays.copyOfRange(categories, 1, categories.size) 38 | 39 | val prices = intArrayOf(1, 2, 3) 40 | 41 | restaurant.name = getRandomName(random) 42 | restaurant.city = getRandomString(cities, random) 43 | restaurant.category = getRandomString(categories, random) 44 | restaurant.photo = getRandomImageUrl(random) 45 | restaurant.price = getRandomInt(prices, random) 46 | restaurant.numRatings = random.nextInt(20) 47 | 48 | // Note: average rating intentionally not set 49 | 50 | return restaurant 51 | } 52 | 53 | /** 54 | * Get a random image. 55 | */ 56 | private fun getRandomImageUrl(random: Random): String { 57 | // Integer between 1 and MAX_IMAGE_NUM (inclusive) 58 | val id = random.nextInt(MAX_IMAGE_NUM) + 1 59 | 60 | return String.format(Locale.getDefault(), RESTAURANT_URL_FMT, id) 61 | } 62 | 63 | /** 64 | * Get price represented as dollar signs. 65 | */ 66 | fun getPriceString(restaurant: Restaurant): String { 67 | return getPriceString(restaurant.price) 68 | } 69 | 70 | /** 71 | * Get price represented as dollar signs. 72 | */ 73 | fun getPriceString(priceInt: Int): String { 74 | when (priceInt) { 75 | 1 -> return "$" 76 | 2 -> return "$$" 77 | 3 -> return "$$$" 78 | else -> return "$$$" 79 | } 80 | } 81 | 82 | private fun getRandomName(random: Random): String { 83 | return (getRandomString(NAME_FIRST_WORDS, random) + " " + 84 | getRandomString(NAME_SECOND_WORDS, random)) 85 | } 86 | 87 | private fun getRandomString(array: Array, random: Random): String { 88 | val ind = random.nextInt(array.size) 89 | return array[ind] 90 | } 91 | 92 | private fun getRandomInt(array: IntArray, random: Random): Int { 93 | val ind = random.nextInt(array.size) 94 | return array[ind] 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /app/src/main/java/com/google/firebase/example/fireeats/viewmodel/MainActivityViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.google.firebase.example.fireeats.viewmodel 2 | 3 | import androidx.lifecycle.ViewModel 4 | import com.google.firebase.example.fireeats.Filters 5 | 6 | /** 7 | * ViewModel for [com.google.firebase.example.fireeats.MainActivity]. 8 | */ 9 | 10 | class MainActivityViewModel : ViewModel() { 11 | 12 | var isSigningIn: Boolean = false 13 | var filters: Filters = Filters.default 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/pizza_monster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firebase/friendlyeats-android/e7d6a647d0857efc06e03db971b3ada4bc4697e4/app/src/main/res/drawable-hdpi/pizza_monster.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/pizza_monster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firebase/friendlyeats-android/e7d6a647d0857efc06e03db971b3ada4bc4697e4/app/src/main/res/drawable-mdpi/pizza_monster.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/food_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firebase/friendlyeats-android/e7d6a647d0857efc06e03db971b3ada4bc4697e4/app/src/main/res/drawable-nodpi/food_1.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/pizza_monster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firebase/friendlyeats-android/e7d6a647d0857efc06e03db971b3ada4bc4697e4/app/src/main/res/drawable-xhdpi/pizza_monster.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/pizza_monster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/firebase/friendlyeats-android/e7d6a647d0857efc06e03db971b3ada4bc4697e4/app/src/main/res/drawable-xxhdpi/pizza_monster.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_shadow.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/gradient_up.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_add_white_24px.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_back_white_24px.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_close_white_24px.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_fastfood_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_filter_list_white_24px.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_local_dining_white_24px.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_monetization_on_white_24px.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_place_white_24px.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_restaurant_white_24px.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_sort_white_24px.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 24 | 25 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_restaurant_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 23 | 24 | 28 | 29 | 30 | 38 | 39 | 50 | 51 | 60 | 61 | 73 | 74 | 85 | 86 | 93 | 94 | 104 | 105 | 117 | 118 | 119 | 120 | 129 | 130 | 131 | 142 | 143 | 144 | 155 | 156 | 159 | 160 | 166 | 167 | 168 | 169 | 170 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_filters.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 19 | 20 | 30 | 31 | 42 | 43 | 44 | 45 | 53 | 54 | 65 | 66 | 67 | 75 | 76 | 87 | 88 | 89 | 97 | 98 | 109 | 110 | 111 | 121 | 122 |