├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable
│ │ │ │ ├── horse.jpg
│ │ │ │ ├── notes.png
│ │ │ │ ├── ic_delete_black_24dp.xml
│ │ │ │ ├── ic_edit_black_24dp.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── layout
│ │ │ │ ├── content_main.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── activity_login_register.xml
│ │ │ │ ├── note_row.xml
│ │ │ │ ├── activity_profile.xml
│ │ │ │ └── activity_examples.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── notesapp
│ │ │ ├── Product.java
│ │ │ ├── Note.java
│ │ │ ├── LoginRegisterActivity.java
│ │ │ ├── NotesRecyclerAdapter.java
│ │ │ ├── ProfileActivity.java
│ │ │ ├── MainActivity.java
│ │ │ └── ExamplesActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── notesapp
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── notesapp
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── encodings.xml
├── vcs.xml
├── misc.xml
├── runConfigurations.xml
└── gradle.xml
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trulymittal/FirebaseNotesApp/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/horse.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trulymittal/FirebaseNotesApp/HEAD/app/src/main/res/drawable/horse.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/notes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trulymittal/FirebaseNotesApp/HEAD/app/src/main/res/drawable/notes.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trulymittal/FirebaseNotesApp/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trulymittal/FirebaseNotesApp/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trulymittal/FirebaseNotesApp/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trulymittal/FirebaseNotesApp/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trulymittal/FirebaseNotesApp/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trulymittal/FirebaseNotesApp/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trulymittal/FirebaseNotesApp/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trulymittal/FirebaseNotesApp/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trulymittal/FirebaseNotesApp/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trulymittal/FirebaseNotesApp/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Notes App
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Sep 15 18:11:01 IST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | /app/google-services.json
15 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_delete_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_edit_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/notesapp/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.notesapp;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Firebase Notes app
2 |
3 | ### To start
4 |
5 | Step 1: Create a new project through firebase console, if not already.
6 |
7 | > [Firebase console](https://console.firebase.google.com/)
8 |
9 | Step 2: Setup firebase project to use with android.
10 |
11 | Step 3: Copy the **google-services.json** in app folder, or as told by me in the setup video.
12 |
13 |
14 | ## Authors
15 |
16 | - [**Truly Mittal**](https://trulymittal.com)
17 |
18 | ## License
19 |
20 | This project is licensed under the MIT License.
21 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/notesapp/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.notesapp;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.example.notesapp", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/notesapp/Product.java:
--------------------------------------------------------------------------------
1 | package com.example.notesapp;
2 |
3 | public class Product {
4 |
5 | private String name;
6 | private int price;
7 | private boolean isAvailable;
8 |
9 | public Product(String name, int price, boolean isAvailable) {
10 | this.name = name;
11 | this.price = price;
12 | this.isAvailable = isAvailable;
13 | }
14 |
15 | public Product() {
16 | }
17 |
18 | public String getName() {
19 | return name;
20 | }
21 |
22 | public void setName(String name) {
23 | this.name = name;
24 | }
25 |
26 | public int getPrice() {
27 | return price;
28 | }
29 |
30 | public void setPrice(int price) {
31 | this.price = price;
32 | }
33 |
34 | public boolean getIsAvailable() {
35 | return isAvailable;
36 | }
37 |
38 | public void setAvailable(boolean available) {
39 | isAvailable = available;
40 | }
41 |
42 | @Override
43 | public String toString() {
44 | return "Product{" +
45 | "name='" + name + '\'' +
46 | ", price=" + price +
47 | ", isAvailable=" + isAvailable +
48 | '}';
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/notesapp/Note.java:
--------------------------------------------------------------------------------
1 | package com.example.notesapp;
2 |
3 | import com.google.firebase.Timestamp;
4 |
5 | public class Note {
6 |
7 | private String text;
8 | private boolean completed;
9 | private Timestamp created;
10 | private String userId;
11 |
12 | public Note() {
13 | }
14 |
15 | public Note(String text, boolean completed, Timestamp created, String userId) {
16 | this.text = text;
17 | this.completed = completed;
18 | this.created = created;
19 | this.userId = userId;
20 | }
21 |
22 | public String getText() {
23 | return text;
24 | }
25 |
26 | public void setText(String text) {
27 | this.text = text;
28 | }
29 |
30 | public boolean getCompleted() {
31 | return completed;
32 | }
33 |
34 | public void setCompleted(boolean completed) {
35 | this.completed = completed;
36 | }
37 |
38 | public Timestamp getCreated() {
39 | return created;
40 | }
41 |
42 | public void setCreated(Timestamp created) {
43 | this.created = created;
44 | }
45 |
46 | public String getUserId() {
47 | return userId;
48 | }
49 |
50 | public void setUserId(String userId) {
51 | this.userId = userId;
52 | }
53 |
54 | @Override
55 | public String toString() {
56 | return "Note{" +
57 | "text='" + text + '\'' +
58 | ", completed=" + completed +
59 | ", created=" + created +
60 | ", userId='" + userId + '\'' +
61 | '}';
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | buildToolsVersion "29.0.2"
6 | defaultConfig {
7 | applicationId "com.example.notesapp"
8 | minSdkVersion 16
9 | targetSdkVersion 29
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 | implementation 'androidx.appcompat:appcompat:1.1.0'
25 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
26 | implementation 'com.google.android.material:material:1.0.0'
27 | testImplementation 'junit:junit:4.12'
28 | androidTestImplementation 'androidx.test:runner:1.2.0'
29 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
30 |
31 | implementation 'com.google.firebase:firebase-auth:19.1.0'
32 | implementation 'com.google.firebase:firebase-firestore:21.1.1'
33 |
34 | // FirebaseUI for Cloud Firestore
35 | implementation 'com.firebaseui:firebase-ui-firestore:6.0.1'
36 |
37 | // FirebaseUI for Firebase Auth
38 | implementation 'com.firebaseui:firebase-ui-auth:6.0.1'
39 |
40 | //Cloud Storage
41 | implementation 'com.google.firebase:firebase-storage:19.1.0'
42 |
43 | //circular image view
44 | implementation 'de.hdodenhof:circleimageview:3.0.1'
45 |
46 | // recycler swipe decorator
47 | implementation 'it.xabaras.android:recyclerview-swipedecorator:1.2.2'
48 |
49 | implementation 'com.github.bumptech.glide:glide:4.10.0'
50 | annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
51 |
52 |
53 | }
54 |
55 | // Add the following line to the bottom of the file:
56 | apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login_register.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
31 |
32 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/note_row.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
24 |
25 |
38 |
39 |
48 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_profile.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
21 |
22 |
33 |
34 |
39 |
40 |
41 |
57 |
58 |
67 |
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/notesapp/LoginRegisterActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.notesapp;
2 |
3 | import androidx.annotation.Nullable;
4 | import androidx.appcompat.app.AppCompatActivity;
5 |
6 | import android.content.Intent;
7 | import android.os.Bundle;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.widget.Toast;
11 |
12 | import com.firebase.ui.auth.AuthUI;
13 | import com.firebase.ui.auth.IdpResponse;
14 | import com.google.firebase.auth.FirebaseAuth;
15 | import com.google.firebase.auth.FirebaseUser;
16 |
17 | import java.util.Arrays;
18 | import java.util.List;
19 |
20 | public class LoginRegisterActivity extends AppCompatActivity {
21 |
22 | private static final String TAG = "LoginRegisterActivity";
23 | int AUTHUI_REQUEST_CODE = 10001;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_login_register);
29 |
30 | if (FirebaseAuth.getInstance().getCurrentUser() != null) {
31 | startActivity(new Intent(this, MainActivity.class));
32 | this.finish();
33 | }
34 | }
35 |
36 | public void handleLoginRegister(View view) {
37 |
38 | List providers = Arrays.asList(
39 | new AuthUI.IdpConfig.EmailBuilder().build(),
40 | new AuthUI.IdpConfig.GoogleBuilder().build(),
41 | new AuthUI.IdpConfig.PhoneBuilder().build()
42 | );
43 |
44 | Intent intent = AuthUI.getInstance()
45 | .createSignInIntentBuilder()
46 | .setAvailableProviders(providers)
47 | .setTosAndPrivacyPolicyUrls("https://example.com", "https://example.com")
48 | .setLogo(R.drawable.notes)
49 | .setAlwaysShowSignInMethodScreen(true)
50 | .setIsSmartLockEnabled(false)
51 | .build();
52 |
53 | startActivityForResult(intent, AUTHUI_REQUEST_CODE);
54 | }
55 |
56 | @Override
57 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
58 | super.onActivityResult(requestCode, resultCode, data);
59 | if (requestCode == AUTHUI_REQUEST_CODE) {
60 | if (resultCode == RESULT_OK) {
61 | // We have signed in the user or we have a new user
62 | FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
63 | Log.d(TAG, "onActivityResult: " + user.toString());
64 | //Checking for User (New/Old)
65 | if (user.getMetadata().getCreationTimestamp() == user.getMetadata().getLastSignInTimestamp()) {
66 | //This is a New User
67 | } else {
68 | //This is a returning user
69 | }
70 |
71 | Intent intent = new Intent(this, MainActivity.class);
72 | startActivity(intent);
73 | this.finish();
74 |
75 | } else {
76 | // Signing in failed
77 | IdpResponse response = IdpResponse.fromResultIntent(data);
78 | if (response == null) {
79 | Log.d(TAG, "onActivityResult: the user has cancelled the sign in request");
80 | } else {
81 | Log.e(TAG, "onActivityResult: ", response.getError());
82 | }
83 | }
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_examples.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
21 |
22 |
34 |
35 |
47 |
48 |
60 |
61 |
62 |
74 |
75 |
88 |
89 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/notesapp/NotesRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.notesapp;
2 |
3 | import android.text.format.DateFormat;
4 | import android.util.Log;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.CheckBox;
9 | import android.widget.CompoundButton;
10 | import android.widget.TextView;
11 |
12 | import androidx.annotation.NonNull;
13 | import androidx.recyclerview.widget.RecyclerView;
14 |
15 | import com.firebase.ui.firestore.FirestoreRecyclerAdapter;
16 | import com.firebase.ui.firestore.FirestoreRecyclerOptions;
17 | import com.google.firebase.firestore.DocumentSnapshot;
18 | import com.google.firebase.firestore.FirebaseFirestoreException;
19 |
20 | public class NotesRecyclerAdapter extends FirestoreRecyclerAdapter {
21 |
22 | private static final String TAG = "NotesRecyclerAdapter";
23 | NoteListener noteListener;
24 |
25 | public NotesRecyclerAdapter(@NonNull FirestoreRecyclerOptions options, NoteListener noteListener) {
26 | super(options);
27 | this.noteListener = noteListener;
28 | }
29 |
30 | @Override
31 | protected void onBindViewHolder(@NonNull NoteViewHolder holder, int position, @NonNull Note note) {
32 | holder.noteTextView.setText(note.getText());
33 | holder.checkBox.setChecked(note.getCompleted());
34 | CharSequence dateCharSeq = DateFormat.format("EEEE, MMM d, yyyy h:mm:ss a", note.getCreated().toDate());
35 | holder.dateTextView.setText(dateCharSeq);
36 | }
37 |
38 | @NonNull
39 | @Override
40 | public NoteViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
41 | LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
42 | View view = layoutInflater.inflate(R.layout.note_row, parent, false);
43 | return new NoteViewHolder(view);
44 | }
45 |
46 |
47 | class NoteViewHolder extends RecyclerView.ViewHolder {
48 |
49 | TextView noteTextView, dateTextView;
50 | CheckBox checkBox;
51 |
52 | public NoteViewHolder(@NonNull View itemView) {
53 | super(itemView);
54 | noteTextView = itemView.findViewById(R.id.noteTextView);
55 | dateTextView = itemView.findViewById(R.id.dateTextView);
56 | checkBox = itemView.findViewById(R.id.checkBox);
57 | checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
58 | @Override
59 | public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
60 | DocumentSnapshot snapshot = getSnapshots().getSnapshot(getAdapterPosition());
61 | Note note = getItem(getAdapterPosition());
62 | if (note.getCompleted() != isChecked) {
63 | noteListener.handleCheckChanged(isChecked, snapshot);
64 | }
65 | }
66 | });
67 | itemView.setOnClickListener(new View.OnClickListener() {
68 | @Override
69 | public void onClick(View view) {
70 |
71 | DocumentSnapshot snapshot = getSnapshots().getSnapshot(getAdapterPosition());
72 | noteListener.handleEditNote(snapshot);
73 |
74 | }
75 | });
76 | }
77 |
78 | public void deleteItem() {
79 | noteListener.handleDeleteItem(getSnapshots().getSnapshot(getAdapterPosition()));
80 | }
81 | }
82 |
83 | interface NoteListener {
84 | public void handleCheckChanged(boolean isChecked, DocumentSnapshot snapshot);
85 | public void handleEditNote(DocumentSnapshot snapshot);
86 | public void handleDeleteItem(DocumentSnapshot snapshot);
87 | }
88 | }
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/notesapp/ProfileActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.notesapp;
2 |
3 | import androidx.annotation.NonNull;
4 | import androidx.annotation.Nullable;
5 | import androidx.appcompat.app.AppCompatActivity;
6 |
7 | import android.content.Intent;
8 | import android.graphics.Bitmap;
9 | import android.graphics.BitmapFactory;
10 | import android.net.Uri;
11 | import android.os.Bundle;
12 | import android.provider.MediaStore;
13 | import android.util.Log;
14 | import android.view.View;
15 | import android.widget.Button;
16 | import android.widget.ProgressBar;
17 | import android.widget.Toast;
18 |
19 | import com.bumptech.glide.Glide;
20 | import com.firebase.ui.auth.AuthUI;
21 | import com.google.android.gms.auth.api.Auth;
22 | import com.google.android.gms.tasks.OnFailureListener;
23 | import com.google.android.gms.tasks.OnSuccessListener;
24 | import com.google.android.material.textfield.TextInputEditText;
25 | import com.google.firebase.auth.FirebaseAuth;
26 | import com.google.firebase.auth.FirebaseUser;
27 | import com.google.firebase.auth.UserProfileChangeRequest;
28 | import com.google.firebase.storage.FirebaseStorage;
29 | import com.google.firebase.storage.StorageReference;
30 | import com.google.firebase.storage.UploadTask;
31 |
32 | import java.io.ByteArrayOutputStream;
33 |
34 | import de.hdodenhof.circleimageview.CircleImageView;
35 |
36 | public class ProfileActivity extends AppCompatActivity {
37 |
38 | private static final String TAG = "ProfileActivity";
39 |
40 | CircleImageView profileImageView;
41 | TextInputEditText displayNameEditText;
42 | Button updateProfileButton;
43 | ProgressBar progressBar;
44 |
45 | String DISPLAY_NAME = null;
46 | String PROFILE_IMAGE_URL = null;
47 | int TAKE_IMAGE_CODE = 10001;
48 |
49 | @Override
50 | protected void onCreate(Bundle savedInstanceState) {
51 | super.onCreate(savedInstanceState);
52 | setContentView(R.layout.activity_profile);
53 |
54 | profileImageView = findViewById(R.id.profileImageView);
55 | displayNameEditText = findViewById(R.id.displayNameEditText);
56 | updateProfileButton = findViewById(R.id.updateProfileButton);
57 | progressBar = findViewById(R.id.progressBar);
58 |
59 | FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
60 |
61 | if (user != null) {
62 | Log.d(TAG, "onCreate: " + user.getDisplayName());
63 | if (user.getDisplayName() != null) {
64 | displayNameEditText.setText(user.getDisplayName());
65 | displayNameEditText.setSelection(user.getDisplayName().length());
66 | }
67 | if (user.getPhotoUrl() != null) {
68 | Glide.with(this)
69 | .load(user.getPhotoUrl())
70 | .into(profileImageView);
71 | }
72 | }
73 |
74 | progressBar.setVisibility(View.GONE);
75 |
76 | }
77 |
78 | public void updateProfile(final View view) {
79 |
80 | view.setEnabled(false);
81 | progressBar.setVisibility(View.VISIBLE);
82 |
83 | DISPLAY_NAME = displayNameEditText.getText().toString();
84 |
85 | FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
86 |
87 | UserProfileChangeRequest request = new UserProfileChangeRequest.Builder()
88 | .setDisplayName(DISPLAY_NAME)
89 | .build();
90 |
91 | firebaseUser.updateProfile(request)
92 | .addOnSuccessListener(new OnSuccessListener() {
93 | @Override
94 | public void onSuccess(Void aVoid) {
95 | view.setEnabled(true);
96 | progressBar.setVisibility(View.GONE);
97 | Toast.makeText(ProfileActivity.this, "Succesfully updated profile", Toast.LENGTH_SHORT).show();
98 | }
99 | })
100 | .addOnFailureListener(new OnFailureListener() {
101 | @Override
102 | public void onFailure(@NonNull Exception e) {
103 | view.setEnabled(true);
104 | progressBar.setVisibility(View.GONE);
105 | Log.e(TAG, "onFailure: ", e.getCause());
106 | }
107 | });
108 |
109 | }
110 |
111 | public void storageDemo(View view) {
112 |
113 | // FirebaseStorage storage = FirebaseStorage.getInstance();
114 | // StorageReference reference = storage.getReference();
115 | // StorageReference horseRef = reference.child("horse__.jpg");
116 | // StorageReference horseRef = storage.getReference().child("images").child("girl.jpg");
117 | // StorageReference horseRef = storage.getReference().child("images").child("profileImages").child("123.jpg");
118 | // Bitmap horseBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.horse);
119 | // ByteArrayOutputStream boas = new ByteArrayOutputStream();
120 | // horseBitmap.compress(Bitmap.CompressFormat.JPEG, 20, boas);
121 | // horseRef.putBytes(boas.toByteArray())
122 | // .addOnSuccessListener(new OnSuccessListener() {
123 | // @Override
124 | // public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
125 | // Toast.makeText(ProfileActivity.this, "upload succesfull", Toast.LENGTH_SHORT).show();
126 | // }
127 | // });
128 |
129 | // FirebaseStorage storage = FirebaseStorage.getInstance();
130 | // StorageReference imageRef = storage.getReference()
131 | // .child("images")
132 | // .child("profileImages")
133 | // .child("123.jpg");
134 |
135 | // imageRef.getBytes(1024*1024)
136 | // .addOnSuccessListener(new OnSuccessListener() {
137 | // @Override
138 | // public void onSuccess(byte[] bytes) {
139 | // Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
140 | // profileImageView.setImageBitmap(bitmap);
141 | // }
142 | // });
143 | // imageRef.getDownloadUrl()
144 | // .addOnSuccessListener(new OnSuccessListener() {
145 | // @Override
146 | // public void onSuccess(Uri uri) {
147 | // Log.d(TAG, "Download url is: " + uri.toString());
148 | // }
149 | // });
150 | }
151 |
152 | public void handleImageClick(View view) {
153 |
154 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
155 | if (intent.resolveActivity(getPackageManager()) != null) {
156 | startActivityForResult(intent, TAKE_IMAGE_CODE);
157 | }
158 | }
159 |
160 | @Override
161 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
162 | super.onActivityResult(requestCode, resultCode, data);
163 | if (requestCode == TAKE_IMAGE_CODE) {
164 | switch (resultCode) {
165 | case RESULT_OK:
166 | Bitmap bitmap = (Bitmap) data.getExtras().get("data");
167 | profileImageView.setImageBitmap(bitmap);
168 | handleUpload(bitmap);
169 | }
170 | }
171 | }
172 |
173 | private void handleUpload(Bitmap bitmap) {
174 |
175 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
176 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
177 |
178 | String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
179 | final StorageReference reference = FirebaseStorage.getInstance().getReference()
180 | .child("profileImages")
181 | .child(uid + ".jpeg");
182 |
183 | reference.putBytes(baos.toByteArray())
184 | .addOnSuccessListener(new OnSuccessListener() {
185 | @Override
186 | public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
187 | getDownloadUrl(reference);
188 | }
189 | })
190 | .addOnFailureListener(new OnFailureListener() {
191 | @Override
192 | public void onFailure(@NonNull Exception e) {
193 | Log.e(TAG, "onFailure: ",e.getCause() );
194 | }
195 | });
196 | }
197 |
198 | private void getDownloadUrl(StorageReference reference) {
199 | reference.getDownloadUrl()
200 | .addOnSuccessListener(new OnSuccessListener() {
201 | @Override
202 | public void onSuccess(Uri uri) {
203 | Log.d(TAG, "onSuccess: " + uri);
204 | setUserProfileUrl(uri);
205 | }
206 | });
207 | }
208 |
209 | private void setUserProfileUrl(Uri uri) {
210 | FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
211 |
212 | UserProfileChangeRequest request = new UserProfileChangeRequest.Builder()
213 | .setPhotoUri(uri)
214 | .build();
215 |
216 | user.updateProfile(request)
217 | .addOnSuccessListener(new OnSuccessListener() {
218 | @Override
219 | public void onSuccess(Void aVoid) {
220 | Toast.makeText(ProfileActivity.this, "Updated succesfully", Toast.LENGTH_SHORT).show();
221 | }
222 | })
223 | .addOnFailureListener(new OnFailureListener() {
224 | @Override
225 | public void onFailure(@NonNull Exception e) {
226 | Toast.makeText(ProfileActivity.this, "Profile image failed...", Toast.LENGTH_SHORT).show();
227 | }
228 | });
229 | }
230 | }
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/notesapp/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.notesapp;
2 |
3 | import android.content.DialogInterface;
4 | import android.content.Intent;
5 | import android.graphics.Canvas;
6 | import android.icu.lang.UCharacter;
7 | import android.os.Bundle;
8 |
9 | import com.firebase.ui.auth.AuthUI;
10 | import com.firebase.ui.firestore.FirestoreRecyclerOptions;
11 | import com.google.android.gms.tasks.OnFailureListener;
12 | import com.google.android.gms.tasks.OnSuccessListener;
13 | import com.google.android.material.floatingactionbutton.FloatingActionButton;
14 | import com.google.android.material.snackbar.Snackbar;
15 | import com.google.firebase.Timestamp;
16 | import com.google.firebase.auth.FirebaseAuth;
17 | import com.google.firebase.auth.FirebaseUser;
18 | import com.google.firebase.auth.GetTokenResult;
19 | import com.google.firebase.firestore.DocumentReference;
20 | import com.google.firebase.firestore.DocumentSnapshot;
21 | import com.google.firebase.firestore.FirebaseFirestore;
22 | import com.google.firebase.firestore.Query;
23 |
24 | import androidx.annotation.NonNull;
25 | import androidx.appcompat.app.AlertDialog;
26 | import androidx.appcompat.app.AppCompatActivity;
27 | import androidx.appcompat.widget.Toolbar;
28 | import androidx.core.content.ContextCompat;
29 | import androidx.recyclerview.widget.DividerItemDecoration;
30 | import androidx.recyclerview.widget.ItemTouchHelper;
31 | import androidx.recyclerview.widget.LinearLayoutManager;
32 | import androidx.recyclerview.widget.RecyclerView;
33 |
34 | import android.util.Log;
35 | import android.view.View;
36 | import android.view.Menu;
37 | import android.view.MenuItem;
38 | import android.widget.EditText;
39 | import android.widget.Toast;
40 |
41 | import java.util.Date;
42 |
43 | import it.xabaras.android.recyclerview.swipedecorator.RecyclerViewSwipeDecorator;
44 |
45 | public class MainActivity extends AppCompatActivity implements FirebaseAuth.AuthStateListener, NotesRecyclerAdapter.NoteListener {
46 |
47 | private static final String TAG = "MainActivity";
48 | RecyclerView recyclerView;
49 | NotesRecyclerAdapter notesRecyclerAdapter;
50 |
51 | @Override
52 | protected void onCreate(Bundle savedInstanceState) {
53 | super.onCreate(savedInstanceState);
54 | setContentView(R.layout.activity_main);
55 | Toolbar toolbar = findViewById(R.id.toolbar);
56 | setSupportActionBar(toolbar);
57 |
58 | recyclerView = findViewById(R.id.recyclerView);
59 | recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
60 |
61 | FloatingActionButton fab = findViewById(R.id.fab);
62 | fab.setOnClickListener(new View.OnClickListener() {
63 | @Override
64 | public void onClick(View view) {
65 | // startExamplesActivity();
66 | showAlertDialog();
67 | }
68 | });
69 |
70 | }
71 |
72 |
73 | private void showAlertDialog() {
74 | final EditText noteEditText = new EditText(this);
75 | new AlertDialog.Builder(this)
76 | .setTitle("Add Note")
77 | .setView(noteEditText)
78 | .setPositiveButton("Add", new DialogInterface.OnClickListener() {
79 | @Override
80 | public void onClick(DialogInterface dialogInterface, int i) {
81 | Log.d(TAG, "onClick: " + noteEditText.getText());
82 | addNote(noteEditText.getText().toString());
83 | }
84 | })
85 | .setNegativeButton("Cancel", null)
86 | .show();
87 | }
88 |
89 | private void addNote(String text) {
90 |
91 | String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();
92 | Note note = new Note(text, false, new Timestamp(new Date()), userId);
93 |
94 | FirebaseFirestore.getInstance()
95 | .collection("notes")
96 | .add(note)
97 | .addOnSuccessListener(new OnSuccessListener() {
98 | @Override
99 | public void onSuccess(DocumentReference documentReference) {
100 | Log.d(TAG, "onSuccess: Succesfully added the note...");
101 | }
102 | })
103 | .addOnFailureListener(new OnFailureListener() {
104 | @Override
105 | public void onFailure(@NonNull Exception e) {
106 | Log.e(TAG, "onFailure: " + e.getLocalizedMessage() );
107 | Toast.makeText(MainActivity.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
108 | }
109 | });
110 |
111 | }
112 |
113 | private void startExamplesActivity() {
114 | Intent intent = new Intent(this, ExamplesActivity.class);
115 | startActivity(intent);
116 | }
117 |
118 | private void startLoginActivity() {
119 | Intent intent = new Intent(this, LoginRegisterActivity.class);
120 | startActivity(intent);
121 | finish();
122 | }
123 |
124 | @Override
125 | public boolean onCreateOptionsMenu(Menu menu) {
126 | // Inflate the menu; this adds items to the action bar if it is present.
127 | getMenuInflater().inflate(R.menu.menu_main, menu);
128 | return true;
129 | }
130 |
131 | @Override
132 | public boolean onOptionsItemSelected(MenuItem item) {
133 | // Handle action bar item clicks here. The action bar will
134 | // automatically handle clicks on the Home/Up button, so long
135 | // as you specify a parent activity in AndroidManifest.xml.
136 | int id = item.getItemId();
137 |
138 | switch (id) {
139 | case R.id.action_logout:
140 | AuthUI.getInstance().signOut(this);
141 | return true;
142 | case R.id.action_profile:
143 | startActivity(new Intent(MainActivity.this, ProfileActivity.class));
144 | return true;
145 | }
146 | return super.onOptionsItemSelected(item);
147 | }
148 |
149 | @Override
150 | protected void onStart() {
151 | super.onStart();
152 | FirebaseAuth.getInstance().addAuthStateListener(this);
153 | }
154 |
155 | @Override
156 | protected void onStop() {
157 | super.onStop();
158 | FirebaseAuth.getInstance().removeAuthStateListener(this);
159 | if (notesRecyclerAdapter != null) {
160 | notesRecyclerAdapter.stopListening();
161 | }
162 | }
163 |
164 | @Override
165 | public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
166 | if (firebaseAuth.getCurrentUser() == null) {
167 | startLoginActivity();
168 | return;
169 | }
170 |
171 | initRecyclerView(firebaseAuth.getCurrentUser());
172 | }
173 |
174 | private void initRecyclerView(FirebaseUser user) {
175 |
176 | Query query = FirebaseFirestore.getInstance()
177 | .collection("notes")
178 | .whereEqualTo("userId", user.getUid())
179 | .orderBy("completed", Query.Direction.ASCENDING)
180 | .orderBy("created", Query.Direction.DESCENDING);
181 |
182 |
183 | FirestoreRecyclerOptions options = new FirestoreRecyclerOptions.Builder()
184 | .setQuery(query, Note.class)
185 | .build();
186 | notesRecyclerAdapter = new NotesRecyclerAdapter(options, this);
187 | recyclerView.setAdapter(notesRecyclerAdapter);
188 | notesRecyclerAdapter.startListening();
189 |
190 | ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleCallback);
191 | itemTouchHelper.attachToRecyclerView(recyclerView);
192 |
193 | }
194 |
195 | ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
196 | @Override
197 | public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
198 | return false;
199 | }
200 |
201 | @Override
202 | public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
203 | if (direction == ItemTouchHelper.LEFT) {
204 | Toast.makeText(MainActivity.this, "Deleting", Toast.LENGTH_SHORT).show();
205 |
206 | NotesRecyclerAdapter.NoteViewHolder noteViewHolder = (NotesRecyclerAdapter.NoteViewHolder) viewHolder;
207 | noteViewHolder.deleteItem();
208 | }
209 | }
210 |
211 | @Override
212 | public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
213 | new RecyclerViewSwipeDecorator.Builder(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
214 | .addBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorAccent))
215 | .addActionIcon(R.drawable.ic_delete_black_24dp)
216 | .create()
217 | .decorate();
218 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
219 | }
220 | };
221 |
222 | @Override
223 | public void handleCheckChanged(boolean isChecked, DocumentSnapshot snapshot) {
224 | Log.d(TAG, "handleCheckChanged: " + isChecked);
225 | snapshot.getReference().update("completed", isChecked)
226 | .addOnSuccessListener(new OnSuccessListener() {
227 | @Override
228 | public void onSuccess(Void aVoid) {
229 | Log.d(TAG, "onSuccess: ");
230 | }
231 | })
232 | .addOnFailureListener(new OnFailureListener() {
233 | @Override
234 | public void onFailure(@NonNull Exception e) {
235 | Log.d(TAG, "onFailure: " + e.getLocalizedMessage());
236 | }
237 | });
238 | }
239 |
240 | @Override
241 | public void handleEditNote(final DocumentSnapshot snapshot) {
242 | final Note note = snapshot.toObject(Note.class);
243 | final EditText editText = new EditText(this);
244 | editText.setText(note.getText().toString());
245 | editText.setSelection(note.getText().length());
246 |
247 | new AlertDialog.Builder(this)
248 | .setTitle("Edit Note")
249 | .setView(editText)
250 | .setPositiveButton("Done", new DialogInterface.OnClickListener() {
251 | @Override
252 | public void onClick(DialogInterface dialogInterface, int i) {
253 | String newText = editText.getText().toString();
254 | note.setText(newText);
255 | snapshot.getReference().set(note)
256 | .addOnSuccessListener(new OnSuccessListener() {
257 | @Override
258 | public void onSuccess(Void aVoid) {
259 | Log.d(TAG, "onSuccess: ");
260 | }
261 | });
262 | }
263 | })
264 | .setNegativeButton("Cancel", null)
265 | .show();
266 | }
267 |
268 | @Override
269 | public void handleDeleteItem(DocumentSnapshot snapshot) {
270 |
271 | final DocumentReference documentReference = snapshot.getReference();
272 | final Note note = snapshot.toObject(Note.class);
273 |
274 | documentReference.delete()
275 | .addOnSuccessListener(new OnSuccessListener() {
276 | @Override
277 | public void onSuccess(Void aVoid) {
278 | Log.d(TAG, "onSuccess: Item deleted");
279 | }
280 | });
281 |
282 | Snackbar.make(recyclerView, "Item deleted", Snackbar.LENGTH_LONG)
283 | .setAction("Undo", new View.OnClickListener() {
284 | @Override
285 | public void onClick(View view) {
286 | documentReference.set(note);
287 | }
288 | })
289 | .show();
290 |
291 | }
292 |
293 | }
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/notesapp/ExamplesActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.notesapp;
2 |
3 | import androidx.annotation.NonNull;
4 | import androidx.appcompat.app.AppCompatActivity;
5 |
6 | import android.os.Bundle;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.widget.Toast;
10 |
11 | import com.google.android.gms.tasks.OnCompleteListener;
12 | import com.google.android.gms.tasks.OnFailureListener;
13 | import com.google.android.gms.tasks.OnSuccessListener;
14 | import com.google.android.gms.tasks.Task;
15 | import com.google.firebase.firestore.DocumentChange;
16 | import com.google.firebase.firestore.DocumentReference;
17 | import com.google.firebase.firestore.DocumentSnapshot;
18 | import com.google.firebase.firestore.EventListener;
19 | import com.google.firebase.firestore.FieldValue;
20 | import com.google.firebase.firestore.FirebaseFirestore;
21 | import com.google.firebase.firestore.FirebaseFirestoreException;
22 | import com.google.firebase.firestore.Query;
23 | import com.google.firebase.firestore.QuerySnapshot;
24 | import com.google.firebase.firestore.SetOptions;
25 | import com.google.firebase.firestore.WriteBatch;
26 |
27 | import java.util.ArrayList;
28 | import java.util.HashMap;
29 | import java.util.List;
30 | import java.util.Map;
31 |
32 | public class ExamplesActivity extends AppCompatActivity {
33 |
34 | private static final String TAG = "ExamplesActivity";
35 | FirebaseFirestore firestore = FirebaseFirestore.getInstance();
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_examples);
41 | }
42 |
43 | public void createDocument(View view) {
44 | Toast.makeText(this, "createDocument", Toast.LENGTH_SHORT).show();
45 |
46 | // Map map = new HashMap<>();
47 | // map.put("name", "iPhone 11");
48 | // map.put("price", 699);
49 | // map.put("isAvailable", true);
50 |
51 | Product product = new Product("iPhone 11", 699, true);
52 |
53 | firestore.collection("products")
54 | // .add(map)
55 | .add(product)
56 | .addOnSuccessListener(new OnSuccessListener() {
57 | @Override
58 | public void onSuccess(DocumentReference documentReference) {
59 | Log.d(TAG, "onSuccess: task was succesfull");
60 | Log.d(TAG, "onSuccess: " + documentReference.getId());
61 | }
62 | })
63 | .addOnFailureListener(new OnFailureListener() {
64 | @Override
65 | public void onFailure(@NonNull Exception e) {
66 | Log.d(TAG, "onSuccess: task was NOT succesfull");
67 | }
68 | });
69 |
70 |
71 | // Map map = new HashMap<>();
72 | // map.put("text", "i wanna watch captain marvel again and again");
73 | // map.put("isCompleted", false);
74 | // map.put("created", new Timestamp(new Date()));
75 | //
76 | // firestore.collection("notes")
77 | // .add(map)
78 | // .addOnSuccessListener(new OnSuccessListener() {
79 | // @Override
80 | // public void onSuccess(DocumentReference documentReference) {
81 | // Log.d(TAG, "onSuccess: task was succesfull");
82 | // Log.d(TAG, "onSuccess: " + documentReference.getId());
83 | // }
84 | // })
85 | // .addOnFailureListener(new OnFailureListener() {
86 | // @Override
87 | // public void onFailure(@NonNull Exception e) {
88 | // Log.d(TAG, "onSuccess: task was NOT succesfull");
89 | // }
90 | // });
91 |
92 | // Map map = new HashMap<>();
93 | // map.put("name", "Mac Pro");
94 | // map.put("price", 9999);
95 | // map.put("isAvailable", true);
96 | //
97 | // FirebaseFirestore.getInstance()
98 | // .collection("products")
99 | // .add(map)
100 | // .addOnSuccessListener(new OnSuccessListener() {
101 | // @Override
102 | // public void onSuccess(DocumentReference documentReference) {
103 | // Log.d(TAG, "onSuccess: Product is added succesfully");
104 | // Log.d(TAG, "onSuccess: " + documentReference.getId());
105 | // }
106 | // })
107 | // .addOnFailureListener(new OnFailureListener() {
108 | // @Override
109 | // public void onFailure(@NonNull Exception e) {
110 | // Log.e(TAG, "onFailure: ", e);
111 | // }
112 | // });
113 |
114 | }
115 |
116 | public void readDocument(View view) {
117 |
118 | Toast.makeText(this, "Reading a doc...", Toast.LENGTH_SHORT).show();
119 |
120 | FirebaseFirestore.getInstance()
121 | .collection("products")
122 | .document("NH74yiFpjYwxakCKXjJj")
123 | .get()
124 | .addOnCompleteListener(new OnCompleteListener() {
125 | @Override
126 | public void onComplete(@NonNull Task task) {
127 | if (task.isSuccessful()) {
128 | Product product = task.getResult().toObject(Product.class);
129 | Log.d(TAG, "onComplete: " + product);
130 | } else {
131 | Log.e(TAG, "onComplete: ", task.getException() );
132 | }
133 | }
134 | });
135 | // .addOnSuccessListener(new OnSuccessListener() {
136 | // @Override
137 | // public void onSuccess(DocumentSnapshot documentSnapshot) {
138 | // Product product = documentSnapshot.toObject(Product.class);
139 | // Log.d(TAG, "onSuccess: " + product);
140 | // }
141 | // })
142 | // .addOnFailureListener(new OnFailureListener() {
143 | // @Override
144 | // public void onFailure(@NonNull Exception e) {
145 | // Log.e(TAG, "onFailure: ", e);
146 | // }
147 | // });
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 | // FirebaseFirestore.getInstance()
158 | // .collection("products")
159 | // .document("NH74yiFpjYwxakCKXjJj")
160 | // .get()
161 | // .addOnSuccessListener(new OnSuccessListener() {
162 | // @Override
163 | // public void onSuccess(DocumentSnapshot documentSnapshot) {
164 | //// Log.d(TAG, "onSuccess: " + documentSnapshot.getData());
165 | //// Log.d(TAG, "onSuccess name: " + documentSnapshot.getString("name"));
166 | //// Log.d(TAG, "onSuccess isAvailable: " + documentSnapshot.getBoolean("isAvailable"));
167 | //// Log.d(TAG, "onSuccess price: " + documentSnapshot.getLong("price"));
168 | // Product product = documentSnapshot.toObject(Product.class);
169 | // Log.d(TAG, "onSuccess: " + product.toString());
170 | // Log.d(TAG, "onSuccess: " + product.getName());
171 | // Log.d(TAG, "onSuccess: " +product.getPrice());
172 | // Log.d(TAG, "onSuccess: " + product.getIsAvailable());
173 | //
174 | // }
175 | // })
176 | // .addOnFailureListener(new OnFailureListener() {
177 | // @Override
178 | // public void onFailure(@NonNull Exception e) {
179 | // Log.e(TAG, "onFailure: ", e);
180 | // }
181 | // });
182 |
183 | }
184 |
185 | public void updateDocument(View view) {
186 | // Toast.makeText(this, "updateDocument", Toast.LENGTH_SHORT).show();
187 |
188 | final DocumentReference docRef = FirebaseFirestore.getInstance()
189 | .collection("products")
190 | .document("123");
191 |
192 | Map map = new HashMap<>();
193 | // map.put("name", "iPhone 6s Plus");
194 | map.put("price", FieldValue.increment(-100));
195 | // map.put("brand", FieldValue.delete());
196 | // map.put("isAvailable", true);
197 |
198 | docRef.update(map)
199 | .addOnSuccessListener(new OnSuccessListener() {
200 | @Override
201 | public void onSuccess(Void aVoid) {
202 | Log.d(TAG, "onSuccess: yay, updated the doc");
203 | }
204 | })
205 | .addOnFailureListener(new OnFailureListener() {
206 | @Override
207 | public void onFailure(@NonNull Exception e) {
208 | Log.e(TAG, "onFailure: ", e);
209 | }
210 | });
211 |
212 | // docRef.set(map, SetOptions.merge())
213 | // .addOnSuccessListener(new OnSuccessListener() {
214 | // @Override
215 | // public void onSuccess(Void aVoid) {
216 | // Log.d(TAG, "onSuccess: yay, set the doc");
217 | // }
218 | // })
219 | // .addOnFailureListener(new OnFailureListener() {
220 | // @Override
221 | // public void onFailure(@NonNull Exception e) {
222 | // Log.e(TAG, "onFailure: ", e);
223 | // }
224 | // });
225 | }
226 |
227 | public void deleteDocument(View view) {
228 |
229 | // FirebaseFirestore.getInstance().collection("products")
230 | // .document("123")
231 | // .delete()
232 | // .addOnSuccessListener(new OnSuccessListener() {
233 | // @Override
234 | // public void onSuccess(Void aVoid) {
235 | // Log.d(TAG, "onSuccess: We have deleted the document...");
236 | // }
237 | // })
238 | // .addOnFailureListener(new OnFailureListener() {
239 | // @Override
240 | // public void onFailure(@NonNull Exception e) {
241 | // Log.e(TAG, "onFailure: ", e);
242 | // }
243 | // });
244 |
245 | FirebaseFirestore.getInstance().collection("products")
246 | .whereEqualTo("brand", "Apple")
247 | .get()
248 | .addOnSuccessListener(new OnSuccessListener() {
249 | @Override
250 | public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
251 |
252 | WriteBatch batch = FirebaseFirestore.getInstance().batch();
253 |
254 | List snapshotList = queryDocumentSnapshots.getDocuments();
255 | for (DocumentSnapshot snapshot: snapshotList) {
256 | batch.delete(snapshot.getReference());
257 | }
258 |
259 | batch.commit()
260 | .addOnSuccessListener(new OnSuccessListener() {
261 | @Override
262 | public void onSuccess(Void aVoid) {
263 | Log.d(TAG, "onSuccess: Deleted all docs with brand = Apple");
264 | }
265 | })
266 | .addOnFailureListener(new OnFailureListener() {
267 | @Override
268 | public void onFailure(@NonNull Exception e) {
269 | Log.e(TAG, "onFailure: ", e);
270 | }
271 | });
272 |
273 | }
274 | })
275 | .addOnFailureListener(new OnFailureListener() {
276 | @Override
277 | public void onFailure(@NonNull Exception e) {
278 |
279 | }
280 | });
281 |
282 |
283 | }
284 |
285 | public void getAllDocuments(View view) {
286 | Toast.makeText(this, "getAllDocuments", Toast.LENGTH_SHORT).show();
287 |
288 | FirebaseFirestore.getInstance()
289 | .collection("products")
290 | .get()
291 | .addOnSuccessListener(new OnSuccessListener() {
292 | @Override
293 | public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
294 | Log.d(TAG, "onSuccess: We're getting the data");
295 |
296 | List productList = queryDocumentSnapshots.toObjects(Product.class);
297 | Log.d(TAG, "onSuccess: " + productList.toString());
298 |
299 | // List snapshotList = queryDocumentSnapshots.getDocuments();
300 | // for (DocumentSnapshot snapshot: snapshotList) {
301 | // Log.d(TAG, "onSuccess: " + snapshot.getData().toString());
302 | // }
303 | }
304 | })
305 | .addOnFailureListener(new OnFailureListener() {
306 | @Override
307 | public void onFailure(@NonNull Exception e) {
308 | Log.e(TAG, "onFailure: ", e);
309 | }
310 | });
311 |
312 | // FirebaseFirestore.getInstance()
313 | // .collection("products")
314 | //// .whereLessThan("price", 1000)
315 | //// .whereEqualTo("isAvailable", false)
316 | // .whereEqualTo("price", 999)
317 | // .get()
318 | // .addOnSuccessListener(new OnSuccessListener() {
319 | // @Override
320 | // public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
321 | // Log.d(TAG, "onSuccess: We're getting the data");
322 | // List snapshotList = queryDocumentSnapshots.getDocuments();
323 | // for (DocumentSnapshot snapshot: snapshotList) {
324 | // Log.d(TAG, "onSuccess: " + snapshot.getData().toString());
325 | // }
326 | // }
327 | // })
328 | // .addOnFailureListener(new OnFailureListener() {
329 | // @Override
330 | // public void onFailure(@NonNull Exception e) {
331 | // Log.e(TAG, "onFailure: ", e);
332 | // }
333 | // });
334 |
335 | // firestore.collection("products")
336 | // .whereEqualTo("brand", "apple")
337 | // .get()
338 | // .addOnSuccessListener(new OnSuccessListener() {
339 | // @Override
340 | // public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
341 | // WriteBatch batch = firestore.batch();
342 | // List snapshotList = queryDocumentSnapshots.getDocuments();
343 | // for (DocumentSnapshot snapshot: snapshotList) {
344 | // snapshot.getDocumentReference(snapshot.getId());
345 | // batch.delete(snapshot.getReference());
346 | // }
347 | // batch.commit()
348 | // .addOnSuccessListener(new OnSuccessListener() {
349 | // @Override
350 | // public void onSuccess(Void aVoid) {
351 | // Log.d(TAG, "onSuccess: YAY");
352 | // }
353 | // });
354 | // }
355 | // })
356 | // .addOnFailureListener(new OnFailureListener() {
357 | // @Override
358 | // public void onFailure(@NonNull Exception e) {
359 | // Log.e(TAG, "onFailure: ", e);
360 | // }
361 | // });
362 |
363 | // FirebaseFirestore.getInstance()
364 | // .collection("products")
365 | // .orderBy("price", Query.Direction.DESCENDING)
366 | //// .orderBy("price", Query.Direction.DESCENDING)
367 | //// .orderBy("name")
368 | //// .orderBy("isAvailable", Query.Direction.DESCENDING)
369 | // .limit(1)
370 | // .get()
371 | // .addOnSuccessListener(new OnSuccessListener() {
372 | // @Override
373 | // public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
374 | // List snapshotList = queryDocumentSnapshots.getDocuments();
375 | // for (DocumentSnapshot snapshot: snapshotList) {
376 | // Log.d(TAG, "onSuccess: " + snapshot.getData());
377 | // }
378 | // }
379 | // })
380 | // .addOnFailureListener(new OnFailureListener() {
381 | // @Override
382 | // public void onFailure(@NonNull Exception e) {
383 | // Log.e(TAG, "onFailure: ", e);
384 | // }
385 | // });
386 |
387 | }
388 |
389 | public void getAllDocumentsWithRealtimeUpdates(View view) {
390 |
391 | // FirebaseFirestore.getInstance()
392 | // .collection("products")
393 | // .addSnapshotListener(new EventListener() {
394 | // @Override
395 | // public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
396 | // if (e != null) {
397 | // Log.e(TAG, "onEvent: ", e);
398 | // return;
399 | // }
400 | // if (queryDocumentSnapshots != null) {
401 | // Log.d(TAG, "onEvent: ---------------------------");
402 | //// List snapshotList = queryDocumentSnapshots.getDocuments();
403 | //// for (DocumentSnapshot snapshot : snapshotList) {
404 | //// Log.d(TAG, "onEvent: " + snapshot.getData());
405 | //// }
406 | //
407 | // List documentChangeList = queryDocumentSnapshots.getDocumentChanges();
408 | // for (DocumentChange documentChange: documentChangeList) {
409 | // Log.d(TAG, "onEvent: " + documentChange.getDocument().getData());
410 | // }
411 | // } else {
412 | // Log.e(TAG, "onEvent: query snapshot was null");
413 | // }
414 | // }
415 | // });
416 |
417 | // FirebaseFirestore.getInstance()
418 | // .collection("products")
419 | // .document("8UpzPzjyzV534fgi78P9")
420 | // .addSnapshotListener(new EventListener() {
421 | // @Override
422 | // public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
423 | // if (e != null) {
424 | // Log.e(TAG, "onEvent: ",e );
425 | // return;
426 | // }
427 | // if (documentSnapshot != null) {
428 | // Log.d(TAG, "onEvent: -------------------");
429 | // Log.d(TAG, "onEvent: " + documentSnapshot.getData());
430 | // } else {
431 | // Log.e(TAG, "onEvent: NULL");
432 | // }
433 | // }
434 | // });
435 |
436 | }
437 | }
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
--------------------------------------------------------------------------------