diff --git a/TASK4_Product_Ordering/.gitignore b/TASK4_Product_Ordering/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/TASK4_Product_Ordering/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/TASK4_Product_Ordering/.idea/.gitignore b/TASK4_Product_Ordering/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/TASK4_Product_Ordering/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/TASK4_Product_Ordering/.idea/.name b/TASK4_Product_Ordering/.idea/.name new file mode 100644 index 0000000..754c9e3 --- /dev/null +++ b/TASK4_Product_Ordering/.idea/.name @@ -0,0 +1 @@ +ShopCart \ No newline at end of file diff --git a/TASK4_Product_Ordering/.idea/compiler.xml b/TASK4_Product_Ordering/.idea/compiler.xml new file mode 100644 index 0000000..fb7f4a8 --- /dev/null +++ b/TASK4_Product_Ordering/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/TASK4_Product_Ordering/.idea/gradle.xml b/TASK4_Product_Ordering/.idea/gradle.xml new file mode 100644 index 0000000..23a89bb --- /dev/null +++ b/TASK4_Product_Ordering/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/TASK4_Product_Ordering/.idea/jarRepositories.xml b/TASK4_Product_Ordering/.idea/jarRepositories.xml new file mode 100644 index 0000000..e34606c --- /dev/null +++ b/TASK4_Product_Ordering/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TASK4_Product_Ordering/.idea/misc.xml b/TASK4_Product_Ordering/.idea/misc.xml new file mode 100644 index 0000000..860da66 --- /dev/null +++ b/TASK4_Product_Ordering/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/TASK4_Product_Ordering/.idea/runConfigurations.xml b/TASK4_Product_Ordering/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/TASK4_Product_Ordering/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/TASK4_Product_Ordering/.idea/vcs.xml b/TASK4_Product_Ordering/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/TASK4_Product_Ordering/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/TASK4_Product_Ordering/README.md b/TASK4_Product_Ordering/README.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/TASK4_Product_Ordering/README.md @@ -0,0 +1 @@ + diff --git a/TASK4_Product_Ordering/app/.gitignore b/TASK4_Product_Ordering/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/TASK4_Product_Ordering/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/build.gradle b/TASK4_Product_Ordering/app/build.gradle new file mode 100644 index 0000000..955baa7 --- /dev/null +++ b/TASK4_Product_Ordering/app/build.gradle @@ -0,0 +1,57 @@ +plugins { + id 'com.android.application' + id 'com.google.gms.google-services' + id 'androidx.navigation.safeargs' + +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.2" + + defaultConfig { + applicationId "com.example.shopcart" + minSdkVersion 16 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + multiDexEnabled true + + + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.1' + implementation 'androidx.navigation:navigation-fragment:2.3.5' + implementation 'androidx.navigation:navigation-ui:2.3.5' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + implementation 'com.google.firebase:firebase-auth:21.0.1' + implementation 'com.google.firebase:firebase-firestore:23.0.4' + testImplementation 'junit:junit:' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + + + + implementation 'de.hdodenhof:circleimageview:3.1.0' + implementation 'com.github.bumptech.glide:glide:4.12.0' + annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' + implementation 'com.android.support:multidex:1.0.3' +} \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/google-services.json b/TASK4_Product_Ordering/app/google-services.json new file mode 100644 index 0000000..8f74d15 --- /dev/null +++ b/TASK4_Product_Ordering/app/google-services.json @@ -0,0 +1,47 @@ +{ + "project_info": { + "project_number": "75601636598", + "project_id": "shreya-2bea6", + "storage_bucket": "shreya-2bea6.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:75601636598:android:264c04640efa1aa2c250d7", + "android_client_info": { + "package_name": "com.example.shopcart" + } + }, + "oauth_client": [ + { + "client_id": "75601636598-jo2vp8qjij7sabm14fmse51mvri87m29.apps.googleusercontent.com", + "client_type": 1, + "android_info": { + "package_name": "com.example.shopcart", + "certificate_hash": "27bc0acd1530f8519c1c6fc4a51636fc36562c01" + } + }, + { + "client_id": "75601636598-vuf1nbne7vjeb7der3tu6lb3hvirb2fs.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyDv5Su4hWhpNabg4TUbAlPlYgENw9z6iXE" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [ + { + "client_id": "75601636598-vuf1nbne7vjeb7der3tu6lb3hvirb2fs.apps.googleusercontent.com", + "client_type": 3 + } + ] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/proguard-rules.pro b/TASK4_Product_Ordering/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/TASK4_Product_Ordering/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/androidTest/java/com/example/shopcart/ExampleInstrumentedTest.java b/TASK4_Product_Ordering/app/src/androidTest/java/com/example/shopcart/ExampleInstrumentedTest.java new file mode 100644 index 0000000..b33033d --- /dev/null +++ b/TASK4_Product_Ordering/app/src/androidTest/java/com/example/shopcart/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.shopcart; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.shopcart", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/AndroidManifest.xml b/TASK4_Product_Ordering/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..09d673a --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/Adapter/CartAdapter.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/Adapter/CartAdapter.java new file mode 100644 index 0000000..345f5ed --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/Adapter/CartAdapter.java @@ -0,0 +1,131 @@ +package com.example.shopcart.Adapter; + +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageButton; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView.ViewHolder; + +import com.bumptech.glide.Glide; +import com.example.shopcart.Model.Cart; +import com.example.shopcart.R; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.firestore.FirebaseFirestore; + +import java.util.List; + +import de.hdodenhof.circleimageview.CircleImageView; + +public class CartAdapter extends RecyclerView.Adapter { + + + List cartList; + FirebaseFirestore firestore = FirebaseFirestore.getInstance(); + FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(); + String userid; + String documentid; + + + + public void setCartList(List cartList) { + this.cartList = cartList; + } + + + @NonNull + @Override + public CartHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cartliststyle, parent, false); + return new CartHolder(view); + + } + + @Override + public void onBindViewHolder(@NonNull CartHolder holder, int position) { + + holder.title.setText(cartList.get(position).getTitle()); + holder.price.setText("Total Price is: " + cartList.get(position).getPrice() + " For the items: " + cartList.get(position).getQuantity()); + + Glide.with(holder.itemView.getContext()).load(cartList.get(position).getImageUrl()).centerCrop().into(holder.imageView); + + + + } + + @Override + public int getItemCount() { + + if (cartList == null) { + + return 0; + + + } else { + return cartList.size(); + } + } + + class CartHolder extends ViewHolder { + + + TextView title, price; + CircleImageView imageView; + ImageButton deleteItem; + + public CartHolder(@NonNull View itemView) { + super(itemView); + + title = itemView.findViewById(R.id.cartproducttitle); + price = itemView.findViewById(R.id.cartdesc); + imageView = itemView.findViewById(R.id.cartmainimage); + deleteItem = itemView.findViewById(R.id.deleteitem); + + deleteItem.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + String title = cartList.get(getAdapterPosition()).getTitle(); + userid = firebaseAuth.getCurrentUser().getUid(); + + + documentid = cartList.get(getAdapterPosition()).getProductid(); + + + + + firestore.collection("Products").document(documentid).update("quantity", 0).addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + + } + }); + + + firestore.collection("Cart" + userid).document(title).delete(); + + + cartList.remove(cartList.get(getAdapterPosition())); + notifyItemRemoved(getAdapterPosition()); + + } + + }); + + + + } + } + + + + + +} \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/Adapter/ProductsAdapter.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/Adapter/ProductsAdapter.java new file mode 100644 index 0000000..1aa62f4 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/Adapter/ProductsAdapter.java @@ -0,0 +1,102 @@ +package com.example.shopcart.Adapter; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import androidx.recyclerview.widget.RecyclerView.ViewHolder; + +import com.bumptech.glide.Glide; +import com.example.shopcart.Model.Product; +import com.example.shopcart.R; + +import java.util.List; + +import de.hdodenhof.circleimageview.CircleImageView; + +public class ProductsAdapter extends RecyclerView.Adapter { + + + List productList; + OnClickedProducct interfaceclickedonProduct; + + public ProductsAdapter(OnClickedProducct interfaceclickedonProduct) { + this.interfaceclickedonProduct = interfaceclickedonProduct; + } + + public void setProductList(List productList) { + this.productList = productList; + } + + @NonNull + @Override + public ProductHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.productstyleslist, parent, false); + return new ProductHolder(view); + + + } + + @Override + public void onBindViewHolder(@NonNull ProductHolder holder, int position) { + + holder.titeofproduct.setText(productList.get(position).getTitle()); + holder.descriptionofproduct.setText(productList.get(position).getDescription()); + + Glide.with(holder.itemView.getContext()).load(productList.get(position).getImageUrl()).centerCrop().into(holder.circleImageView); + + + + } + + @Override + public int getItemCount() { + + + + if (productList == null) { + + return 0; + + } else { + + return productList.size(); + } + } + + class ProductHolder extends ViewHolder implements View.OnClickListener{ + + + TextView titeofproduct, descriptionofproduct; + CircleImageView circleImageView; + + public ProductHolder(@NonNull View itemView) { + super(itemView); + + titeofproduct = itemView.findViewById(R.id.proudcttitlte); + descriptionofproduct = itemView.findViewById(R.id.productdescriptionmain); + circleImageView = itemView.findViewById(R.id.productmainiamge); + + + titeofproduct.setOnClickListener(this); + descriptionofproduct.setOnClickListener(this); + circleImageView.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + interfaceclickedonProduct.OnProClicked(productList, getAdapterPosition()); + } + } + + public interface OnClickedProducct{ + void OnProClicked(List productList, int position); + + + } +} diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/CartFragment.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/CartFragment.java new file mode 100644 index 0000000..3ad4c41 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/CartFragment.java @@ -0,0 +1,199 @@ +package com.example.shopcart; + +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; +import androidx.navigation.NavController; +import androidx.navigation.Navigation; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.shopcart.Adapter.CartAdapter; +import com.example.shopcart.MVVM.CartViewModel; +import com.example.shopcart.Model.Cart; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.firestore.DocumentSnapshot; +import com.google.firebase.firestore.EventListener; +import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.FirebaseFirestoreException; +import com.google.firebase.firestore.QuerySnapshot; + +import java.util.ArrayList; +import java.util.List; + +public class CartFragment extends Fragment { + + + RecyclerView recyclerView; + CartViewModel viewModel; + CartAdapter mAdapter; + + TextView displaytotalprice; + int totalprice = 0; + NavController navController; + FirebaseFirestore firestore; + FirebaseAuth firebaseAuth; + String userid; + + Button checkOut; + List savetotalprice = new ArrayList<>(); + + + + public CartFragment() { + + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + return inflater.inflate(R.layout.fragment_cart, container, false); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + firebaseAuth = FirebaseAuth.getInstance(); + + firestore = FirebaseFirestore.getInstance(); + + displaytotalprice = view.findViewById(R.id.totalPriceordercart); + checkOut = view.findViewById(R.id.buttoncheckout); + navController = Navigation.findNavController(view); + + userid = firebaseAuth.getCurrentUser().getUid(); + recyclerView = view.findViewById(R.id.recyclerviewcart); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + mAdapter = new CartAdapter(); + + + viewModel = new ViewModelProvider(getActivity()).get(CartViewModel.class); + + viewModel.cartLiveDataShit().observe(getViewLifecycleOwner(), new Observer>() { + @Override + public void onChanged(List carts) { + + + mAdapter.setCartList(carts); + recyclerView.setAdapter(mAdapter); + } + }); + + + + + firestore.collection("Cart"+userid).addSnapshotListener(new EventListener() { + @Override + public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) { + + + for (DocumentSnapshot dsn: value.getDocuments()) { + + Cart cart = dsn.toObject(Cart.class); + + int total = cart.getPrice(); + + savetotalprice.add(total); + } + + for ( int i=0; i < savetotalprice.size(); i++) { + totalprice += Integer.parseInt(String.valueOf(savetotalprice.get(i))); + + displaytotalprice.setText(String.valueOf(totalprice)); + + + + } + savetotalprice.clear(); + + totalprice = 0; + } + }); + + + + + checkOut.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + + + firestore.collection("Products").get().addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + + + if (task.isSuccessful()) { + QuerySnapshot shit = task.getResult(); + + + for (DocumentSnapshot shs: shit.getDocuments()) { + + + + shs.getReference().update("quantity", 0); + + } + + + + } + + + } + }); + + + firestore.collection("Cart"+userid).get().addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + + + if (task.isSuccessful()) { + + QuerySnapshot tasks = task.getResult(); + + for (DocumentSnapshot ds: tasks.getDocuments()) { + + + + ds.getReference().delete(); + } + + + + } + } + }); + + + + + navController.navigate(R.id.action_cartFragment_to_productsFragment); + Toast.makeText(getContext(), "Order Placed", Toast.LENGTH_SHORT).show(); + + + + } + }); + + } + +} \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/LoginFragment.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/LoginFragment.java new file mode 100644 index 0000000..1c806e0 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/LoginFragment.java @@ -0,0 +1,157 @@ +package com.example.shopcart; + +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.SwitchCompat; +import androidx.fragment.app.Fragment; +import androidx.navigation.NavController; +import androidx.navigation.Navigation; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.Toast; + +import com.example.shopcart.R; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.android.material.textfield.TextInputLayout; +import com.google.firebase.auth.AuthResult; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.firestore.FirebaseFirestore; + + +public class LoginFragment extends Fragment { + + SwitchCompat toggle; + NavController navController; + + + FirebaseFirestore firestore; + FirebaseAuth auth; + TextInputLayout etemail, etpassword; + String email, password; + Button signIn; + + public LoginFragment() { + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + return inflater.inflate(R.layout.fragment_login, container, false); + } + + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + + toggle = view.findViewById(R.id.gotosignUpSwitch); + navController = Navigation.findNavController(view); + + + etemail = view.findViewById(R.id.emailfieldSignIn); + etpassword = view.findViewById(R.id.passwordfieldSignIn); + + firestore = FirebaseFirestore.getInstance(); + auth = FirebaseAuth.getInstance(); + signIn = view.findViewById(R.id.signInButton); + + + signIn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + email = etemail.getEditText().getText().toString(); + password = etpassword.getEditText().getText().toString(); + + + if (email.isEmpty()) { + + etemail.setError("Enter Email"); + + + } else if (password.isEmpty() || password.length() < 6) { + + etpassword.setError("Password length must be more than 6"); + + } else { + + + SignInUser(email, password); + + + + } + + + + + + } + }); + + + + toggle.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (v.isClickable()) { + + navController.navigate(R.id.action_loginFragment_to_registerFragment); + } + + } + }); + + + + + } + + + // this is helping us to sign in the user + + + private void SignInUser(String email, String password) { + + auth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + + if (task.isSuccessful()) { + + navController.navigate(R.id.action_loginFragment_to_productsFragment); + Toast.makeText(getContext(), "Signed In", Toast.LENGTH_SHORT).show(); + + } + + } + }); + } + + + + @Override + public void onStart() { + + FirebaseUser firebaseUser = auth.getCurrentUser(); + + if (firebaseUser!=null) { + + navController.navigate(R.id.action_loginFragment_to_productsFragment); + + + + } + super.onStart(); + } +} \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MVVM/CartRepo.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MVVM/CartRepo.java new file mode 100644 index 0000000..3b92365 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MVVM/CartRepo.java @@ -0,0 +1,65 @@ +package com.example.shopcart.MVVM; + +import com.example.shopcart.Model.Cart; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.firestore.DocumentSnapshot; +import com.google.firebase.firestore.EventListener; +import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.FirebaseFirestoreException; +import com.google.firebase.firestore.QuerySnapshot; + +import java.util.ArrayList; +import java.util.List; + +public class CartRepo { + + FirebaseFirestore firestore = FirebaseFirestore.getInstance(); + String userid; + FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(); + List cartList = new ArrayList<>(); + CartINTERFACEShit interfaceCart; + + public CartRepo(CartINTERFACEShit interfaceCart) { + this.interfaceCart = interfaceCart; + } + + public void getCartShit() { + + assert firebaseAuth!=null; + userid = firebaseAuth.getCurrentUser().getUid(); + + firestore.collection("Cart"+userid).addSnapshotListener(new EventListener() { + @Override + public void onEvent( QuerySnapshot value, FirebaseFirestoreException error) { + + cartList.clear(); + + + for (DocumentSnapshot ds: value.getDocuments()) { + + Cart cart = ds.toObject(Cart.class); + + cartList.add(cart); + + interfaceCart.CartlIST(cartList); + + + + } + + + } + + + }); + + + + + } + + + public interface CartINTERFACEShit{ + void CartlIST(List carts); + } +} \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MVVM/CartViewModel.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MVVM/CartViewModel.java new file mode 100644 index 0000000..1ad4510 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MVVM/CartViewModel.java @@ -0,0 +1,30 @@ +package com.example.shopcart.MVVM; + +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; + +import com.example.shopcart.Model.Cart; + +import java.util.List; + +public class CartViewModel extends ViewModel implements CartRepo.CartINTERFACEShit { + + + MutableLiveData> mutableLiveData = new MutableLiveData<>(); + CartRepo rep = new CartRepo(this); + + public CartViewModel() { + rep.getCartShit(); + } + + public LiveData> cartLiveDataShit() { + return mutableLiveData; + } + + + @Override + public void CartlIST(List carts) { + mutableLiveData.setValue(carts); + } +} \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MVVM/ProductRepo.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MVVM/ProductRepo.java new file mode 100644 index 0000000..dc8c5be --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MVVM/ProductRepo.java @@ -0,0 +1,64 @@ +package com.example.shopcart.MVVM; + +import androidx.annotation.ArrayRes; +import androidx.annotation.Nullable; + +import com.example.shopcart.Model.Product; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.firestore.DocumentId; +import com.google.firebase.firestore.DocumentSnapshot; +import com.google.firebase.firestore.EventListener; +import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.FirebaseFirestoreException; +import com.google.firebase.firestore.QuerySnapshot; + +import java.util.ArrayList; +import java.util.List; + +public class ProductRepo { + + + FirebaseFirestore firestore = FirebaseFirestore.getInstance(); + List productList = new ArrayList<>(); + + OnProductInter interfaceprodcuts; + + public ProductRepo(OnProductInter interfaceprodcuts) { + this.interfaceprodcuts = interfaceprodcuts; + } + + public void GetAllPRO() { + + firestore.collection("Products").addSnapshotListener(new EventListener() { + @Override + public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) { + + productList.clear(); + + for (DocumentSnapshot ds: value.getDocuments()) { + + Product product = ds.toObject(Product.class); + + + productList.add(product); + + interfaceprodcuts.Products(productList); + + + + } + } + }); + + + + + + + } + + + public interface OnProductInter{ + void Products(List products); + } +} diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MVVM/ProductViewModel.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MVVM/ProductViewModel.java new file mode 100644 index 0000000..6fa21a3 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MVVM/ProductViewModel.java @@ -0,0 +1,34 @@ +package com.example.shopcart.MVVM; + +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; + +import com.example.shopcart.Model.Product; + +import java.util.List; + +public class ProductViewModel extends ViewModel implements ProductRepo.OnProductInter { + + MutableLiveData> mutableLiveData = new MutableLiveData<>(); + ProductRepo productRepo = new ProductRepo(this); + + + public ProductViewModel() { + productRepo.GetAllPRO(); + } + + public LiveData> getAllProducts() { + return mutableLiveData; + + + + + + } + + @Override + public void Products(List products) { + mutableLiveData.setValue(products); + } +} diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MainActivity.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MainActivity.java new file mode 100644 index 0000000..faddc81 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/MainActivity.java @@ -0,0 +1,16 @@ +package com.example.shopcart; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; + +import android.os.Bundle; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); + } +} \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/Model/Cart.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/Model/Cart.java new file mode 100644 index 0000000..ed31a86 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/Model/Cart.java @@ -0,0 +1,63 @@ +package com.example.shopcart.Model; + +import com.google.firebase.firestore.DocumentId; + +public class Cart { + + + String title; + String productid, imageUrl; + int price, quantity; + + + public Cart() { + } + + public Cart(String title, String productid, String imageUrl, int price, int quantity) { + this.title = title; + this.productid = productid; + this.imageUrl = imageUrl; + this.price = price; + this.quantity = quantity; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getProductid() { + return productid; + } + + public void setProductid(String productid) { + this.productid = productid; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public int getPrice() { + return price; + } + + public void setPrice(int price) { + this.price = price; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } +} diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/Model/Product.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/Model/Product.java new file mode 100644 index 0000000..8ef78ba --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/Model/Product.java @@ -0,0 +1,72 @@ +package com.example.shopcart.Model; + +import com.google.firebase.firestore.DocumentId; + +public class Product { + + + @DocumentId + String productid; + String title, imageUrl, description; + int price, quantity; + + public Product() { + } + + public Product(String productid, String title, String imageUrl, String description, int price, int quantity) { + this.productid = productid; + this.title = title; + this.imageUrl = imageUrl; + this.price = price; + this.quantity = quantity; + this.description = description; + } + + public String getProductid() { + return productid; + } + + public void setProductid(String productid) { + this.productid = productid; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public int getPrice() { + return price; + } + + public void setPrice(int price) { + this.price = price; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/ProductsDetailFragment.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/ProductsDetailFragment.java new file mode 100644 index 0000000..4965dab --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/ProductsDetailFragment.java @@ -0,0 +1,231 @@ +package com.example.shopcart; + +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.navigation.NavController; +import androidx.navigation.Navigation; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import com.bumptech.glide.Glide; +import com.example.shopcart.Model.Product; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.firestore.DocumentSnapshot; +import com.google.firebase.firestore.EventListener; +import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.FirebaseFirestoreException; + +import java.util.HashMap; + +public class ProductsDetailFragment extends Fragment { + + + + TextView quantitydisplay, titleview, descview, priceview; + int quantity = 0; + Button addquantity, subquantity, addtocart; + FirebaseFirestore firestore; + FirebaseAuth firebaseAuth; + ImageView imageView; + String title, imageUrl, desc, productid, userid; + int position = 0; + int price = 0; + int finalprice = 0; + + NavController navController; + + + public ProductsDetailFragment() { + + } + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + return inflater.inflate(R.layout.fragment_product_detail, container, false); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + + firestore = FirebaseFirestore.getInstance(); + firebaseAuth = FirebaseAuth.getInstance(); + userid = firebaseAuth.getCurrentUser().getUid(); + + navController = Navigation.findNavController(view); + + + quantitydisplay = view.findViewById(R.id.quantitycounterproductdetail); + addquantity = view.findViewById(R.id.addquantity); + subquantity = view.findViewById(R.id.subquantity); + addtocart = view.findViewById(R.id.buttonaddtocart); + titleview = view.findViewById(R.id.productdetailtitle); + descview = view.findViewById(R.id.productdetaildetail); + imageView = view.findViewById(R.id.productdetailimage); + priceview = view.findViewById(R.id.totalPriceproductdetail); + + imageUrl = ProductsDetailFragmentArgs.fromBundle(getArguments()).getImageUrl(); + title = ProductsDetailFragmentArgs.fromBundle(getArguments()).getTitle(); + desc = ProductsDetailFragmentArgs.fromBundle(getArguments()).getDescription(); + position = ProductsDetailFragmentArgs.fromBundle(getArguments()).getPosition(); + productid = ProductsDetailFragmentArgs.fromBundle(getArguments()).getProductid(); + price = ProductsDetailFragmentArgs.fromBundle(getArguments()).getPrice(); + + titleview.setText(title); + descview.setText(desc); + Glide.with(getActivity()).load(imageUrl).centerCrop().into(imageView); + priceview.setText("Price for 1 item is " + String.valueOf(price)); + + + + firestore.collection("Products").document(productid).addSnapshotListener(new EventListener() { + @Override + public void onEvent(@Nullable DocumentSnapshot value, @Nullable FirebaseFirestoreException error) { + + Product product = value.toObject(Product.class); + + + String latestquantity = String.valueOf(product.getQuantity()); + + + quantitydisplay.setText(latestquantity); + + } + }); + + + + addquantity.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + quantity = Integer.parseInt(quantitydisplay.getText().toString()); + + quantity++; + + + finalprice = quantity * price; + priceview.setText("Total is " + String.valueOf(quantity) +" x " + String.valueOf(finalprice)); + + firestore.collection("Products").document(productid).update("quantity", quantity).addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + + } + }); + + + + } + }); + + + subquantity.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + + quantity = Integer.parseInt(quantitydisplay.getText().toString()); + + + + if (quantity <=0) { + + quantity = 0; + finalprice = 0; + + + } else { + + quantity--; + finalprice = quantity * price; + priceview.setText("Total is " + String.valueOf(quantity) +" x " + String.valueOf(finalprice)); + + firestore.collection("Products").document(productid).update("quantity", quantity).addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + + } + }); + + + + + + } + + + + } + }); + + + addtocart.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + + if (quantity ==0) { + + + + navController.navigate(R.id.action_productsDetailFragment_to_productsFragment); + Toast.makeText(getContext(), "Nothing Added to Cart", Toast.LENGTH_SHORT).show(); + + + + } else if (quantity!=0) { + + + AddedInCart(); + ProductsDetailFragmentDirections.ActionProductsDetailFragmentToProductsFragment actions = ProductsDetailFragmentDirections.actionProductsDetailFragmentToProductsFragment(); + + actions.setQuantity(quantity); + navController.navigate(actions); + + Toast.makeText(getContext(), "Added In Cart", Toast.LENGTH_SHORT).show(); + + + + } + } + }); + + + + + + } + + private void AddedInCart() { + + + + HashMap hashMap = new HashMap<>(); + hashMap.put("quantity", quantity); + hashMap.put("price", finalprice); + hashMap.put("title", title); + hashMap.put("imageUrl", imageUrl); + hashMap.put("productid", productid); + + firestore.collection("Cart"+userid).document(title).set(hashMap).addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + + } + }); + } +} \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/ProductsFragment.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/ProductsFragment.java new file mode 100644 index 0000000..f8f66cf --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/ProductsFragment.java @@ -0,0 +1,184 @@ +package com.example.shopcart; + +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; +import androidx.navigation.NavController; +import androidx.navigation.Navigation; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.example.shopcart.Adapter.ProductsAdapter; +import com.example.shopcart.MVVM.ProductViewModel; +import com.example.shopcart.Model.Cart; +import com.example.shopcart.Model.Product; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.firestore.DocumentSnapshot; +import com.google.firebase.firestore.EventListener; +import com.google.firebase.firestore.FirebaseFirestore; +import com.google.firebase.firestore.FirebaseFirestoreException; +import com.google.firebase.firestore.QuerySnapshot; + +import java.util.ArrayList; +import java.util.List; + +import static android.content.ContentValues.TAG; + +public class ProductsFragment extends Fragment implements ProductsAdapter.OnClickedProducct { + + + RecyclerView recyclerView; + ProductViewModel viewModel; + ProductsAdapter mAdapter; + FloatingActionButton fab; + TextView quantityincart; + + FirebaseAuth firebaseAuth; + FirebaseFirestore firestore; + String userid; + int sum = 0; + + + NavController navController; + List savequantity = new ArrayList<>(); + + + public ProductsFragment() { + + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_product, container, false); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + + firebaseAuth = FirebaseAuth.getInstance(); + firestore = FirebaseFirestore.getInstance(); + + userid = firebaseAuth.getCurrentUser().getUid(); + + recyclerView = view.findViewById(R.id.recyclerviewproduct); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + + mAdapter = new ProductsAdapter(this); + fab = view.findViewById(R.id.fabMainProductPage); + navController = Navigation.findNavController(view); + quantityincart = view.findViewById(R.id.cartquantity); + + + + + + + + + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + navController.navigate(R.id.action_productsFragment_to_cartFragment); + } + }); + + + + firestore.collection("Cart"+userid).addSnapshotListener(new EventListener() { + @Override + public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) { + + for (DocumentSnapshot ds: value.getDocuments()) { + + Cart cart = ds.toObject(Cart.class); + + + int quantitycounter = cart.getQuantity(); + + // add all integers into Integer arraylist + savequantity.add(quantitycounter); + + + } + + + for (int i =0; i < savequantity.size(); i++) { + + + sum+= Integer.parseInt(String.valueOf(savequantity.get(i))); + + } + + quantityincart.setText(String.valueOf(sum)); + + sum = 0; + savequantity.clear(); + + + + + } + }); + + + + viewModel = new ViewModelProvider(getActivity()).get(ProductViewModel.class); + viewModel.getAllProducts().observe(getViewLifecycleOwner(), new Observer>() { + @Override + public void onChanged(List products) { + + mAdapter.setProductList(products); + recyclerView.setAdapter(mAdapter); + } + }); + + } + + + + + + + // for going to next fragment product detail. + + @Override + public void OnProClicked(List productList, int position) { + + ProductsFragmentDirections.ActionProductsFragmentToProductsDetailFragment + actions = ProductsFragmentDirections.actionProductsFragmentToProductsDetailFragment(); + + actions.setTitle(productList.get(position).getTitle()); + actions.setDescription(productList.get(position).getDescription()); + actions.setProductid(productList.get(position).getProductid()); + actions.setPosition(position); + actions.setImageUrl(productList.get(position).getImageUrl()); + actions.setPrice(productList.get(position).getPrice()); + + navController.navigate(actions); + + + + } + + + @Override + public void onResume() { + super.onResume(); + sum = 0; + } +} \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/RegisterFragment.java b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/RegisterFragment.java new file mode 100644 index 0000000..9ed2c76 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/java/com/example/shopcart/RegisterFragment.java @@ -0,0 +1,161 @@ +package com.example.shopcart; + +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.SwitchCompat; +import androidx.fragment.app.Fragment; +import androidx.navigation.NavController; +import androidx.navigation.Navigation; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.Toast; + +import com.example.shopcart.R; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.android.material.textfield.TextInputLayout; +import com.google.firebase.auth.AuthResult; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.firestore.FirebaseFirestore; + +import java.util.HashMap; + +public class RegisterFragment extends Fragment { + + SwitchCompat toggle; + FirebaseFirestore firestore; + FirebaseAuth auth; + NavController navController; + TextInputLayout etname, etemail, etpassword; + String name, email, password; + Button signUp; + + + + public RegisterFragment() { + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_register, container, false); + } + + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + etemail = view.findViewById(R.id.emailfield); + etname = view.findViewById(R.id.nameField); + etpassword = view.findViewById(R.id.passwordfield); + + firestore = FirebaseFirestore.getInstance(); + auth = FirebaseAuth.getInstance(); + signUp = view.findViewById(R.id.signUpButton); + + + toggle = view.findViewById(R.id.gotosignInSwitch); + navController = Navigation.findNavController(view); + + + signUp.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + name = etname.getEditText().getText().toString(); + password = etpassword.getEditText().getText().toString(); + email = etemail.getEditText().getText().toString(); + + if (name.isEmpty()) { + + + etname.setError("Enter name"); + } else if (email.isEmpty()) { + + etemail.setError("Enter Email"); + + + } else if (password.isEmpty() || password.length() < 6) { + + etpassword.setError("Password length must be more than 6"); + + } else { + + CreateUsers(name, email, password); + + } + + + + } + }); + + toggle.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (v.isClickable()) { + navController.navigate(R.id.action_registerFragment_to_loginFragment); + } + + } + }); + + + + } + + + private void CreateUsers(String name, String email, String password) { + + auth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + + if (task.isSuccessful()) { + + FirebaseUser user = auth.getCurrentUser(); + + String userid = user.getUid(); + + HashMap hashMap = new HashMap<>(); + hashMap.put("username", name); + hashMap.put("email", email); + hashMap.put("userid", userid); + + + firestore.collection("Users").document().set(hashMap).addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + + } + }); + + + Toast.makeText(getContext(), "Registered", Toast.LENGTH_SHORT).show(); + + + navController.navigate(R.id.action_registerFragment_to_productsFragment); + + + + } + + } + }); + + + + + + + } + + +} \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-hdpi/custom_size__4.png b/TASK4_Product_Ordering/app/src/main/res/drawable-hdpi/custom_size__4.png new file mode 100644 index 0000000..9be3733 Binary files /dev/null and b/TASK4_Product_Ordering/app/src/main/res/drawable-hdpi/custom_size__4.png differ diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-hdpi/rectangle_3.png b/TASK4_Product_Ordering/app/src/main/res/drawable-hdpi/rectangle_3.png new file mode 100644 index 0000000..8ea6770 Binary files /dev/null and b/TASK4_Product_Ordering/app/src/main/res/drawable-hdpi/rectangle_3.png differ diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-ldpi/custom_size__4.png b/TASK4_Product_Ordering/app/src/main/res/drawable-ldpi/custom_size__4.png new file mode 100644 index 0000000..6d76fe6 Binary files /dev/null and b/TASK4_Product_Ordering/app/src/main/res/drawable-ldpi/custom_size__4.png differ diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-ldpi/rectangle_3.png b/TASK4_Product_Ordering/app/src/main/res/drawable-ldpi/rectangle_3.png new file mode 100644 index 0000000..a819487 Binary files /dev/null and b/TASK4_Product_Ordering/app/src/main/res/drawable-ldpi/rectangle_3.png differ diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-mdpi/custom_size__4.png b/TASK4_Product_Ordering/app/src/main/res/drawable-mdpi/custom_size__4.png new file mode 100644 index 0000000..1b7f704 Binary files /dev/null and b/TASK4_Product_Ordering/app/src/main/res/drawable-mdpi/custom_size__4.png differ diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-mdpi/rectangle_3.png b/TASK4_Product_Ordering/app/src/main/res/drawable-mdpi/rectangle_3.png new file mode 100644 index 0000000..31d8acf Binary files /dev/null and b/TASK4_Product_Ordering/app/src/main/res/drawable-mdpi/rectangle_3.png differ diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-v24/cart.xml b/TASK4_Product_Ordering/app/src/main/res/drawable-v24/cart.xml new file mode 100644 index 0000000..cf0dcc8 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/res/drawable-v24/cart.xml @@ -0,0 +1,10 @@ + + + diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-v24/deleteitem.xml b/TASK4_Product_Ordering/app/src/main/res/drawable-v24/deleteitem.xml new file mode 100644 index 0000000..b0b1d8d --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/res/drawable-v24/deleteitem.xml @@ -0,0 +1,10 @@ + + + diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/TASK4_Product_Ordering/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-xhdpi/custom_size__4.png b/TASK4_Product_Ordering/app/src/main/res/drawable-xhdpi/custom_size__4.png new file mode 100644 index 0000000..390471b Binary files /dev/null and b/TASK4_Product_Ordering/app/src/main/res/drawable-xhdpi/custom_size__4.png differ diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-xhdpi/rectangle_3.png b/TASK4_Product_Ordering/app/src/main/res/drawable-xhdpi/rectangle_3.png new file mode 100644 index 0000000..d2602f1 Binary files /dev/null and b/TASK4_Product_Ordering/app/src/main/res/drawable-xhdpi/rectangle_3.png differ diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-xxhdpi/custom_size__4.png b/TASK4_Product_Ordering/app/src/main/res/drawable-xxhdpi/custom_size__4.png new file mode 100644 index 0000000..d815a10 Binary files /dev/null and b/TASK4_Product_Ordering/app/src/main/res/drawable-xxhdpi/custom_size__4.png differ diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-xxhdpi/rectangle_3.png b/TASK4_Product_Ordering/app/src/main/res/drawable-xxhdpi/rectangle_3.png new file mode 100644 index 0000000..cf3f838 Binary files /dev/null and b/TASK4_Product_Ordering/app/src/main/res/drawable-xxhdpi/rectangle_3.png differ diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-xxxhdpi/custom_size__4.png b/TASK4_Product_Ordering/app/src/main/res/drawable-xxxhdpi/custom_size__4.png new file mode 100644 index 0000000..4e01aed Binary files /dev/null and b/TASK4_Product_Ordering/app/src/main/res/drawable-xxxhdpi/custom_size__4.png differ diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable-xxxhdpi/rectangle_3.png b/TASK4_Product_Ordering/app/src/main/res/drawable-xxxhdpi/rectangle_3.png new file mode 100644 index 0000000..5af3441 Binary files /dev/null and b/TASK4_Product_Ordering/app/src/main/res/drawable-xxxhdpi/rectangle_3.png differ diff --git a/TASK4_Product_Ordering/app/src/main/res/drawable/ic_launcher_background.xml b/TASK4_Product_Ordering/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TASK4_Product_Ordering/app/src/main/res/font/allerta.xml b/TASK4_Product_Ordering/app/src/main/res/font/allerta.xml new file mode 100644 index 0000000..d64580c --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/res/font/allerta.xml @@ -0,0 +1,7 @@ + + + diff --git a/TASK4_Product_Ordering/app/src/main/res/font/carrois_gothic_sc.xml b/TASK4_Product_Ordering/app/src/main/res/font/carrois_gothic_sc.xml new file mode 100644 index 0000000..b3cd206 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/res/font/carrois_gothic_sc.xml @@ -0,0 +1,7 @@ + + + diff --git a/TASK4_Product_Ordering/app/src/main/res/layout/activity_main.xml b/TASK4_Product_Ordering/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..ec3fdea --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,19 @@ + + + + + + + + \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/res/layout/cartliststyle.xml b/TASK4_Product_Ordering/app/src/main/res/layout/cartliststyle.xml new file mode 100644 index 0000000..5baff70 --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/res/layout/cartliststyle.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TASK4_Product_Ordering/app/src/main/res/layout/fragment_cart.xml b/TASK4_Product_Ordering/app/src/main/res/layout/fragment_cart.xml new file mode 100644 index 0000000..0d926ab --- /dev/null +++ b/TASK4_Product_Ordering/app/src/main/res/layout/fragment_cart.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + +