├── .gitignore ├── .idea ├── .gitignore ├── .name ├── appInsightsSettings.xml ├── compiler.xml ├── deploymentTargetDropDown.xml ├── gradle.xml ├── migrations.xml └── misc.xml ├── app ├── .gitignore ├── build.gradle.kts ├── google-services.json ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── firestorepklearnings │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── firestorepklearnings │ │ │ ├── AddingLocationActivity.java │ │ │ ├── AddingNameContactAndEmail.java │ │ │ ├── LoginActivity.java │ │ │ ├── ModelClassData.java │ │ │ ├── ModelClassFirestore.java │ │ │ ├── RetrievingDataFirestore.java │ │ │ ├── SplashScreen.java │ │ │ ├── UserRegisterationActivity.java │ │ │ ├── firebaseStorageProfileImage.java │ │ │ └── util │ │ │ └── FirebaseUtil.java │ └── res │ │ ├── drawable │ │ ├── background_black.xml │ │ ├── background_lines_email_password.xml │ │ ├── baseline_arrow_back_24.xml │ │ ├── firstimgofapp.png │ │ ├── ic_launcher_background.xml │ │ ├── ic_launcher_foreground.xml │ │ ├── img.jpg │ │ └── mario.png │ │ ├── font │ │ └── abeezee.xml │ │ ├── layout │ │ ├── activity_adding_location.xml │ │ ├── activity_adding_name_contact_and_email.xml │ │ ├── activity_firebase_storage_profile_image.xml │ │ ├── activity_login.xml │ │ ├── activity_retrieving_data_firestore.xml │ │ ├── activity_splash_screen.xml │ │ └── activity_user_registeration.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_background.png │ │ ├── ic_launcher_foreground.png │ │ ├── ic_launcher_monochrome.png │ │ └── ic_launcher_round.webp │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_background.png │ │ ├── ic_launcher_foreground.png │ │ ├── ic_launcher_monochrome.png │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_background.png │ │ ├── ic_launcher_foreground.png │ │ ├── ic_launcher_monochrome.png │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_background.png │ │ ├── ic_launcher_foreground.png │ │ ├── ic_launcher_monochrome.png │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_background.png │ │ ├── ic_launcher_foreground.png │ │ ├── ic_launcher_monochrome.png │ │ └── ic_launcher_round.webp │ │ ├── raw │ │ ├── firestorelottie.json │ │ └── svs.json │ │ ├── values-night │ │ └── themes.xml │ │ ├── values │ │ ├── colors.xml │ │ ├── font_certs.xml │ │ ├── preloaded_fonts.xml │ │ ├── strings.xml │ │ └── themes.xml │ │ └── xml │ │ ├── backup_rules.xml │ │ └── data_extraction_rules.xml │ └── test │ └── java │ └── com │ └── example │ └── firestorepklearnings │ └── ExampleUnitTest.java ├── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle.kts /.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 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | FIRESTORE Set and Retrieve Data -------------------------------------------------------------------------------- /.idea/appInsightsSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 26 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/deploymentTargetDropDown.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/migrations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | id("com.google.gms.google-services") 4 | } 5 | 6 | android { 7 | namespace = "com.example.firestorepklearnings" 8 | compileSdk = 34 9 | 10 | defaultConfig { 11 | applicationId = "com.example.firestorepklearnings" 12 | minSdk = 24 13 | targetSdk = 34 14 | versionCode = 1 15 | versionName = "1.0" 16 | 17 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | isMinifyEnabled = false 23 | proguardFiles( 24 | getDefaultProguardFile("proguard-android-optimize.txt"), 25 | "proguard-rules.pro" 26 | ) 27 | } 28 | } 29 | compileOptions { 30 | sourceCompatibility = JavaVersion.VERSION_1_8 31 | targetCompatibility = JavaVersion.VERSION_1_8 32 | } 33 | } 34 | 35 | dependencies { 36 | 37 | implementation("androidx.appcompat:appcompat:1.6.1") 38 | implementation("com.google.android.material:material:1.10.0") 39 | implementation("androidx.constraintlayout:constraintlayout:2.1.4") 40 | testImplementation("junit:junit:4.13.2") 41 | androidTestImplementation("androidx.test.ext:junit:1.1.5") 42 | androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") 43 | 44 | 45 | //FIREBASE 46 | implementation(platform("com.google.firebase:firebase-bom:32.3.1")) 47 | implementation("com.google.firebase:firebase-analytics:21.3.0") 48 | implementation("com.google.firebase:firebase-auth:22.1.2") 49 | implementation("com.google.firebase:firebase-database:20.2.2") 50 | implementation("com.google.firebase:firebase-storage:20.3.0") 51 | implementation("com.google.firebase:firebase-firestore") 52 | 53 | 54 | //LOTTIEFILES 55 | implementation("com.airbnb.android:lottie:6.0.1") 56 | 57 | //Glide 58 | implementation ("com.github.bumptech.glide:glide:4.16.0") 59 | } -------------------------------------------------------------------------------- /app/google-services.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_info": { 3 | "project_number": "525331547324", 4 | "firebase_url": "https://hello-world-5230b-default-rtdb.asia-southeast1.firebasedatabase.app", 5 | "project_id": "hello-world-5230b", 6 | "storage_bucket": "hello-world-5230b.appspot.com" 7 | }, 8 | "client": [ 9 | { 10 | "client_info": { 11 | "mobilesdk_app_id": "1:525331547324:android:1f6cc41827e04d10723cb9", 12 | "android_client_info": { 13 | "package_name": "com.example.firestorepklearnings" 14 | } 15 | }, 16 | "oauth_client": [ 17 | { 18 | "client_id": "525331547324-attheqqffm87qts1s1cl091evivkpt1q.apps.googleusercontent.com", 19 | "client_type": 3 20 | } 21 | ], 22 | "api_key": [ 23 | { 24 | "current_key": "AIzaSyAyluYOk1XrGzMxbUjSGEpf1NmOrQ57DOw" 25 | } 26 | ], 27 | "services": { 28 | "appinvite_service": { 29 | "other_platform_oauth_client": [ 30 | { 31 | "client_id": "525331547324-attheqqffm87qts1s1cl091evivkpt1q.apps.googleusercontent.com", 32 | "client_type": 3 33 | } 34 | ] 35 | } 36 | } 37 | } 38 | ], 39 | "configuration_version": "1" 40 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/firestorepklearnings/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.firestorepklearnings; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.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.getInstrumentation().getTargetContext(); 24 | assertEquals("com.example.firestorepklearnings", appContext.getPackageName()); 25 | } 26 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 15 | 18 | 21 | 24 | 27 | 30 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/firestorepklearnings/AddingLocationActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.firestorepklearnings; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.view.View; 9 | import android.widget.Button; 10 | import android.widget.ImageButton; 11 | import android.widget.Toast; 12 | 13 | import com.example.firestorepklearnings.util.FirebaseUtil; 14 | import com.google.android.gms.tasks.OnCompleteListener; 15 | import com.google.android.gms.tasks.OnFailureListener; 16 | import com.google.android.gms.tasks.Task; 17 | import com.google.android.material.textfield.TextInputEditText; 18 | 19 | public class AddingLocationActivity extends AppCompatActivity { 20 | 21 | TextInputEditText inputEditTextCity, inputEditTextState, inputEditTextCountry; 22 | Button nextSubmitButton; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_adding_location); 28 | 29 | inputEditTextCity = findViewById(R.id.enterCityTextView); 30 | inputEditTextState = findViewById(R.id.enterStateTextView); 31 | inputEditTextCountry = findViewById(R.id.enterCountryTextView); 32 | nextSubmitButton = findViewById(R.id.nextSubmitButton); 33 | 34 | nextSubmitButton.setOnClickListener(new View.OnClickListener() { 35 | @Override 36 | public void onClick(View view) { 37 | String city = inputEditTextCity.getText().toString(); 38 | String state = inputEditTextState.getText().toString(); 39 | String country = inputEditTextCountry.getText().toString(); 40 | 41 | if (city.isEmpty()) { 42 | inputEditTextCity.setError("Invalid"); 43 | } else if (state.isEmpty()) { 44 | inputEditTextState.setError("Invalid"); 45 | } else if (country.isEmpty()) { 46 | inputEditTextCountry.setError("invalid"); 47 | } else { 48 | addingUserData(city, state, country); 49 | } 50 | } 51 | }); 52 | 53 | 54 | } 55 | 56 | private void addingUserData(String city, String state, String country) { 57 | 58 | ModelClassFirestore modelClassFirestore = new ModelClassFirestore(city, state, country); 59 | 60 | //WE WILL ADD HIS DATA WITHOUT USER INPUT //STATIC //EXAMPLE OF DYNAMIC Line No. 81 61 | 62 | // Map city = new HashMap<>(); 63 | // city.put("name","valsad"); 64 | // city.put("State","gujarat"); 65 | // city.put("Country","india"); 66 | 67 | 68 | //this way you can add data to the firestore data or go to line number 78, code starts from LNo.81 69 | 70 | // FirebaseFirestore firestoreDB = FirebaseFirestore.getInstance(); 71 | // 72 | // firestoreDB.collection("users").document("location").set(modelClassFirestore). 73 | // addOnCompleteListener(new OnCompleteListener() { 74 | 75 | 76 | //by creating FirebaseUtil class in util package under 'com.example.firestorepklearnings' and creating a function currentUserDetails() which will get or return FirebaseFirestore.getInstance(); 77 | 78 | //USER WILL PROVIDE THE DATA AS INPUT //DYNAMIC 79 | FirebaseUtil.currentUserDetails().set(modelClassFirestore).addOnCompleteListener(new OnCompleteListener() { 80 | @Override 81 | public void onComplete(@NonNull Task task) { 82 | if (task.isSuccessful()) { 83 | Toast.makeText(AddingLocationActivity.this, "Data Added Successfully", Toast.LENGTH_SHORT).show(); 84 | Intent intent = new Intent(AddingLocationActivity.this, AddingNameContactAndEmail.class); 85 | intent.putExtra("city", inputEditTextCity.getText().toString()); 86 | intent.putExtra("state", inputEditTextState.getText().toString()); 87 | intent.putExtra("country", inputEditTextCountry.getText().toString()); 88 | 89 | startActivity(intent); 90 | finish(); 91 | 92 | } 93 | } 94 | }).addOnFailureListener(new OnFailureListener() { 95 | @Override 96 | public void onFailure(@NonNull Exception e) { 97 | Toast.makeText(AddingLocationActivity.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show(); 98 | 99 | } 100 | }); 101 | } 102 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/firestorepklearnings/AddingNameContactAndEmail.java: -------------------------------------------------------------------------------- 1 | package com.example.firestorepklearnings; 2 | 3 | import androidx.activity.result.ActivityResultLauncher; 4 | import androidx.activity.result.contract.ActivityResultContracts; 5 | import androidx.annotation.NonNull; 6 | import androidx.appcompat.app.AppCompatActivity; 7 | 8 | import android.content.Intent; 9 | import android.icu.text.StringPrepParseException; 10 | import android.net.Uri; 11 | import android.os.Bundle; 12 | import android.view.View; 13 | import android.widget.Button; 14 | import android.widget.ImageButton; 15 | import android.widget.ImageView; 16 | import android.widget.Toast; 17 | 18 | import com.example.firestorepklearnings.util.FirebaseUtil; 19 | import com.google.android.gms.tasks.OnCompleteListener; 20 | import com.google.android.gms.tasks.OnFailureListener; 21 | import com.google.android.gms.tasks.OnSuccessListener; 22 | import com.google.android.gms.tasks.Task; 23 | import com.google.android.material.textfield.TextInputEditText; 24 | import com.google.firebase.auth.FirebaseAuth; 25 | import com.google.firebase.firestore.SetOptions; 26 | import com.google.firebase.storage.UploadTask; 27 | 28 | import java.util.Objects; 29 | 30 | public class AddingNameContactAndEmail extends AppCompatActivity { 31 | TextInputEditText inputEditTextName, inputEditTextPhoneNumber, inputEditTextEmail; 32 | Button submitInputButton; 33 | ImageView proPicImgView; 34 | String url; 35 | String email; 36 | @Override 37 | protected void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | setContentView(R.layout.activity_adding_name_contact_and_email); 40 | 41 | inputEditTextName = findViewById(R.id.enterNameTextView); 42 | inputEditTextPhoneNumber = findViewById(R.id.enterPhoneTextView); 43 | inputEditTextEmail = findViewById(R.id.enterEmailTextView); 44 | submitInputButton = findViewById(R.id.submitButton); 45 | proPicImgView = findViewById(R.id.profilePictureImgCardView); 46 | 47 | proPicImgView.setOnClickListener(new View.OnClickListener() { 48 | @Override 49 | public void onClick(View view) { 50 | activityResultLauncher.launch("image/*"); // "*/*" //for any types of files 51 | 52 | } 53 | }); 54 | 55 | submitInputButton.setOnClickListener(new View.OnClickListener() { 56 | @Override 57 | public void onClick(View view) { 58 | String name = inputEditTextName.getText().toString(); 59 | String number = inputEditTextPhoneNumber.getText().toString(); 60 | email = inputEditTextEmail.getText().toString(); 61 | 62 | String city = getIntent().getExtras().getString("city"); 63 | String state = getIntent().getExtras().getString("state"); 64 | String country = getIntent().getExtras().getString("country"); 65 | 66 | if (name.isEmpty()) { 67 | inputEditTextName.setError("Invalid"); 68 | } else if (number.isEmpty()) { 69 | inputEditTextPhoneNumber.setError("Invalid"); 70 | } else if (email.isEmpty()) { 71 | inputEditTextEmail.setError("invalid"); 72 | } else { 73 | mergeWithExistingData(city, state, country, name, number, email, url); 74 | } 75 | } 76 | }); 77 | 78 | 79 | } 80 | 81 | private void mergeWithExistingData(String city, String state, String country, String name, String number, String email, String url) { 82 | 83 | ModelClassFirestore modelClassFirestore = new ModelClassFirestore(city, state, country, name, number, email, url); 84 | FirebaseUtil.currentUserDetails().set(modelClassFirestore).addOnCompleteListener(new OnCompleteListener() { 85 | @Override 86 | public void onComplete(@NonNull Task task) { 87 | if (task.isSuccessful()) { 88 | Toast.makeText(AddingNameContactAndEmail.this, "Added Successfully" + task.getResult(), Toast.LENGTH_SHORT).show(); 89 | startActivity(new Intent(getApplicationContext(), RetrievingDataFirestore.class)); 90 | finish(); 91 | } 92 | } 93 | }).addOnFailureListener(new OnFailureListener() { 94 | @Override 95 | public void onFailure(@NonNull Exception e) { 96 | Toast.makeText(AddingNameContactAndEmail.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show(); 97 | } 98 | }); 99 | } 100 | 101 | 102 | 103 | ActivityResultLauncher activityResultLauncher = registerForActivityResult(new ActivityResultContracts.GetContent(), results -> { 104 | 105 | //i have created this medthod in FirebaseUtil class 106 | FirebaseUtil.firebasestorage().getReference().child("images") 107 | .child(Objects.requireNonNull(FirebaseAuth.getInstance().getUid())) 108 | .child("IMG_" + System.currentTimeMillis()) 109 | .putFile(results) 110 | .addOnCompleteListener(new OnCompleteListener() { 111 | @Override 112 | public void onComplete(@NonNull Task task) { 113 | 114 | if (task.isSuccessful()) { 115 | task.getResult().getStorage().getDownloadUrl().addOnSuccessListener(new OnSuccessListener() { 116 | @Override 117 | public void onSuccess(Uri uri) { 118 | //global variable 119 | url = uri.toString(); 120 | Toast.makeText(AddingNameContactAndEmail.this, "" + url, Toast.LENGTH_SHORT).show(); 121 | proPicImgView.setImageURI(results); 122 | } 123 | 124 | }).addOnFailureListener(new OnFailureListener() { 125 | @Override 126 | public void onFailure(@NonNull Exception e) { 127 | Toast.makeText(AddingNameContactAndEmail.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show(); 128 | } 129 | }); 130 | 131 | } 132 | } 133 | }); 134 | 135 | }); 136 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/firestorepklearnings/LoginActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.firestorepklearnings; 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.os.Bundle; 9 | import android.text.TextUtils; 10 | import android.util.Log; 11 | import android.view.View; 12 | import android.widget.Button; 13 | import android.widget.EditText; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | import com.example.firestorepklearnings.util.FirebaseUtil; 18 | import com.google.android.gms.tasks.OnCompleteListener; 19 | import com.google.android.gms.tasks.OnFailureListener; 20 | import com.google.android.gms.tasks.Task; 21 | import com.google.firebase.auth.AuthResult; 22 | import com.google.firebase.auth.FirebaseAuth; 23 | import com.google.firebase.auth.FirebaseUser; 24 | import com.google.firebase.firestore.DocumentSnapshot; 25 | import com.google.firebase.firestore.EventListener; 26 | import com.google.firebase.firestore.FirebaseFirestoreException; 27 | 28 | public class LoginActivity extends AppCompatActivity { 29 | private EditText email, password; 30 | private Button loginbutton; 31 | private TextView txtWelcomeBackForTestingLayout, registerUser, forgetpassword, txtpasswordStatus, txtEmailStatusMessage, txtStatusMessage; 32 | FirebaseAuth firebaseAuth; //abstract class 33 | // DatabaseReference databaseReference; 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_login); 38 | 39 | 40 | email = findViewById(R.id.editTextEmailAddress); //linking this with XML 41 | password = findViewById(R.id.editTextTextPassword); 42 | registerUser = findViewById(R.id.textReturnToLoginPage); 43 | forgetpassword = findViewById(R.id.textViewForgetPassword); 44 | loginbutton = findViewById(R.id.loginButton); 45 | txtpasswordStatus = findViewById(R.id.passwordMessage); 46 | txtEmailStatusMessage = findViewById(R.id.emailMessageStatus); 47 | txtStatusMessage = findViewById(R.id.messageStatus); 48 | 49 | //Testing 50 | // txtWelcomeBackForTestingLayout = findViewById(R.id.textWelcomeBack); 51 | // txtWelcomeBackForTestingLayout.setOnClickListener(new View.OnClickListener() { 52 | // @Override 53 | // public void onClick(View v) { 54 | // startActivity(new Intent(LoginActivity.this, SavingDataInFirebaseRealtimeDatabase.class)); 55 | // } 56 | // }); 57 | 58 | 59 | //instance variable 60 | firebaseAuth = FirebaseAuth.getInstance(); 61 | 62 | 63 | //CREATE A NEW USER 64 | registerUser.setOnClickListener(new View.OnClickListener() { 65 | @Override 66 | public void onClick(View v) { 67 | startActivity(new Intent(LoginActivity.this, UserRegisterationActivity.class)); 68 | finish(); 69 | } 70 | }); 71 | 72 | 73 | loginbutton.setOnClickListener(new View.OnClickListener() { 74 | @Override 75 | public void onClick(View v) { 76 | String txtEmail = email.getText().toString(); 77 | String txtPassword = password.getText().toString(); 78 | 79 | // Toast.makeText(LoginActivity.this,txtEmail, Toast.LENGTH_SHORT).show(); 80 | Toast.makeText(LoginActivity.this, txtPassword, Toast.LENGTH_SHORT).show(); 81 | 82 | 83 | if (TextUtils.isEmpty(txtEmail) || TextUtils.isEmpty(txtPassword)) { 84 | // if (txtEmail.isEmpty()) { 85 | // txtStatusMessage.setText("Enter Email Address"); 86 | // } else if (txtPassword.isEmpty()) { 87 | // txtStatusMessage.setText("Enter Password"); 88 | // } else { 89 | // txtStatusMessage.setText("Empty credentials"); 90 | // } 91 | // 92 | // txtEmailStatusMessage.setText("www.indianrocks@example.com"); 93 | } 94 | if (txtEmail.isEmpty()) { 95 | txtStatusMessage.setText("Insert Email Address"); 96 | txtStatusMessage.setText("Empty credentials"); 97 | 98 | } else if (txtPassword.isEmpty()) { 99 | txtStatusMessage.setText("Insert Password"); 100 | } else { 101 | txtStatusMessage.setText(" "); 102 | } 103 | 104 | 105 | if (txtEmail.length() < 7) { 106 | txtEmailStatusMessage.setText("www.humanbeing@example.com"); 107 | } else if (!(txtEmail.endsWith(".com"))) { 108 | txtEmailStatusMessage.setText("email must ends with .com/org"); 109 | } else { 110 | txtEmailStatusMessage.setText(" "); 111 | } 112 | 113 | if (txtPassword.contains(" ")) { 114 | txtpasswordStatus.setText("Spaces are not allowed"); 115 | } else if ((txtPassword.length() < 6) || (txtPassword.length() >= 15)) { 116 | txtpasswordStatus.setText("Minimum of 6 characters is required, Maximum 15"); 117 | 118 | } else if ((txtPassword.length() < 6) || (txtPassword.length() >= 15)) { 119 | txtpasswordStatus.setText("Minimum of 6 characters is required, Maximum 15"); 120 | } else if (txtPassword.contains(" ")) { 121 | txtpasswordStatus.setText("Spaces are not allowed"); 122 | } else if (!(txtPassword.contains("@") || txtPassword.contains("#") 123 | || txtPassword.contains("!") || txtPassword.contains("~") 124 | || txtPassword.contains("$") || txtPassword.contains("%") 125 | || txtPassword.contains("^") || txtPassword.contains("&") 126 | || txtPassword.contains("*") || txtPassword.contains("(") 127 | || txtPassword.contains(")") || txtPassword.contains("-") 128 | || txtPassword.contains("+") || txtPassword.contains("/") 129 | || txtPassword.contains(":") || txtPassword.contains(".") 130 | || txtPassword.contains(", ") || txtPassword.contains("<") 131 | || txtPassword.contains(">") || txtPassword.contains("?") 132 | || txtPassword.contains("|"))) { 133 | txtpasswordStatus.setText("at least 1 special character is required"); 134 | } else { 135 | userSignIn(txtEmail, txtPassword); 136 | 137 | txtpasswordStatus.setText(" "); 138 | txtStatusMessage.setText(" "); 139 | txtEmailStatusMessage.setText(" "); 140 | } 141 | } 142 | }); 143 | 144 | } 145 | 146 | private void userSignIn(String email, String password) { 147 | 148 | firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener() { 149 | @Override 150 | public void onComplete(@NonNull Task task) { 151 | if (task.isSuccessful()) { 152 | // assert user != null; 153 | FirebaseUser user = task.getResult().getUser(); 154 | if (task.getResult().getUser().isEmailVerified()) { 155 | 156 | txtStatusMessage.setText("User SignIn Successfully"); 157 | startActivity(new Intent(LoginActivity.this, AddingLocationActivity.class)); 158 | finish(); 159 | 160 | FirebaseUtil.currentUserDetails().addSnapshotListener(new EventListener() { 161 | @Override 162 | public void onEvent(@Nullable DocumentSnapshot value, @Nullable FirebaseFirestoreException error) { 163 | if (value.exists()){ 164 | startActivity(new Intent(getApplicationContext(), RetrievingDataFirestore.class)); 165 | finish(); 166 | } 167 | } 168 | }); 169 | 170 | 171 | } else { 172 | txtStatusMessage.setText("Email Not Verified"); 173 | } 174 | } else { 175 | txtStatusMessage.setText("Invalid Login Credentials"); 176 | } 177 | 178 | } 179 | 180 | 181 | }).addOnFailureListener(new OnFailureListener() { 182 | @Override 183 | public void onFailure(@NonNull Exception e) { 184 | Log.d("TAG_name", "onFailure: " + e.getMessage()); 185 | } 186 | }); 187 | } 188 | } 189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/firestorepklearnings/ModelClassData.java: -------------------------------------------------------------------------------- 1 | package com.example.firestorepklearnings; 2 | 3 | import java.io.Serializable; 4 | 5 | public class ModelClassData implements Serializable { 6 | String name; 7 | String countrycode; 8 | String phone; 9 | String email; 10 | String password; 11 | 12 | public ModelClassData(){} 13 | 14 | public ModelClassData(String name, String countrycode, String phone, String email) { 15 | this.name = name; 16 | this.phone = phone; 17 | this.email = email; 18 | this.countrycode = countrycode; 19 | 20 | } 21 | 22 | public ModelClassData(String name, String countrycode, String phone, String email, String password) { 23 | this.name = name; 24 | this.countrycode = countrycode; 25 | this.phone = phone; 26 | this.email = email; 27 | this.password = password; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public String getCountrycode() { 39 | return countrycode; 40 | } 41 | 42 | public void setCountrycode(String countrycode) { 43 | this.countrycode = countrycode; 44 | } 45 | 46 | public String getPhone() { 47 | return phone; 48 | } 49 | 50 | public void setPhone(String phone) { 51 | this.phone = phone; 52 | } 53 | 54 | public String getEmail() { 55 | return email; 56 | } 57 | 58 | public void setEmail(String email) { 59 | this.email = email; 60 | } 61 | 62 | public String getPassword() { 63 | return password; 64 | } 65 | 66 | public void setPassword(String password) { 67 | this.password = password; 68 | } 69 | } 70 | 71 | 72 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/firestorepklearnings/ModelClassFirestore.java: -------------------------------------------------------------------------------- 1 | package com.example.firestorepklearnings; 2 | 3 | import java.io.Serializable; 4 | 5 | public class ModelClassFirestore implements Serializable { 6 | public ModelClassFirestore(){ 7 | 8 | } 9 | 10 | 11 | 12 | String city; 13 | String state; 14 | String country; 15 | String name; 16 | String phone; 17 | String email; 18 | String url; 19 | 20 | public ModelClassFirestore(String city, String state, String country) { 21 | this.city = city; 22 | this.state = state; 23 | this.country = country; 24 | } 25 | public ModelClassFirestore(String city, String state, String country, String name, String phone, String email, String url) { 26 | this.city = city; 27 | this.state = state; 28 | this.country = country; 29 | this.name = name; 30 | this.phone = phone; 31 | this.email = email; 32 | this.url = url; 33 | } 34 | public String getCity() { 35 | return city; 36 | } 37 | 38 | public void setCity(String city) { 39 | this.city = city; 40 | } 41 | 42 | public String getState() { 43 | return state; 44 | } 45 | 46 | public void setState(String state) { 47 | this.state = state; 48 | } 49 | 50 | public String getCountry() { 51 | return country; 52 | } 53 | 54 | public void setCountry(String country) { 55 | this.country = country; 56 | } 57 | public String getName() { 58 | return name; 59 | } 60 | 61 | public void setName(String name) { 62 | this.name = name; 63 | } 64 | 65 | public String getPhone() { 66 | return phone; 67 | } 68 | 69 | public void setPhone(String phone) { 70 | this.phone = phone; 71 | } 72 | 73 | public String getEmail() { 74 | return email; 75 | } 76 | 77 | public void setEmail(String email) { 78 | this.email = email; 79 | } 80 | 81 | public String getUrl() { 82 | return url; 83 | } 84 | 85 | public void setUrl(String url) { 86 | this.url = url; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/firestorepklearnings/RetrievingDataFirestore.java: -------------------------------------------------------------------------------- 1 | package com.example.firestorepklearnings; 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.view.View; 9 | import android.widget.Button; 10 | import android.widget.ImageView; 11 | import android.widget.TextView; 12 | 13 | import com.bumptech.glide.Glide; 14 | import com.example.firestorepklearnings.util.FirebaseUtil; 15 | import com.google.firebase.auth.FirebaseAuth; 16 | import com.google.firebase.firestore.DocumentSnapshot; 17 | import com.google.firebase.firestore.EventListener; 18 | import com.google.firebase.firestore.FirebaseFirestoreException; 19 | 20 | public class RetrievingDataFirestore extends AppCompatActivity { 21 | TextView retrieveNameTextView, retrievePhoneTextView, retrieveEmailTextView, 22 | retrieveCityTextView, retrieveStateTextView, retrieveCountryTextView; 23 | Button logOutButton; 24 | ImageView proPicImgView; 25 | String email; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_retrieving_data_firestore); 31 | 32 | retrieveNameTextView = findViewById(R.id.textViewName); 33 | retrievePhoneTextView = findViewById(R.id.textViewPhone); 34 | retrieveEmailTextView = findViewById(R.id.textViewEmail); 35 | retrieveCityTextView = findViewById(R.id.textViewCity); 36 | retrieveStateTextView = findViewById(R.id.textViewState); 37 | retrieveCountryTextView = findViewById(R.id.textViewCountry); 38 | logOutButton = findViewById(R.id.logoutButton); 39 | proPicImgView = findViewById(R.id.profilePictureImageView); 40 | logOutButton.setOnClickListener(new View.OnClickListener() { 41 | @Override 42 | public void onClick(View view) { 43 | FirebaseAuth.getInstance().signOut(); 44 | startActivity(new Intent(getApplicationContext(), LoginActivity.class)); 45 | finish(); 46 | } 47 | }); 48 | 49 | 50 | retrieveData(retrieveNameTextView, retrievePhoneTextView, retrieveEmailTextView, retrieveCityTextView, retrieveStateTextView, retrieveCountryTextView, proPicImgView); 51 | } 52 | 53 | // private void retrieveData(TextView retrieveNameTextView, TextView retrievePhoneTextView, TextView retrieveEmailTextView, TextView retrieveCityTextView, TextView retrieveStateTextView, TextView retrieveCountryTextView) { 54 | // 55 | // FirebaseUtil.currentUserDetails().get().addOnCompleteListener(new OnCompleteListener() { 56 | // @Override 57 | // public void onComplete(@NonNull Task task) { 58 | // if(task.isSuccessful()){ 59 | // DocumentSnapshot dataSnapshot = task.getResult(); 60 | // if (dataSnapshot.exists()){ 61 | // Toast.makeText(RetrievingDataFirestore.this, ""+dataSnapshot.getData().toString(), Toast.LENGTH_SHORT).show(); 62 | //// Log.d("TAG_data", dataSnapshot.getData().toString()); 63 | // }else{ 64 | // Log.d("TAG", "no data"); 65 | // Toast.makeText(RetrievingDataFirestore.this, "No Data", Toast.LENGTH_SHORT).show(); 66 | // } 67 | // 68 | // } 69 | // } 70 | // }); 71 | // } 72 | 73 | private void retrieveData(TextView retrieveNameTextView, TextView retrievePhoneTextView, TextView retrieveEmailTextView, TextView retrieveCityTextView, TextView retrieveStateTextView, TextView retrieveCountryTextView, ImageView proPicImgView) { 74 | 75 | FirebaseUtil.currentUserDetails().addSnapshotListener(new EventListener() { 76 | @Override 77 | public void onEvent(@Nullable DocumentSnapshot value, @Nullable FirebaseFirestoreException error) { 78 | if (value.exists()) { 79 | 80 | // Map map = value.getData(); 81 | // map.get("name"); 82 | // retrieveNameTextView.setText(map.get("name").toString()); 83 | 84 | 85 | String name = value.getString("name"); 86 | retrieveNameTextView.setText(name); 87 | String phone = value.getString("phone"); 88 | retrievePhoneTextView.setText(phone); 89 | email = value.getString("email"); 90 | retrieveEmailTextView.setText(email); 91 | String city = value.getString("city"); 92 | retrieveCityTextView.setText(city); 93 | String state = value.getString("state"); 94 | retrieveStateTextView.setText(state); 95 | String country = value.getString("country"); 96 | retrieveCountryTextView.setText(country); 97 | String url = value.getString("url"); 98 | 99 | Glide.with(RetrievingDataFirestore.this) 100 | .asBitmap() 101 | .load(url) 102 | .placeholder(R.drawable.ic_launcher_background) 103 | .error(R.drawable.ic_launcher_background) 104 | .into(proPicImgView); 105 | } 106 | 107 | } 108 | }); 109 | } 110 | 111 | 112 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/firestorepklearnings/SplashScreen.java: -------------------------------------------------------------------------------- 1 | package com.example.firestorepklearnings; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | 5 | import android.content.Intent; 6 | import android.os.Bundle; 7 | import android.os.Handler; 8 | 9 | import com.google.firebase.auth.FirebaseAuth; 10 | import com.google.firebase.auth.FirebaseUser; 11 | 12 | public class SplashScreen extends AppCompatActivity { 13 | FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 14 | FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(); 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_splash_screen); 20 | new Handler().postDelayed(new Runnable() { 21 | @Override 22 | public void run() { 23 | 24 | if ( firebaseAuth.getCurrentUser()!= null) { 25 | startActivity(new Intent(SplashScreen.this, RetrievingDataFirestore.class)); 26 | finish(); 27 | } else { 28 | startActivity(new Intent(SplashScreen.this, LoginActivity.class)); 29 | finish(); 30 | 31 | } 32 | 33 | } 34 | }, 3820); 35 | } 36 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/firestorepklearnings/UserRegisterationActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.firestorepklearnings; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.os.Handler; 9 | import android.view.View; 10 | import android.widget.Button; 11 | import android.widget.EditText; 12 | import android.widget.ImageView; 13 | import android.widget.TextView; 14 | import android.widget.Toast; 15 | 16 | import com.google.android.gms.tasks.OnCompleteListener; 17 | import com.google.android.gms.tasks.OnSuccessListener; 18 | import com.google.android.gms.tasks.Task; 19 | import com.google.firebase.auth.AuthResult; 20 | import com.google.firebase.auth.FirebaseAuth; 21 | import com.google.firebase.auth.FirebaseUser; 22 | import com.google.firebase.database.DatabaseReference; 23 | 24 | public class UserRegisterationActivity extends AppCompatActivity { 25 | 26 | ImageView backiconImg; 27 | private EditText email, password; 28 | private Button registration; 29 | private TextView alreadyAccount, txtpasswordStatus, txtEmailStatusMessage, 30 | txtStatusMessage; 31 | 32 | FirebaseAuth firebaseAuth; 33 | DatabaseReference databaseReference; 34 | 35 | @Override 36 | protected void onCreate(Bundle savedInstanceState) { 37 | super.onCreate(savedInstanceState); 38 | setContentView(R.layout.activity_user_registeration); 39 | 40 | 41 | //LINKING WITH XML 42 | backiconImg = findViewById(R.id.backIconimageView); 43 | email = findViewById(R.id.emailAddressRegisteration); 44 | password = findViewById(R.id.passwordRegistration); 45 | txtpasswordStatus = findViewById(R.id.passwordMessage); 46 | txtEmailStatusMessage = findViewById(R.id.emailMessageStatus); 47 | txtStatusMessage = findViewById(R.id.message); 48 | alreadyAccount = findViewById(R.id.textViewAlreadyRegistered); 49 | registration = findViewById(R.id.buttonSubmitRegistration); 50 | 51 | 52 | //INSTANCE VARIABLE 53 | firebaseAuth = FirebaseAuth.getInstance(); //ABSTRACT CLASS 54 | 55 | 56 | //BACKICON IMAGE ON CLICK 57 | backiconImg.setOnClickListener(new View.OnClickListener() { 58 | @Override 59 | public void onClick(View v) { 60 | finish(); 61 | 62 | } 63 | }); 64 | 65 | //ALREADY HAVE AN ACCOUNT INTENT 66 | alreadyAccount.setOnClickListener(new View.OnClickListener() { 67 | @Override 68 | public void onClick(View v) { 69 | finish(); 70 | } 71 | }); 72 | 73 | 74 | //REGISTRATION 75 | registration.setOnClickListener(new View.OnClickListener() { 76 | @Override 77 | public void onClick(View v) { //ON CLICK 78 | String txtEmail = email.getText().toString(); //TAKING INPUT STORING IT IN String txtEmail VARIABLE 79 | String txtPassword = password.getText().toString(); 80 | 81 | Toast.makeText(UserRegisterationActivity.this, txtPassword, Toast.LENGTH_SHORT).show(); // TOAST TO SHOW PASSWORD 82 | 83 | 84 | //CONDITIONS FOR TAKING INPUT 85 | 86 | 87 | if (txtEmail.isEmpty()) { 88 | txtStatusMessage.setText("Insert Email Address"); 89 | 90 | } else if (txtPassword.isEmpty()) { 91 | txtStatusMessage.setText("Insert Password"); 92 | } else { 93 | txtStatusMessage.setText(" "); 94 | } 95 | 96 | 97 | if (txtEmail.length() < 7) { 98 | txtEmailStatusMessage.setText("www.humanbeing@example.com"); 99 | } else if (!(txtEmail.endsWith(".com"))) { 100 | txtEmailStatusMessage.setText("email must ends with .com/org"); 101 | } else { 102 | txtEmailStatusMessage.setText(" "); 103 | } 104 | 105 | if (txtPassword.contains(" ")) { 106 | txtpasswordStatus.setText("Spaces are not allowed"); 107 | } else if ((txtPassword.length() < 6) || (txtPassword.length() >= 15)) { 108 | txtpasswordStatus.setText("Minimum of 6 characters is required, Maximum 15"); 109 | 110 | } else if (!(txtPassword.contains("@") || txtPassword.contains("#") 111 | || txtPassword.contains("!") || txtPassword.contains("~") 112 | || txtPassword.contains("$") || txtPassword.contains("%") 113 | || txtPassword.contains("^") || txtPassword.contains("&") 114 | || txtPassword.contains("*") || txtPassword.contains("(") 115 | || txtPassword.contains(")") || txtPassword.contains("-") 116 | || txtPassword.contains("+") || txtPassword.contains("/") 117 | || txtPassword.contains(":") || txtPassword.contains(".") 118 | || txtPassword.contains(", ") || txtPassword.contains("<") 119 | || txtPassword.contains(">") || txtPassword.contains("?") 120 | || txtPassword.contains("|"))) { 121 | txtpasswordStatus.setText("at least 1 special character is required"); 122 | } else { 123 | createUser(txtEmail, txtPassword); 124 | txtEmailStatusMessage.setText(" "); 125 | txtStatusMessage.setText(" "); 126 | txtpasswordStatus.setText(" "); 127 | } 128 | if (txtEmail.isEmpty() && txtPassword.isEmpty()) { 129 | txtStatusMessage.setText("Empty credentials"); 130 | } 131 | } 132 | }); 133 | 134 | 135 | } 136 | 137 | private void createUser(String email, String password) { 138 | firebaseAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener() { 139 | @Override 140 | public void onComplete(@NonNull Task task) { 141 | if (task.isSuccessful()) { 142 | FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser(); 143 | // firebaseUser.isEmailVerified() 144 | firebaseUser.sendEmailVerification().addOnSuccessListener(new OnSuccessListener() { 145 | @Override 146 | public void onSuccess(Void unused) { 147 | txtStatusMessage.setText("verification mail has been sent to your email"); 148 | 149 | } 150 | }); 151 | 152 | 153 | new Handler().postDelayed(new Runnable() { 154 | @Override 155 | public void run() { 156 | startActivity(new Intent(UserRegisterationActivity.this, LoginActivity.class)); 157 | finish(); 158 | 159 | } 160 | }, 3000); 161 | 162 | 163 | } else { 164 | txtEmailStatusMessage.setText(task.getException().getMessage()); 165 | } 166 | } 167 | }); 168 | 169 | } 170 | 171 | } 172 | 173 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/firestorepklearnings/firebaseStorageProfileImage.java: -------------------------------------------------------------------------------- 1 | package com.example.firestorepklearnings; 2 | 3 | import static com.google.common.io.Files.getFileExtension; 4 | 5 | import androidx.annotation.NonNull; 6 | import androidx.annotation.Nullable; 7 | import androidx.appcompat.app.AppCompatActivity; 8 | 9 | import android.content.ContentResolver; 10 | import android.content.Intent; 11 | import android.net.Uri; 12 | import android.os.Bundle; 13 | import android.view.View; 14 | import android.webkit.MimeTypeMap; 15 | import android.widget.ImageView; 16 | import android.widget.Toast; 17 | 18 | import com.google.android.gms.tasks.OnCompleteListener; 19 | import com.google.android.gms.tasks.OnSuccessListener; 20 | import com.google.android.gms.tasks.Task; 21 | import com.google.firebase.storage.FirebaseStorage; 22 | import com.google.firebase.storage.StorageReference; 23 | import com.google.firebase.storage.UploadTask; 24 | 25 | public class firebaseStorageProfileImage extends AppCompatActivity { 26 | ImageView profilePictureImg; 27 | Uri imageUri; 28 | private static final int IMAGE_REQUEST = 2; 29 | 30 | @Override 31 | protected void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.activity_firebase_storage_profile_image); 34 | 35 | profilePictureImg = findViewById(R.id.profilePictureImageView); 36 | 37 | profilePictureImg.setOnClickListener(new View.OnClickListener() { 38 | @Override 39 | public void onClick(View view) { 40 | openImage(); 41 | 42 | } 43 | }); 44 | } 45 | 46 | private void openImage() { 47 | Intent intent = new Intent(); 48 | intent.setType("image/"); 49 | intent.setAction(Intent.ACTION_GET_CONTENT); 50 | startActivityForResult(intent, IMAGE_REQUEST); 51 | } 52 | 53 | @Override 54 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { 55 | super.onActivityResult(requestCode, resultCode, data); 56 | if(requestCode == IMAGE_REQUEST && requestCode == RESULT_OK){ 57 | imageUri = data.getData(); 58 | uploadImage(); 59 | } 60 | } 61 | 62 | private String getFileExtension(Uri uri) { 63 | ContentResolver contentResolver = getContentResolver(); 64 | MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); 65 | return mimeTypeMap.getExtensionFromMimeType(contentResolver.getType(uri)); 66 | } 67 | 68 | private void uploadImage() { 69 | if (imageUri != null) { 70 | StorageReference reference = FirebaseStorage.getInstance().getReference().child("uploads").child(System.currentTimeMillis() + "." + getFileExtension(imageUri)); 71 | reference.putFile(imageUri).addOnCompleteListener(new OnCompleteListener() { 72 | @Override 73 | public void onComplete(@NonNull Task task) { 74 | reference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener() { 75 | @Override 76 | public void onSuccess(Uri uri) { 77 | String url = uri.toString(); 78 | 79 | Toast.makeText(firebaseStorageProfileImage.this, ""+uri, Toast.LENGTH_SHORT).show(); 80 | Toast.makeText(firebaseStorageProfileImage.this, "Image Upload Successfull", Toast.LENGTH_SHORT).show(); 81 | } 82 | }); 83 | } 84 | }); 85 | } 86 | 87 | } 88 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/firestorepklearnings/util/FirebaseUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.firestorepklearnings.util; 2 | 3 | import com.google.firebase.auth.FirebaseAuth; 4 | import com.google.firebase.firestore.CollectionReference; 5 | import com.google.firebase.firestore.DocumentReference; 6 | import com.google.firebase.firestore.FirebaseFirestore; 7 | import com.google.firebase.storage.FirebaseStorage; 8 | 9 | public class FirebaseUtil { 10 | public static String getCurrentUserId() { 11 | return FirebaseAuth.getInstance().getUid(); 12 | } 13 | 14 | public static DocumentReference currentUserDetails() { 15 | return FirebaseFirestore.getInstance().collection("users").document("User Id : " +getCurrentUserId()); 16 | } 17 | 18 | public static CollectionReference allUsersCollectionReference() { 19 | return FirebaseFirestore.getInstance().collection("users"); 20 | } 21 | public static FirebaseStorage firebasestorage(){ 22 | return FirebaseStorage.getInstance(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/background_black.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/background_lines_email_password.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/baseline_arrow_back_24.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/firstimgofapp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laidbackvalen/Firebase-Firestore-DataApp-/dc1e844e4ca3eff8da47fb751f83c83cabcc29a4/app/src/main/res/drawable/firstimgofapp.png -------------------------------------------------------------------------------- /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/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/img.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laidbackvalen/Firebase-Firestore-DataApp-/dc1e844e4ca3eff8da47fb751f83c83cabcc29a4/app/src/main/res/drawable/img.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/mario.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laidbackvalen/Firebase-Firestore-DataApp-/dc1e844e4ca3eff8da47fb751f83c83cabcc29a4/app/src/main/res/drawable/mario.png -------------------------------------------------------------------------------- /app/src/main/res/font/abeezee.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_adding_location.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 21 | 28 | 29 | 30 | 38 | 45 | 46 | 47 | 55 | 62 | 63 | 64 |