Creating Movie App - Parsing JSON from url into RecyclerView

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we are going to create a movie app that parses json from url and display results into recycler view exactly like this app hello my friends and welcome to master coding channel if you want to learn coding and start your programming career you came to the right place hit subscribe and like so you help us making new tutorials let's begin i will divide this video into many sections in order to understand every step by step so the first step is json link on the internet now let's create a json file uh into internet we go to moki dot io designer dot moki dot io and click onto new mock this http okay 200 okay application json and http header we don't need it and http response body we paste this code so check the description below for this uh this file or this uh data okay generate my http response this is the url of the uh of our json file okay this is the url of our json we copy it and now let's uh let's check for its validity for that we need to go to jasonlind.com this is website for adjacent validity so we copy let's copy this and let's paste it paste here and we click validate json the result is the valid json so we ensure that our json file is the correct 100 percent now back to android studio we we paste it here okay in order to save it for later use now let's create the string private static static this is static sorry drive it's static string okay i will call it json url okay and we paste it here this is our link okay guys now step number two as i told you let's create our uh layouts first of all we go to to activity mainly uh main layout we delete this and we search for recycler view search for recycler view here and you add a click on adding the dependency into the project okay we have finished here and let's now add the card view for later if you want to to like add cards later on into recycler view and this is the card view has been added now let's drag and drop a recycler view till now and later on we will use the card views in the next videos we make it here zero add the constraints here as zeros and also here zero let's give it an id as its recycler view and for the main activity we have finished our layout now we need a layout for the items of the list or the items of the recycler view for every movie that we are going to parse for that we need for to create a layout here and i will call it movie underscore item the movie that we are going or the gsm that we are going to parse contain a string of id the name and the image okay guys so i will we can also uh like uh change the name or change the the image or change the id but till now let's go through this processor processing now i will drag and drop two texts and one image view i will put here the text view and i will add it for constraints okay this is the constraint i will add it to 16 16 it's good and i will make the size for it as text size as 30 sp and wrap the content for it wrap content okay and the family for this i will make it a black okay now let's drag and drop another text this text sorry i will give it a text view i will name it name underscore text this is good and i will i will drag and drop an image sorry a text view and i will call it an id image view this is id underscore text okay this is the text of usually not the image view i will give it 20 24 is big i will give it 18 sp okay now i will drag and drop an image view as i told you here and i will give it for this and i will change okay this is good this is good i will give it here and here okay which is good like this 16 is good and 28 is good and the image view is the id is image view text view id the text and just to link the text view with this i will change now this is very important the constraint layout i will change the height to wrap content and we have finished designing our layouts let's go to step number three close this and this is the creating the modal class so i create a new java class called movie model class okay this is our class since we need to parse id name and image these are three strings we need to create a string id a string name and ice string image okay the second step we need to make a constructor alt plus enter uh sorry l plus insert and we select all and we create an empty and constructor constructor and select none okay now let's create getters and setters also l plus insert and getters we are getters and setters and we select all them and click ok this way we have finished creating our modal movie model class now let's move to the next step which is creating the adapter class let's create a new class java class and i will call it as movie or i will call it as adapter adaptory okay this is our class so i will extend extends the recyclerview dot adapter adapter and i will pass the adaptory dot my view hauler class that we are going to create before we are going before we implement the classes here we are going to create or sorry implement the methods we are going to create a public public static class my view holder extends the recyclerview view holder recyclerview.viewholder this is our class that we are going this is an inner class my view holder that we ex that we extend from the recycler view my view holder and adapter class this will also extend a recyclerview.adapter class now let's configure this later on we are going to to configure this class but now let's add here the the uh with the variables and then implement the methods private context and context and context and private list and of movie model class and called m date this is the data of the movies that we are going to store inside a list alt plus insert to import the class and here we click if either on the red bulb here implement the methods or alt plus enter so we need to implement this methods for recyclerview so in order to understand recyclerview and why we use this please go back to their course and search for recyclerview in the advanced view section okay one last thing here we need to add is the constructor and we select the two variables that we have created the context and the movie list now or the list let's now configure the oncreate view holder remove this and call the view we remove this view v and import it the layout create an instance of inflate layout inflator equal layout layout why we are layout inflator dot from context and context okay so v equal to inflator dot inflate and r dot layout dot then the layout that we have created which is called movie movie item and passing the second parameter as parent and the third parameter is false which is attached to root okay till now we are doing well so so return here that my new my view holder and i will pass v for it okay guys okay now in the my binder view holder my bind view holder here i will create the holder and and instantiate the widgets that we have created before so holder dot id sorry dot id or we have we need to create here before the the context or sorry the methods here uh before and then we move to it so the first step here create the constructor we are going to create the constructor and we pass the widgets here then we go back to the holder so i will keep it till about two minutes before that i will create and instantiate the widgets that we have created so we have created text view called id a text view called name and an image view called image okay and for inside this constructor i will initialize this so id equal item view dot find view by id r dot id dot uh text view or what i've call it okay name or sorry id dot underscore text and name equal item view ho the item view dot find the view by id r dot id dot name text and an image for that called movie pic or image equal item view dot find the view by id r dot id dot image view for that we have finished creating the my my uh my view holder this is the class that we have created so this is the class that we have created and uh let's go back to here on by on the combined view holder and let's create this or set that the data or the sources to be displayed into the text so the text view is created what we are going to put inside this text view we are going to bind the data with it this class or this uh this adapter class is responsible for that doing that by using the onbindviewholder so i'm telling now the android studio to go to the text view of id and set the text that's the text m data from the list and get position get the position and we put get id in the same way i going to put the text sorry the name id dot set text to mdata dot get position into the get name okay the third way we are going to use the glide library for using using glide to display the image okay now let's go to the documentation online and it is called uh bomb tech dot get uh hub dot io this is the official site for the uh for uh glide version four and i will scroll down i will add the repositories here i will go to the build.gradle add the project project level and i will paste this i will click on sync now and syncing is going good now i will copy this okay i'm not going to use integration libraries so i will copy this integration libraries like retrofit okay http and others so i will copy only this now i will go to the build.gradle and add the glide library here and this is the annotation sorry this is the dependency and click now sync now and everything is working fine so the last step we are going to create in this class glide integration so mcontext dot load m data dot get position in the same way as above and dot get image and load into holder dot image okay guys so everything is working fine this is the image the last thing is the last code is called mdata dot size okay everything is working fine now let's move to the last step which is step number four and let's create uh the cla the code into the main activity now let's move to the last step into our video and let's create the codes into the main activity so we go to create the variables here list of and passing the the modal movie model class as generics and the movie list and i will create a recycler view a recycler view okay alt plus insert or sorry alt plus enter and we have imported the package now into the main activity we will or sorry on the main activity of uh oncreate method we called move a list equal new array list and recycler view equal find view by id find the view by idr.id dot recycler view now we need to create an async task so if you want to learn about asynctask and using json so i will create an async task at the previous video so go back to the uh to learn more about asynctask throughout the course and you can see the previous video about json and using asynctask for that till now i will create a get data get data and equal new get data get data and this is our class asynctask class uh and i will create here get data dot execute this methods are not now showing but until i will create this here here i will get data through the async task as i told you so public class and get data extends async async task remember guys this is a the async task has been deprecated and maybe the replaced and we are going to make uh more videos about about using json and replacing the sync task so uh make sure you rate us five stars in endemium under subscribe to our youtube channel to get all them now i will create a method called do in background this is um this is the method that we are going to do of getting the string of json uh let's create json a string called current and i will initialize it by empty and let's try to get the json here we start as i told you in the previous videos about json start by url and this then that second step is http connection yeah url connection equal to null now and going at this moment to the you a try here url equal new url and i will pass the json url that we have created in the first step and let's create a url connection or initialize the url connection and equal to http http url connection url dot open connection and you see the red the line alt plus enter add the clutch close and it will be automatically resolved now the second step in getting the json the json data we get the input stream i n equal url connection dot get input stream and input stream reader equal input stream isr equal to new input input stream read okay and i will pass here the is the input stream that we have created now let's go in the third step and make an end data equal to isw isr dot read reading the input stream and then i will create a loop while loop for data does not equal to minus -1 if the data is not null or it's not empty current plus equal to car of data and data equal is r dot read and and here we go for the third step and the first step is turning the current as the results okay i remove the spaces here and i need to close the connections so finally i if the url connection does not equal to null go and close it url connection dot disconnect and here we go add catch close here and i will return the current okay let's create into the final method in this video the and override the method here sorry here it's called on post execute you see it in the previous videos so in this method that we have get it the string and we will pass it to the post execute the post execute will go and analyze this string and get the json object from it and then passes it to the adapter class uh sorry the module class and then adapter class and then this the adapter class will display them into the recycler view it's a very complicated method but i divide it into various steps to understand how everything works in a recycler view and the json parsing processor processing okay now i will remove this the super and our work will go through this i will increase the size of that font and try we start json object just i will remember you with a very important thing very very nice to understand how json works and how you look at the document and see where is the jsons where are the arrays where are the objects and nested objects so guys see how i think this is an object this is a json object called movies this is a first object i create json object json object this is the root and equal new json object and i will get from the string s because i'm getting this remember guys do in background it will return a string called current this current is passed the string s and then the jason will return json object will get the string as and for and start analyzing it i will add here the catch close in order not to have any error and i will start by getting the array so the json object here is called movies and i will start by this array so the next step from the object is going through this array what is this array called movies jason array this jason array so as i told you guys i need to understand how json works this is the object of string and this is the string that we have uh parsed and the array is called movies so the movies is the array name now json array equal new js sorry equal to equal to json object dot get json array this is getting the array and cold move is okay it's very important as i told you guys in the previous videos to get the exact name of the string or the json string now getting the objects since this is an array inside the arrays we see the objects json objects similar to others so similar to each other's one two and three so inside this object still have uh any nested objects no so this is the last thing that we need to configure is getting the objects uh through a loop i less than jason array dot length okay and i will create here json object since it is the last json objects that we are creating and getting json object or sorry the json array dot get json object and i and movie model class model equal new more movie model class and inside this mode in movie model class i will go through and put these objects that that we have created through the model class into the list that we have created for that i need to do these steps model dot set id json object 1 dot get string and what is the string that we have used is the id copy and paste the same way model dot set name json object name and model of set image json object one string as image okay and last thing i need to make is movie list dot add more model okay okay guys so this is removing the spaces this is the our uh on post execute method the final method our final thing that we are going to to make is putting the data into recyclerview i will make a small method called put data into recyclerview okay i will pass list model and gold movie list this is movie model class and i will create it i will create it here private void private void put data into recycler view taking the parameter list and movie model class movie list sorry i'm making here a big big error so adaptory adaptory adaptory equal new adaptory this passing the context and movie list recycler view and the last line is the set adapt adapter and here we go we have finished making our amazing application let's see guys if there is any error i think no we have added now yes uh i need to add here the in the manifest the user permission and internet permission this is very simple so are you excited guys to run the application yes we are so uh i need your help say is seeing our one billion dollar application and here we go guys and this is a very amazing thing that we have created this is the name the id and the image for the movie let's uh make some [Music] some amendments on the texts this is the text okay okay let's see and here we go it's very very good guys i remove this and i hope you benefit from this video guys i need your support in i need your support in rating us five stars on udemy and subscribing to our youtube channel master coding and uh downloading our master coding application this is our application master coding so you can get all texts and all written lessons and all thing for free on play store so go and rate us five stars and i hope you benefit from this video thanks guys see you next videos you
Info
Channel: Master Coding
Views: 16,084
Rating: 4.8456593 out of 5
Keywords: parse json in android, retreive json response in android, android tutorial jsonobject, jsonobject android tutorial, json android java, android complete course, learn android programming, learn android application development, android application development course, how to parse json in android, android studio, json, Parsing JSON from Assets into RecyclerView, parsing json ito recyclerview, how to parse json, parsing json into recyclerview, Parsing JSON from url into RecyclerView
Id: 3uAqwnxZMwI
Channel Id: undefined
Length: 38min 33sec (2313 seconds)
Published: Tue Oct 06 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.