Android Learning - ROOM Database, SQLite Database, Camera, Saving Picture in Database

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we are going to take the empty we are going to start a new project we will see that how we can work with the room database and how we can use our camera to take a picture and how we can save that particular picture inside of a database and retrieving it back with the other data okay so that what we want to in do this for this demonstration so we start with that demo empty screen next and then we give that particular what name we should be giving database with image and to date fine I want to use that one in my projects and then I have okay I just try to keep that one copy it and then I called my location where I want to save it here I don't want it here projects inside I have the opie inside I have this this is the and let me see if I can put it this one here and at the end we are going to put that particular database with the kibbutz date image end date and then I click on the finish one so it is creating that particular project for us first of all what we need to do remember we need to create the architecture or the structure of that or database so when we are need that particular okay walk inside our java code library or the folder I am creating a new package okay so we see that data model and just to be separated from the other part of the data okay so I say that data model I want to create a new Java class so we can say that this is our user class simple user class and inside that particular user class we can have the int s ID or UID the user ID we can have our string full name we also have string username and then we also have string password and then we can also have our date okay we need to have that particular page which gauge the value to know Java and then we can set it to several date of birth and then we can have that particular byte array and that will be ever in it okay so we have all those matters what you can set your objects so if I just say control end it will be a control and for you for me so this like command and so when I say command and we it is asking us to you wanted to meet a constructor you wanna generate a getter so as you know that for the entity we need to provide those getter and setter so we can say that we have the Gator select all those fields and click OK it will automatically create those methods for us P and then again I say that I want to have the setters against at all those things press ENTER so we are have all our setters and get in that fits over there one more thing if you I don't have an entity here the reason is that we have not imported our room architecture here so let me import that fun I'm just trying to use from the other project and copy pasting here okay so what we need to do we need to go into the cradle field this is our application Gradle and inside these dependencies we need to add that particular dependency of our room architecture so what we are saying that we have the room architecture 1.1 this is a version number and here we have this one implementation and then this is the annotation processor how we are going to process those annotations which are being given inside our entity classes so once we have synced I mean if you look at that particular specific say that entity I don't know but here when we are sinking it will say that you need to import that for current or maybe I can just write look now I have that for the current we can i press enter automatically it has imported that particular specific entity annotation for me and it is there now and then again you can say that table name users this will be our primary key there today about primary key and then we can say that auto-generate and we stay there see here we can say that every net of column info and we have name and we can name like we can suggest name only okay and then here we are to say that column info and then we can have a name and then we can say that user underscore or username let me use that underscore as well okay and then password keep it like that I don't want to change that specific password field name date of birth keep it like that image keep it like there's no problem the other thing that I need to mention here is that particular specific that I need to create that for tell this particular specific below that will be binary data so again added a top column info and then we are saying that type affinity and then we say that column info dot below understand we are just telling this particular specific that what will be the type we are saying that be the sorry this should not be coming here that should be coming there because bytes so that will become a be log type of the field inside our database is it clear so we are just telling that particular specification at than that we are all set entity is done is it fine so we have ah this is originated but we don't need even that provide input from the user only needs the user name username password date of birth and date of birth again that's a tricky part that we need to see and then we have that particular image okay any questions or not so we have to read our entity let me now we need to create our data access object I say that I want to be the class I want to make it a I say that it's a user da oh it's an interface fine and then here in that particular interface I just say that add the date of D a oh so now that particular interface has been another dignity data access object here I say that I want to add the date of fury select static from what is the name users and then of course we need to provide it will return me a list of user and you get all users and then we can provide a sellable ok look at that similarly if we want to insert a student insert someone someone we can say that it does not return me anything insert user and then we can say that we will provide a user object as an input and we will annotate that one as a insert again we want to update user and then we can say that we will provide a user user object and we will say that we want to update similarly if we want to delete it does not return me anything delete user again we are providing the user as an input and we annotate it with T so we have insert we have update we have to be we have getting the data is it clear any questions still no we have to deliver Dao that's it we can make it that complex whatever we want to do but this is a simple thing that's how you want to come back what when you say here primary key then this particular specific thing must be provided other than that we have not mentioned anything so maybe we can provide that particular specific features here or you can during the implementation of your project you can say that if the image is not there sorry we can't really user data no object or we can't insert it out of this we can put source you know if conditions check into all those conditions no not by the code when you say add negative primary it's a primary key that's a unique and not luck but for the other you have not mention anything if we want to specify then you have to specify okay so you have to you look you can go into that particular annotation system of the entity when we are defining and go on to document it and see how you can perform that particular that's your form sounds like field and you go and see it will do not that's difficult you can just specific what you can say that inside this column just like I say type infinity is equal to column dot block it means this particular data is going to be saved inside the block type of the field similarly you can have some time column info and you say that null or not now you just need to set that particular specific setting for that particular column it means if you say not null it means the user must provide that particular specific value if the user does not provide that value it will not be allowed to be inserted inside it otherwise okay so you can do that but that's you lose yourself oh is it fine to long bao entity Dao and the third step is we are going to create that particular database but before that we do let's go and see if we can see I mean we can have that particular specific we can take that picture and show it on the screen and what is the format that is going to going to come in so let me change that particular specific layout to the simple one we have already talked about those constraints a lot so let me convert it with linear one remove that particular specific behavior and the other thing is I want to put a gravity here that is Center and then I put my button here I say wrap content wrap or not match parent wrap content and then I say text and then I say take a picture okay so take picture and then I say that I want on click even I want to go that big picture method and you know that what we need to do is with that image view 250 DP and then again 250 DP and what else okay I also need to make that orientation vertical orientation vertical so now we have sent to find I need to because I want to change the image here so I need to provide the ID so that we can access it inside our database inside of the java code so what we can say that image or user image user image then we can have to add a text we can say that much parent and the exact content I want to put our margin of the five DP around it okay and I'm just trying to use that particular copy this one and int to give full name and we also need to access it so I will provide the ID here as a full name we have our dictionary here that will point out my English spelling errors so I have that particular second is the username okay so here I can give the hint and then I say that the username and then I again provide the ID to this one and I say that that ID we also have that password huh user password and then we also need to give the paint here [Music] password and then one more thing remember that input type it should be number or text button next password okay so I mean it will show me static instead of that particular specific thing okay okay everything is we have full-name username we have the we need a date of birth so we have added text again I say no we have proper testing so let me P we have the ID and then we can say that use a date of birth and then I give that int and I say that mm / DD / YY life so you have to provide that particular specific but in the specific form that you need to provide that particular specific date okay okay and we have that particular specific very server so we have save and show thee so we have two buttons more so we have button as a wrap content wrap content and then say text and then I say that what you can tell save it no and then we have button wrap content wrap content and then we can say that text we want to show the Beavers okay so that will start another activity that we will talk about later and then we also have the on click on click we are going to say save the user and then we also have that particular specific on click even that will be two users okay so let me create those methods inside and then I think that let me remove this one first and we'll just try to go and implement that part I'll enter create the spa trip again go back inside this one and then I call them to create this method and then other thing is that all denture and you get this bucket but first of all we are going to implement that particular take picture this first method the first standard steps so what is that first what we need to do how we can start that camera remember or not remember what type of intent we are going to use it here explicit intent then you know the camera application package name and everything class name was okay inside your own Android phone do you know that no we don't know that so how we can start into explicit one implicit we are asking the Android system that we want to start use the camera which is available inside our Android phone and we want to take a picture and what we are expecting we will start activity or startactivityforresult start activity if we are starting the activity camera take the picture we don't want to get it back inside our application we want so if we want then we have to start that particular specific intent start activity for results so the member that for start activity for results yes we can create an intent like intent intent is equal to what you can say that it's a new intent and then we are providing the media store dot take okay action M image image capture yep this one so we have created that particular specific and the member that if we want to start that particular if you want to check that if we can resolve this one so we can say that in intent dot resolve activity and then get back his manager if it is not null then we are going to start start activity for where is that right pivot II start activity for result look we need to provide that particular specific request code yes or no so that we can read to receive the results back into our this activity so we say that you can that's fine but we need to provide that particular specific what we can do public or maybe I can just simply say final int and then we can give the Canberra under scold in int int and I give some name what 51 and then here I say that camera in turn we will start my camera but he's already there inside of a mobile and then it will take that pixel and it will return it back when it return it back we need to receive it back and for that what we need to do what we need to do which specific how we can receive that result back on activity result method we need to implement we need to override that particular method inside our activity on activity result and remember that it has a request code which should be exactly that what we are coming here we have result code and then we have the intent data okay so we are making a switch on what request code and then we see that case Canberra intent break and that's where we are going to handle we are checking that if result code is double equal to in 10 dot not this one so we we can check that particular activity dot result okay okay if that is our board is okay then we are going to perform something on it because if this is not okay it means that there is something wrong with that particular specific action and we have no to see back over data I understand so we have that particular data inside our this one this data okay intent object we need to get that into the what we can say that from this particular data we want to get that particular information that is actually our data itself so I say that like one more thing before I can do that the reason is that remember we have the image view image view and then we also have that particular specific we need to create that particular specific bitmap image MV MP image okay so we need to initialize that particular image view here image view is equal to find by view ID art or ID dot user not let me see what is that ID that we have given here we have that image view it says user image okay so dot user image that's fine and when we also say that BMP image is equal to MA okay so here we need to get that particular data so we say that BMP image is equal to data dot get bundle extra go get extras not get taught get extras and from there we are getting yet and we are providing that particular key and that is our data small the other thing is we need to convert that particular into the VM bitmap so from that particular intent which is contain some extra data we have say that our requests code is exactly the same when we started over camera and the dessert code is okay then we are from that particular intent which can thing in that image itself we are saying that data don't get extras from the extra item it is available inside the intent we are getting that particular specific data at dat via data and that a data is actually representing the image and we are converting that particular into the bitmap is it fine and then what we can see what we can do if BMP image is not equal to null it means there is something inside the BMP is not a default value that is null then we are saying that our image view dot set image bitmap not the image resource because now it is not coming from the resource it is coming from a bitmap so image bitmap and then we get BMP image is it clear or not clear we are calling the camera with a camera intent request code so that we can receive the image that is taken by the camera into our program we have created the BMP bitmap image object we are getting the data they provided that the request code is exactly the same of our camera intent and then the dessert code is okay then we are reading the data from over that I intend that is coming from our camera into our application and converting that into the bitmap and then we are putting that bitmap into our image is it clear run it was her finger one more thing we need to provide something inside of our manifest file so what is that one so we have this user use feature then we have named Android dot hardware dot camera - I think that's another thing let me see so we also have we can also make that it should be are like required so it means if we want to install that particular application inside the Android system then it must have the camera facility to install that particular application understand but we are saying that that particular feature should be there otherwise our application is not going to install on that particular specific so let me run that one and see if it is where is my cursor here so still gradall running building running and everything it is the old one it is you are you can see right now installing the epic am launching the activity and we have this one when I say take picture it is there your brilliant teacher you know and I will just take a picture maybe we can I just we can make it up huh do you agree okay thank you very much for being active in here I just change that one so now it's that imaginary image view I take a picture okay and then I save it when I save it oh my okay we are saying that set with image bitmap am i doing the right method or but yeah sad bit bit matte lip okay okay let me see else I just try to you know make toast and if toast you got make those this and then we can have the message result note okay and then we have two dot short and dot so and similarly in the else part I also try to what you can say that toast dot make best this and then I say that the bit map is up and then I say that I want to toast dot short and or so so let me see and it show me some messages here because this maybe does not work executing this particular line for us so we can take a picture we go here we and then we say okay result not okay Wow what's happened activity the result note ok ok so let me let me do this thing and let me make it for mint huh this particular part I want to make a comment I don't want to check the desert ok or not of it and just want to show this thing and then it is let me see if it is working or not we need to see that what is that particularly so it is take a picture it is taking a picture yeah so we need to see that what kind of result it is going to return ok so we have to look into documentation of that camera what is going to be returned back maybe we can pass it but keep it like that one don't check normally we should be checking this thing ok it is giving me the desert result code should be the okay maybe I'm using the this one activity good result on the spool ok is not right one so let me see what is that fitting the problem is but image is coming up here inside of our bitmap now we can the user can give the value username a more like password one two three four five six seven eight and then 59 okay and then I click on the save but right now we have not implemented the save part and the other thing is that's very important here right now the images in the bitmap not in the bite of the rain I'm all right so we need to convert that into the part or anything then we can say with inside our user object and then it can be saved inside the galleries so we need a data converter that is going to convert that particulars Pacific what you can see that that specific bitmap image into our string of array or the table array of bytes Donita data so let me first make that one where is my cursor here which is here yeah so I just say that I want to inside our data again I say that I want to croc have a class I say that it is a data converter and that's it okay so I have that particular specific data converter I want to put some method here public because we don't want to create the object of this class we just want to use that particular method we want to make that public static method public static what it will take it will give me a byte array as a answer and what we consider convert image to by away and then it will take a bitmap image now we need to determine something first of all I say have we have a byte array output stream and then we say that stream is equal to MU byte array output stream and then we have image bitmap image dot compress and then we need to provide that particular specific three things okay format in which we want to compress the quality and what will be the output stream okay what will be the output string so we are saying that bit map dot compress form it look compress form it dot PNG or JPEG whatever you want is use it and then we have the quality that I say is zero and then I say my stream and at the end or sorry we need to put a semicolon here and at the end we say if we want to return stream dot yet dot to bite away we have that out of string and we are converting into the pie plate and returning it on that particular market similarly remember that whenever we are reading data back inside of a user object that is coming from over database that image is stored inside the PI planet and we need to convert back into the victim just like we have done doing here just to save the information image inside the user object and getting the user object from the user object get that bitrate convert it into the bitmap and show it in the image view all right so we need hominin because we already directly matter why not we implement that matters has ever again public now it will it will be a static it will give me a bed map as an output and convert byte array to bitmap or maybe I think we are using the image so we are trying to do the same thing and here we are going to give the byte not not the capital V this should be a byte array and we say that okay and then here what we need to do we are going to return bit map factory dot decode byte array we are decoding that particular byte array and then we are providing array itself that is the and what is the offset and then what is the length so we can say that array dot length so it is a bitmap factory which has a specific method which can decode the byte array and convert that acuity bitmap and send it back is it clear so we have those static method which we can use anywhere in other methods so now we come to our save user then you click on that particular person then we need to see if that particular first of all we need to create deputies user object okay so we can say that user user is equal to new user fine that's a default behavior before math constructor will be called over there now we want to see if the user has given some input or values or not if the user has not given input value we are not going to save the information inside it so first of all we can check before we can check we need to provide those added methods okay so every text name you name that's a user name then we have pass and then we have DOB okay so we need to initialize those objects here so we can say that name is equal to find by view ID r dot ID dot user name and then we can say that you name is equal to find by find find by you ID card or ID door user what is that okay we have to name let me see we have the full name okay the first one is the full name and second one is activity user me okay then we have the pass so we can say that find by UI dr dot ID dot you use a password and then we can say that we have the OB is equal to you find by ID r dot ID dot use a bingo B and we have initialized those values now once we have initialized then we can check if user name dot get text dot to string is empty or now we are saying that if it is empty that the username has not been given or we can say that you name dot get text dot to string dot is empty and then we can say that or fast dot get X dot to string dot is empty or what data but dot get X dot to string dot is empty if anything is empty or we can also check or the BMP image where is that our BMP image yeah BMP image is double equal to now maybe I can just put it over there or I can just try to put that okay if this is the case then what we need to do because either one of the information is missing that we want to put inside together if we say overall or any one is true it means it is there's something missing and then we can simply say that toast dot make text and then we shape this user data is missing and then we can say that toast or lecture and then thought in the else pas de else part we are going to add that if we have checked it if the sum some information is missing then we will ask the user that we will give the we were not going to do he create that particular user even we can have that we don't need to create that particular user here first we check if the user all the informations are there we are creating the user and then we say that user dot set full name and then what we can get we can say that we have that particular full name here where is my cursor go sorry not and if you're using an all of them should be true then we will go here it means if some information is missing we will come here in that as far if any one of them is true we will go here if one make out of it you are saying if we put an over there if all the informations are missing then it will go to the else part all the informations are missing then it will go to the else part but this is not what you want well you won't say that anyone is missing we will not go into the S part we will remain in the if condition and show that particular tones message to the user okay or and then all of them or on only one of them so if one of them you see we are going to the if condition note yes but if all of them are false then we will go into the else part and that is it means everything is there so set user user dot set user name okay and then we say that you you name dot you get text dot to the string and then we say that user dot set what we can say that set set that particular user name full name password set password path dot to get string dot to the string and then what else we have named you name done passed on D open data but we need to do some conversion the reason is that it is not going to be save over there so user dot set image again we need that particular so we are calling that particular data converter dot convert image to D by tray and then we are going to give the BMP as an input okay what's the problem here where is that problem it's say that into byte in the user cannot be applied what we have done here okay yeah it should be by not the capital nor the class so we are going to fix that our entity class here there must be second one where you okay so now if you look at that it's fine it should be convert that particular PNP in to be bytearray and set that image over there and then the last part is we need to set our date of birth set DOB okay again that's a date that we are expecting okay so where is my I just I'm just going to copy paste you know set date of birth I'm just copy pasting instead of I just doing that it's a simple date format okay so we are saying the simple date format DD mm YY and then dot parse I put a capital mm and then we have the user Dao P so it's not as user D yogi it is a b or b dot get x dot new strength okay it's saying that this particular parsing can result in the past exception so how we can going to handle it okay so let me I will say that surround with try and cat law so this particular specific statement go into the try catch block and if there is some exception occurs it will go into that particular specific cash flow otherwise it will just simply convert that particular specific string into the date and set that particular so we have said the cool name username password image and the date of birth anything else that we are missing here so we have that we don't need to provide the ID because it are auto-generated we have the username we have we have names we have username we have the password we have the date of birth we have the Infinity and the other thing that is very important here before we can move forward is the date if we look into our date here that's a date object date class inside the Java libraries that's coming from the Java dot util dot library okay but inside of our SQL that is actually stored as a norm teacher already long very not as a date object so again we need to do some conversion we have not created about database class let's remember that let me do it database first and then I will show you that what is the problem here so we go into that one now we want to create our database class so I say that it's a class so we say that user database okay and I say okay and it should be an abstract class okay and the other thing is it should be like add the native database and here we have some and these entities will be user dot plus fine what is the version number of course we say that it is one and then we have export schema is equal to false I mean it's say that you want to explore that particular schema that you have fitted here inside the entities I want to make it fall because there is if we're make it true then it gives me some LMS is that we can't resolve it right now so I try to make it simple false okay and then inside of this we are saying that we have a private static method Jews are so sorry we are saying that B's and that will be a sorry user database not the user in database the exact look actually I am creating a static object of the same class inside this method and then we are saying that our user PB is equal to now by default inside the values now and then we are saying that we have a public abstract method which is going to give me a we have the user da oh okay and it will return it's in a public method we are describing abstract method and we say that the user Dao it's an abstract method with the name user Dao it does notice take any input but it will return me the da of Dao object that we have here it will return me that object because all those methods have been defined inside this path object and then we used that particular object dot get all dot insert user dot update user dot delete user we are going to that particular user da object to call these methods understand and then of course we need to create that particular specific we say that pub public static synchronized I will explain you what is a synchronized mean and it will give me back a user database and we can say get DB instance the instance of that particular database it will create that database for us and it will take the context as an input so in this particular method we are going to create it first we set check if the user DB is double equal to null then we are going to do that otherwise we are not going to do that I mean create that particular database again if someone has already created some other application has already created it it will just return that particular user DB object back to the if it is not it is the first time that this particular specific method is being called then we are going to call the created what is that user DB is equal to remember that we that room dot database builder in-memory database builder so we are going to use the database filter and from the database builder we are say that context dot okay not the capital small context don't get application context so that is the context of your database then we say we have our user database dot class that is exactly the same class that in which we are writing that particular course and then we give the name what name user nineteen block to okay so that is the name of that particular database that will be created and then here we are saying allow main thread Curie's dot bill okay so what's the problem here the room doors database builder they say that user database for type T is not within the bounds shell extent okay we have not extended room database here that was the reason it say that I'm going to turning at doom database but this is not the type of loomed another so that's why it's not a child of the fund for that motivation so this is where I am saying that allow me to run those da o dot get all dot I'm sorry user user those methods which are the database actions inside my main activity without creating but thread and so on that is what I am trying to do here and then at the end we are saying that with these options allow me to run the theories on the main activity or the activity class and then we are building that particular and definitely after that we are going to return the user to DB so that is our database class if I try to run this particular program it will give me an error message when we are going to submit because this date object and if I just try to make that particular date object not there and then I also just try to go back into my database is fine in the main activity okay so that method is there okay I just also try to keep it like this because now this there does not exist any so here I just try to make that particular comments it will be fine I will show you some specific issues like when we changing the architecture of that unit that this particular one then how we can solve that kind of stuff without the date okay we have set images and everything inside of our main activity now we also need to save it once we want to save it what we need we need that Dao object and then we say that dot insert user first of all we need to create that one so what we can do we can say that user Dao user Dao and then we can say that user Dao is equal to what the user database dot get DB in text and then we provide to this and dot the abstract method inside it which is going to return me that particular Dao object so what we are doing because this is an abstract class user database we can't create its object and we have created a static public method inside get DB instance so we are using the only the name of that class following this DB instance method it will create that particular database and database object and from that database object we are trying to access that abstract method which we have defined which is going to return me a user behavior object so we are calling that particular module and we are saving that information here now we have that user Dao here once we have set all the users informations then we can simply say that user deep user the Oh dot insert and then we can give our user of text to it this is look we create a user we set the name username password we convert that particular image of bitmap image into the like this one and then we are saving that it is it we have not shown anything let me let me see that okay so we are saying that it is not returning anything so we can't test anything over there those dot make text this and then we can say that insertion successful and then we can say that 2 dot short got show okay we are just trying to make sure that we are getting some message over there take a picture okay where is my cursor here I said okay it's on here a boss Malik give the name a monic passport one two three four five six seven eight and I say that protein fine and then I yeah okay I want too many times I have clicked on that so let me once again be patient take a picture where's my clothes fit it's here just coming here Molly like whatever it is 14 then 1959 and then I want to access my save button look inside successfully now the point is how we can check that it is successfully inserted for that I just go through with that particular specific reading a new activity and putting all those things together so let me do it quickly because we are going to use that particular specific recyclerview activity empty activity I say that so users activity finish it and we have the most activity I will just keep it like that will natural activity again I don't want that for the specific constraint me out I want a linear layout I want our orientation vertical and then I say that the gravity I will say that what is on the center and then what I need here okay I'm not going to use that but anyway this is not what you want the reason is that what we I got it I got it design you I want a recycler view okay and it is already done fine I go into that one and instead of having that particular specific orientation and this central activity I will just go there and say that I want a recycler view okay this is a recycler view and I also provide an ID this one ID user 3 cycler view okay and you know that because we are going to recyclerview we need a specific layout to showed one item so I will create a layout resource 5 user user under school item underscore layer okay the main layout will constrain it at the point I don't know and remember that we are judging to guard you so we are going to serve that one how do you let me do it quickly I have it here so I will just try to create that particular Troyer belly layouts quickly and instead of like having it completely from there I am just point trying to linear layout and I just go there and inside this one I am going to paste it okay and of course I am going to change that particular to 1 to D card view and I'm going to change some properties here what are those properties I would say that these are the properties here okay so glance these all enter here the definition is let me I am missing that particular specific name space here let me do that and that so I can see it I'm just putting that particular main space okay so now everything is set so we have that particular we have tato but we don't have the data but right now okay so what we need to do here so we have name and then we have okay I will keep it like that data but later on I will show the data but why we are not showing everything yeah this one your name date of birth and the image not all the information inside it okay so we have those that set a layout here that is there fine and we just close it down and this is the main activity so activity fine that I can work many tests by we don't need user file we may require database okay that's fine and then we need to come have that particular recycler so we can say that user recycler and then we say that recycler view [Music] no it's an adopter yeah recycler view a doctor so that is what we want to do I said okay we have certain method that we need to implement before that we need to add that particular Sabich viewholder class so again i go and add that particular user view holder and that should be a view holder we have this one we hold up that will be subclass of this one and I say press ok and here it is saying that you need to implement that particular periodical structure matching disappear here and remember that we have inside our the sauce layer 5 we have the card image we have the card name and we have the card DoD okay so there is my boss so I need to create that image view because we need to change the value at the inside so we say that image view and then we say that we have the text view and then we have name we have b.o.b I just keep it like that of course we are not going to show the digital work over there and then we can say that we have the name is equal to item view dot find by do i dr dot ID dot card name and then we have B of B is equal to item view dot find by view ID r dot ID dot card that's a bo P and then we have the image view is equal to item dot find by view ID r dot ID dot card image very the card Cardinals okay so we have we set all those values we have not implemented any click even here you know that how we can do that so we have card name card the other birth card image and that is all done in the view holder and here we can say that we want to do with that particular user view holder and then we need to implement those methods implement those methods yes we want it limit all of them and you know that for that first of all I say that we want to have a list of user we have this data okay and then we are going to create that particular use a recycle view public constructor that will take the list user that will be users and then here I'm going to create that one what is that we are going to feed data is equal to users and then here instead of returning the 0 we are saying that data dot size it will give me the size of that particular list that is there and then here we are going to return what we are going to determine you say that we want to get a view and view is equal to MU is equal to let me where is that one so we have the layout inflator dot from and then we can say that you group dot get context dot inflate we want to inflate and then we had our dot layout dot user item underscore layout and then we can say that the new group that will be the owner and then we have Falls and then we can finish this thing and then we can say that we want to create a new user view holder and we will pass that particular you as an input to this one so if you need that particular specific you holder for us I mean again that when you managed by the recycler view itself and then at the end what we are doing whenever we are want to bind the data we need to do that so what we need so we say user user is equal to data dot yet and we are saying that in I so actually it's a list of users add a specific index value we are getting that in our user object and then we are trying to we have the user view holder dot we have the image okay and we are sir image view dot set bitmap but again it's side inside that user if we have byte array we need to convert it back so we have a data convertor becoming complex huh data converter and then we want to convert the byte array to the image so we are going to say user dot get image so we are providing that image to this material method that we can work back into the bitmap and that we are going to show in our image view fine and then we have user view holder dot name dot set text and then we have user dot get full name and then we have user we holder dot DOB dot set text and then we have user dot wherever whatever man you want to show it get username okay so it will display all those things over there that is all done fine now we are going to come very complex huh main activity so inside the main activity first of all we need to create that particular recycler view no not the main activity actually this is this will be inside our show this one here we are going to create that particular recycler view recycler view and in here we are saying that recycler view is equal to find by v yd r dot ID dot user recycler view and then we need to create that particular we use the user recycler user recycler is equal to new user recycler and then here we need to provide a list of user and that we are going to get from thee database how we can get from the database how we can get can I make this particular specific object that user da of the other public static no public static is not going to work reason is that we are is initializing it here so we can create this object inside of this one time okay and then we are I'm just going to you use a dao object again the same thing that we are done here it will of course it will not create this thing okay so now here we can say that user Dao dot get all users it will give me a list of users of fine so we are passing that list of user form of database whoever recycled you it will have that particulars and that's it then we can say that we have a recyclerview dot set layout manager new linear layout manager I think yeah this this will do the trick let me where is my other activity here show users yeah we are setting up the list way and then dot layout manager this and then we also need to set the adopter here I just want to make sure that recycler view dot set a doctor and that is our user recycler and then we can yep that's it run my application no no we need to show star that activity so we can say that intent intent is equal to new intent and we say this and then we have show user activity dot class and then this is an explicit one start activity and then we say that intent and then we are going to click on this application and then I will show you that what's the problem with paid and then we also need to provide some converter for the data object in the Java into the long object and that how we can set into our database class so that it can automatically do for us so if we show you that I have the information okay okay and then I say that full name is law to 2019 be two one nine whatever it is and then we have the date today is all set 17:04 2019 and i just need to click on it one time here and then i say save we have successfully saved it should show me two users over there okay we have must make some mistake it's actually there we have to - but it's like trying to cover the whole screen user item layout so actually if we look at that particular margins and everything so hide should not be the match parent it should be me wrap contents so if i just try to run that application again you will see that we record over there without any issue if we don't need to or just show there so you can see that we have HP report over there now what's the problem with that particular date if I just try to go into my user and I say that I don't want to make a comment and then of course I need to uncomment these farce as well it will give me an error message and the other thing is we we have not we have changed our schema when I have a change of a schema and I just try to run this application it will straight away go back I mean it will not even fit on this one from pilot and field output of the details so if I just click on that if I just configure so you can configure how to save the field you consider the type converter and so on so we need to have the type converter okay so what is the type inverter again I'm just going to copy paste because it is already a long demonstration so I just copy paste and I will explain you what is that one inside my type converter I'm putting all those things we've set type converters time converters we have to date we have been working title to the date converting to prom date and actually we are converting the long information which is inside the SQL database into the date and from the data object which is inside a java class of code into the long so that we have this one and the other thing is that we need to go and again we need to provide that particular specific and a patient with our database in number database class that 4d type in version it will go and check in to the d8 converted or class ok day 2 not a class that we have created so let me run it it will give you another error message show the users it is giving me an error which is going into that particular error field actually it is saying that something that you have changed your structure of your database and your schema has changed you need to go and change that particular specific version number where is my user database go and change that particular version number two and then when you see it do that and then you say that from the previous data which is already there you need to make what is a migration project migration thing that how we can migrate the previous data to the new one and so on so the simple solution is that it's a game not the ideal solution especially in the real field field real time so what we go that the name of the application is database with so I will just go there I just make sure that we are in the right yeah this is the right one so I just go there and I say that I want to delete uninstall that one one I uninstall it it will be fine um it is remove that everything so it is uninstall and then all which ones we done it with you install that what if you think a beam so now we can have that particular specific what you can say that and the other thing is inside of a main activity we need to uncheck this one as well we are putting that particular data inside the word so we have that particular database one more tone inside the word user recycler I will just show you that instead of getting the user name inside a b.o.b we are going to get get user VOB okay and of course we need to convert it back that's another thing that is where we have that particular sector so we need to dad a converter we have this one we have this particular specific master and we are going to get that particular user dog and ego-t string dot value or whatever that value of that data is it will show over there instead of life because that's a date object it's going to lit up but we need a string so we are converting that equal respect fine so let me move on that application to also our finger everything this was that application installation failed okay what's the problem spawn is starting what why is this bonus started so let's see if it is working perfectly fine installing the apk is running so we take a picture now there will be no dad of course okay what happened where is my okay guys yeah it is coming up bit slow now it is tired I suppose huh after this long so we can say that open hello it is not responding me very well okay may I see Oh PA I see and then we have 0 1 0 1 2019 and then we can say that we want to save it I just try to make another picture like thinking back okay date it's not responding I think the computer has also tired after this long recording and everything huh so let me ki scummy I take another picture okay and I say yes where is my okay yes yes I want to send it back I say okay okay it is coming here again I have the same information doesn't matter I will just says maybe I can just change it here okay Maalik just one thing and change this one to 17 so that you can see the difference of actually of them it would be I save it I just flipped it on here and show me look it is showing me those two because so now they turn version and everything is working perfectly fine so we have those conversions we have set that converter with our database okay and similarly whenever remember that if you are trying to save some Java objects inside the database and the inside database they are being saved in a different way then you need to provide that particular inverter so you can write those matters over there and tell the database this is my converter class then they can find that for this specific matter to convert the data from the Java object into the SQL night all data type or from SQLite data type to go back into the Java which would that will automatically managed by the convert database class and the comarca texture so that is our small demonstration now where is my okay where is my hey it is so I will just stop my video for the next time
Info
Channel: Android Mobile Development
Views: 6,451
Rating: 4.8165135 out of 5
Keywords:
Id: Sd5BaeEeUPs
Channel Id: undefined
Length: 92min 32sec (5552 seconds)
Published: Wed Apr 17 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.