Project#2 Android Food Order/Delivery App (Java) | 2021

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back to my channel in today's video i'm going to show you how you can build a food delivery app in android using the java for that i already built a json file which i'm going to keep it in the row folder so it have the restaurant information like name address delivery charges their image their arts and the menu type of options what kind of the menu and their images so i already built that json with few restaurants names as you can see on the screen so we are going to use this json so let's begin with adding the dependencies in our project so first i'm going to use glide this is for the image so we already have the urls we just need to make it api call and get the second is the json json library that is going to just parse our json file into the objects so these two dependencies you are going to use in it i am creating a separate activity for the splash screen so as you know all the projects have the splash screen so i'm creating a splash screen first [Music] so this is past screen is just going to keep an image view and will stay on the screen for just two seconds and then it will launch or launch it will take us to the main activity for that we need an image so i'm downloading it from the flat icon i'm choosing one image for my splash so this is how it image is downloading now we need to import that so that's the svg file so that's what the reason i'm importing it this way and here we are going to use it inside our main activity we are going to use the handler for handler with the pause delete function for 32 second before that we need to set our navigation bar to the full screen so that it doesn't show any title on the top of the screen so i'm hiding simple over navigation bar when once two second delay will be done then it will send us to the main activity and we'll close the splash in our main activity we need to set a title to a navigation so i am setting restaurant list now i'm creating a separate function for getting our json file and convert it into the list so this is the model i'm creating a separate package for all the data model and inside this model package i'm creating a class the restaurant model so this is basically our the model class which is going to hold the object and this is the way we read json file or any file from our raw folder you you now we are going to use json just to simply get our json into the object since our json have the restaurant type of object or the list or the arraylist so that is the reason it is going to return the arraylist of restaurant model and now i am simply converting that area of restaurant model into the list of restaurant model type you so we are going to show our restaurant list on a recycler view so let's go to our layout file and add one recycler view as you know we need to set or set the layout manager to our recycler view so i'm setting linear layout manager and we need to set an adapter as well so we don't have adapter yet so we need to create it so first create a separate package where we are going to keep our adapter since in this project we are going to have multiple adapters i am keeping them in the separate package so now i'm giving it as a name restaurant list adapter you can choose any name since we have the static data so we can simply take it inside the constructor but i am still creating a separate function if we need to update the data from the outside now we need to inflate one layout so now create a layout for our recycler view i want to use the constraint layout so i'm just simply adding a constraint layout inside it and also we are going to use the card view i think the corner radius 10 dps are fine and the margin from right left bottom is 20 db inside this we need first of all the image image for the restaurant so i'm giving it as a height with a 120 db inside the linear layout i am giving i'm adding some textures for maybe we'll use it for the display the name [Music] and the address i'm putting few textures now we'll pass the layout file inside our adapter and we will initialize all these views since we haven't declared any variables inside our restaurant model so let's check what we have in our json file and create a same as in our restaurant model since you are using json library so make sure to give the same name what you define inside the json file so delivery charge could be any value it could be in the decimal as well so that's what the reason i'm keeping it as a plot we have ours so it is a separate object and for the menu it's an again array so let me create another data class or the model class for arts so it already have that object as a and the variable name as sunday so i'm declaring it as with the same name now i need to create the setter getter for it so you can directly create it and here i am creating a separate function which basically is going to return the r for the day from the current day so it is going to check what they exactly said in your phone so if you have sunday then it will return the odds for sunday if it is monday then it will return in the hours of monday it should be simple date format you so here we will define ours now we need a menus so we will create a separated class for manuals and this is the simple class it is holding the three parameter name price and url so we'll define it since price could be in the decimal so i am using float and url again as string and implementing partiable this class because we need to pass some data from one activity to another activity so i want to pass the whole object that's the reason i'm implementing it as a participle so it's very easy if you want to implement any model class into the passable so it's like auto generated since it is the area of menus so i am declaring it as a list of menus menu the class name and the name is manuals as you define it in the json file now this class also we are going to implement as a possible and now i will generate the segregated so our model classes are ready now i'll use them in the bind view folder so still we are implementing our restaurant list adapter you so here i am using what function we have created inside our arts class and now we are going to use the glide so we have already restaurant url inside our json file so that you are going to get the image using the glide and set it on the image view now on the restaurant click we need to handle that so i'm declaring the defining interface to handle the restaurant click so when user will click on any restaurant name then we'll see the menu and then they can add some item in the cart and then they can place an order so for that we need to handle the click of restaurant you now i will use this adapter in our main activity and we will implement the on click function or the interface there you go so that adapters need a restaurant list so we are passing inside the constructor and the interface click listener so let's run and see the splash is there i see it's not displaying the name instead it is printing the url so maybe we made some mistake in our adapter there it is so we need to use the get name instead of get image let's run it again and see you can see the splash and the restaurant list image is also able to download successfully that's great so first screen restaurant list is ready there you go you can see the arts you can see the address you can see the name and image as well now on click of restaurant name we need to uh open another activity so i'm giving it as a name restaurant menu activity so this activity we are going to open when user tap on and restart name this function is going to call when user will tap on the recyclerview [Music] item when we are going to launch restaurant menu activity inside this we are going to pass our restaurant model so that we can just display the data or some restaurant information like name and address on the screen now let's compute our layout by adding some views so first of all i'm adding a recycler view and i am adding a button on the bottom of the screen that is going to call checkout i need a background for the button like round corners and also i am creating a shape and i'm giving the corner radius that's it and now i'll set this background to my checkout button now i will extracting the value of the object restaurant model which we pass from the previous screen so now i am converting it into the real object and i'm setting the restaurant name and address on my action bar setting the subtitle as a address and we need the back button also on our action bar so i am enabling it by setting the display home as up enable true on this screen we just need to display the menus so i am retrieving menus list from the restaurant model object and creating a separate function for initialize overview model or recycler view i am keeping the menu list in the global variable so that we can access throughout this activity and this layout manager is going to be the grid layout manager i want two items to display parallely and now we need the adapter also we need to handle the button click so let's handle the button click first for adapter we'll be simply copying the existing adapter as we already created and then we'll just make some modification in it i'm giving it a name menu list adapter and will simply modify this the data is going to be the menu type object also the separate listener for item click now i am setting the adapter to our recycler view and we need to handle the click listener of menu items there you go now go back to our adapter and create a layout so i am again copying the same recycler row and will make some modification in this recycler row for our photo display our menu so we don't need image on a side we need maze on a top and then on the menu will make it a little bit small we need to rename it to the menu name like the item name [Music] and the item or we can say menu price and we need a button which is going to call add to cart button we'll use the same background as we created we'll add some item later on the layout like quantity adding the quantity so first let she made change relevant changes to our menu adapter and add to card button we just need to handle its click on button click we'll call our listener so i'm changing a name on the add to cart click listener let's call it this change we need to make in our activity as well and i'm putting dollar sign in front of price and we'll use the layout what what we created for our menus let's run and see how it look like if you find any small issue then we'll okay so button is on place maze is on place name and price is on place we just need to make little bit modification in our button so let's make them so it need to be have some padding and text for the left line so we need to set it gravity to center horizontally and i'm increasing a little bit margin as well let's run and see there you go so it looked pretty good so just to add a quantity i am adding a plus and minus symbol and the quantity on a texture so for that i am adding us another linear layout that is going to be the another layout when user click on add to cart button that add to cart button will hide and it will show a view where you can add quantity or increase or decrease your quantity for that i am adding two image view and one text view so from this layout user can add or reduce the quantity for that we need some icons so let's get some icons i'm getting this plus icon and we'll import it i need another icon yeah we'll use this minus for reducing the quantity similarly we'll import it we need one textview to update the quantity what user have selected or added videos so now we'll handle on button click and this plus minus image use click so based on these buttons our card will get prepared so let's check it so when add to cart button will click will simply make the visibility of for more layout and add to cart button will be gone here we need to declare one more item of any type like how many items in the card so i'm going to name the total in card so when user will click on add to cart so quantity will change to one so item will be added in the card as one and we'll update the text view with number one or we'll read it from the menu dot get turtle in card let's run and see the strength okay you can see now but plus minus button we need to handle still so let's go and add little bit padding in it and now we'll simply handle our plus minus buttons click so based on that quantity in the card will exist now we need to have one method in our interface which is going to handle the quantity inside the cart we need one function which is going to like remove item from the card as soon as user will hit minus when quantity is 1 we need to show the add to cart button and we'll remove that item from our card and we'll hide our add more layout and now on the plus button click we need to update the quantity but user can add up to 10 items only so i am changing this condition as well the user cannot add more than 10 item you can adjust it according to you but currently i am giving as the 10 max for one item so one item quantity can be 10 as max now we need to override those two function which we added in our interface there you go so for cart we i'm creating a separate list so that we can just add whatever item or the object is added inside the card so we can simply handle from this separate list we don't need to modify the existing list that is just to display for first time but we need a lot of calculation on this list this total item in cart integer type will tell us like we'll i'll help in calculating how many items we have in our card and we'll display that number on the button that is called checkout button so we'll delete this button as a global variable so that we can access it easily and here we will set the text as checkout and the quantity of our total items in cart we'll simply update the list with uh by updating the quantity so we don't need to add that object again and again in the same list we can simply update it by checking the contains function will get the index of our object and based on that index will update that particular menu items quantity inside our list and now this block of code will remain same as it's going to iterate the whole list and get the total number of item and update the button text in case of remove when there is no items in the cart when user is tapping minus button so at that time will simply remove that item from our menu and update our ui and we forgot to handle the back button on our top left corner of the screen so let's handle that back arrow as well will simply close the activity and on click of checkout button we need to open another activity to review your card and then user can place their order so before that we need to check if there are certain items in the card or not if there are nothing in the card then we will simply show a message to the user so this is the basic validation that's it and when there are some certain items in the card then we will launch a new activity before that we need to update the menus in our main restaurant model and we'll simply pass this restaurant model to the new screen new activity why i am using start activity for results so that user do not come back to this screen after placing that or you can directly reach out to the home screen where we display the restaurant list now i'm creating another activity which is going to call place your order activity on this screen user can review their card make the payment enter their address or they can choose their own delivery or the pickup so since i have called on activity with results so we need to override on activity result as well and here we will check the request code what request code we passed above we'll going to check the same the thousand i create call i put there i'm using and then the result code is equal to result okay activity dot result okay if that's the one then we'll simply close this activity and user can land on the main activity or the restaurant list else if user is simply pressing the back button then they can come here and make the modification in their menu we need the same block of code in our place your ad place your order activity here we'll build our layout so i'm adding a scroll view on top it needs some scrolling as it's going to display the so many items it is going to ask user to input their details so i'm adding a scroll view so this is just the layout i'm adding few text views edit text and a recycler view and a button this switch is going to choose between the delivery and the pickup here user can input their name address the full address if they opt for the delivery then we need to ask user to enter their address if they pick for the pickup then we don't need the address so in that case we just need user to input their name so this is about the customer details now we need the car details so user can make the payment by answering their credit card or any mechanism so in this video uh you are just going to see how user is answering credit card details or anything it's not actually going to make the api call it just to show the demo that's it you and here we need to display the items what user added in their card and in under this we need to add a recycler view so that user can see what items they have added and what the quantity they have choose to order so this is kind of reviewing the order one more time before placing it actually to the owner on the bottom i'm adding a some subtotal total and the delivery charge and how much actually user need to pay to the restaurant owner and that will be calculated based on the cart items you have selected on the previous screen so delivery charge will only be displayed when user has selected delivery from the switch if it is selected as a pickup then there will not be any delivery charge i'm not going to add anything for the taxes and all because that's all based on the country or the state so i'm not going to add that and simply writing the subtotal and the total for a timing and on the bottom we need a button as well that is going to call place your order so layout is ready and let's go to our activity and handle it so thing we need to get over all the added text and text views where we need to display the total subtotal delivery charge so let's get all these you you now we'll handle the button clicks on the button click will simply display another screen later and that is going to show successfully place your order that's it this is again the same thing for our recycler view to set the layout manager and adapter it will handle the switch click so when switch is set to the delivery then we need to display a address city state or chip and total delivery charge don't need to display we need to grab the amount as well delivery amount so we need to hide that as a oh sorry make it visible as well but when users select to pick up at that time we don't need to display address city state zip and delivery charts based on the selection of delivery or pickup our total price will be changed so let's calculate that as well i'm putting some validations so these validations are like if user has entered name or not so just checking like if it is empty or not you can ask user to enter but address is gonna be the exceptional because we need to check the state of switch for that we can have one boolean if there is only delivery selected then only we are going to check the emptiness of address japan city state and once all the information is filled at that time we'll start a new activity just to show the user a message like your order has successfully submitted to the restaurant and here also we need to override on activity result and we'll check the request code so once user has successfully placed an order and he can go back to the restaurant list so we don't want to see this activity again similarly we need to handle the back arrow so that user can go back and adjust their menu so simply copy paste that block of code [Music] now we need to create a new activity as i said it is going to show the message to the user so i am giving it is auto success [Music] activity in the calculate total amount we need to simply iterate our menu items in the cart here we'll calculate the total amount sub amount subtotal total based on the item we have in our cart and how many quantity we have in our card so we'll calculate everything here stream.format i'm using just to format the amount to the two decimal places so this is the amount get delivery charge we have defined in our json file so from where it's reading it now you need another adapter so let's copy and paste the manually adapter and i'm giving it as a separate name we don't need to handle the click of it so i'm simply removing it user can this is just to review so either don't need to perform any action over it you don't need a add any buttons over here i'm removing all these and we'll set this place your order adapter to our recycler view and we'll modify this layout as well and use it so here we don't need this button we don't need this plus minus layout we need the price and we need to display the quantity so we'll add that quantity and we don't need this card layout as well let's remove it we can make it as much as simple you and now we'll adjust our view adapter as well so we just need we don't need everything so i'm removing we just need quantity as the new parameter you so it will show the price based on the quantity you have at it also the quantity what is selected on the menu screen known success activity will simply display the restaurant name and the address we don't need a back button here so let's make it false let's build this layout so i'm just going to add a text view in the center of the screen and a button on the bottom of the screen so i'm going to copy and paste it as you already have that so i'm giving it as a name done this that's it and i'm renaming it id that's it for this screen and now we'll handle the click of that button and that will simply close this activity i'll call finish function now let's run and see so we can see the restaurant list you can see add there you go okay and there is some issue with the quantity it's not updating properly on the button okay but let's see further the back button is working delivery pickup so name is there i selected delivery it changed it to the address and all and it's calculating and the image is a little bit up need to adjust little bit so it's center horizontal instead we need center vertical and validations are working fine card number input place your border okay and it's taking me back to the restaurant list so everything looks good to me except some minor change so need to check why the quantity in the chair card is not updating on the button so layout looks good adapter look good i took out this function there it is i think something is missing so we are not using this okay so for loop we are doing but we are actually not using it there you go that's the reason it was not updating it properly run it select a restaurant add quantity yeah there you go so it's working fine now let's add it a few items and then checkout button there you go quantity and the price is also getting updated subtot the still subtotal delivery charge is not updating uh something is still missing let's see inside work place your order activity so calculate total amount is not called on the on crate that is also called from the switch only so that's the reason it was not updating it let me add it again check out there you go since it was pickups or delivery charge was zero now i change it to delivery so everything is updated now it is asking to and put some details items place your order that's it so that's all for today's video thank you so much for watching thank you
Info
Channel: LearningWorldz
Views: 16,500
Rating: 4.9191918 out of 5
Keywords:
Id: DOkPTN6X2AY
Channel Id: undefined
Length: 91min 54sec (5514 seconds)
Published: Mon Feb 01 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.