Android Shopping Cart Tutorial - Android Firebase eCommerce App like Amazon
Summary
TLDRIn this tutorial, Muhammad Ali demonstrates how to implement an 'Add to Cart' feature for an e-commerce app using Firebase. The video covers adding a user-friendly button to the UI, capturing the current date and time, and storing product details in Firebase under both user and admin views. The process includes handling product ID, name, price, quantity, and discount. It also shows how to navigate users to the home page after adding products to the cart. The tutorial ends by confirming successful database entries and previewing future steps for cart display and final order placement.
Takeaways
- 😀 The video demonstrates how to add a product to the cart list in an Android app using Firebase.
- 😀 A new 'Add to Cart' button is added to the product details activity, replacing the floating action button.
- 😀 The button is styled with specific properties like background color, margins, and white text.
- 😀 A click listener is set up for the 'Add to Cart' button to trigger the process of adding the product to the cart list.
- 😀 The current date and time are captured using `Calendar` and `SimpleDateFormat` to track when a product is added to the cart.
- 😀 Firebase is used to store product information (like ID, name, price, quantity, and discount) in a user's cart list.
- 😀 A `DatabaseReference` is created to interact with Firebase and store the cart data under a unique identifier (user's phone number).
- 😀 The cart data is stored both for the user and admin, ensuring access for both parties in different views.
- 😀 After adding a product, the user is redirected to the home activity to view their updated cart.
- 😀 The app is tested by adding multiple products (iPhone X and MacBook Pro) to the cart and confirming that they appear in Firebase correctly.
Q & A
What is the purpose of the new button in the tutorial?
-The new button, labeled 'Add to Cart', is introduced to allow users to add products to their cart in the app. It replaces the floating action button previously used for this functionality.
Why is the floating action button removed from the layout?
-The floating action button is removed because the tutorial demonstrates the use of a regular button instead, which is considered more visually appealing for this use case.
What changes are made to the layout XML file for the new button?
-The layout XML for the new button includes properties like `match_parent` for width, `wrap_content` for height, a background color, margin settings, and text size. The button is also aligned at the bottom of the screen.
What is the role of the `addToCartButton.setOnClickListener()` method in the code?
-The `setOnClickListener()` method is used to define what happens when the 'Add to Cart' button is clicked. It triggers the `addToCart()` method, which adds the selected product to the user's cart.
What kind of data is being stored when a user adds a product to the cart?
-The data stored includes the product ID, product name, price, the current date and time, quantity, and discount (if applicable). This data is stored in a `HashMap` called `cartMap`.
How is the current date and time formatted before being stored?
-The current date and time are formatted using `SimpleDateFormat`. The date format is `MM/dd/yyyy` for the date and `hh:mm:ss a` for the time, which includes AM/PM.
Where is the cart data stored in Firebase?
-The cart data is stored in Firebase under the `cartList` node. The user's data is stored under the `userView` child, which is further identified by the user's phone number. The product details are stored under `products`.
What is the significance of using `currentUserPhone` in the Firebase path?
-The `currentUserPhone` is used to uniquely identify the user in the Firebase database. It ensures that each user's cart data is stored separately and is easily retrievable by their phone number.
How does the script handle the admin's view of the cart?
-For the admin's view, the same cart data is also stored under the `adminView` child in Firebase. This allows the admin to see the products in the cart for each user, identified by the user's phone number.
What happens after a product is successfully added to the cart?
-Once a product is successfully added to the cart, a success message is displayed to the user, and the app navigates the user back to the home page to view the updated cart list.
Outlines
このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。
今すぐアップグレードMindmap
このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。
今すぐアップグレードKeywords
このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。
今すぐアップグレードHighlights
このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。
今すぐアップグレードTranscripts
このセクションは有料ユーザー限定です。 アクセスするには、アップグレードをお願いします。
今すぐアップグレード関連動画をさらに表示
Build a modern android ecommerce app from scratch | Kotlin, Firebase, MVVM
😱 Crazy new Supabase feature: Understand and learn about anonymous users
🔥📱 Flutter x Firebase CRUD Masterclass • Create / Read / Update / Delete
Creating Admin App in Flutter with Firebase Auth and Firestore (Your App Idea 1)
Laravel 11 Multi Auth For Ecommerce Website | Step By Step
Online Shopping System | Java E-Commerce Project with Source Code | Shopping Cart | Part-1 : DEMO
5.0 / 5 (0 votes)