To-Do App with Clean Architecture - Android Development | Kotlin | Stevdza - San | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

To-Do App with Clean Architecture - Android Development | Kotlin

teacher avatar Stevdza - San, Android Developer & UX/UI Designer

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

55 Lessons (4h 22m)
    • 1. Introduction

      2:22
    • 2. All Dependencies for our Project

      1:31
    • 3. To-Do Application Preview

      1:58
    • 4. IMPORTANT NOTICE

      0:55
    • 5. Introducing with Navigation Component

      3:36
    • 6. Create Navigation Graph

      4:43
    • 7. Design ListFragment Layout

      5:27
    • 8. Design AddFragment Layout

      8:04
    • 9. Design UpdateFragment Layout

      4:56
    • 10. Create Menu for ListFragment

      4:07
    • 11. Create Menu for AddFragment

      2:14
    • 12. Create Menu for UpdateFragment

      2:10
    • 13. Introducing with Transition Animations

      3:17
    • 14. Implement Transition Animation between Fragments

      7:51
    • 15. Introducing with ROOM library

      2:37
    • 16. Create Priority - Model class

      1:42
    • 17. Create Entity (ToDoData) - Model class

      2:08
    • 18. Create Dao (ToDoDao)

      4:20
    • 19. Create Database (ToDoDatabase)

      6:01
    • 20. Create Type Converter (Converter)

      4:04
    • 21. Create Repository (ToDoRepository)

      3:22
    • 22. Create ViewModel (ToDoViewModel)

      3:29
    • 23. Insert Data to Database

      8:35
    • 24. DB Browser for SQLite

      4:14
    • 25. Create Shared ViewModel (SharedViewModel)

      2:04
    • 26. Apply Color to Spinner Enteries

      4:10
    • 27. Design Row Layout for RecyclerView

      6:57
    • 28. Create RecyclerView Adapter (ListAdapter)

      7:23
    • 29. Display Data in RecyclerView

      6:29
    • 30. Safe Args - Pass ToDoData object to UpdateFragment

      9:47
    • 31. Update Selected Item

      7:25
    • 32. Delete Single Item from Database

      7:03
    • 33. Delete Everything from Database

      4:30
    • 34. Show no_data Views if Database Empty

      6:16
    • 35. Introducing with Data Binding library

      6:40
    • 36. Data Binding for ListFragment

      10:05
    • 37. Data Binding for UpdateFragment

      6:45
    • 38. Data Binding for ListAdapter

      9:04
    • 39. Add ItemTouchHelper Callbacks

      4:32
    • 40. Undo - Restore Deleted Item

      3:53
    • 41. Implement DiffUtil

      7:51
    • 42. Add Animation to RecyclerView

      3:29
    • 43. Search the Database

      9:55
    • 44. Sort Data in RecyclerView

      5:29
    • 45. Apply Different Layout on RecyclerView

      2:27
    • 46. Final word

      1:30
    • 47. #1 Staggered Grid Layout | Undo function App crash - Fixed

      3:59
    • 48. #2 Title overlap with Priority indicator - Fixed

      3:10
    • 49. #3 Software keyboard issues - Fixed

      5:18
    • 50. #4 Backstack issue - Fixed

      2:32
    • 51. verifyDataFromUser - Cleanup

      1:56
    • 52. Migrate from kotlin-android-extensions plugin

      5:53
    • 53. #5 Search/Undo Bug - Fixed

      6:30
    • 54. Code Cleanup, Dependency Update + RecyclerView Animation

      5:28
    • 55. FragmentContainerView

      2:20
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

450

Students

--

Projects

About This Class

So this course will be a little different from my previous ones, because in this course we are going to build a fully functional To-Do application. We are going to build our app using Kotlin programming language, and you'll see all the benefits and power of concise way of programming with Kotlin. Our To-Do app will combine different android architecture components like Navigation Component, ROOM database, LiveData, ViewModel, Data Binding and more...

You will learn how to follow the principle of single activity and multiple fragments in your app. You will learn how to use Navigation Component in your app, how to work with Safe Args to pass data between fragments, and also create custom made Transition Animations for your destinations.

So why is a To-Do app important, well first and foremost because it teaches you how to build and maintain a database, how to write SQL queries to insert, update, delete data from database, but also how to write custom queries to search through Database, Sort your database by certain criteria and display it in proper way to your RecyclerView.

Also we are going to have a clean architecture in our project, you will learn how to organize your project structure and maintain good code readability.

At the later section of this course I'm going to teach you how to implement data binding to your app, and you'll see all the benefits of using it, because we are going to have less boilerplate codes in our app, plus everything will be separated, and our fragments will look a lot cleaner and simple. You will also be introduced with custom BindingAdapters.

At the end of this course we will implement swipe to delete function to our RecyclerView, also I'll show you how to easily change RecyclerViewlayout, apply a different look to your app with Grid and Staggered Grid layout as well. And when we are talking about RecyclerView, I should also mention that we will implement DiffUtil in our app and that way, increase overall app performance.

Also I need to mention that this course is NOT  for ABSOLUTE beginners in android development. Because this course assumes that you already have a basic knowledge of programming in Kotlin, and a basic knowledge of android architecture components.

But if you wish to continue improving your skills and building your knowledge furthermore then this course is definitely the right option for you.

Project Files: https://github.com/stevdza-san/To-Do-App-Kotlin

Meet Your Teacher

Teacher Profile Image

Stevdza - San

Android Developer & UX/UI Designer

Teacher

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction: hello there and welcome to my course. So this course will be a little different from my previous ones because in these course we're going toe build a fully functional toto application were going toe build our app using a chortling programming language, and that you will see all the benefits and the power off coincides way off programming with Courtney. Our toto app will combine a different enjoyed architectural components like navigation component, the room database live eight view model data binding and more. You will learn how to follow the principle off a single activity and the multiple fragments in your app. You will learn how to use the navigation component in your AP photo work with a safe, are stalked past later between fragments and also create a custom made transition animations for your destinations. So why is to app important? Well, first and foremost because it teaches you how to build and maintain a database how to write the SQL queries to insert of the daily data from databases, but also helped to write the custom queries to search through a database, sort your database by a certain criteria, and that this plate in a proper way tore your a cycle of you. Also, we're going to have a clean architecture in our product and you will learn how to organize your project structure and the main thing and good code readability at the later section of this course. I'm going to teach you how to implement the data binding to your app and that you will see all the benefits off using it because we're going to have a less boilerplate codes in our app plus, everything will be separated and our fragments will look a lot cleaner and simple. You will also be introduced with custom binding adapters. At the end of this course, we will implement a swipe to the right function to our a cycle of you. Also, I'm going to show you how to easily change recycler, relay out, apply a different look to your app with a grid and stage would greatly out as well. And when we are talking about the recycler view, I should also mention that we will implement a day futile in our app and that way increase overall app performance. Also, I need to mention that this course is not for absolute beginners in Android development because this course assumes that you already have a basic knowledge of programming courting and the basic knowledge off android architecture components as well. But if you have to continue improving your skills and building your knowledge, furthermore, then this course is definitely the right option for you. 2. All Dependencies for our Project: Hello there and welcome back. So in this video, I just want to show you the greater bill files off our our projects. So ah, you need to check if you have type the right dependencies, repositories and plug ins So this product will be available for you to download from Get hub and you contracted by yourself. But this is just a preview off. What dependency we're going to. It was inside our property. So here you can see a safe arcs as well. And it's which the other great a bill file. And on the top you will see black beans for courting kept and navigation component safe ARDS down below. The minimum sdk version for our project will be 26 down below. Also, we can check this build futures that we have enabled the data binding. So this one is also important for using data binding and down below. We have also compile options and courting options. Toe version 1.8 in the At the bottom of this great orbital file, we have all our dependence is so First we have dependencies for our navigation component. Then for our room library, then for our life, second component and for a view model as well. Down below we have dependencies for quoting co routines. And here we also have a view model scope which were went to use in this course for the coffin Cortines and, of course, data binding dependencies and the third party library for ah, animating over a cycle of you. So again, thesis project will be available for you to download that from the get hub. So you contract this code by ourselves. But this was just a preview. 3. To-Do Application Preview: held there and the welcome back. So this is our application purview, and this is the final version which we're going to create inside the scores. And as you can see, I have already populated some of those data inside the database. And here also, we have an option toe searched through our database and displayed it. The result inside our a cycle of you surgery in cities, such option is working perfectly fine. And there is also an option for us to sort this list by a priority. So let's sort this by priority high. And as you can see, those items now are shown from the priority high to the priority low. And we can also select different sort function to see the first item so far, priority low. And this concede We can also see this beautiful recycle view animation as well. So when we select one of those items, we will get navigated to this Abbott fragment and from here we can update our ah, our data from our item and just click this button and, uh, the sighting will be automatically updated. So also there is an option for us to the late this item So just like this menu and select delete, you will get this a lot of dialogue. And where New press? Yes, you will get this success message. Now what do we click our voting? Actual button. We're going to see this ad fragment, and from here we can add a new data to our database. And here, let's just type some random text. And for the priority, we can also change priority accordingly. And just presidents check money button and it can see our data is a successfully added to our database. So all of that, they're working perfectly fine and our sort function function as well. So now let's try to delete everything from our database. So that's also possible. So so like this and delete or and when you press, yes, you will see that all items will disappear and we're going to see this is a message saying no data 4. IMPORTANT NOTICE: Hello there and welcome back. So why this video, I just want to make one important announcement. So at the time of creating the scores, I have used the Kotlin x synthetic to get a reference of all our views from a layout files and Kotlin x synthetic part of a cotton enjoyed extensions plug-in which is no longer available and now that the plugin is deprecated and instead of using a coffee next, synthetic together reference of all our views. Now we need to migrate to a view binding. And I have already made a video about that migration and that, that video is available under the Lecture number of 51. So be sure to check that lesson to see how to migrate from dead deprecated cotton next, synthetic to a new view binding. And that's all I wanted to share for this video. 5. Introducing with Navigation Component: Hello there and welcome back. So in this video, I want to introduce you with the navigation component which is a part off android architectural components. Those days when we had to write intense for navigating from one activity to another and get those a support fragment manager arrows that we faced the while dealing with the fragment Navigation and data exchange are over, and the android navigation component is here to take care off the in app navigation data, passing navigation drawer bottom, navigation of you and all other stuff about the navigation navigation refers toe interactions that allow users to navigate across in tow and back out from the different pieces off content within your app on navigation component helps you implement an allegation from a simple button. Clicks toe a more complex patterns, such as at bars and the navigation Drover, the navigation component consists off three key parts on the 1st 1 is a navigation graph and ah, it is basically an XML resource that contains all navigation related information in one centralized location. This includes fragments in most cases and they are called the destinations inside. Navigation graph in our APP navigation graph will contain a all fragment destinations. And inside those fragment element, tex, we're also going to add the action texts which will describe where a our destination can navigate in our app. And I'm also going to show you how toe was a safe arcs to pass the primitive types between destinations. But also hope s a custom objects as well. On the second main component, off navigation is a net host and it is basically an empty container that this place destinations from our navigation graph and the inside never host. We need to specify our navigation graph. The full never host implementation in the navigation component is a never host fragment which displays fragment destinations and the third main component off navigation is a never controller. It is basically an object that managers app navigation within and never host the net. Controller orchestrates in the swiping off destinations in the net. Host as a user, smooth throughout your application. Aziz, you never get through your app. You'll tell the Neve controller that you want to navigate either along a specific pet in your navigation graph or directly to a specific destination. The never controller then shows the appropriate destination in the Neve host and that you can easily integrate the navigation drawer, toe, a bar action bar or a bottom bar with the never controller. The navigation component provides a number off other benefits, including handling fragment ring sections, handling up in the back actions correctly by default, providing a standardized The resource is for transition animations implementing in candling deep linking outside the application. Like Webb, you are else, including navigation you I patterns such as the navigation drawers and the bottom navigation with minimal additional work safeguards. Gretel Plug in that provides type safety when navigating in passing data between the destinations and the view model support so you can scope of you model toe navigation, graft or share you why related data between the graph destinations. So why the next video? We're going to create the navigation graph and start implementing a navigation component in our act, so our APP will have only one activity and the multiple fragments this way. Having only one activity can have many benefits, especially on our application performance 6. Create Navigation Graph: Ah, hello there and welcome back. So with this video, we're actually starting to build our application. So our project only have one activity and the first let's never get to this a resource manager. And we want to create first navigation for our application. So here, press this red button and let's create a new navigation resource file. This file will represent the navigation graph. So here, select this green icon, which says a new destination. And as you can see, we only have a one activity and the throughout the scores, our application will have only one activity and multiple fragments. So we're going to create the three different fragments so clear this create new destination button. The first fragment will be named the list fragment. And this fragment will basically have a recycler view in which we're going to populate and read all the data from our database and that this list fragment will be a starting destination. Okay, so the next fragment will be at the fragment and in this fragment, we're going toe. Basically add our items to our database and let's great the third in the final fragment which will be named the update fragment and inside this right meant we're going toe basically update our current data. OK, so now that we have created those are fragments, we can arrange those fragments as we want. And let's connect those dots or arrows, which are called, actually actions. So let's connect those actions. So we want to be ableto navigate from list fragment to add fragment and from ed fragment to list pregnant. Okay, so that's how we have connected those arrows. So let's connect this list. Find meant with Abit fragment and update fragment with the least fragments. So from least fragment, we will be able to never get toe those two fragments as well. Okay, so now, as you can see, we have those three fragments here and we're going toe open up those those files. And here, as you can see, the there is a bunch off unnecessary code which is automatically generated. So we're going to remove basically everything from here. Just leave this own creative you function. Okay, so it's open up, this least framing now and here as well delete everything except this own creative you method. Okay. And let's close this one, and it's open up. This update fragment as well. So dilate everything from here. Okay. And now we have cleaned our fragments. Okay, so next we're going to organize our product structure. So let's create a new package. Name the fragments. And inside this package, we're going to create three more packages for each of those fragments. Okay, so the first fragment, the first package should be named the least. The next package could be named ad, and the 3rd 1 could be named the update. Okay, And now we're going to move our fragments inside each of those package. So let's drag and drop this ad fragment first. So, just like this, a re factor button. Next is a list fragment, the re factor and the abbot fragment as well. So just the dragon drop that. Okay. And now our project structure looks even better. Okay, so for this video, we have just wanted to create this navigation for our application. And now goto this activity main, and we want to remove this the fourth text for you, and we're going to find the never host fragment. So this never host fragments or select this navigation graph. Okay, so this Annette host fragment will hold our navigation graph, which contains our fragments. Okay, so inside our main activity layout, we're going to see our least fragment because our list fragment is a starting destination inside our navigation graph. OK, and there's concede this is our never host fragments. So as you can see, we can see this attributes the knave a graph and our Napa graph is linked to this never host fragment. And let's change the idea. Tonev host fragment. It kind of looks better. And that will be all for this current video. So we have created our navigation. Basically, we have added our navigation graph and the inside that graph we have specified three different fragments and our list appointment is started destination and in the next videos , we're goingto design each of those fragments. 7. Design ListFragment Layout: Ah, hello there and welcome back. So in the previous video, we have ah created the three different fragments for our navigation graph. OK, and that looks fine. So in this current video, we want toe design a layout for our least fragment. Okay, so let's open up the XML code and we're going to change this frame lee out constraint layout and we want to remove this the fourth text few. Okay, So as I mentioned in the previous video, we want to have a recycle review inside this fragment. So let's add it and let's connect vertical and horizontal constraints here with a parent. So let's add the i d for our cycle of you as well, because we're going to need that later in the scores. Okay. And the next what I want to do, I want to add a two icons. So it's like this vector ass it and the first icon will be for ah, no data, and I want to select this icon from my desktop. Okay, this is just the personal preference, okay? And this first image, as you can see, it is basically a vector file converted toe xml. So this image will be used in our list Fragment Well, when there are no any data and the second item or the second vector will be this plus icon and that this icon will be used for our floating extra button. So click next and finish. And now, as you can see, this is basically a vector file converted into XML and this is how it looks. Okay, so it's Ah, close that. And here we want to search for a floating extra button. So now, So, like this icon which we added and connect the right in the bottom constraint and the set those constraints to 24 ok, and now open XML so we can add the some absolute So for example, it's at first this focus able to true and let's open up this equaliser sex smell. So I want to paste all the colors which I want to use inside this project. So you can copy all those qualities if you want or you can use your own, that's on you. So let's close that for now. And I want to add the one, actually, but here, which will change the color off our plus vector icon. Okay, so just a distant like this color white. And as you can see, our A plus icon is changed. And that's exactly what we wanted. So next we want to add the image view, which, and now it's like this image which we added the first Let's connect all those constraints left, right, top and bottom. And, uh okay, so let's open up this XML file. And from here we can change the color directly. Okay, so let's see. Was this a light great, which I added the previously and then you can see our icon looks even better. So I'm going to increase this bias vertical bias toe 0.32 for example. But we might change that later. Okay, so now we want to add one text view, and this text will be below our image view and that this text, we will say no data. So this text you and image view will be shown here inside our list, pregnant only when there aren't any data inside our database. But we're going to create the logic for that later in the scores and not right now. So let's add the ideas for those toe views for image, you and text view. Okay. And let's train the text here. Toe. No data. Al, it's at this. Ah text. Two hours during sex email. Okay? And we want to add a text size attributes and let's say a 16 sp. OK, so I think we should change the opacity for this text view. So let's at the Alfa attribute to 0.5 and now our text view looks even better. So now we can run our application to see how this least fragment will look like. Okay. As you can see, we have this image you. But I think this imagery is too large. So I want to change the width and height of this interview toe 1 20 or maybe 100 DP. Okay, that's even better. And now let's run our application to see how will that look like? Okay, so that looks even better. And there is only one more thing I want to change and that is ah, vertical bias. So let's like this image view and let's set the vertical bias toe 0.37 for example, somewhere there, Okay. And I think that would be perfect. And it is eso here. I want to set the visibility toe invisible for those two views for image view and the text view. And as I mentioned earlier, I want to add the logic which will change the visibility for those two views, depending on whether there is a data in our database. But we want to do that thing some of the later videos. For now we have just designed our least fragment layout, and that's it for this video. 8. Design AddFragment Layout: Hello there and welcome back. So in the previous video, we have designed our least pregnant layout. So, as you can see, we have a recycler view floating extra button and the image view and the text of you, which will be shown only when there is no any data inside our database. But we're goingto, um, fix that later. So for now, a Zaken, see, when we open up our navigation graph in the XML file, we can see that we have a three fragments, and each of those fragments have one action except the least fragment which have to actions . One pointing to the ad fragment and the second pointing toe update fragment. Okay, now we're going to run our application to see how it looks like, and you will see that when we press this putting action. But nothing happens that because we haven't implemented on click listener for our floating extra buttons. So open up, least fragment in here. We're going to store this inflator inside its view object, and let's return this view. And in the middle, we're going to is this view to find the idea of floating action button and the add on click listener and inside we want toe use Nev controller to navigate toe Add fragment. Okay, so you can see we have used this I d action least fragment to add fragment. And that's the same I d off our action, which is pointing from the least fragment toe add fragment. So basically what? We run our application Now we will be able to navigate toe add fragment. So let's click our floating extra button and check it out. Okay. And as you can see eat, that works perfectly fine. So we have one more problem. So our action bar does not change. So we need to set up our extra bar with navigation controller. So use this method. The set up extra bar with never control and passed the Net controller and is in the parameter just past the i. D off. Our never coast fragment is concede That's the ivy off our never host fragment and the down below. We need to override one method named the own support. Navigate up in here, create an air controller object, and we're going to return and have controller daughter and never get up. Method. I don't never get up. OK and that's it. So let's run on application and you will see that our extra bar title will change depending on which fragment we have in our and have host fragments. So it's going to see our fight look has changed. And we can see the Baquero when we when we are a navigated inside the ad fragment. So if you want to change the title off your fragment, you just need to open this navigation graph and change the label actually boot. So for the least pregnant were going toe type A total east. And for our Ed fragment, we're going to say just at and for our update fragment just update. OK, so let's run our application to see if our extra bar title has changed and his concede it is. So when we never get to our ad fragment, we can see the new name and also this back arrow So everything works fine. And now that we have set up our extra bar with navigation controller, we need to start designing our ad fragment. Okay, so here we're going to change the route layout to constraint layout, of course. So let's remove this default text view and here we're going to add a petting toe 24 dp to our route way out. So next we need to add Ah, one simple at a text for now and the connect top constraint and left and right, of course, horizontally. Next we went to add the spinner. So search for a spinner and let's add it, billow our at a text and let's connect the top constrained to our every text and horizontal constraints to a parent. And the final is ah, multiplying text. Okay, so, uh, connect the this multi line text toe spinner and the horizontally with the parent and the bottom concerning toe apparent as well. Okay, so we need to. It was this motor line. Thanks because ah, in this small town in text, we will be able to type multiple lines. So let's set the layout width and height for this one toe match. The constraints or zero dp. And for our first edit text said the high to 60 and layout with 20 dp or natural strength And for the spinner height is exactly the same 60 dp and the layout with zero dp. Okay. And this is how it looks now, so we're going to modify our design for their more. And next we're going to set the top margin on our spinner toe, eight dp and the top margin toe Our second edit text toe eight dp as well. Okay. And they look so fine. So we're next. I'm going to remove this text attributes, and I'm going to add a hint. So this hint will say title. So click old plus enter toe extract this string resource file. Ah Stringer resource into our strengths XML file. And here you will see that this is automatically added for us. So that's fine. So we can close this now, Okay. And, uh, down below, we want to set the background to transparent. So we will do this. Android caller slash transparent, And we're going to remove this line which we had on our edit text. And we're going to do that the same for all our viewers here. So and here on our multi line a text were going toe added him toe description. So what? Plus enter toe? Add this text in our strings XML and the women to add the gravity toe top left. So our texter should start from the top left corner and we will add the petting petting Start toe 24 dp Okay, and petting a top to 16 dp. Okay. And this is how it will look like So Okay, so we need toe replace this left with the start and that's fine. And we need to wear this a petting end as well to 24 dp so we can remove this warning which we received from the Android studio. Okay, so that's fine. So let's copy those toe attributes and let's paste them inside our first at a text as well . Okay. And for our spear, we should create a race during Okay, So inside our storing, sexy Mel, let's create a stunning array named the Priorities. And we're going to have a only three priorities priority high, medium and low, and the user can choose which priority for the current item should be. Okay, So now let's use that this entries actually it and let's connect our student gray and now we will be able to see this. Okay, So we should also add the petting started petting end to our spinner. So let's space this code and it said that 20 dp and set off 24 because it will look even better. Okay, as can see, this is how our layout should look like. So let's run our application to see to see that. Okay? And there it is. So we have Ah, this title, this spinner And we can choose those priority lists. And we also have this description. So later in this course, we're going to create the logic to change the color of the spinner items. But for now, it will stay this way. Okay, And now we need to change the ideas. So for our first added text, want to set the idea toe title underscore e t. It is short for edit text. Our spinner, we have ah, the I D off priorities Spinner and our second edit text will have Ah, I d often descriptions underscore ET okay, and that's it. So we have created our layout for ad fragment and we have ah customized those ID's. And that's it for this video. In the next video, we're going to customize a layout for our update fragment 9. Design UpdateFragment Layout: Hello there. And welcome back. So in the previous video, we have designed our head fragment layout. So as you can see, we have to edit text and one spinner. So let's open up our application toe. Check it out once again. Okay, so it works fine. And in the previous video, we have also set up our extra bar with navigation controller. So now we need toe make a logic somehow to navigate from our list. Fragment toe update fragment. Okay. And to do that, we need to open up our least fragment. And I want to add the i d on our route constraint layout. And I'm going to use this idea to create their own click listener inside our least fragment . Okay, So, uh, I'm going to set the on click listener for this route layout. And whenever I press somewhere on the on this fragment, I will be able to navigate toe our Abdic fragment. Okay, so let's do this and have controller to navigate to our update fragment. And now let's run our application to see if that's going to work. Okay, So click somewhere on the screen and you will see that we have a navigated to our update fragment, and it works perfectly fine. Okay, so this is just a temporary solution. We're going to change that in the future. But for now, in order to see our update fragment in our application, we will implement that on quick. Listen, So next we will design our rabbit fragments. So let's copy those three views from our ad fragment, because our update fragment will have those reviews as well, so we can just copy them. And let's first change this road layout concerning layout. Remove this text new and based. Those three views it. Now just click both plus enter on this code so we can import this. Okay, that's fine. And all its at the different ideas for those views. So I'm going to add a current worthy in front off this I d. And we're to copy that in all of those. Okay, so not like that. So just at this title 80 Okay, So the current spinner and this current description on any text Okay, so we have changed those ideas and we can add the petting 12 Ruth L. A. Out as well. So I went with just one more thing to our update fragment. So I'm going to create a customer input customer background input. So here, let's name this new resource filed toe custom input and the root element is a selector. And here we're going to add the two items. So first item will have this state enable to true and the state focused True as well. Okay, so it's greatest AG and basically this first item, this first item style will be added to our input fields only when our input field is focused. Okay, so we're going to hear the shape off a rectangle with the solid color off white. Next, we went with a stroke stroke with could be maybe one dp okay. And the stroke color should be color primary, which is a purple color. So whenever our input field is focused, we went to see the border cholera off purple, OK. And let's also added, these are radios here. So let's said the corner corners element and let's add the radios toe five dp. OK, so we're going toe copy this first item, and we're goingto pace that down below. So let's select this all and the pace that here. So now in the second item. Just remove this state focused true. Remove that and change this stroke caller toe white or maybe light. Great. So this second item will be applied only when there is no focus on our input field and the first night and will be applied when there is focused on our input field. So now that we have created that we need to modify our background attribute on our I items so here, instead of this transparent, let's link our new custom input. OK, so we're going to apply this background toe all our views. But this won't work on our spinner because if you want to customize Spinner, you're going to do that the different way. But for those any text, it will work. So ah, let's run our application to see how will that work? So click here and let's focus. Okay, so when you click or tap on, each of those at the text on the style will change. Of course, on the spinner it won't work. But that's not important, okay? And that this is how our update fragment will look like eso. Death will be all for this video and in the next videos were going toe Ah, implement menu options to each of those fragments 10. Create Menu for ListFragment: Ah. Hello there. And welcome back. So in the previous videos, we have a design, our three fragments. So, as you can see, it's never get to this added pregnant, and it looks very nice. And it's never gave to our Abit fragment as well. So it looks nice as well. Okay, so now we need to create options. Many for those three fragments. And in this video, we're going to create the options menu for our least fragment. Okay, so, uh, we're going tohave. Ah, three or four different menus. We'll see. So now, open up a resource manager and open up a menu tab here, so create a new menu resource file. And let's name this file A list fragment menu. Okay, so as simple as that and flick. Okay, So, uh, first, we're going to start by adding menu for our search widget. So it's at the I d here toe manual search. Now it's said the title. First, just search and press old plus enter toe added this text toe string six ml. All right. And next, we need to add the icon for this search. Okay? So just select in the this search icon and Let's rename the search toe. I see search. Okay, that's fine. Click next and finish so below that that we need to add the icon. So ah, icon is like that and I continues to color white and we need to set their show as action toe if room. So our search a widget will be visible on our action bar. And you need to specify this action of you class and the android except compact, which it dot search for you. So basically, with this attribute, we're linking our A search for you widget and the down below. We need to create the group menu so this group will have a checkable behavior. It'll single and let's add this item with the idea off, soared by in the title should be soared by. Okay, let's at this string toast during Sex ml and inside this item we're going to have a menu, so this sort by menu will be apparent. Menu toe two different items, so the first item will be manual priority high. And let's just add the title here. We're not going to use icons. Okay, let's click old plus enter toe at this string. Two strings XML, and the second item will be, Ah, menu priority. Low end. Of course. Let's add a title here as well. Toe priority low. Okay, let's click or plus center. And at this, and as you can see, our sorted by manual is actually parent menu, which has, ah to child menu items and down below. In the end, we want to add the one more menu named Delete All. So we just said this show as action toe never because we are not going to show this pipeline in Action bar, and that's basically it. Okay, so now that we kept designed our menu, we need toe go to our list fragment because a Zaken see, we haven't linked our menu yet. So in the list fragment we need toe Ad said his options many to true. And let's just add this common here, and we need to override one method named their own create options menu, and in this method, we need to inflate our menu. So let's locate our manual least climate menu. Okay, in the second perimeter should be menu from the parameters. OK, and now let's around our application to see how will that look OK, so here we have our search widget. And when we click on that, we will be able to see this search widget on our action bar in the here Weaken type basically anything. So let's close that now and hear a Zaken. See, we have delete all and the sort by, as you can see when we press this sort by our new menu appears with those two child menu items. Okay, and the little bill for this video. In the next video, we're going to create a menu for our ad fragment. 11. Create Menu for AddFragment: Hello there and welcome back. So in the previous video, we have created the menu for our least fragment. There's an end. As you can see, it looks very nice. So in this video we will create a menu for our ad fragment. And our ad fragment will have just one Manu, which will basically represent the button which will save item in our database. So here, let's create a new menu resource file and let's name this ad fragment menu, so click OK, and here it's at the one and only item. So the idea for this item should be ah, menu ad and let's specified the title. So just add and let's added the stool. Stunning, sexy male. So now we need to specify icon because our menu will be shown on our action bar. So we need to select icon. Let's ah true this check Mark, I can't. Okay, so let's rename this toe. I see. Check. Okay. As simple as that. Like next and finish. And now it's Ah, link our I can hear. Okay. And we are going toe Add the thing for this icon as well. White collar. And we need to set show as action if Rome and that this is how our menu should look like. So after that, we need to navigate through our ad fragment. And just above this inflator we need toe had method set his options menu. So said that true. Okay. And we need to override the method, the own create options menu. And here we just need to inflate our menu, which would just create Okay, so past the name off our menu. And the second perimeter is ah, the menu from above. Okay. And let's run our application to see how will that look? Okay, so just never get to our environment. And as you can see, we have our check model button. So we're going to implement the logic when we press this check mark, it will add the item to our database in the in the next video, we are going to create a menu options for our update fragment 12. Create Menu for UpdateFragment: hell there and the welcome back. So in this video, we're going to create our final manual file for update fragment, and ah, our update fragment will have only two menus. So let's create a new menu resource file. Name the public fragment menu. Okay, click OK, and here let's first create the item for saving the or updating our current items. So the idea should be menu safe. The title should be safe and let's add the I call for this menu as well. So in our job, all directories like this vector acid and let's choose and search for safe icon. So this one will be fine. Just to rename this to something more simpler, I see save Okay, click next and finish and it's added this I could hear. So that's at also attend color toe white and the show as action toe. If room and our first item will be always visible inside the action bar, and the second item will be for deleting a single or our current item inside our update fragment, let's set the title to the elite, and the show is action to never. So this second item will not have icon and just at this toast during sex Americain. So that's basically it. So we need toe open up our update fragment and just enable this menu options. So So I never get here. And, uh, just above our inflator willing to set our set his options menu to true. And we need to override on create options menu as well. So just override that and inflate our menu. So, uh, Abbott Fragment menu and the second parameter menu. So let's run our application to see how will that look? So click here. And as you can see, our menu looks very nice. So we have greater old three menus for our of fragments. And in the next video, I'm going to show you how to create the transition animations for those fragments. 13. Introducing with Transition Animations: Ah, hello there and welcome back. So in this video, I will try to explain you how our transition animation work, how they are created and the used inside the navigation graph. So, first and foremost, you should learn how screens our presented on our smart devices so well, let's take a look at this image. So here we can see some values and also X and y axis. So the X represents a horizontal axis and why represents a vertical access? The top left corner off the screen is always zero. And when we go from left to the right side, then we will get the Mex value off a 100% on the X axis. And when we go from top to bottom, we will get the next value off 100% on the Y axis. So we're now you might be asking, How can we get the negative values off X and Y axis? Well, negative values are on the opposite side off positive values. So in the case, off a horizontal X axis, the negative value will be on the left side outside of the screen and in the case off a vertical y axis, the negative value will be on the top outside of the screen. And if you're still wondering, why do we need to know all of this? Let me answer you with the question. How can we move our screens, activities or fragments? If we don't know how the basic android coordinate system works now we know which values and the access we need to use to move our screens from each and every side. In the next video, we will create a custom transition animations in XML, and you will see how all of this can be applied. Now there is one more thing which I need to explain you, and the thing is associated with the navigation graph off our navigation component. So in the navigation graph, we can specify four different animations for one destination. So we have enter animation exit animation for enter animation and pop exit animation. So supposedly have two screens screen a and screen be, and we need to specify those four animations to our screen. A. So how can we know? What's the purpose off each one of those four Well, first, enter animation will be applied on the screen be because when we never get from our screen , a the screen be will enter and replace our screen A. And the exit animation will be applied on screen A because in this case, screen a will exit and be replaced with screen being right. So what about those of Pope Enter and pop exit animations? Well, the word pop is referring to the application back. Stack and the pope enter, and pop exit animations are triggered when we put off a screen off a bag stack. So well, let's say we're now it's screen be and we want to get back to screen A. Normally, we would step on a navigate up arrow in the top left corner and that would trigger Pope Enter and pope exit animations So pop enter animation will be applied to screen A. Because we're leaving screen B and entering screen A and the Pope exit animation will be applied on screen Be because we are exiting screen B and entering screen A right. Okay, so I think now you'll get it, how it works and, ah, go ahead and watch the next video 14. Implement Transition Animation between Fragments: Hello there and welcome back. So in the previous videos, we have created the three different menus for our of fragments. And as you can see, they all look very nice. And in this video, I want to show you how to create the transition animations between those three fragments. So, as you can see, when we never get from each of those fragments to another, we don't see any animation, and that is the most interesting part here. Okay, so when we open our navigation graph and select this action on the right side in the properties panel, we can see four different inputs for our information so we can enter animation, exit animation, pope enter and exit animation. So we just need to create the four different animations in this video. And we want tolling those for different animations in our navigation graph. So first, open up this resource manager and selective animation tab and the first we want to create the animation resource file named from Left. So we're going to have four different animation files and think OK, so the root element is set and we want to translate the element inside because we want to move our screens from the left and the right side. So in that case, we need to use ah from X Delta and the two X delta. So, as you can see, this file has the name off from left and from eggs. Delta needs to be minus 100% and two eggs, Delta Tau 0% and the Federation toe 300 milliseconds. Next, let's create another file on named the to Write and click Just okay, So, again, in this file, we're goingto have a translate element from X delta and to excel time. So this time we're going to hear from eggs elta to zero and the two x Delta Tau 100%. Because we want to move our A screen from the center to the right side, as the name suggests. And of course, duration should be the same on our all animations to 300 milliseconds. This is just an example. You can change that, of course. All right. Next, let's greet the third animation so this one should be named from right, and we're going to also either translate, but this time from eggs, Delta will be 100% and the to exit. That will be 0% because we want to move our screen from the right side to the center. Okay. And here just specified the duration as well. Okay, okay. And let's add the last animation resource file. So clear this Plus, and this one should be named the two left. So this time we're going to share from eggs, elta, toe zero and two eggs. Delta Tau minus 100%. Because thesis on emission will basically moved from the center, which is zero to the left side, minus 100%. And of course, duration should be 300 milliseconds. So now we have created all our animation resource files. So we have four different animations and the next we need to open up our navigation graph, and we're going to link those animations to our actions. So select this action, which is pointing from the list fragment to our ad fragment, and we're going to start by adding enter animation for us. So our enter animation will be used for our ad fragment because our ad fragment will enter the the screen. So our advertisement should come from the right side and exit animation should be applied to our least Fryman because the least fragment will be exiting the screen and we want toe exit the screen, toe the left side. So So like this to left information resource file and think. OK, so now let's run our applications so you can check it out and see how will that work? Okay, so click this 14 extra button. And as you can see, our ad fragment is coming from the right side and our least pregnant is exiting toe the left side. Okay, Surprises floating in from button again. And it works Very nice about there is the one problem. So when we press this back arrow, we don't see any transition animation. And that's why we human specified the pop enter and pop exit animation. See it? So let's specify those animations. So our pop enter animation will be applied toe least fragment because when we press our Baquero from our employment, our least fragment will come in. So we want toe our least fragment come from the left side and our employment to exit to the right side. So let's ah, run our application to see again. Okay, so clear this floating action button, Click this back arrow. And as you can see now, when we press our back after we can see the transition animation and it works very well. So now that we have specified those four different animations on our action, which is pointing from the list fireman toe the deployment. Now we need to specify to more animations on our action, which is pointing from the ad fragment to a list climate this time. So select this arrow and here we just need to specify to animations We don't need to specify pop, enter and pop exit just enter and exit animation. Okay, so those two animations will apply when we implement the logic for our check mark options menu for our ad fragment. And basically, when we navigate directly from our ed fragment toe the list fragment, then those two animations will apply. So I'm going to rearrange this name graph toe Just show you how the transition animations should work. So when the center we have our list, five mental came and on the right side we have environment. And on the left side, we kept our update fragments, so our ad fragment should come always from the right side in our update Fragment will always come from the left side. And I just want to show the visually how will our transition animation work? Okay, so it's simple as that, and now it's Rearrange back those on those screens here. Okay, So you should be able to understand how this world works. So now that we have specified those animations for our ad fragment, at least fragment we need to specify animations for our public fragments. So here, we need to select for the enter animation from the left, because our update fragment will come from the left, and our least fragment will exit to the right side. Okay, So for the pope, enter, it should be the opposite. So select this from right and the pope exit toe the to the left. Okay. And for this action as well, we need to specify just the enter and the exit animation. So the inter animation should be from the right side because our least fragments would be come should come from the right side and our update financial exit to the left side. So let's run our application to see how this transition animation will work. So, as you can see, our update fragment is coming from the left side and our ad fragment is coming from the right side. So it's kind of similar to a bottom navigation view, transition animation, and this is very nice and convenient for all the users. And it was their experience, of course. So that will be all for this video I hope to enjoy. If you don't understand some parts of this obvious current video, I suggested to wash the previous video where I explained everything about transition animations. 15. Introducing with ROOM library: Hello there. And welcome back with this video, we're going to start implementing a room database in our project. But first, for those of you who are not familiar with the room later based, don't worry, because in this video I'm going to introduce you with this library. So what is this room library? Well, a room library is a part off android architecture components, and it provides in an abstraction layer or escalate toe. Allow ah fluent database access, while a harnessing the full power off escalate room is that considered is a better approach for a data persistence than escalate database. It makes it easier to work with the Escalade database objects in your app, decreasing the amount off boilerplate code and the verifying esque reliquaries at the compile time. So the main components off a room library are entity dow in the database. So entity represents a table within the database room. Library creates a table for each class that has an entity annotation, and the fields in the class corresponds to combs in the table. Therefore, the entity classes tend to be a small model classes that don't contain any logic next that we have now which is short for a data access object, and the House are responsible for defining the methods that access the database. So our Dow will basically contain all SQL queries, and there are already some pretty fine queries, which we can access with the annotations like insert, update and delete. Or we can write our own custom s krilic. Where is using a query annotation In the initial escalate, we use their cursor objects, but with room we don't need the old. The course of related code and weaken simply define our KWEHR is using annotations in the Dow class and finally, a data race. So the database contains the database holder, and it serves is the main access point for the underlying connection to your applications data. The main advantages off using room library are compiled time verification, off esque reliquaries. So each query and the entity notation is a checked into compile time and that preserves your application from crash issues at the right time and not only checks the syntax but also missing tables as well. Next advantages. Off course, a less boilerplate code, and lastly it's easily integrated with other architectural components, like a live data eso For those of you who have worked with escalate open helper class for implementing escalate database in the past, then you know how hard it is to build and maintain one escalate database. So in the upcoming videos, we're going to implement the room library in our product and you will see how we can easily implement it in the real project. 16. Create Priority - Model class: Hello there, and welcome back. So in this video, we're going to create a model class named the priority. And the priority will be one off four different combs. Inside our database table priority will be an Inam class, which will have a three constants high, medium and low. Okay. And now this is how our application looks like in the moment. So in the previous videos, we have created our navigation graph, and we have created a three different fragments, as you can see. And also, we kept out of the transition animation between those fragments. So when we never get from one form into another, we're going to see this beautiful and smooth the transition animation. So with this video, we're going to start creating room database. So Well, first, we need to create a new package inside our application and the here, we're going to name this package data, and this data will contain all the classes for our room database. So first we need to start by creating model class priority. Okay, so let's name this class priority and select this class below that. Okay, so this class will be actually an intern class which will contain a three constants. So first, high, medium and low. And that's basically all we need for our priority, more class. And this priority will be one off four different columns inside our database table, and in the next video, we're going to create an entity for our database. 17. Create Entity (ToDoData) - Model class: Hello there and welcome back. So in this video, we're going to create an entity class. So if you don't know already what the entity is, it basically represents a table within the database. And the room library creates a table for each class that has an entity annotation. The fields in the class corresponds to columns in the table. Therefore, the entity classes tend to be small model classes that don't contain any logic. And as you can see on the seamers thesis cover our entity table will be represented. The usually so it will have a four different columns. Okay. And, ah, as you can see in the previous video, we have created this priority class which will be one off four different columns inside our database table. So next, inside this data package, we need to create the new class, and this class will be actually our entity. So let's name this to do datum. Okay? We can convert this Class two data class if we want, so it's just at that. Okay? And our total data class will have four cones. So the 1st 1 will be i d. The second title on the third will be actually priority. So we can already created our priority model class and that that will be our turn field, and our fourth will be description. So if we want hotel room library, that this class should represent an entity winning toe, declare this entity annotation and we need to specify a table name. Okay, so that's all you need to do. And now we need to set this idea as a primary key and that we want this I, d Toby automatically generated by a room library. So how can we do that? Well, very easily with just one simple annotation name, the primary team and inside parameters we need to specify auto generate equal to true. And the room database will auto generate this idea column. And that's basically all we need to do to create our entity class 18. Create Dao (ToDoDao): Hello there, and welcome back. So in this video, we're going to create Dow, which stands for a data access object Dowse our responsible for defining the methods that X is a database. So our that will basically contain a or SQL queries. And there are already summer pretty fine, Aquarius, which we can access with annotations like insert, update and delete. Or we can write our own custom. SQL where is using a query annotation. Okay, so in the previous video, we have created our entity class, so it has four different fields which will represent the combs inside our database table and the next inside our data package. We need to create a new interface this time so our dow will be actually an interface. I remember that. Okay. And our interface should be inundated with this dow annotation. And that's how our room library will know that this interface represents a dow. Okay, so here we need to add the functions for each of those SQL queries. So I'm going to name dysfunction, get all data because this function will actually receive all data from our database table. And this function will be a type off leased to do data all wrapped in a live data object. So ah, room library is working perfectly fine with our life data. And as you saw, our function has a type off least Toto data wrapped in a live data object. So that means that we will be able to observe these data changes off this live date object from our fragment. So we're going to create an observer in our list fragment later. And whenever we insert a new value in our database, our observer will be notified about that. And afterwards, we can update our you I Okay, so we need to annotate this ah function with the proper in notation so we can use a pretty fine the annotations, or we can write our own custom SQL choirs. So this time we're going to write our own custom query. So let's imitate our get all day to function with the query notation. And here, let's write our own query so select all from and type the name off. Your table is conceived. The compiler will automatically recognize this table name and we will order the stable items by i d in ascending order. Okay. And that's all we need toe ad for our query. So if you consider the square, we will return a list off to data objects with wrapped in a live datum, so it will make more sense later. In this course, you will seem so for now, we're going to create the only two functions and that this second function will be for inserting the data. And we will add that to the data as a parameter here. So we need to innovate our function with the insert query because this is a pretty finder invitation for insulting the data in our data raise. And that's all we need to right here. Okay, so for now, we're going to have only those two questions, but we're going to add more of them later, and we add one more thing here for our insert data function. So here we will specify own comic strategy. So basically, that means that when the new item comes into our database, which is basically the same as, ah, the item we already have in our database, that means that we can specify strategery on what should our own database do, So we will just ignore that and we'll add the this suspend keyword in front off our function. Okay, so ah, suspend. Keyword is used in front of the function hotel, the compiler, that our function will be running inside a core routine and that that means that we want our function to run on a background thread later in the view model. So you will see. And it is always a good practice to use the court things for all your database squares. Okay, so now that we have, ah added that we have a completed our doubt for now. So later in this course, we're going to add the more of those squares. But for now, let's just use those two, and that that will be all for this video. 19. Create Database (ToDoDatabase): Hello there, and welcome back. So in this video, we're going to create a database. So if you don't already know what the database is, it basically contains the database holder. And the service is the main exits point for their connection to your application data. Okay. And here, as you can see, we have already created our down interface. So it has to Aquarius for now, but we're going to add the multiple choir is later in this course. Next, we have our entered the class, which have a four different fields that you can see. And it looks nice. And here also, we have a priority class, so everything is separated, and now it's time to create a database. So inside our day data package, we need to create a new class named to do Day two days. Okay. And this class should the heaven annotation off database. So that is how we will tell the room library that this class will be database. So hearing to specify few parameters. So the first parameter is entities. So here we need to write our entity classes, and we just have only one entity class. But if you have a multiple entities than you would just separate them by a comma here inside next week ever parameter aversion. So here just type number one. But whenever you change your database scheme and you want toe migrate to a new version, you just need to increase this number. And the third parameter is export schema so that the fourth value for this is true and I'm going toe specify force value. But it is always a good practice. Tohira version history If you're a database is keeping your core base and in this case, I don't need exports. Came a So that's why I have said it affords. But for the product application, you would want to create this export scheme. Um, OK, and next we need to make our database to look database class, abstract class. So let's at this abstract keyword in front of our class and they're willing to extend a room database, okay? And now we need to create one abstract function named ah to do Dow, and this function will basically return our to our class. OK, OK, so nice that we need to create a companion object. So if you don't know what the companion object is it's basically the same as, ah, public static final class in Java and that that basically means that we will be able tow directly, get the reference off our function from these companion object to other different classes and here, inside, a companion object. First, we want to create one variable. Okay, so we're going to name this variable instance, and this instance variable will be basically a null and it will be a type off to the database. So it will be a notable type and it will have a volatile annotation. So what does it means so well, basically, it means that the rights to this field are immediately made visible to other threads, and they're willing to train this Tovar instead. Okay, and now that's fine. So basically, we're setting this instance is the fourth value to now, and we're going to create a function, get database with the perimeter of context, and we want toe favorite turn type off to do database, which is the name off our database class. And the first what we're going to do inside our get date of dysfunction. We want to create a variable name temp instance and we're going to store this instance inside our new variable. So we're always gonna check if this instance is not know. So basically, that means that we already have the instance off our total database. And when we have our instance, we just want to return that same instance and we're not going to create another one. We just want to return the same instance because creating multiple instances off our database is too expensive for the performance and the next that we would use this synchronized block. So when a thread calls a synchronized, it acquires the lock off that synchronized block. So other threads don't have the permission to call the same synchronized block as long as previous thread, which had acquired the lock and does not release that look. So basically, inside this synchronized block, we want to create a new instance off our total database and the first let's create ihsaa variable instance, and we're going to use the room class to create this database instance. So we're going to pass three parameters here. The first is, ah, context or application context, and the second perimeter is the name off our database class and the third parameter is the name off our database, okay. And we will use this build toe, build our instance, and we want toe stored a new instance inside our instance, a variable, vital, volatile variable on the top. Okay. And we want to return that instance. So what does it mean? This thesis in Christ Block and all of that. So basically, we want to have only one instance off our database class and that that's why, as you can see inside this, get database function first, we're checking if our instance is not know, so if our instance already exists, we want tojust return that same instance. And if there is no instance, or if our instance is actually on all then and only then inside a synchronized block, we want to create our instance off our database class and, uh, the reason why we're using us synchronized because we don't want that multiple threats create multiple instances. And there, with a synchronized block, we're going toe. Be sure that only one thread is able to access this code inside there. Cink, Rice Block and the only one trial will be able to create an instance off for this class. Okay. And that's basically for our database class. In the next video, we're going to create a repository 20. Create Type Converter (Converter): Ah, hello there and welcome back. So in this video, I'm going to show you how to use a type converter. Official documentations say that room provides a functionality for converting between primitive and box types, but does not allow for object references between entities. So what does this mean? Actually, Well, it means that the room database allow only primitive types like string integer, boolean float and so on. But it does not allow a custom objects like our priority class. And you already know that in our entity, we have a specified A field off a priority type. So how is that possible? Well, it is possible with a type converter. So with type converter, we will create two functions one for converting our priority object to string and the other for converting back, starting to priority object. So when we write to our database, we need to convert priority object to string. And when we reading from our database, we need to convert back strength toe the priority object. Okay, So ah, in the previous video, we have created our database class and ah, it looks fine here. So when we open up our total data or our entity class. We can see that our third field is type off a priority. So with a type converter, we need to convert this priority to string. When we I need to write or insert our data to our database. And we need to convert back string toe this priority object when we are reading from our database. So too great the type converter we need to create annual class. Okay. And inside our data package, we're going to create a new class. And let's name this just simple as our converter off case of this class will not extend their anything and here we need to create the two functions. So first function is for converting our priority object toe string so fun from priority, and we will take a priority. Object is a parameter, and we want to return a string. OK, so here we want to return Priority dot name and the one repressor control Q on this name will see that it says that returns the name off this in them constant exactly as declared in its Inam Declaration. So that means it will return either high, medium or low, and we need to annotate this function with the type converter invitation. So with this invitation, the room will know that this function is used for a type converter and the second function will convert back string toe our priority object. So we need to add the string is ah parameter and we want to return priority this time. Okay, so here, ah, type return and we will use our priority class dot value off and we will pass our priority string. So let's ah, hit the control Q on this value off and it says that the returns the enemy constant off this type with the specified name. So basically, we are going to convert our string toe priority object, okay? And we need to annotate our second function with a type converter as well. And basically, that's everything we need to right inside our conversion class. And now we will open up our database class and that we need to add the one more invitation type converters in here. I wanted to specify our converter class, so just type converter class, okay? And that's everything you need to do. So Room library is a smart enoughto know that those two functions inside our converter class are exactly for converting the type. Okay. And it's very easy toe set up, as you saw already. So now our room database will convert our priority object to string whenever we insert data to our database and it will convert back from string to priority object whenever we are reading a date. 21. Create Repository (ToDoRepository): Hello there and welcome back. So I in this video, we're going to create a repository. So if you're not familiar with the repository repository is a class that abstract the access to multiple data sources. The repository is not the part off android architectural component libraries. But it is a suggested Toby, the best practice for a code separation and architecture. A repository class provides clean a p I for a data access to the rest of the application. OK. And as you can see in the previous video, we have created our type converter class and that we have added a type converters invitation to our database class and that works fine. So next, inside over data package, I went to create a new class. So we're going to name this class toe do repository, okay. And we're not going to extend anything, but we're going tohave a one parameter off type toe. Do thou so our repository will get the reference toe. This thou interface. Okay. And here we will create first this variable named get old datum, and we're going to send the type of this variable toe at least off total data, and we're going to rapper alive data around this. So let's use live data and just pays that here. OK, so it's the same type as our get old data from our dow. So what we do is ah this now to get the access off that get all data from our doll class and the we will be able to hold the reference from our doubt toe our repository. Okay, So below that, we will create one function for inserting the data as well. Okay, so our positively will contain those functions for accessing the database. So I'm going to name this the same as previously. So insert data and I'm goingto passed to the data is a parameter and inside. I want to use this to do doll from the parameters and I want to get the access to this insert data function from our doll. And of course, I'm going to pass this to the data object. Okay, so basically, that's all we need for our repository. And of course, in the later videos. So the scores we're going to add more of functions for ah, later. Bay Square is, But for now, we only need those two. Ah, those to function, So are one function in a variable. So next what I want to do, I want to create a package named the Models, and I want to rearrange those classes a little bit. So let's ah, place, priority class and the total data class inside the models package. So just click re factor and we're going to create another package here named the Repository . So in this package, we're going to place our newly create the class to do repository click re factor. And that's okay. So now our ah structure looks a little bit better. So we have our data, and inside the data, we have a model sand repository. And of course, the data is since stuff and for now it looks fine. So we're going to improve the structure. Furthermore, in the scores, but for now, it will stay this way 22. Create ViewModel (ToDoViewModel): Hello there and welcome back. So why in this video we're going to create a view model, So ah, view model role is to provide the data to the U. Y. And the survive configuration changes view model acts as the communication center between the repository and the U y. Okay, so we're in the previous video we have successfully created our repository and now it's time to create a view model. So inside a data package, we need to create the new class and we're going to name this class to do view model. OK, so this class will not extend a regular view model. Instead, it will extend the enjoyed view more. Okay, so the main difference is that this android view model contains application context. Okay, so here inside we will create Ah variable named ah Tao. And basically, we will use our database class, together database and pass our application contest and get the reference off our Dow class and now down below. We need to create a repository Soto Dio repository and we have a warning saying that we need to initialize this repository and we're going toe Add the in it blocks. So any block is ah called whenever to do a view model is initialized first. So here we're going to initialize our repository, okay? And we need to pass our dow Here is a parameter. Okay, so now we need to create one more variable. And we're going to name this Get all daytime, so this variable will hold the will. Hold the live data object off least off total data. And basically, we want toe get all the data from the repository. So well, it's I use this and get all data equal to repository. Don't get all data. And now this variable will hold the least off total data from our database and our fragment will later observed this field. And, ah, we're going to get notified whenever a new data is inserting to our database. So down below, we need to greet one more function on name the insert data and here we need to pass to the data is a parameter. And we want to use the view model scope to launch a courting, so ah, well, telescope is a part off quoting Cortines. And ah, if you can't watch the some of my first videos of these course, Then you saw already what dependency we needed to add for this view model a scope toe work . So basically, we're running our background thread and ah, we want to run this insert data function from our background threat. So that's why we need to use the coatings inside the view model. OK, OK, so it's always a good practice toe run, Ah esque reliquaries in a quarantine or ah on the background threat. And that's why we're going toe use a remodel scope to lunch quarantine on most off our SQL queries for inserting, updating and deleting the data from the database. Okay, so our view model is completed and for now, we don't need any more functions. We're going to add more functions later in the scores. And now I'm going to create a new package and I'm goingto dragon drop this new view model inside its package. So our structure will be clean, okay, and that's it for this video. So, in the next, videos were going toe start actually adding some data to our database 23. Insert Data to Database: Ah, hello there. And welcome back. So in the previous videos, we have created everything we need for our room database to work. So we have our model classes, our doubt, database converter repository and the view model as well. So in this video, I want to show you how we can actually create the logic for adding our data to the database . So we're going to open up our ad fragment and we can open our ad fragment layout. Okay, So as you can see here, we have a two input fields and the one spinner. So we want to make the logic when we press our menu item on our ad fragment, we want to be able to insert a date in our database. So first here, we want toe store this inflator inside this view variable. And we want to return this view and let me just cut in Pace hero in the middle here. All right, so it will look even better. All right, So, uh, now let's run our application and let's a navigate to our employment by clicking floating action button. So here we want to make the logic When we press this check mark menu item. Then we want to insert those data from this from those input fields inside our database. Okay. And that's what we're going to do in in this video. So first, never get to this ad fragment, and we will override the method named the own options items selected and that this method will handle on click listeners for our menu items. So here, we're going to write if items dot item i d is equal toe are dot i dot menu ad and that's the I d off our menu from this ad fragments. So we contract that out, so open up this ad fragment manual. And as you can see, that's in the same idea which we used. Okay, So be sure to check that once again. And here we're going to create a new ah function named the insert data to the database. Okay. And the click old plus enter and let's create this method down below. Okay, so this method will he have the logic for inserting the data in the database. So first we need to create three variables which will hold the values from our input fields in the spinner. So first for the title, and we're going to get a text from our title appetites. And you can check those ideas for those views to be sure and get a text and converted to strings. So for the priority spinner, we're going to this priorities. No prayer. It is a spinner, I d. And we need to use a method called the Selected item. And we want to convert that to string. So we're going toe, basically grab the text like a high priority medium priority and low priority, and down below, we will create. Ah, we will get the text from our description. Added text. Okay, And now that we have created there were added those values in those variables. Now we can ah, greater the logic for a inserting the date. Okay, So before we continue, I want to create a new function here, and I'm going to name that function, something like verify data from the user. So before we add our data to do you tow the database, we want to check if it's empty or not. So I'm going to pass here two parameters for the title and for the description. So those will be type of string and we want to return a Boolean value. Okay, so here I'm toe type return. I want to say if and I went to use this text you till text you till's daughter is empty and we topaz this title, OK? And I'm going to use this or operator and I'm going to use this again. This time I'm going to pass in the description. So if those two are empty, I'm going to return False and in else block, I'm goingto say 12 this ah inflammation mark And I'm going to say if title is empty and I'm going to pass another here for the description. So if those are empty, I'm going toe return. Actually, the truth, okay? And now that we have created this function, I'm going to use this function inside our insert data to database. So our function here will return force for those input fields are empty and it will return true if they are not empty. We don't need to check her for the spinner because peanut always has a value. And here we want to create this variable invalidation and we've been to validate those title in description input fields swing with to say here If validation returns true, only then we can insert data to data base. OK, so here I'm going to create a new ah toe data object and ready to pass four different parameters. So the first parameter is I d. So don't worry. You just need to pass here a zero and the room database will handle everything else and it will automatically increase this I d. So the second parameter is a title. The third is priority. But as you can see, we have type this mismatch. So this is type of string and we need priority object. Okay, so I went to write one more function which will parse this string and get back our priority object. So here is a parameter. We want to set priority as a string type and we want to return priority object. So we're going to say something like when and the let's pass our priority string. So when our priority is ah has the value off high priority, then we want to return priority dot high constant. Okay. Next. We want to say if our priority has the value of medium priority, then we want to return priority dot medium constant and for the low as well. So that's how we are goingto be ableto parts this string toe priority object and the nails block. We just need to specify, for example, priority dot low Okay, And let's use this function here and let's pass our m priority, which is a string, and it will parse the priority and get back to And I get back our priority object And the fourth and final parameter is, of course, the description. So now that we have created our total data object with the new values on, now we can create ah view model and initialize view model here. And he was the method Insert data toe insert our new data to database. Okay, so on top off our fragment, we're going toe initialize our total view model. So private ball and toe the view model and it's said the type toe to the view model and there were going to use ah, delegate this by keyword and willing to delegate that to review models. So now we're going toe copy this variable name and we would use the method insert data from our end to do view model class and we want to pass our new data or to do date object here. So after that, we want to display a simple toast message saying, successfully added or something. So it's respects the context here and here. Let's write, successfully added okay for liberation women to set the length short and the show and will be inside the data and showed the message. We want to navigate the user back from our ad fragment to the list fragment. Okay, so just it was a finance controller to navigate that user. Okay? And basically, now our ad fragment looks ready. So we have everything we need. So we have over. I did this on options items selected. We have created the view model. We have created this insulated to database function. We are also verifying the data from input fields and we're passing the string toe the priority object. So everything is already here. And OK, so we forgot to add the else block here. So we're goingto this play a simple thoughts messaging the as block, saying something like, Please fill out all fields and that's basically so now we have everything ready. And in the next video. I'm going to show you how toe at the this Ah data toe database and the help to manually track your database and see if those values are actually there. And that's of course, before I teach you how to read a dating the recycler view. So that will be all for this video. 24. DB Browser for SQLite: Ah, hello there and welcome back. So in the previous video, we have created all the necessary logic needed for us to insert the data in the database. And in this video, we're going to run our application and actually add some data to our database. Also, I'm going to show you how you can manually track your database and see how or if those values are written successful in your database. So we're going to use Ah program named the DB browser for esque, right? And if you're wondering why I'm going to show you that, well, it's because we haven't passed yet. The lecture about the reading, the database in the recycler view and that that's why we need toe. Learn how to check our database manually. So first, let's run our application and add some data. 12 database. So inside our employment, we went to write some random data. So for the title, it's a house work for the priority. Let's choose the medium priority for the description. Let's ah, add something like, Ah, room cleaning, let's say, washing the dishes and let's add ah, taking out the trash as well. So well, it's pressed this Ah check Mark a button on the top and you will see a message saying is successfully added But we don't see anything here. And that's because we haven't implemented the logic yet. But I'm going to show you how toe check that manually. So first you need to open this device file Explorer, And here you need to select this data directory. So find that and inside the data directory, we need to open another data directory and they hear you need to find the name of your product so that the name off this project is a com dot example dot the room app. So we're going to find that okay, Just like missy. Okay, there it is. So let's open that and you will see a database directory. So inside his directory, we're going to see three different files for our database, so select them. All right, click and click Save. As so we're going to save those files on the desktop and think OK, and now we're going toe down with the the store, which I talked about earlier. So open up your Web browser and search on Google DB browser for s quite open up this first link and take dollars. And here you will see this knowing Stoller version so you can download that. And I have already downloaded that. So just open this directory and find the exit file. So open up. That okay? Just like okay, if you see this message and now click open data is a button here and then never get to the desktop and choose all files. So down below, you will see all our three files which we exported or saved from our android studio. And, you know, it was like this 1st 1 and just like open. And here you will see our table named the Total Table. In here, we can see our column. So we have the I D, which is a primary key. We have the title which is type of text priority. As you can see, it's type of text. So that means that our type converter did the job perfectly fine. So our three fields or combs on the type of text in the ideas type of inter. So here, let's select our to the table and we will see the values which we have inserted so far. And that is just one item. So here we have the idea we have the priority with your description or title. So, as you can see, we have converted this priority data from the priority object to the string. And we did that with our type converter. And here in our employment, we have, ah parts to this string and converted that the priority object as well. So everything works fine here so far. And that that's all I wanted to show you in this video. So now you know how you can manually track your a database to see if the values are written correctly and in some later videos I'm going to show you also how you can read the data and the display that inside the recycler view 25. Create Shared ViewModel (SharedViewModel): held there and the welcome back. So in this video, we're going to create another view model named the Shared View model. And we're going to share that view model between our fragments. So, as you can see inside our ad fragment, we have those two methods for verifying data and for passing the priority. So we don't need actually, those two functions inside our ad fragment instead, we're goingto paste them inside our share of the model. So inside our fragments package, we're going to create this class name, their shared view model, and that this class will extend the android view model, which has, ah, application context and that we're going to need this application context later. So you will see. But for now, let's just stay this way. And inside this shared the model. I'm going toe cut those two functions and the just place them inside our new class. So just the base name here and we can basically now get the reference of those two functions inside our ad fragment. But first we need to initialize our new view model. Okay, so let's ah, initialized that share your model. Okay. Just the same as the previous one. So let's delegate that toe view models so down below, Just copy this name and the based in front of this verified data from user. Okay, so we have an error, and that is because we forgot to remove this private excess modifier. So let's remove that and here as well. So now we will be able to get the reference of those two functions without the problem. And as I said earlier, those two functions will be used for our update fragment later as well. So we don't need to repeat those two functions two times. Instead, we can just to ride them in one place and then share them between those fragments. So that's all for this video. We have ah separated our code a little bit in our ad fragment looks Ah, a little bit cleaner and everything works fine. 26. Apply Color to Spinner Enteries: Ah, hello there and welcome back. So in this video, I want to show you how we can change the text color off our spinner items. So as you can see, when we never get to our ad fragment, we have this high priority, medium priority and low priority. So we want to make the logic. When we select each of those, we want to change their color. There are thanks to call her. Okay, so the logic for that will be located inside their shared view more than okay. So here I'm going to create this variable name, their listener, and that we want to implement adopter view dot own items selected listener, okay. And the reason why I'm doing this in this shared view model, it's because we're going to re Was this a listener inside our update fragment as well? So we don't want to repeat that two times. And, of course, our ad fragment will look more cleaner. So here we need to implement two methods, so press control. Oh, and the implement those two methods, so just select them all and click. OK, So for these first method, we're not going to implement anything. We just need this second method named the own items selected. And here I just want to rename those parameters so they can make more sense to you. So the first is parent. A second view. The third is a position, and the 4th 1 is i d. So it's a rearranged those, ah, parameters. Ah, a little bit more. Okay. And here, let's Ah, here. Are we going to implement the logic toe? Check the position off our item as from the spinner. So we want to say if position off our spinner is ah 01 or two. And that's because our spinner items count from the zeros on the position of zero. We have our priority high when position one, we have priority, medium and on position to weaken our priority low. Okay, so here, we're going to use up parent and get the trial at. So just based past this zero and the past, this is text view. So now let's see was a set text color and we want to change the test collar off our spin. Right. Um okay. So, first willing to pass our context, comp it and the get the caller. So just passed. This application is Ah, first parameter. And there's a second just pass our resource color. Okay, so play press old plus center. Twin poor debt. All right, so now we're going to copy this line of code two more times so you can use a shortcut. Control D so controlled the and again. Okay. And here, just renamed those ah ah, values to zero in two. And now in the at the end Just changed the color to yellow for our second item. And for the third item just changed the call to green. Okay, so our high priority will have ah, red color. Our medium will have yellow in our low will have green. So also at the same question mark to the parent because parent is actually a knowable type . And that's why we haven't We have to add this question mark, and that's basically it. So we have created our own item selected listener for our spear. And inside our ad fragment, we need toe use this view, operate, and we need to find our priority spinner. So here we're going to call our own items, selected Reasoner, and we're going to lose our shared view model toe find our listener, which which we just created. Okay. And that's all we need to right inside our ad fragment. Okay, so our experiment looks clean and simple and our shared view, Muller contains all the logic for this. And of course, we're going to use this listener inside our update fragment as well. So that's another plus. And the now let's run our application and see if that works. Okay, so I never get to this employment. And as you can see, our high priority is called in the red. So when we select our medium priority, as you can see, we can see the yellow color. And when we select our low priority, we can see the green color. So everything works perfectly fine. And of course, we're going to implement that same logic inside our update fragment play during this course . But for now, that's all 27. Design Row Layout for RecyclerView: Hello there and welcome back. So in the previous videos, we have implemented the all the necessary A logic and the functionality needed for us toe actually insert the dating to our database. And with this video, we're going to slowly start by implementing the function for our or a cycle reviews so we can show our data from database in a recycler view. So ah, in this video specific, we're going to create ah, lay out for our item in the recycler view. So first, we need to create a new resource file for our layout. So, uh, let's name this way out. File a rolling out Okay, so simple as that. Okay. And here we went to change this height layout height, but later in this video, for now, just at the layout margin to four DP. Okay. And now I went with the one more constraint layout inside that this constantly out and the hour rolling out well containing basically toe text views for the title and the description and one card view which will basically be in a priority indicator. So you will see. And let's add the i d for our constantly out named the row background. Okay, so later we want to change this layout height a swell. So for now it will stay match, parent. And the next thing I want to create a new customer Drobot resource file. So Ah, I'm going to name this file item background and this item background will be used on our constraint layout. So I'm going to set the initial element or the fourth element to shape. And here we want to create Ah, basically shape with solid color off white. We're going to add ah, stroke toe one dp and with and they will have the light gray color. And also we're going to set the radius to 16 dp okay. And that's all we need toe do for our item background. So now we're going tolling this item background inside our constantly out. So just at this background attributes, okay, and after that we need to add the card view so this card of you will represent a priority. So we're going to create certain from this card view, so open up. That and the first let's ah, let's ah, change the layout within high to 16 deep in. So this will be basically a small circle which indicate our priority. So we're going to set this bigger on color to red so we can actually see this on our screen . And we went toe added the radios to our card view toe 100 gps so we can have a full circle can. As you can see, it looks nice. So I wanted to connect the right in the top constraint to our constantly out. Okay, so the top and left constraints should be 16. Okay? And our priority indicator will be located on the top right corner off our item. Okay, so after that, let's add the i d for our card view. So we're going to set the I d to priority indicator. Okay. And the next let's add the text view here inside our constantly out. So let's connect the left in the top constraints through. Ah, left constraint will be 20 in the top 16. Okay, so next we need to cut them pace this text, you bellow our card view. Okay, So it will look better. And the here, I'm going to set the idea toe title text or txt. And let's change this text attributes to some random data, for example, night title. So we can actually see this on the screen and see how it will look like so text style. I should be too bold in the text size to 20 ESPN. We're going to set the mark the maximum length off our characters to 20. So this is my personal preference because I don't want to. My title be longer than 20 characters, and the text color should be dark gray. So below this title, we're going to add one more text view and this text we will represent a description. So connect the top and left constraints to our title text view and said the top constrain toe eight dp Okay, that's fine. And ah, now let's connect the bottom constraint as well and said that toe 16. Okay, so you can see our text series on the meal. So we need to change the constraint layout high to wrap content and the rep content on our route out as well. So now this is called our role layout will look like So we have the title with your description, and we have ah, this priority indicator. Okay, so that looks nice. So here. Let's change the idea for our description. Text butto description. Txt. All right. And here we're going to set the maximum length of the characters toe 300. So that's also my personal preference. And then we said the Mex lines of the text toe 10. So if we have ah, less than 300 characters, we want toe limit our alliance off our text. You to 10. Okay, so for the text timeto just type some random text or description here. Okay? So this is just for testing purposes, of course, Women to change that dynamically for our from our recycler of your adapter. So for now, it looks it looks fine. Okay, so there is one more thing that we should add and that is ah, right constraint to our parents from our description text and said that constraint to 16 and move that text in the left side. So ah, for example, when we have a longer text for our description, let's see, How will that look? It can see our view. Our way out is kind of messed up. So the way we're going to fix that Little said the layout with toe zero dp for our description. Thanks. And that basically means that our our text will measure the constraints. Okay. And we can fix that. And now our layout looks perfect. So of course you can change. This layout is your one. But this is my personal preference. And to me, it looks very nice. Inkling So if we want to add the for example, more text, as you can see our I think we'll expand because I work constantly out of ah ah, You have, um, rep. Contact is the height, and you can see the next character length is a 300 it will not show more than 300 characters. If we want to see more text, we need toe site, decide him and go to our update fragment. But we're going toe come toe that late during this course. So for now we have designed our way out and ah, that's fine. For now, 28. Create RecyclerView Adapter (ListAdapter): Ah, hello there and welcome back. So in the previous video, we have a designed our rollaway out which we're going to use inside our recycler view. Of course. So this thoroughly out has ah, constraint Lee out. He has Ah, this card view and to text feels okay, so it's basic and simple, but it looks very nice. So inside our least package, we need to create our recycle view adapter. Okay, so let's create a new course in class. And the name of this class should be least adapter. Okay, so this class will extend the recycle view adapter. Okay, so type of recycler view dot adapter. Okay, lets import this, and we need to specify view holder. So we want to create our own view holder. So our view hold that Ah, class should be created inside this least adapter. And the name of that you holder will be my view holder. So click old plus center and let's create this class inside our least adapter of. So select this Selous adapter. Okay. And this class will extend the recycle view view holder. So let's extend that dot You holder okay. And, ah, let's change the constructing location here. So let's add those brackets and here as well. So we need to add the Vue here, which will represent our role a out okay, which we have created, of course, in the previous video so past this view right of you and the here press old plus center and changed the constructing location. So we need to have those brackets and here place a press old plus enter to implement those three methods, So select them all and click OK, So before we start with those methods, let's create the list off tool data in on top of this class. So so far data list and that these data least variable will be basically a list off to do data. Okay. And inside, it's to get item count. We want to return the sides off this data list. And of course, this data list will be populated from our list fragment in the next video. Okay, so inside it's own creative. You. We want to get the reference off our rolling out, which we have created in the previous video. So basically we will create a variable named the View and here we want toe use the layout inflator. And here we need Topaz, the context So I would do this view group and together context. And the next time you toe call the metadata inflate and I need to pass the first parameter the layout off our file. So r dot layout about the rolling out. That's the file which we have created in the previous video, is the second parameter willing to pass the parent and is 1/3 just type false. And as you can see, this one creative you holder class, you have a return type off my view holder, and that's the class which we have created. So we need to return my view holder and we need to pass a view. And as you can see, our my view holder class actually contains that view and that your represents our rolling out, which we have created the in the previous video. So inside our own buying view holder, we will basically bind the viewers from that layout with our data. So first we can decrease the lines off cold inside his own creative you holder, so we can just type return my view holder and just passed this layout inflator in the in the parameter. Okay, okay. And now we will get with our own buying view holder method. So here I'm going to type a holder. And that's basically my view holder object. And I want to get this right in view. And this item, you basically represents our rolling out. And now with this item view, I want to get the reference of those views inside our rolling out like text you for ah, titled in description and card view. So let's first find our title 60. As you can see, we can see that this idea is from our role a out file. So click enter. And here we want to change the text of this title text, and we want toe use our data least and get the position dynamically and dot title. Okay, so basically, our data list is a type of total data and we want to get the title from this object and basically place that inside our title text. Okay, so you're going to see that in action in the next video. But for now, let's just populate those of use. So now we're going to this description and text, and we want to do that the same from our data list. So get the description for from that total later. And for the card view, we need toe right, some different. So here we want to create a priority object and we're going to get that priority from our data list. And now we need toe. I had the when. So when our priority is ah Priority daughter High. So when our priorities high, then we need to change our card view background color to red. So we need to use this holder and item view and get the reference off our priority indicator card view. And we need to use this a method called the set card background color. And here we need to pass the course. So let's use this context. Comp it don't get car. And here we need to pass the first perimeter context. So let's pass. Ah, holder daughter item view dot context and there's a second parameter. Let's get the reference off our color. So our daughter color dot the red. So when our priority is high, then we want to change this card view background color to red. And when this priorities the media, we want to train the cholera toe yellow and so on. Now we're going to have the the logic for those so spinner items as well. So priority dot low And then we just want toe copy and paste this call from above when we don't need to write that again and just changes the caller. Okay. And now we need to have this priority medium first. So let's add that above and let's paste that quote again. So just change the caller from red to yellow. Okay. And down We need to change the green for our low. Okay. And let's ah, rearrange this coat. So I'm going to click off, plus ah, control plus l through former this code. Okay. And that's basically it for our own buying view holder. And we're going to basically get the text dynamically from our data least and set that to our views s owing to create one more function here. And I'm going to name that certain data and we need toe set. The total data is a parameter. So basically, this is a list off to the datum, and here we need to set this daughter data list, and basically, we want to set this total data from the parameters to our total data from our list adapter . And we want to notify our secular view about those changes. Okay, so this set data function will be used from our least fragment when we are observing live data object. So you will see that in the next video. But for now, we have just created our list adapter, our A cycle re adapter, and that's it for now. 29. Display Data in RecyclerView: Ah, hello there and welcome back. So in the previous video, we have created our recycler you adapter named the least adapter. And of course, as you can see, we have implemented all the methods that we need for our recycle view adapter. So that looks fine. And also, we have greater this certain data function inside our list adapter as well. So we're going to use this function inside our least fragments. So, uh, first that what we're going to do, we're going to create a new variable here inside our own creative you method so that this variable will be named the recycler view. And we're goingto get this recycle view I d from our view object. And then we're going to set the adapter for our recycler view. So let's first create our adapter. So on top off our fragment class, we need to create variable named adapter, and this will be a type of least adapter. So we're going to lazily initialize this list adapter and down below when you just took place, this adapter and that's all we need to do. So below that, we need to set our layout manager and in this case, I'm going to is a linear layout manager. But at the end of this course, I'm going to show you how to use a different layouts for your recycle of you are like a great layout and so on. So you will see. But for now, it will stay this a linear, okay? And after that that we need to initialize here our to do view model so we can get the reference off our Guettel data like they topped it. So let's ah, initialized this here. So, Toto view, model and we're going to delegate this initialization toe this view models so old plus enter toe, add that OK? And now inside our own creative you method, we're goingto get this. Get all data about As you can see, we cannot find that here so well, it's open up our to do view models so we can see what this is all about. So Okay, so our get all data has a private access modifier, so we need to remove that. And now we will be able to observe this, get all data from our least fragment. So call this observed method and the here we need to pass two parameters. So the first perimeter is a life cycle owner and that this life cycle owner basically represents fragments. View. Okay. And there is a second perimeter we need to pass the observer. So basically, we will observe these get all data live data object, and we're going to get the notified every time there is a change inside our database. So, for example, when we insert update or delete, there's something from our database. Our Guettel data will notify our observer inside this list fragment, and we're going to use that the new data toe basically set the data inside our adapter. So we're going to call this adapter and call this set of data, and we're going to pass this later, which is basically a list of to do data. So whenever there is a new change, we're going to get notified, and we're going to update our recital of you. So as you can see, this said data is getting this least off to the date is a parameter. And it is a populating that data list which we have in our adapter and down below. We're notifying our recycle every about that. Those changes so Everything is understandable here. So we are observing this. Get all data live data objects. As you can see, this is a type of life data at least Toto Datum. And whenever there is a new change inside our database, we will be notified. And we basically want to settle data to our recycled every time we get a new date. Okay, so, Well, it's run our application and see, How will this look like? So we should be able to see our first item in our a cycle of you and they're ago. So this is our first data which we have inserted inside our database. So as you can see, we can see the title, the description, and we can see the priority indicator, which is quality in yellow. OK, and it's great A new item here. So it's said the title toe something like a work number number two. And that said the priority to a low priority. And for the description, of course, let's type something like, I don't know, cleaning or clean sister's room. Okay, Cletus menu item. And they're ago. So we have our new item inside our recycler view. So every time there is a change in our database. Our observer will get their data and we're going toe update our recycler view. So it's simple as that. And now, for example, it's at the one more item and the here. We're going to write some longer description so you will see that our item will accept only 300 characters for our description. And if you want to see more of that description than you would need to navigate from this to recycle view toe update fragment. But we're going to implement that logic later in the scores. So let's open this rolling out and you will see down below the tower description text. Here's a max length of 300 characters or a Mex lines to 10 lines. So if you have less than 300 characters, then the Mex lines will apply. Okay, so, uh, now, when we open up our fragment least layout, we will see that we forgot toe set the layout within height for our a cycle of you. So we're going to send that to zero DP, which is basically the same as a match constraint, and we need to add the few more parameters or sorry arguments here. So let's at the petting top toe. Aidan dp and let's add this clip toe petting to false. Okay, so this clip toe Pettinger means that it basically I will clip it's Children and resize any add effects. Okay, so let's run our application again and you will see that our sack review now looks even better and we have our margarine from the top. And as you can see between those items, we have a margin as well. So on the top we have eight dp padding when our a cycle of you and for each off our row, we have a layout margin off for DP. So as you can see between those items, we have actually eight dp off margin because it is counting from the top and the bottom an item. So top item. Here's a layout margin to four and bottom item. Here's the layout modern toe for as well. So when you at that, you will get NDP in ah layout margin. So everything looks fine and ah, that will be all for this video 30. Safe Args - Pass ToDoData object to UpdateFragment: Ah, hello there and the welcome back. So in the previous video, we have, ah, implement that all the necessary logic needed for us to this player, our data from our database inside the recycler view. So that works perfectly fine. And then this video, we want to implement the logic. So when we select one of those items, we transferred the data from that same selected item to our update fragment. So first, let's never get toe least pregnant. And we want to remove this own click listener from our list fragment, which is pointing us to the update fragment. So we're going to add the that don't click listener inside our least adapter instead. So well, it's open our released adapter firsts. Open up fragments package the least and open our list adapter. So, inside our own buying view holder, we're going to add that on click listener. So, uh, let's use this holder object, then. Ah, get the reference of this sighting view then. Ah, let's find this idea off our constraint layout, which is Rome background, and we're going to add the on click listener for that constantly out. And ah, as you can see, that's the same I d for our constraint layout. So it's named the robot ground. And whenever we click on the their Titan, we want to navigate our users to update, fragment and passed the total data object from our least fragment to our update fragment. So here I am with you. Is this item you to find the net controller and basically navigate from our list fragment to our update fragment. Okay, so let's run an application to see if this navigation actually works. So click one of those items and this conceit were successfully navigated to this update fragment. But we don't see the data from that selected right in which we have chosen. And now we're going to implement the large occurred so we can pass that. So the data object from our list fragment to our Ablett fragment so tool that we need to use a safe arcs. OK, so now open up a navigation graph and select this update fragment and on the right side in the properties panel, we need to create a new argument. So, as a type of this argument, we need to choose the customer parcel able. So at this moment, we don't have a custom possible object. So we need to create one on that. We already have one. And that is a little data. So what? This class would extend the class named the possible. Okay. And we care warning from enjoy studio. And that means that we need to add the one more details from here. And that is a notation named the Parse Allies. Okay. And that's all we need to do to make our to the data class a parcel of Okay, So for those of you who are coming from the Java, you know how hard it is to create custom parcel. So next we need to create a new argument. So type the name off this argument toe current item, and as a type, we're going to select a custom. Personable. Okay, so now you will see this total data class. And if you don't implement this parcel, herbal and parcel is annotation inside your class, then you will not see this class here. So select that and click OK, and click. Just add. We don't need any of the fourth value of this time, okay? And on the right side, in the arguments you will see that we have created this argument named the current item. So in the list adapter, Now we're going to create a new variable name the action in here. We're going to specify that argument. So we went through this Ah, class Name the least fragment directions. So this class is automatically generated by safe arcs, plugging. And of course, we're going to specify this actually fragment toe, other fragment. And if you don't don't see this parameter name, then just to rebuild your product. And now you should be able to see this perimeter name when you press the control. P So now, press control P. And you should be able to see the parameter, which we need to add. And that is a current item with a type off to the data. So here are going to specify to the data object and women to is our data list and get that object dynamically with the position, okay. And this action should be now specified inside. This never gave method. Okay, And now inside our of the fragments. So let's first open up our Ablett fragment and now we need to read that data which we have sent from our list adapter to our abject fragment. So first I'm going toe cut and paste this on the top and I'm going toe. Ah, create And I'm going to create view. Ah, object here. So I'm going to start this inflated inside of you and I'm going to return the view. Okay, so in the top off our fragment, I'm going to create the new variable named arcs. Okay? And then we do this by keyword and specifying never arcs. And the type should be update fragment arcs. So this class from an update, ours is automatically generated by our safe arcs plugging. Okay, So the suffix arcs is ah added for those classes or fragments which will receive the argument and this direction. So fix is added for those classes that needs to transfer or past this argument to other classes. So we're using here list fragment directions, toe pass the argument to our Abit fragment. And in update fragment, we're using this class of these pregnant arcs to actually get that argument inside our update fragment. So here, inside our own creative you method, I want to use this serve. You object to find viewers from our update fragment and I'm going toe first populate this current title a text. So I'm going to set a text and I mean toe extract the text from our arguments. So arcs dot current item and there's concede that's the same name off our argument, which we have great inside our navigation graft. So if you open navigation graph, you will see this that same item. And now from this current item, we can extract a title description I d and priority. So I'm going to use the title a tous moment and down below. I'm going to find the the idea off our current description of text and said the text toe description. And of course we're going to extract this description from our safe arcs as well. And for the priority, it will be a little different. So I need to use this method name the set selection, and I need to specify an integer number. So 01 or two and the zero position we have a priority high at position one week, a priority medium and in position to we hear priority low. So we went toe parts. Our priority object to integer so to do that, we would create a new function named the parts Priority. And this function will have Ah, well, take a priority is a parameter and it will return an integer And afterwards we're going to use that method or function inside our set selection. So here, let's let's specify your priority object is a parameter and our function will have a return type off integer so just type int. Okay, And here I'm going to return and I mean to say when priority object. So now when priority object is a priority dot high So So, like that and the when priority is a priority high. Then we need to return zero. When priority is media, we need to return one. And when priorities low, we need to return number two. OK, so now let's copy the name of this function and we're going to pay that function inside this set selection method. Okay, and just specify this priority object, so we're going to get our priority object from our arcs. So current item dot priority and that's all we need to do. OK, so, uh, this function is pretty much a self explanatory. It takes the priorities parameter and it returns the string and that in the returns, the integer and that English is used in this priority spin a little, said the selection. So now we can run our application and check it out. So when we select one of those items, you will see that in our object fragment. Now we can see the exact same data which we have a selected from our recycler view. So we have work number two, low priority and the description as well. So let's elect another writing. And as you can see, we can see the different result as well. So it works perfectly fine. And now there is only one more thing which we need to change. And that is ah, color off hours spinner items. So it's first get the reference off our current priority speaker and I'm going to say this on items selected listener. And as you recall, we have already created this own items selected listener inside our shared the model. So here we're going to initialize our share of the model. Okay, and then we're going to use this shared the model to get the reference off. This a listener from our shared remodel. So this listener is used for, Ah, our update in our ad fragment as well. So now let's run the application and let's check it out. And as you can see now we can see the exact color off this spin right there so we can see yellow, red and green as well. So it works perfectly fine and therefore Bill for this video. 31. Update Selected Item: Hello there. And the welcome back. Selling the previous video, I showed you how to create an argument in a update fragment and the hell toe pass. Ah, to data object from least fragment to update fragment. And as you can see, inside the least adapter, we have this own click listener. So whenever user selects one item from a recycler view, we are going to never get our user toe update fragment and, of course, passed to the data object and the inside the update fragment. We're getting that to data object. And we are extracting the title description and priority and were populating our input fields. So Ah, as you can see, when we run our application, everything works fine. So in this current video, I want to show you how toe Abdic the current item. So when repressed this menu item eyes save icon, we can actually update our current item. Okay, So first I want to ah, select this parts priority method and the cut that in the Paste insider shared the view model instead. So just pays that down below, and it's changing its name Toe Paris priority toe end. Because we already have a method named Paris priority. I'm just going to put this method here inside a shared view model instead off, you know, crowding space inside our abject fragment. So just call this part sprayer alito int method from shared Remo, and everything is OK, so next I want to override the method called the own options items selected and that this method will handle Ah, please click events on our menu items. So here, I'm going to say if item daughter item i d. Is equal toe, um, the I d off the same menu. So the idea is a menu safe. So, uh, we need to double track if that's the idea which we wanted. So open up this subject fragment menu and ah, as can see our save menu has the i d off menu say Okay, so now that we have checked that, we can proceed next and ah, inside it's own options selected on options night and selected, we can create a new method called the update item. So click old plus, enter and create a new functions here. Okay. And inside this update tight and function, we're going to create three variables which will hold the values from our inputs and from our spinner as well. So the first title, the second description. So I'm just getting the text from this from those input fields and for the priority as well . So when our user presses that this ah, men, you'll save Ah option. Then we should get that text from our input fields and then we can update our current item . Okay, so after that, we're going to create a new variable name validation and we're going to with this function , verified data from users from our shared view model, and we're going to pass our title and description so because so, we are very fine. If those fields are not empty, so only if they are not empty, then we can update our current item. So here we're going to create new ah toe data object named the updated item. So is the first parameter we should pass the current item I d. So we're going to use the arcs toe to find that here are just past the title on the Is it'll parameter. We need to pass a priority object, so we need to convert the string from our spinner to priority so we already have that method. So inside the trailer view model, we have Ah, a method called the Paris priority which takes a string as a parameter and the returns priority object. So just passed this get priority string and there's ah last parameter. We just need a description. OK, So as you can see, this is our A method which takes string is a parameter and returns priority accordingly. OK, so it works perfectly fine. We have this method the inside our ad fragment as well. So is afford perimeter. Just add a description, okay? And ah, now we have created our toe the data object for a current titan and next we need to create Ah in actual query toe update our item. So first tell, it's add this to the view model on top off our fragment. Okay? And now we're going to ah, find the our doll class and let's open that and let's open our repository in the view model as well. Okay. And now it's open our doll first. So we're going toe. Add the rabbit query. So let's create a new function here named the update item or update data and express a total data as a parameter. And we just need to annotate our function with the update invitation because we already have a pretty fine an invitation for updating our item in the room database. So after let open up repository and here as well create a new function of the data so passed to data and inside. Just call this update data from our Dow. Okay, so just close the repository and lower open up view model in here as well Cola or create a function name the update data and the women he was courting cooler things to run this Abdic query inside the protein and the owner background threat. Okay, so that's basically it. So we can close our you more than now and inside our update fragment. And now we can call our to the view model and call this update data function and just pass our So the data object, which is called the updated item. Okay, so that's all fine. And now we can display a simple toast message saying successfully updated. Okay. Just like the toast. Length short and show that. Okay, so here we can add the comment as well. So Abit current item and down below eso. When we update our item, we want to navigate back from our abject fragment to our list fragment. So let's find them controller and let's never get back. Okay? And inside the else book, I'm going to add the simple those message saying, Please fill out all fields and that's basically it. So as you can see inside our own option, citing selected, we have this update item function and it basically do everything we want. So ah, now we can run our application and check it out. So let's select one of those items, for example, on this one. And let's rename our title, for example, toe something like my work. And let's change the priority toe, for example, medium priority and let's change description as well. So let's type here something like a clean whorehouse and click this save button. So we got this successfully updated the toast message, and our item is updated. So as you can see it, there works perfectly fine. So let's update that again, only the priority and it works like a charm. So that will be all for this video 32. Delete Single Item from Database: Ah, hello there. And welcome back. So in the previous video, I showed you how to update the current item. So when you select there one of those items from a recycler view you will get redirected toe update fragment. And from here, you can easily update your item. So that function works perfectly fine. And in this current video, I want to show you how you can delete single items. So from our update fragment, you have an option to click There it. And in this video, we're going to implement older functionality needed for that function. So so here inside this own options items selected, we need to create LCF block, and we need to handle a click event on our delete menu. So here I want to say if items dot item i d is equal toe menu delete ideas. So let's double check to see if that's the right idea. So open up, update fragment manual. And here, as you can see, it is the exact same idea. So that's fine. All right, so, uh, here we're going to create a new function, so I'm going to name that function, confirm item removal, and you can click old plus enter and they're just created a new function here. Okay, so before we continue, I just want to replace this if and else if with when So ah, we were going to make this code a little bit cleaner. So inside this when just type item that item i d And here just had this manual say first. So when item I d is equal toe manual, save them, execute this update item method. And when I tell my day is equal toe this magnet delete then call this second firm item removal so it looks nicer. And now that we have created that we can proceed in the create all the functioning that for our confirm item a removal. So before we continue, actually, we need to open our dow and we need to open repository and the view model as well, because we haven't created SQL query for deleting one item. Okay, so first, let's open a Dow class or interface and the here, let's create a new function and suspend function named the delete item, and here just passed a total data object. And let's annotate the dysfunction with the delete invitation. So this is a pre defined invitation for a rumor library, and it will just be late that to do data object from a parameter. Okay, and now let's go to the repository. And here again, let's great the new suspend the function name the delete item passed to the data and the Let's call this delete item from our down. Okay, and now it's closer repository and in the view model, it's and the new function as well. So here are create a functioning, really tight impasse. This to date is a parameter in the let's. He was quoting Cortines to run our delete query from a background threads. So that's totally okay. Like we did in the previous function is since Well, so now let's close this view model. And here inside our confirm item removal weaken, start grating the logic. So first, what? What we need to do? You are going to create teller dialogue, a biller, and basically we went toe show our user our dialogue when when a user will be prompted, toe klik, yes or no? So we're going to say something like, Are you sure you want to remove the current item in the name of the current item and user will have two options to click Yes or no. So here I'm adding this positive button named the Yes. And when user clicks Yes. We went toe called this deal it item function from our total view model and just passed this current item from our arcs. And below that, we want to display a simple toast message saying something like successfully removed. And we can use a string template toe get the title from our current items. So just Ozarks dot current item the title inside the brackets like that. Okay, okay. Setting the length for short and show. Okay. And the Belo, our toast message. We can also add the navigation. So it was a finance controller. So we want to navigate our user back from our abject fragment toe least fragment when we remove that item. And let's he was, ah, builder to call set the negative button. So ah, let's set that tone. Oh, and we're not going to implement anything here, so just leave that as it is. And let's call a set title method here. So the title should be something like a delete. And let's get the name from our current item and at the question mark. So for the message, we're going to say something like, Are you sure you want to delete and let's use a string template toe find the the title from our current item and add the question mark. Okay. And below that, we can call a method called Create and Show. Okay, so where everything looks fine here, So we are calling soul. It's a cut in pace. This function below our update item function. Okay. And then went to set the comic here saying something like a show alert dialogue toe. Confirm removal. Okay, so basically, this function will be called the When the user clicks this menu delete. Okay. So we can run our application now and check it out. Okay, So now select one of those items from a recycler view and from the options like this delay it. And as you can see, we're going to see the message saying the elite and the name off our current item and ah, you can click yes or no. So when you press, no and nothing will happen, this Lord Allah will disappear, and I just want to change one thing here. So I need to read the quotes around that this title. So just at the single single quotes around the title and here as well, so it will look even better. And now let's around our application again. Okay, so here, select for example, this item cleaning delete. So when you're pressed, no, nothing will happen. But when you press Ah, yes, then, ah, you will get that those message saying is successfully removed in the name off this item. And as you can see now, recycler view, we don't have our item, which we just aerated. So everything works fine. And here, let's just create the new item. So it's type here, something liquor cleaning everything. Okay, so we can hear three elements here, and that's it for this video. In the next video, I'm going to show you how toe delete all data from your database. 33. Delete Everything from Database: Ah, hello there and welcome back. So in the previous video, I showed you how to create function toe Remove a single item from, ah, update fragments. So, as you can see, we are basically displaying a simple all our dialogue to our user. And in this video, I want to show you how to delete everything from your database. And we're going to do that from our list fragments. So we have an option here and there. It all, and we want to create a candle, that click event for that menu items. So first, let's open our least fragment. And I want open ah Tao interface as well. And let's open a view model and repository before first. We want to create our query for regulating everything from our database. So open Dow and Bellow debt. Let's create the new suspend function named the Deal It all. And this function will have no parameters. Just a simple custom query. So we're going to right here, delete from and the name off our table. So that's all we need for our query. And now it's close. Our Dow and ah, let's create a new function inside our repository. Okay, so down below, it's create the new suspend function named the Delete all So we don't need any parameter just used out to get the reference of this little method okay and down below. For our view model, let's create a new function named a little. We don't have any parameters. And let's use a view model scope to run a chortling Corentin and ran our query on a background threat. So that's what we need So we can close this view model as well. Okay, and inside the list fragment. We want to override the methadone options item selected. And here we want Toe Sandal, a click event for our menu item. So it's right here if our item item I d is equal toe are dot i d manu del it all. So it's a double check to see if that's the right idea for our manual. So let's open our least fragment manual and down below. You will see that the manu is pretty much the same. So that's good. And the here, let's create a new function named the confirmed removal so old plus enter to create one and here we want to copy basically the same thing from our rabbit fragments. So navigate toe update fragment and copy everything from this Ah function here. So we're going toe only change a few things here, so go to list pregnant and pace that. So first that what we need to change their willing to change this still it item function, toe delete. All Now change this toe something like successfully removed everything. Okay, so here, just type something like a really everything in question mark And for the message. Are you sure you want to remove everything and the question mark as well? And from here, we also don't need this fine air controller because we don't want to navigate Ah anywhere. So just remove this line of cold as well, Okay? And I think that should be fine. OK, so just a this playing simple Oliver dialogue message. So I'm going to also add a common here on top of this function show, uh, alert dialogue to confirm removal off all items from database table. And now let's ah, run our application and see How is this gonna work? Okay, so now choose the deal. It all from the menu. Okay, so it looks nice basic and simple. When you press no, nothing will happen. And when you press, yes, you will get the toast message thing successfully removed everything. And as you can see from our cycle of you, we don't have any item in our database. So it's just at the one item so we can have ah, at least one item inside our a cycle of you. And you already saw that our delete and a little queer is working perfectly fine. So that will be all for this video. 34. Show no_data Views if Database Empty: Ah, hello there and welcome back. So in the previous video, you saw how we implemented the function to delete everything from our database. So when you run our application and like this little you will be prompted to select yes or no And that function works perfectly fine. So when you open up this fragment least layout, you will see our image. You in text, you if you can't forgot them and they are, visibility is set to invisible. But if we remove that, you will see that we have a text using no data and this simple image view. So basically, in this video, I want to show you how to implement the logic. So when our database is empty, we want toe show those two views. And when our databases not empty, we want to hide those of yours. Okay, so it will be very simple. We're going Teoh live data object or mutable. Live date object. So, um okay, so here inside the shared view model, we're going toe, create a mutable live data object, name the empty data or empty database, and we're going to set on the type to bullion. So the fourth value of this mutable live eight, I will be true. So let's say that the truth and the below that we want to create the function. So well, it's name that function or check if database anti. Okay, so here is a perimeter. We want to have a list off to data total data objects. So just at that and inside this function, we want to check if this list is empty or not. So eso here, we're going to set the value of this empty database. Mutable aviator object from above. And here we're going to get a stool data object and check if it's empty. So if our list of to the data is empty, then the value should be true. And if it's not empty than the value of this empty database should be set to false. Okay, so it's simple as that. And now inside our list fragment, we're going to implement the logic which will handle all of that. And basically, from our list fragment, we're going to observe this mutable life data. And whenever this value changes, then we're goingto do something, so you will see. Okay, so here first, let's initialize our a shared view model because our mutable life data is located inside its shared view model. So let's initialize that okay, down below, we're going to create observer. So So, like this empty database mutable like data object and let's observe that object. So is the first parameter just was this view lifecycle owner is ah, in the above example and ah, there's a second parameter just type observer. And as you can see, our empty database is basically a mutable ividata object with the type of bullion. The fourth value is true. So here we want to observe this value. And whenever that value changes, we want to create and cola this function named the show empty database views. Okay, And then let's create that function now. So what? Plus enter and quick create function all right. And they hear our function will have ah one parameter and that is bullion which will be named the empty database. So here we went to write if block So we're to say if empty database is true, then we want toe set in the visibility off those views image you and text butto visible. So let's get the reference of those views or no date aimed view. So send the visibility toe view not visible. And we're goingto do that the same for our second view, which is named the no data text for you. Okay. And the else If our empty database is false, then we want to set their visibility toe invisible. Okay, so, ah, whenever data changes Ah, for our anti database mutable live data object. We will. We will call this function, and we're going to set the visibility accordingly. So, uh, where should we change that value? Exactly. So inside our observer above where it says where we are observing, get old data. We're going toe call our share the model, and we're going to call this check if database empty and we're goingto pass our data or leased to the data. Whenever our data changes inside this get all date. Ah, live data object. Then we're going to call this. The ejaculated was empty. And if you recall this, check it database. Empty function is basically setting the value off our empty database. So if death data, which we passed earlier, is empty, we're going to return true. And if it's not empty, we're going to return false, and that's Ah, exactly how we're going to implement that function. So that a bellow we have this different observer and when that value value off our anti database changes were calling this show anti database views and setting the visibility off our views. So that's all you need to implement. And now let's try and delete everything from our database. So when you press yes, as you can see, the visibility of those two items is a visible. And when we add the new item in our database, for example, it's type new work and hear some random work. So let's add this to our database. And as you can see now, those two views are no longer visible, so our functionality works perfectly fine. And as you can see, when we remove that, we can see that those two views are again visible, so everything works perfectly fine. So we're using your live data, and we're observing the value of that mutable ividata from our list fragment and everything works fine. So that'll be all for this video 35. Introducing with Data Binding library: Hello there, and welcome back. So with this video, we're going to start using a data binding library in our project. So what is a data binding library? Well, enjoy. Data binding library is a very powerful support library, which makes it possible toe buying data to views in the clarity format using XML layouts instead off setting them programmatically. So ah, data binding library helps you deal with the Find your body in a more elegant way to reduce boilerplate code. But when he was the in its full power data binding library has many other benefits. So before you start using data binding, you need toe enable data binding from a great of scripts and by adding the following piece of code inside the enjoyed block off the module level building greater file. And if you're using Katelyn, you should also add that quoting kept plugging and for the dependency, you should add the dependency for enjoyed X and enabling data binding doesn't automatically generate binding implementations for all your layouts. So in order to let your library know that you want to implement a daytime biting for a specifically out, then you need to make some small changes in the layout. In order to let your library knows that you want to implement data binding for a specific layout, then you need to make some small changes in the layout file. So I suppose you have a layout like this. Just a simple constraint. Layout is the root element and some viewers inside. And then you will need to wrap this ruutli out inside the layout tags, and it will look something like this. You don't need to manually at this tag layout, Andrews told you, can automatically convert your layout toe data mining layout easily. You just need to click on your constraint layout element in this case and the press or plus enter, and you will see the option to convert data binding layout. This small change is enough for generating a binding class for this layout and binding the views inside. When you rebuild your project that enjoy studio will generate a binding implementation class for this layout and the name it by converting the name of the layout toe Paschal case and the adding abiding so fix. So, for instance, if the layout file is named the activity main XML, then the generated binding class will be named the activity main binding. And if your layout is named fragment least XML, then your binding class will be named the fragment list binding. So basically, it will also add this binding so fixed to your ah layout name. In orderto have access to these views from your courting code, you will need toe get the instance off the generated binding class, and it is recommended to get this instance while inflating the layout. So in most cases, you would want to convert your fragment layout, file to data binding layout and that you would write the code which will look something like this. But if you want to use it in activity, then it should look something like this. If your compiler cannot find that binding class, then you should probably just a rebuild your project and everything will work fine. Once you have an instance off your binding object, you will have the access to the views on that layout. As a properties off that binding object each, we will be named accordingly toe their view ideas converted toe a Paschal case. For instance, if you have a view with the idea off product. Underscore name. Then you can call it on your binding object like this. Suppose we have created our custom model class and we want to bind it with our data binding layout. Now, in most cases, in our data binding layout, we would have a data element tag and another variable element tag inside. And this variable element will have to actual roots our name and the type. So for the name we can specify a let's, say, a person. And for the type in most cases we want to choose the path off our model class. Suppose that we have a model class named the person and the our person Classic has two fields first and last name, then a type attribute on our variable element. We would type the full path off that class. For example, if the person classes a located in a package named Fragments, then we would write something like this condo to my app dot fragments, not person. Then from our activity or a fragment, we would want to bind this smaller class with our variable element from our layout file. And for that we would just you was already defined instance off a binding object. Get the reference off that variable name and the bind it with our model class. And now, from our data binding layout, we can just use this variable toe directly X. Is this a person class and its fields? So, for example, we can use it to set the text to our text view. But we need to follow the proper Syntex. So if you want oh, reference you're a variable fields, then you need to. It was the at sign with the curly brackets and inside that you would specify your variable . And this way we have avoided writing boilerplate codes in our fragment class and instead we have a specified the text directly on our text view. In this case, there are many more great things which we can Ah, you was from our data binding library, for example of binding adapters. So what are those? Are binding adapters. Well binding adapters are essentially just a regular functions annotated with the binding adapter annotation which can be used as a custom view Action boots in our layout file. Ah, very typical use case for the finding. The custom binding adapter is for loading images with guide or Picasso library, and that we can define a custom absolute, which takes the image, or l and the loads the image by using Glide or Picasso. And as you can see, binding adapter is just a simple function with the parameters. And the first parameter is the actual view on which we're going to use our custom binding adapter and that we don't need to specify it explicitly. And now we can apply that custom absolute on our imagery directly. Of course, this means that we have already created the variable with the name off model, for example, and that we have a binding that variable with some off our custom. Other classes which contains the image or L field in this case, and with the custom binding adapters that we can remove a lot off the border plate codes from our activities or fragments. And if you're still confused with the data binding library, don't worry, because it is normal to be confused if this is the first time you're hearing about data binding library. But I assure you that everything will make more sense in the next videos when we start using data binding library on the real practical examples 36. Data Binding for ListFragment: held there and the welcome back. So we're in the previous video. You'll learn something about the data binding and ah, binding adapters. So in this video, we're going to actually implement data binding in our project, and we're going to start first with our fragment least layout. So we're going to reduce the lines of code inside our list fragment as well. And you will see all the benefits in the in this data binding library. So, first, before we continue, you should check if you have all the necessary dependencies for data binding. And, ah, again, check if you should enable the data binding in your project. So watch one off my first video in the scores to see all the dependencies which we use in this project. Okay, so next what we need to do, we want to create a new class inside our fragments package, and this class will be named binding adapters. So inside this binding adapters, we're going to add a companion object, and this class will contain all the customer binding and actress for our product. And we want to create first function for our binding adapter. And let's name this function never get toe add fragment and there's the first perimeter. We're goingto pass floating extra button and the second parameter Just a simple buoyant Okay. And here dysfunction will be used to navigate from least fragment toe al fragment. So here I'm going to this view toe settle, click listener on our floating action button. And I will say, if this navigate bullion is true, then we want to navigate our user to add fragment. Okay, just import that. And after that, we need to annotate this function with two invitations on the first invitation is binding adapter, and the second invitation will be JV EMA static. So let's first at this binding adapter and here we need to pass the name off the attributes . So we're going to create a new custom attribute named the Navigate to add fragment and down below just at the this invitation give'em aesthetic. So this customer attribute will be used on our floating extra button. So when we tried toe type that the name off that function, we cannot see anything. And the reason why it's because the first we need to convert our layout to data binding layout So sad this constraint layout which is the root way out and the quick old plus enter and you will see an option here saying convert toe data binding layout. So select that, and you will see that now our route element is layout. And also we have this data element as well. So inside this data, we went to had a variable a little bit later. But for now, this is how it will look like. And now, when we try to type that custom binding adapter inside our floating action button, we are going to be able to see that. And here, just use a this ETH sign and in the brackets type true. Okay, So basically, now we're goingto be ableto navigate from list fragment toe ed fragment, and we can remove on click listener from our list Fragment. Okay, so now in list fragment, we cannot freely remove this own click listener because we don't need that anymore. We have implemented the data binding for that purpose. Okay, so we're going to use the and create another binding adapter here, but for now, let's check if everything works fine. So when repress our footing Extra button. As you can see, we are not navigated to our ad fragment and the reason why it's because we need to do one more thing. So we need to implement a data binding in our list fragment. So here, let's create a new variable with the name of binding and we want to set the other score a za first character. So this will be a type of fragment least binding, and the forth valley will be no. So this pregnant list binding is a automatically generated class for our fragment list class. Okay. And the down below, we're going to create another variable name binding. And basically this binding will get the value off our underscore binding from above. So here, inside our own creative you method, we want toe was in the initialize our binding. So let's see what this fragment least binding. And we want to inflate our layout. So just past the inflator container and the force is a total parameter so down below, Instead of this view, we need to return binding dot route. And we need to replace this view from a recycler view toe binding daughter recycler view. Okay. All right, so now we're going toe like this recycle of your court were going toe cut that and I'm going to create a new function named the set up for a SEC review. And now press Old plus center and let's create dysfunction. And here we're going toe paste, all our code for initializing our recycler view. So just a let's add fuel comments here. Here. I'm going to add one more comment for observing the live data. Okay. And now everything should be fine. And there is only one more thing. But it is a very important. So we need to override a method on destroy view and inside this method, willing to set the binding object to now. So whenever our fragment is destroyed, we need to set our binding to now. And this way we can avoid memory leaks. So this step is a very important and crucial. So be sure to remember that. And now we can run our application and you will see that we should be able to navigate toe add fragment this time. Okay, so you can see it. There works perfectly fine and we can remove the number off lines from our list fragment with our data binding. So it works very well. So the next thing we need to create another binding adapter. So this time I'm going to create a binding adapter for those image view and text view for no data. But first, we need to create a variable here named the shared View model in this very bill, Will this variable will be the type off shared view model. So just link that class. As you can see, this variable will be the type of shared view model. So inside our list fragment that we need toe we toe set this very both to our shared view model object from here from our least fragments. So just at that and you need toe, add also this life cycle owner, because now, from our shared view model, we're going to observe the value off empty database live data. And now, let's add for us this binding adapter. So the customer attributes should be named the Sunday like empty database. And that's at the Sadri VM static invitation as well. So the name of this function will be empty database and it will take viewers the first parameter. So this amputated this function will be was the own our image view and the text fuel. And the second perimeter is a mutable live data object with a type of a 1,000,000,000. So basically, with this biting adapter, we're going to observe a mutable iveta from our shared view model. Okay, so here we're going to say if or when empty database value is true. Then we want to set the view visibility toe visible. Okay. And when empty database value is false, then we want to set the view visibility toe invisible, and this binding adaptor will be used the on our image and our text you as well. So instead, off observing this beautiful, I've yet the object from least fragment. We're going to actually observe that from our layout. Okay. And we're going to remove a number off lines of code from our list fragment as well. So you will see. And also be sure to add this lifecycle owner from the binding because this way, we should be able tow actually observe our live date object. And if you don't have this life cycle over and then you might not be ableto observe. Ah, live data. So here, as in see, it all looks fine. and in our fragment lease layout, I'm going to add the new attribute here on our image view and the text view. So here, just get the reference off this variable and choose this empty database. Mutable. I've data object. So let's copy and paste that inside our text. You here as well. Okay. And this way we are going to observe those values from our fragment lease layout. And now, from our least pregnant, we can remove some codes from here so we can remove this observer which were upsetting empty database so we can remove that. And also we can remove method from down below named the show empty database views. So well, let's remove that. And here are Let's remove this okay and that. All right, so we no longer need those observers from our list fragment. Instead, we're going to observe the values from our fragment, least lay out. Everything should be working fine. So now we can run our application and check it out. So well, it's at the new item here. And let's see if those imagery and text you will disappear when we add the new item. Okay, So as you can see, it works fine. So let's remove or from our database so we can see if everything works fine as well. And as you can see now, those two views are visible, so everything works pretty much the same as previously. But now the only difference is that we have reduced the number off lines of cold from our list fragment. And we feel implemented the data binding to our project to our least fragment layout. And we are observing this empty database immutable live data object from our fragment lease layout. So everything works perfectly fine. And in the next video, we're going to implement a data binding on our fragment update play out as well. 37. Data Binding for UpdateFragment: Ah, hello there. And welcome back. So in the previous video, we have implemented data binding toe our least fragment. And also, we have created some custom binding adapters. And in this video, we're going to implement a data binding on our update fragment. Okay, So, uh, in this video, we're going to also create some custom binding adapter here. OK, And now let's close those classes. Accept binding adapter. We're going to leave that here, and let's open our update fragment and the update fragment layout as well. Okay, so first that what we're going to do, we're going to convert our fragment update. Ah, toe with data binding layout. So just click both plus enter here and click this convert toe data binding layout. Okay, so the root element will be a way out now and inside the date element, we want to add their variable. So the name of this variable will be ours. In the type of this variable will be Abdic fragment arcs. So, basically, we want to directly populate all our fields inside our fragment update from this variable. So before that, let's go to our update fragment and its implement a data binding here. So we're going to do that The same thing which we did in the previous video. So we're going to create this binding and that it will be the type off fragment public binding. So this class is automatically generated from a data binding library. Okay, so after that, inside our own creative you method, we're going to remove this view variable and women toe. Add the binding. So we're going to initialize our our data binding layout. So let's use this fragment update binding class, and let's inflate. Okay. All right. So next we want toe, get the reference of these arcs are variable from our fragment update, and we want to bind this variable with this arcs from above. Okay, so now from our fragment abjectly out, we're goingto be ableto directly. Get those values from these arcs, OK? And now down below. Just return binding dot route. And from here we can remove those views so we're not going toe populate those at the text and spinner from our Ablett fragment. Instead, we're going to do that from our layout and here, just replace this view with the binding and just find the idea of this priority spinner. Okay. And the down below. Don't forget toe override the method on the story of you. So this is a very important so set the data binding tonal. So whenever our fragment is destroyed, we want to remove ah or the reference from our binding. And that way we can avoid the memory leak. So this is a very important step. Okay, So from our fragment update layout, we can now set the text to our every text and we can populate in those fields. So here, when our first any taste, let's add a text attribute here, and we're going to use our arcs variable toe, get the reference off our current item and now extract the title. Okay. And this way we can directly extract the title and set on our every text. Okay? And we no longer need to do that inside our abbot fragment. And here on our description that it takes women to do the same thing. So get a description from the current item and for the spinner, it's going to be a little different. So ah, for the spinner, we need to create a custom binding adapter this time. So we need to open up binding adapters class and down below. We need to create a new function. So first, let's set a binding adeptly notation in this custom binding adaptor will be named the Paris priority. So that said this J V m static and let's create the functioning the purse Paris priority toe end. Okay, so let's ah, copy and paste this on the binding adapter as well. So we can have the same name. And here is the parameters. And so the first parameter will be spinner. Of course, because we're going to use this binding adapter own our spinner and there's a second perimeter. We want tohave our priority object. So we want to take priority object and well, we want to return an integer So we already have the similar function inside our shared remodel. So basically, we're going to do the same thing here with just a few more changes. So from our shared view, mother, we can remove now this function because we don't need that at the moment. And we're going to create that function inside our binding adapter. Okay, so here we want to create off when, So when priority is Ah, priority high on then we want to take this view, which is actually our spinner and we want to set the selection toe number zero. Okay. And when our priorities media, we want to set the selection when our spinner to number one. And for the priority low to number two. And that's all we need to do. So now from our layout, we're goingto added this attribute Name the powers priority to end and everything will work . Fine. Okay, so here, just add that. And here we need to pass our priority object, which we're going to extract from our current item. And that's what we need to do. It came. So basically we are taking priority and we're setting the selection accordingly. Okay, so now I think we could run our application and check if everything works fine, so everything should work as before. It's just that we have implemented the data buying this time. So let's just add one item so we can actually navigate to our abject fragment. And when we never get to our Ablett fragment, all our fields there will be populated as before, so I can see everything works fine as before. We have just implemented our data binding and reduced some number off alliance inside our update fragment. So that will be all for this video. So we have implemented the data binding toe our least fragment and to our update fragment and the in the next video, I'm going to show you how to implement the data binding to your recycle view adapter or, in this case, a list adapter. And we're going to add the data binding layout to our custom rolling out. So you will see and the little bill for this video. 38. Data Binding for ListAdapter: Ah, hello there and the welcome back. So we're in the previous videos, we have implemented a data binding toe our least fragment into our update fragment as well . So ah, that Ola is working perfectly fine. And in this video, I'm going to show you how to implement data binding toe a recycler view adapter or, in this case, to our least adapter. And it's going to be a little bit different. But don't worry, it's not hard. I'm going to show you how to do that. So let's close all of that and let's open up our least adapter and let's open our rolling out, which is used inside our list adapter. Okay, So first, what we're going to do, we want to change our data binding layout. So inside our rolling out click what? Plus center and converters toe data binding layout. So our layout will have one variable named the total data, and this variable will hear the type off to date. Of course. So just get the reference off this class. Okay, So Ah, that's fine. For now. Open up. Least adapter. And okay. So we can make this data like they released Private. We for Goto that previously. But that's OK. So here inside our my view holder class, we want to replace this view with the binding. Okay, So just create a private vault binding and type Perot layout binding. So this class is automatically generated by our data binding library because we have converted our rolling out dough data binding layout and here, just past binding dot route. OK, so inside our my view holder class, we're going to create two functions. So the first function will be named the bind and it will take a total data a za parameter and inside were going toe bind the our to do data variable with this tool data from the parameters. OK, and we want to call this method name the execute pending bindings. So basically, this will update our views in our rolling out. So that's all we need toe. No. For that and the Belo dysfunction, we're going to create a companion object, and we're going to create a functions in function inside named their from And it will take a view group as a parameter and it will return my view holder. Okay, so here inside, we want to inflate the layout. So let's create variable name the layout inflater in the here unit Topaz. The context. So Justin's parents together context and the down below we need to create a binding are variable. And basically, we're meant he was a role layout binding toe inflate the layout. And now we need to return my view. Holder. So now let's see, Was this binding is a parameter okay. And the next inside our own creative you holder, we're going to remove everything and we're going to return my view holder dot from because we're going to use from metal, which we just created, and we're going to pass a parent here, and that's all we need toe enter inside this method. Okay, so basically, this will return our inflated layout, and that's it. Okay, so a down below inside our own buying view holder, we're going to remove everything from here, so select all of that and we're going toe to replace this with just two lines of code so removed that and here, we're going to create Ah, new variable name the current item and this variable will have the type off total data. So we're going to get our total data dynamically from our data list. And we're going to use Holder and the women toe Call this bind the function from above and we're going to pass this current item, which is actually a total date object. And, as you can see, inside our bind function were basically binding our variable from our layout with the total data object which we have in our parameter. And we have passed that to date object from our own buying view holder. Okay, so our least adapter is now ready. And next open up a rolling out, and here we're going to use this to the data variable. So inside, those two text views were going to do with our variable. So here, just really that and the type at and open up the brackets and type total data dot stifle. So we're going to extract the title from our total data variable and down below. For the description, we're going to do the same thing, so just call this variable and select description. Okay? So for our card view are our priority indicator is goingto be a little bit different. So in this case, we need to create our custom binding adapter. So just never gave toe our binding adapter class. And here we're going to create a new binding adapter. So, uh, let's create this invitation and we're going toe type here. Ah, powers, Priority caller. Okay. And down below, Just at this jbm static And let's create a new function Name the priority Prosperity Caller . And this will have ah card view as a parameter because we went through this attribute on our card view and the second perimeter is priority object. So inside dysfunction we're goingto say when priority object is priority high. Then we want to change the carve. You cut background color to red So let's use the card. You object here together context and get the core So select Qala red, OK, And just copy this line of court two more times and change this to medium and they stole Oh , and the color to yellow and green. Okay, so basically, women toe Paris our priority object, and we're going to set the color to our card view accordingly. Okay, so here, let's open our rolling out in here. Let's added that actually good. So Paris Priority caller And here just you was this total variable and just past the priority. Okay. And our binding adaptor will do the rest. Okay. And there is only one more binding adapter which I want to add, and that this binding adaptor will basically navigate our user from least fragment to update fragment. So let's name this banning gay adapter. Send data to update fragment and ah, okay, let's great that function. So we're going to have two parameters. The first is constraint layout. Because we're going to do with this attribute on constraint layout. And the second parameter is a total data object. OK, eso here, we're going to use our constantly out in set on click listener. So whenever we ah, step on our item, we want to create a new action. So we went through. Is this a list framing directions so we can actually send our to do data object to our Abit fragment? Okay. And down below you is the view and just find never controller and navigate to our action, which we specified above. Okay, so here we can add the android in front of that. So this is just my personal preference, but you can do it your own way, and now we will be able to navigate our update fragment, and we're going to pass our total data object as well. So open up our rolling out. And when our constraints the outlets at that new actually boot or a new custom binding adapter. And here we're going tojust based our our variable toe daytime. Okay, so that's all we need to do. And now, basically, whenever we select one off those items from our cycle of you were going to navigate toe update fragment and we're going toe pass our to the data object as well. So everything is ready. Everything is fine here. So we have added everything we need toe in our list adapter, and our least adapter looks away better now, so we don't have ah, lots of code there. And now let's Ah, let's first try an add one item here. So let's create new white and let's right the title here for us. Okay, select low priority. And they're just type some random text here and you will see now, as you can see, everything works fine. Inside our a cycle of you, we can see the Priority Qala as well. So it is parsed nicely. And when we select one of those items were navigated to our A bit fragments. So everything works fine. And as before, so we could be implemented our data buying to our site of your adapter. And in the previous video, we have implemented the data binding to our least and a bit fragment as well. So everything works fine, and that will be all for this video. 39. Add ItemTouchHelper Callbacks: Hello there and welcome back. So in this video, I'm going to show you help to implement swipe to the right functions. So we're toe make our cycle of you items swipe, herbal. And whenever we swipe our item on the left side, we're going to remove that item from the database. So we're going to do that with help off item touch helper class. So first, let's create a new package inside our least package named the adapter and the inside this package, we want to place our recycle view adapter so we can make a clean architecture here. Okay, so, inside a release package, we need to create a new class, and this class will have the name off, swipe toe the lead. Okay, so this class will be an abstract class. So let's at this keyboard in front of that, and we're going to extend the class. Name the item. Touch helper. Not simple call back. So here we need to add the two parameters. So the first perimeter is a zero because we're not going toe use that this drag were going toe only use a swipe. So for the second parameter, just other. I didn't touch, help or that left Because we're going toe swipe our items on the left and the inside this class we're going toe override the two methods on move and own swiped. So this own moved on will return force because we're not going to use this method. We don't need to move our items. We need to swipe them. So we're going to just It was this own swiped, okay. And the inside our list fragment, we're going to create a new function just below our set up recycle view. So let's name this function swipe to the late, and this function will have a one parameter, and that is a recycle review. So inside we're going to create a new variable name, the swipe to delete call back. And they were going to initialize our a swipe to the late. Okay. And here were in tow, override method on Swiped. So just press control all and the here, inside our own swiped we're going to create a new variable named the item to delete. And basically, in this variable, we're going to store our item that we are currently swiping. So we're going to do that with the help off adapter. So just passed this data list and women to get our item dynamically using view holder daughter at that position. And they load that women to call our delicate item a query. And we're going to pass our item to the late and we will display just a simple message off our success. So, basically, inside our own spiked method, we're storing our current item, which we are actually swiping inside this item to the late and we're passing that total data object inside our deal. It item okay. And we're basically deleting our I think, from the database. All right, so we're goingto do one more thing. So just below our this swipe, we're it. Quebec were going toe create a variable name the item Touch helper, and we're going toe pass our swipe to the elite call back here. Okay? And just below that we went to was a method called attached to recycler view. And we're going to pass our a cycle of you hear from our parameters. And then we went to call this function inside this set up recycler view, and we're going to pass the recycler. You Okay? So that's all we are going to do and basically, with this, we're going to be able to swipe our recycle of your items. So from our swiped delete, we can now actually remove this one swipe because we can override this method inside our list. Fragment. Okay, so, Well, it's run now. Our application. And let's see if everything is gonna work fine so it can see our items are a swipe a ball. And when we swipe our item, we will get that those message saying successfully removed and the title off our current recycle rewriting. And it's going to see it works perfectly fine. So you might wondering, Why have we created this swiped relate class? Well, because we need toe override those two methods on move and on swiped Because if we over I dressed one method, we're going to get an error because our item touched the upper class needs to extend both of those methods. And I don't want to crowd this a list fragment with those two methods. I just want toe create a new class which will hold this one move method and that that's why I have separated this and the next video. I'm going to show you how to restore deleted item when we slide that 40. Undo - Restore Deleted Item: hell there and the welcome back. So in the previous video you saw that we have implemented swipe to the late function So now our recycler view items are asswipe herbal. And in this video I'm going to show you how toe implement, redo or restore deleted item. So I went wear the just the two random items inside our cycle of you. Okay. And here in our least pregnant, we're going to create a new function named the Restore Deleted data and the dysfunction will take three parameters. So the first perimeter is a view object. The second parameter is a total data object. And we're going to name this. Ah, the heated item. Okay. And the third perimeter will be actually position position in Ah, recycle you. Okay, so basically, this function will display a snack bar message and they were going to create a snake bar object. So here we need to pass the three parameters. The first perimeter is a view object, and we're passing the view from the parameters. On the second parameter is the actual message. So we're going to type deleted in the title off our deleted item. Okay. And the third parameter is actually adoration. So women set a duration toe length along okay and down below. We're going to create an action button on top off our A snag power. So you was this a set? Action mattered. And let's name this button, Ondo. So whenever we press this and do we want to insert back that deleted item? So just call this incident date. Ah, metal from our total view model in the past, the lead item. And we want to use our adapter and notify our a cycle of you about those changes. Okay, so we're going to also notify our adopter about changes from our own swipe their method. So just call this notify item removed and passed this of you Holder daughter adapter position. Okay, so here, we're going to call our restore deleted data function, and we're going toe pass. Ah, eso Let's use this view holder daughter item view. So women Topaz. The first parameter view, the second parameter is a deleted item. So I'm going to remove this a variable named item to delete toe ah deleted item so it can look better and it will make more sense and just replace those variables as well. So let's spend this nearly three item and the perimeter will be actual position. So we're going to use this view holder to get their current adapter position off Swipe herbal item. Okay. And, uh, now I'm going to just at this common here saying daily Titan. So whenever user swipes some of the item from the recycler view, we're goingto basically delete their tight them. And we want to display a snack bar message saying deleted that that item. And we would also said this Ando buttons whenever I user clicks and do, we're goingto basically restored that the same deleted item. Okay, so we need to add this snake bear dot show. So we need to show our a snack bar and they were going to remove this toast message because we don't need that anymore. We have our messaging side, our snack bar, so Well, it's a run our application and see, how will this work? So let's try and swipe this item on the left and that you will see a snake bar message saying and deleted in the title of that item. And when we press and do as you can see, we can undo and restore that same item in the same position and that this function works perfectly fine. So that will be all for this video. 41. Implement DiffUtil: Hello there and welcome back. So in this video, I'm going to show you how to implement the futile to your ah recycler view. So what is the deputy? Well, this is a class, and it finds the difference between the two lists and it provides the updated list is an output. So this class is used to notify updates toe a recycler view adapter. Okay, so you already know that inside our least adapter in a set of data function, we have added a method called the notified data set changed, and that this method is used to notify our a cycle of you that the data has changed and the true the refresh or update its items. And the main problem with the notify data set change. The method is that it's a big overkill for a performance. So how is that possible? Well, notify data set changed is updating all the views inside our recycler view whenever recall it. So it doesn't matter that you have only updated the single item and not 10 of them. This method will update the whole list all over again so you can see why this is a problem . But don't worry With the futile class, we will be able to fix this. And as I already mentioned and if you tell, will calculate the difference between our old and annual list. And if it detects that the only difference between those two lists is a just one single item, then it will send the update only for that one single item and not for all recycle of your list. So bottom line D futile is a huge benefit for our application performance. Okay, so before we start implementing the futile, I just want to fix that one a small issue. So when we run our application, you will see that in a blink off a second we saw those two no data. You always imagery and text view, which shows the no data, and we need to fix that. Okay, so it's very easy. Just goto shared view model and change the default value off this empty database. Mutable. Live data from true to false. Okay. And this will fix that issue. So whenever we run our application, we will no longer see those two views in a blink of a second. So I can see this time it works perfectly fine. Okay, So next we're going to create our D futile class. So inside the list package and inside the debtor package, we're going to create our new quoting class, and we're going to name this class to do the futile. So this is class that is located inside our adapter package because the futile is going to be used along with the list adapter. So this class will have a two parameters, old list and new list, and those two variables will have the type off a list off total data objects. Okay. And then you list as well, So this class will extend. The deputy will call back. Okay, so here inside our class, willing to override four different methods. So we have four different methods. And let me just introduce you with those for so the 1st 1 get old list size basically returns the size of the old list which were specified in the parameters and get new lease returns the size off a new least, which was specified in the parameters as well. On the 3rd 1 Our items the same. It is called by the Defu tilt to the side whether to object represent the same item. And if your items have unique ideas, this method should check their i d equal t and the only if this third the method returns true. Then the fourth method will be called our contents the same. So basically it checks whether two items have the same data and you can change its behavior depending on your you. I on this method is called by D futile only if our items the same returned true. So if the start metal return is true, then this method will be caught. Okay, otherwise it will not be called. Okay, so now let's implement those for methods. All right, so let's first start with those and get old list and get no list size. So just to return the size of the old list here. Okay, so old list dot size. Okay. And just specify the return, of course. And here return the sides off a newest and that's all for those two methods. So I'm going to cut those two methods and place them on the top. Okay, it will better this way for me now our items the same. So this method is returning a bullion so we need to compare our or list in the new list toe find if those lists are the same so past this old lighting position dynamically. So we're using a triple equal sign, and that means that it will basically check if those two items are identical. And as you can see, basically this class is called by the futile to decide whether to object represent the same item. Only when that this method the returns true, then we're going to call our our content are contents the same method. And this method should check the contents from our lists. So we're going to check the title I d description and the priority object as well. Okay, so this method return is bullion as well. So we need to return from boy and as well. So let's compare those toe those contents between those two lists. So I'm going through his old list and the past this position dynamically and And we used the i d. And it's compared those tourists i d. So don't I d now. I'm going to this end. Ah, operator. So I'm going to say now title so only if all of those contents or data from our to the data . Objects are the same for both of those lists. Then this least then this method will return true. Otherwise it will. It will return false. So only if I d title description and priority for both of those lists are equal. Then this method will return true. Otherwise it will return a false okay. And this is my personal way off implementing those for methods. There might be an easier way, but this is my personal preference. So that's already to do for our deputy, our callback class. Okay, so let's get to our least adapter and scroll down until we find the our method the second later. And inside this second later, we're going to implement our different deal, and we're going to remove this notify data set changed and and instead of this method we're going to is a method from our different deal. So you will see for now, let's create our Toto difficult objects. So let's initialize that and it's pasa toe items. So the all list is actually the least from our list adapter, and the new list is the list which we pass to our settle later function is a parameter, okay? And we're passing that parameter inside our list fragment. So next I'm going to create a new variable name the Todo def result, and I'm going to use a d futile toe. Calculate the difference between those toe lists. So I'm going to pass our totally futile object here, and it will calculate the difference and see if those two lists are the same and which items are not the same and so on and below that I'm going to call this dispatch updates to method. And I'm going to pass this because this is actually our list adapter. And that's how we removed. They said, change the method and we share implemented the d futile, and now our application performance will be a lot better. So that's all you need to do to implement at the futile. And now we can run our application and everything should be the same as ah, previously. But only this time our application performance is ah, lot better. So that will be all for this video 42. Add Animation to RecyclerView: Hello there and welcome back. So in this video, I'm going to show you helped implement different animations to your recycler view. So as you can see, even when we insert update or delete items from our database, we don't see any animation inside our a cycle of you. So even when we swipe our item, we just see this blinking effect in one second. And that's all. So what, we need to change that and for that purpose is we're going to use already made the library for recycle view animations. And it's made by a guy named there wasa beef so you can see them below. We can change the demo and see what kind off animations were having this library. So there are so many animations in this library, and you can check all of them by yourself. But in this video, I'm going to show you only the two of them. So before we start the unit to check if you have the correct repositories in your enjoy studio products, so check for this Movil Injuries Central and the truck. If you have already added this dependency for this recycle of your animation, okay, so down below. Also, you can see how it easy toe how it sees it toe implement this animation. You just need to use this item animator on your respective you object and they're just passed This a custom made animation down below We can see that you might need to call those notify item changed or ah those similar methods but that's not always necessary. But nevertheless I have already added the two of those methods inside the product and the dam below. You also can apply the different generations for your animations. So this customization is pretty much good quality. So down below has been seeing our product inside our site set up recycle of you were going to call this item animator and women toe past this custom made animation It's going to see there are many different animations But I'm going to use this slide in up animator and I'm going to apply adoration off 300 milliseconds so it can change this by ourselves. But this is just an example of course. Okay, so down below you can see those and notify item removed and notify item changed which we have added in the previous videos you don't have to add those those methods. But this library says that we might need them. You know, this animation toe work. So that's why I have added those two methods. And now let's check this animation inside our application, so I wouldn't try to swipe our item. As you can see, this is the animation which we will get. So our items site are coming from the from the bottom. And this animation looks very nice. Okay, so I'm going to change the different animation to show you one more. This is Theis Animation is named the Landing Animator. And you can check by yourself the whole documentation for this library to see more of those animations. But this is just an example. This one looks very nice as well. Okay, let's just add a new item here. Okay, let's set it. And as you can see, we have this animation works very fine. So I'm going to change this previously because I like the previous one even better. And I want to leave this sliding up animator. Okay, so that's a bill for this video 43. Search the Database: Hello there and welcome back. So in this video, I'm going to show you how to implement search function to your application. So basically, we want to be able to search through our database and that this play results inside the recycler view. So basically, when we start typing, we want to see immediately results inside our a cycle of you. So that's what we're going to implement this video. So first we need to open up our Dow our view model and repository as well, because we're going to create a new query for a searching. Okay, So open up, Dow interface. And here, let's create a new function named the Search Database. So this function will accept only one parameter. And that is a search query off type of string, OK? And that this function will return at least off total data objects inside the A live data. OK, All right. So this function should be annotated with a query annotation, and here we're going to write a custom annotation for searching our database. So I'm going to write something like select all from and our table name. So select a where the title, because we're going to search our title column where the title alike and we're going to pass this parameter from our function. Okay, so just use a column here, toe toe past this parameter from our function. And if you don't know what this is like operator means basically it is used nowhere close to search for a specified better in a corn. And you can combine this like operator with the percentage sign or with the underscore sign . And in this case, we're going to combine that with the under with the percentage, um, sign. And basically, this is how we're going to use that. So we went to use the 2% signs and inside those inside those science, we're going toe paste, our search query. So you will see. For now, let's open up a repository in here. Let's create the new function as well. So this function will be named the same so social database and this function will return least off to the data. Objects are wrapped in a live date object as well. Okay and goingto pass Ah parameter here. So let's return on Go thou and it's called a certain database and reto also add the parameter search query off a type string. Okay, and let's pass this query here. So now it's open up our view model, and here, let's create an your function as well. So let's name dysfunctional search database as well. So past this search query is a type of string and just return. Okay, this list of through data wrapped in a live data and the oh it's returned this search database and passed the query. Okay, so now that we have created that we can close this view, model and repository as well and let's open up our least fragment and our least fragment should implement one interface named the Search Your Daughter on a query text listener, and this interface demands that we need to implement or override toe methods. One query, text submit and on query text changed. So let's implement those two methods and the 1st 1 on query text submits will trigger when we type of text and press enter in. Our search for you in the 2nd 1 will be basically triggered whenever we start typing something inside our search widget. So I'm going to change this the name of this parameter to query because this is actually a query, which we went toe type inside our search bar. And they're willing to check if this square is not know, so only if this square is not know. We're going to call one new method named the search through a database, and we're going to create this method immediately. So enabling Topaz. This query is a parameter. Okay, so let's create dysfunction. All right, so let's just cut and paste this function below our own query text changed your method. Okay, It looks even better this way. And we need to return true, just okay. And that's all. So basically, when we start typing inside, our search of injured were going toe check. If this square is not know and only if it is not know we're going to call this function. So just copy paste that same quote inside this on quit exchanged method and inside our new function search through a database willing to create a variable named query, and we're going to store our query from the parameters inside in here. We're going toe past this query between those percentages symbols. Okay, so this step is a very important because this is the Texter, which we want to pass inside our query, which we have created. So now, inside our search database query past this search query and we want to observed It's alive , Gator. So at the Observer. And ah, okay, I'm going to name this list of to the data as a list. And whenever a data changes, or whenever we start typing something inside our search widget, this observer will be notified. And basically, we want to notify our recycle your adapter with the changes. So we need to pass our to the data object here, and that's all. So whenever we started typing inside our search bar, we're going to trigger this observer, and the Observer will notify our recycle of your adapter about new changes, and that's all. So remember, toe pass this query between those percentage symbols because that's why, and that's how we are going to be able to search through our database easily. If you don't know about the SQL query is, I highly suggest you to check some of the the documentation on W three school. You have, ah, great documentation and tutorials out there about SQL. Query is So now let's ah, let's Ah, go to our own create options many. And here we need to just add one more thing. So we need to find our menu item and just type the idea off our search manual so that the the idea is a menu surge. But we can double check that to make sure that this is the right I d. So open up this least fragment menu. And as you can see, this is the same exact menu idea. So manual search and the Dambulla we're going to create another variable name, the search for you. And basically, we want to convert our search menu item toe toe, an action of you off search view. So just type search, not the action view as. And OK, so the question might goes here So as search view and now this search of your which it can be yours, toe said the listener and call a method named is Submit Button enabled. So just best true here and the down below we're going to send the listener. So said the query text listener and just passed through this in the parameter because we have already implemented this listener inside our list fragment class, so you can see There it is. And now we can run our application and see if everything works fine. So basically inside our own create options, many we have, Ah, said the inquiry text listener to our search for you. And then we have implemented those two methods on query, text, submit and on quite exchange. And whenever we start typing something inside our search widget or when we type something in press enter, we're going to call this search through a database function, and that function will convert that string in tow. This starting with this percentage simple, surround and debts. And that's the exact string which we want to pass inside our search database function. So, as you can see, our search query needs to be inside those percentages. Ah, symbols to work. So now let's try this again. So, as you can see, this is, this means that it will find any values that you have this text in any position so well, it's run our application and see if everything's gonna work. Fine. So click this search icon and start typing. Okay? So when nothing happens and I think I know why we have this issue. So it happened to me one more time. And so we need to change our import. And so, as you can see, we have our enjoyed dot rigid daughter search view. And we need to replace this with android x dot com Pit that widget dot search for you. Okay, so this is the right import we need for our search view with the Android X library, and now our application should work. Fine. Okay, So I need one more thing toe change, so we can change those two lines in one, and I'm going to just copy, cut this and paste up here, and I can pass this query directly, hearing our first line. Okay? And I can just change this volatile while, okay? And he talks even better. So let's around our application again. And let's see if our search function will work this time. So click on the search rigid and start typing. And as you can see, it works perfectly. Fine s so basically we're searching through our, uh, titles and for example, it's type new in, As you can see, we're in tow only. See the items that contains this new keyword inside the title. And when we stop start typing title it was It will search the titles only so on your title as agency. So everything works perfectly fine and the little bill for this figure. 44. Sort Data in RecyclerView: Ah, hello there and welcome back. So in the previous video, we have implemented the search functions so that function works perfectly fine as against C . And in this video, I'm going to show you how we can sort our items from the database from the priority high end from the priority low. So we already have a menu items for that. So, as you can see, we have this sort by priority, high and sold by private Dillo. So we're going to implement those two functions. So first we need to open our dow and willing to create to custom queries for a searching through our database and sorting our items. So here, let's name our first function soared by high priority and the dysfunction will not hear any parameters. It will just return least off to the data objects wrapped in a light data. OK, so it will have a custom query and it will be a little bit longer, but don't worry. So we need toe type select all from the table name and the order by so case when our priority and ah, like I went through this like word again and here in this single quotes. I'm goingto passed this ah percentage symbol. And in front of this percentage symbol, I'm going to write the character age, which is the first character off our high priority, and I'm going to type then one on. And that means that I want to return this high priority results first, and the one priority like and then I'm going to return those searches is the second and final. I want to return low priority results. So basically Theis percentage symbol and with the character in front of that means that it will search for the for the priorities which starts with that character. So, as you can see, let's check this documentation again, so down below you will see, like operator in description. So, as you can see, it means that it will find any value that starts with the word that we have typed in front of this percentage symbol. And basically, this is how we're going to be able to search through our database in this play, our high priority items first, then our medium priorities. Then it led at least our low priorities final, and now we're going to create another query. And this time I'm going to just copy and paste the same thing in just ah replaced this high with the low and ah, here I'm to say, low first than medium and in the end, high priority items and that this will sort our items from the low to the highest. And basically, that's it for our queries. So inside our repository, I'm going to create two variables named the sort by high priority and soared by a low priority. So those two variables will have the type of least off to date objects wrapped in a live data. And I'm going to call those queries from our doll. Okay, so do the same thing from our sorted by. Low priority just changed the function. Okay, so now from our view model here, we're going toe create the new variables as well. So pretty much the exact thing as our get all data variable. So just said the type off least off to the data wrapped in live data and willing to initialize this those two variables. But first, let's at this sword by low priority. And here it's initialized those by calling the repository and those functions for from the repository Okay, so you might see this. Ah, a message that those can be private, but we're not going to make those variables private because we're going to use them from our list fragment and the, you know, released fragment. We're going toe use this own option sytem selected. And we want to change this if Brooke toe when? So when Item I d. Is equal. For example, this menu did it world. And we're going to call this confirmed removal and that when our menu item I d. Is priority high as can see this those are the exact same ideas from our menu. Ah, layout and ah, when we step on this man, apparently high. And then we want toe call this sword by high priority from our view model And we want to observe that live date them so called the Observer. And we need to notify our recycle video adapter on each of those changes. So, basically, whenever we tap on our property already sort manual, then we're going toe call this observer and we're going to observe the changes. And when and whenever we tap on that we're going toe, call the adapter and the update our cycle view items, so that's pretty much it. And now let's start our application and see if this is gonna work fine. So before we actually lounge those sort functions, let's add some items, some more items to our database. So I'm going toe have ah toe items for each priority Soto items for high priority toe items for ah, medium priority in that whitens for ah, low priority as well. So just type some random here, OK, and now let's say you was our sort functions. So let's first sort by priority high. And as you can see first in our list, we can see all the items with the high priority, then with the medium priority and finally with a low priority. Let's try it now with the low priority so it can see it works exactly the same, so it works perfectly fine and that will be all for this video 45. Apply Different Layout on RecyclerView: Ah, hell there and the welcome back. So in this video, I'm going to show how we can change your a recycler view layout. So from the start of this course, I have used the only linear layout for our recycle view. And now I'm going to show you how you can apply a great lay out in the stage of the great layout as well. So do that. We just need to change one line of code and go inside this set up recycler view method and just change this cell in your layout. Manager to greet layout manager If you're willing to pass the one more parameter and that is ah, spend count. So basically the count off the cones for greens and I want to type the number two. So let's run our application and see how will this look like? So, as you can see now, we have our agreed layout and it looks very nice. So we cant even sort our items and that they will look amazing. So there is only one issue with this really out. So, for example, if one of those items have ah longer description and bigger height, so let's see, How will that look? As you can see, when some of those items have a bigger height, then, Ah, our other column will be kind of different. We're going to have this blank space on top, on and on the bottom. So how can we change that? Well, we can change that. Using a different layout manager and rhythmically was a stage of degree layout manager. So this will fix that issue. So let's change this great layout toe stage greatly out Manager. And here is the first perimeter willing to pass a span count. So the first perimeter will be, too. And the second perimeter will be the orientation off our stated Gridley off manager. So is the the orientation. We're going to vertical. So type stager, the great layout manager dot Vertical. And now let's run our application and see if this is going to fix our issue. Okay. And now, as you can see, we don't We no longer see that the blank space between our items and we can increase the height off our items as much as we want. Our layout will not change, and it will look amazing all the time. And, uh this layout kinda reminds me off. We will keep application. And this layout is also a good way. So you can use any layout manager you want. That's on you. And now you learn how to you that. 46. Final word: Wow. So you came. Ah, long way. If you're watching this video, there were a lot of information to process throughout the scores. And you watching this video means that you were strongly motivated to learn and improve more. As an android developer, I must congratulate you for that. You need to keep in mind that the most important thing is a developer is a strong will for permanent education and the continual learning. We, as a enjoy developers, must adapt toe constant changes in the world off mobile apps. Basically, every day there are some new things libraries which are introduced, and we need to keep reading a learning every day. You must keep practicing every day. Only that way you can become a good developer. So I have invested a lot of my time and effort in planning, organizing, recording, editing and generally preparing this course for you so that you can learn all of this in only three or four hours. And I've spent a lot off more time in a researching, practicing and experimenting before I started making a course. So I would like to hear your feedback. And if you keep any critics suggestions feel free to send me a message. And if I missed to explain some topic which you might find it hard to understand, then please let me know and I will create an uploaded a new video here for that purpose. So that would be all for this course. And you can keep practicing on this application by improving it. Furthermore, the EP, which we have developed during the scores, has ah lot more room for improvement. And I would like to see how you would improve this app. So if you will create a better version with some extra additional functionalities, I would love to check out. 47. #1 Staggered Grid Layout | Undo function App crash - Fixed: Hello there and welcome to my first video in by hunting series for this course. So this is a new section in which I'm going to read your reports on a different kind of bugs in this application. And then we're going to fix them together one by one. So the first report either received from Ali quad dummy. I don't know if I pronounced that correctly. So the bike is connected with the staggered grid layout only. And when we swipe to delete one item from a stage or the grid layout, it works. But when we click the Undo button on our snag br, our application crashes. So our application crashes even though the item is restored successfully. And then we get an error array index out of range minus1. So now let's open up our project and let's fix that. Okay, so first, let's open up our application and let's see how this bag will occur. So let's swipe that. Let's clean this undo. And as you can see, our application crashes. So when we check our logcat, we will see this message saying array index out of range minus1. So basically what we need to do, we need to remove just one line of code inside or at least fragment. And you will see. So down below scroll until you find the method or a function called the restore deleted data. And here we need to remove this adapter notify item changed. So the only reason why I have added this line of code is because in, in third-party library for recycler view animation. And it says that we need to add this notify item changed in order this animation for work. But still, even without this line of code, our n-dimensional will work fine. So let's run our application and let's see if this bug Wheeler occur now. So let's swipe this item on the left. Okay, click Undo. And as you can see, our application is working perfectly fine, so we have removed that bug. Okay, let's say Kandel once more again and it works fine. So the next thing, what they want to do, I want to commit the changes and the update my GitHub repository. So I'm going to commit the changes first. So as you can see here, we can see all those blue files are files that are marked with a blue color. Those are the files which we have changed. So I have already updated the build Gradle file, that dependency from 4002 or four or one. And here, let's first create a new commit message. So I'm going to just say, and all function on the staggered grid layout which caused app crash is now fixed. And when they click, I will see that there are some warnings here. So let's review those warnings. And down below, let's double-click on this warning and it will show us immediately where is the warnings. So here of course, we do not need this position anymore, so let's remove that. And let's remove this parameter from above as well. So just to remove that, and now we have successfully removed all those warnings. So let's try and commit our files. So once more, archaic Greek commits and justly this committee button, so there should not be any warnings anymore. Okay, and we can see this success message. So now that our files are committed, now we need that to push this update to our, to my GitHub repository. So I'm going to select this push, ok, and here you can see all the files which are committed and just click push. And the wait until enjoy studio update is GitHub repository. And there you go. So let's open up our GitHub repository. And let's see, I went to refresh this page so we can see the updates. And as you can see, our repository is now successfully updated. So now you can check that out and you can download this new update, and that's it for this video, we have fixed this arrow successfully. 48. #2 Title overlap with Priority indicator - Fixed: Hello there and welcome to my second video in this bug hunting series where the scores, so the second report I received from a username there, just Brit. And here we actually have a tour reports. One is associated with the title overlapping with a priority indicator and the other associated with the software keyboard. So in this current video, we're going to focus on the title overlapping with the priority in their getter. And in the next video we're going to fix software keyboard issue as well. Okay, and here I have opened the project and now I'm going to run this application in the emulator so I can show you the, the issue. So here we just have a for different items in our database and let's add a new one. But this new one will have a little bit longer title than usual. So this title or will be longer than 20 characters. And let's type some random description here, okay? And let's add it. And here as you can see, our title is overlapping with the priority indicator and that we cannot see the whole title. So the reason why we cannot see the whole Python is because I feel settled the next character length to 20 on this text view. So I'm going to remove that. And now let's run our application. And there we should be able to see the whole title. Okay? And now we can see the full title, but still our title is overlapping with our priority indicator. So next unit, torque on this row layout and select this title text. So now we need to connect the right constraint to the left constraint of this priority indicator. And they're willing to set the layout width to match constraint or 0 dp. And let's set the right constraints to 16. Okay, so let's run our application and see if this will fix our bug. Now. Okay, and now as you can see, our title is no longer overlapping with this priority indicator, and now everything looks fine. So we can fix this second bug as well. And now I just want to committing those changes and uploading those new trainers to my GitHub repository. So I'm going to commit this change and here I want to write a different message. So are something like title overlapping with priority indicator fixed r, k. And now I'm going to click Commit. So here I have a one warning and let me double click on that. So in this row layout, I need to remove this unused their namespace. So I'm going to just remove this one line of code. And now when I click Commit, everything should work fine. Ok, and that was a successful. So now I want to push this project on GitHub. Oh, okay. Okay, just, I'm going to just clean this merge button here. And our GitHub repository is now updated. So now you can go to this link and you can check this repository by yourself or you can do with a change in your own project. 49. #3 Software keyboard issues - Fixed: Hello there and welcome to my third video in this bug hunting series. So this is actually a report from a previous video where we have a fixed bug associated with a title overlapping with the priority indicator. And in this video we're going to fix a bug associated with the software keyboard. So the reason why I haven't noticed that this bug earlier is there because I have the same old software keyboard in my Android emulator device. But now I'm going to enable it again and show you how it affects our application. So basically, when we focus our input fields, software keyboard will show up and it will move all our viewers on the top or outside of the screen. Plus, when a software keyboard is visible and we navigate back to list fragment, software keyboard does not disappear it now, let's fix that. Okay, so this is our project and as you can see now we have fixed than the previous burger are associated with the title overlapping with the priority indicator. So now let's navigate to this add fragments or select this floating action button. And here let's select this input field. And now as you can see, our software keyboard is shown up, but our views are pushed on the top. And that's a bad thing. But don't worry, we're going to fix that easily. Inside the AndroidManifest file. Inside this activity element tag, we want to add the attribute name, their window, soft input mode to adjust pen. And basically one, this one line of code, we'll fix that. So now we can run our application again and see if that works. Okay, so now let's navigate to add fragment, select the simplest field. And as you can see, our views are not pushed on the top. But there is one more issue. So when we never get back from our ad fragment or from our update fragment to our list fragment. Our software keyboard is still visible and we need to fix that. So whenever we come back to our list fragment, that keyboard shouldn't be, should not be visible. Okay, so how can we fix that? Well, very easily, and to do that, we're going to create a new file. So first let's create a new package for that. And it's named is a package, your tills. And this package will have only one Katelyn file. So this will not be a class, it will be a file. Because in this file we're going to create one top-level function. Okay? I'm going to just leave this cancel and this function will be top level. So basically, we don't need any class and let's create the function name, the height keyboard. It will have only one parameter which is activity. And down below, let's create a new variable named input, a manager. In here we're going to use our activity to get system service. And here we will use our context to get the input methods service. And we're going to cast that to input metadata manager. And down below we're going to create one more variable named the current focused you. And here we're going to use activity as well to get the current focus. And here basically we want to hide our software keyboard. So let's use our input method manager and let's call this Hyder method. And down below, we're going to call this current focused view and pass the window token. And as a second parameter passed this height. Not always. Okay, and we're going to call this top-level function from our list fragment. So just inside this onCreateView, let's call this function so we do not need to initialize anything just called the function and pass this require activity are K and that's basically it. So we are calling this function from our list fragments onCreateView. And whenever we open up our list fragment, the software keyboard should not be visible anymore. So let's test that out. And as you can see now, if VT is visible and when we get back to our list fragment, it is no longer visible. So let's navigate to the Sunday ablate fragment. And now let's get back to this list of segment again. And as you can see, our software keyboard is no longer visible as well, so it works perfectly fine. And the next thing I want to commit those changes, So here, and it will select this utils Katlyn file. So I need to push that on my GitHub repository as well. So I'm going to commit that. Okay, so whichever one warning and they'll let me see what this is all about. Okay, so we need to add one attribute inside our application element. And now it's added this attribute named for the backup content and set that to true. Okay, and that's all we need to do. So now I'm going to commit changes and I'm going to the new commit message clear. So something like a soft keyboard pushing views up fixed and keyboard hides automatically when we get back to at least relevant, ok, this is fine. And now let's commit those changes. Okay? And I'm going to pull this commit to my GitHub repository so you can check that out and Don and the download the new object, OK. And that'll be all. 50. #4 Backstack issue - Fixed: Hello there and welcome back to another video in this bow hunting section so I can receive another bug from a user and basically our application crashes when we press our beg button after performing insert, update, or delete from our database. And let's first go to our enjoyed the sodium. And let's examine that arrow. And let's first go to our Android Studio project and let's see how this error occurs. So here I have basically run the app and I would just great at some random items here. So for example, let's select this one and let's, for example, update here the title. So just click this Save icon. And now when we press this bag button, our application will crash. And the reason is because we haven't popped off this update fragment of our back stack. And when we get back from our update fragment to the list frame width, willing to pop off this abit fragment from our bags. Thanks so our application can exit and not trying to get back to this update fragment. So we're going to fix that bug by going to this navigation graph. And you need to select this arrow, which is pointing from update fragment to the wrist fragment. You need to open this pop behavior and where it says pop up to, we need to select the least fragment. And we need to check this. Pop up to inclusive. So set that to true. And now let's run the app and see if this bug will be fixed. Okay, so now let's try and apply this item once again, click Save icon, and now press this back arrow. And now our application just exits. Okay, so we don't have application crash anymore and we need to fix that with our ad fragment as well because that burger exist on our ad placement as well. So we need to select this arrow which is pointing from add fragment to the list flagrant. And we're going to check this list fragment. And down below we need to check this option to true. So now when we run the app, you will see that with our ad fragment will not going to see that error anymore. So for example, let's try and add something here. I knew item. And now when we try to get back, as you can see, our application exits and we no longer have this application crash. So that will be all for this video. Thanks for watching and thank you for submitting those bugs. I'm always happy to help. 51. verifyDataFromUser - Cleanup: Hello there and welcome back. So in this video, we're going to clean up some code so I can receive a lot of messages about one specific function from this class named a shared view model. So it's all about this function of verified data from your xr. And this function is kinda confusing. So we're going to simplify this example and let me show you how to do that. Okay, so first we're going to delete everything and start over. So I'm going to write if title dot is empty or if the description is empty, then we want to return false. Okay? And in the else block, we want to return true. Okay, so now we get one hint from Android Studio. So let's press alt plus enter, and let's remove this if statement. And as you can see, now, our function is simplified and it looks all better. So let's run the app and see if this is going to work still. Okay? Okay, so let's add the new item here. And let's press this button to see if we're going to see a toast message. And as you can see, we can see the toast message that we need to fill out all fields. So let's add input here on our first field. And let's leave description empty. So let's try again. And it works as well. And only when we type description and the title, then it will work. Alright? So there you go again. Thank you all for a noticing this small part of the code. Apparently, I forgot to clean up and they remember, you cannot create a perfect code. In the first try, you will need to maintain and update your code on a regular basis, and that's how you can make your call. Perfect. Thank you for informing me about this. And that will be all for this video. 52. Migrate from kotlin-android-extensions plugin: Hello there and welcome back to another video in this bike hunting series. So why in this video we're not going to fix any bug. Instead, we're going to migrate from one deprecated plugin name that Katlyn enjoyed the extensions so well for those of you who are not familiar with this plugin. And this plugin is for our Katlyn x synthetics and therefore Paris allies annotation. So a few weeks back, enjoy team has announced that they are going to deprecate this plugin. And now we need to migrate from our Katlyn x synthetics to our view binding. And also we need to apply a new plugin for our parse Alus annotation software. Instead, what we're going to do, we're going to remove this plugging in from here, RK and click sync now. So now you will see a couple of errors inside our project. So first let's open up our list fragment right here. And you will see that our list fragment is totally fine because here we already have a data binding and in our update fragment we have an error. As you can see here, we have used this Plotly next synthetics and to remove that for now. And let me see what are those errors. Ok, so now instead of using this courtly next synthetics inside our update fragment that we're going to use that data binding which we have already applied inside this fragment. So I'm going to just add binding in front of that. Then a current title, ET R k. So I can remove now this one, right? And here lets call binding dot current description ET R k. So we can remove this old one and here as well. So binding daughter current priority is spinner and we can remove this one as well, our case. So inside our update fragment that we no longer have this Katlyn x synthetics. So our update fragment in our list fragment are totally fine. And inside our ad fragment we need to add view binding. So here let's first open up our Gradle build file and you will see that we have already enabled the data binding. And now I want to add here a view binding as well. So type view binding equal to true R k and press sync now. So basically now that we have enabled this view binding, then for each layout file we have in our project, there are some classes that which will be automatically generated by our view binding and your C. So first let's open up our ad fragment here. And here I'm going to create two variables. One will be named the other score binding in the second one will be named as simple as a binding. So here let's use a private var underscore binding and the type of this should be fragment add binding. So this class was automatically generated by our view binding. And as you can see, the name of our layout file for this ad fragment is a fragment add. And this binding was concatenated to this name. So now we have received basically a class with this binding suffix. And now we can say its value to be noted first. Then I'm going to create a read-only variable named are binding. In here. I'm going to basically use this getter to get the value of underscore binding and just add this a double bang operator. So next inside our own create view, I'm going to use this underscore binding in here. I'm going to call a fragment, add the binding case so dot inflate in here, I'm going to pass a layout inflator instead. And here I'm going to return a binding daughter growth. And now we can remove this question mark in here. Instead of calling this view, I'm going to call our binding dot priorities spinner R, k. So now it works. And down below, let's change a few more lines of code. So here I'm going to call a binding Datta title II T R k. So I can remove that. And here I can call binding dot. Its priority is a spinner. And here binding dot description AT RK. And basically we have a fixed our ad fragment as well, and we can remove those two lines of code from our imports so we no longer use quasi next synthetics. So basically we have a migrated to our view binding and there is one more thing which we need to fix. So let me just open this data package than models in here. I'm going to open up this to-do data. So here as you can see, we have a warning from Android Studio and we are no longer able to access this Paris allies because we have disabled, enjoyed the cotton Android extensions plug-in. But don't worry, there is a new plugin for this power series notation. So let's open up our Gradle build file. In here. I'm going to apply a new plugin. So here just type are called lean forward slash Paris allies, nor case or click sync now in our case, so now let's go to our two data and that there is only one more thing which we need to do. So as you can see, we have a warning here and we need to change our import package. So we're here instead of costly next or enjoy dot par self.position delays, we need to use a clocking x dot parse allies are K parcels. So now everything will work just fine and we have successfully migrated from data deprecated, plug-in named enjoyed their cotton extensions. Okay, so there is only one more thing left here, incent our ad fragment. So at the end of this fragment, we need to override the metadata onDestroy view. And here we need to set our underscore or binding to now so we can avoid them memory leak. Okay? Alright, so add this underscore binding to now inside the onDestroy view and therefore build for this video. 53. #5 Search/Undo Bug - Fixed: Hello there and welcome back. So after awhile I heal, received a new bug report for our to-do application. And apparently this bug is associated with our undo option and with our research View widget. Ok, So back in Android Studio, and now I'm going to run this application to show you how this bag will actually occur. So as you can see, when we try to swipe to delete some of those items, and when we use this undo option, everything works just fine. Okay, so as you can see, whenever I tried to delete one of those items and retrieved back, it works perfectly fine. But when we try to, for example, search something here, anything we want. And then when we try to swipe one of those items and click undo option, we should get some very strange result. And the reason behind that is because whenever we search an item, I witness search view widget. Then as you can see inside our list fragment, when we scroll down below, let me just scroll until we find this one query text submit and their own query text change. So both of those functions are calling this search through database function. And this search through database function is basically observing our database. And of course, this observer is called multiple times, even if we no longer search our search view widget. So to show you that, let me just add here one simple log statement. I'm going to write here, list fragment in here. I'm going to write search through the database. So now I'm going to observe this log from our logcat and you'll see that this observer will be called a multiple times even if we close our surgery widget, which is of course a default behavior for live data object. So let's open our MP. And here as you can see now when I swipe one of those items, that logger will not be executed. Type here, anything, as you can see, whenever we type a character, that log is executed. And now I want to close that. And when we try to swipe one of those items, as you can see, that item or that lager was executed them multiple times. And that's actually a bad behavior. And as you can see, that's why we're getting this strange result. So now basically, if we want to fix this bug, we basically need to execute this code inside our search through the database only once when we actually call this function. But as you can see at this moment, this observer is trigger the every time we search here. And it's triggered each time afterwards. And they wanted to change that. And that will fix this issue. I'm going to create one extension function on live data class. So I'm going to do that inside this utils Katlyn file. So I'm going to open that in here. I'm going to create a new extension function for our live data class. So I'm going to use the generics here and I'm going to of course call a live data dot. And I'm going to name this function observe once and hearing to pass a lifecycle owner, of course. And the second parameter should be. Server k. So let me just best here, Generics as well. And here inside this function, we need to call observer function. So not this observed from the parameters of this observed once function, but this observed so-called that in here as the first parameter we need to pass a lifecycle owner. And as a second one, I need to instantiate this observer. And here I need to override the one method, suppressor control plus o in here I need to override the onchange and inside this ONE change the function. I need to call observer from the parameters of this observer or observed once function then r dot unchanged in here I need to pass a t from the parameters of this ONE changed. And below that, I need to call remove observer function and the hero into pairs. And this solar, basically this function, we'll update our live data object only once and after that, it will remove its observer. So that's the exact behavior which we want to add that into our application. So now let's get back to our list fragment. And here inside our search to database function, I need to replace this observed with Observer once function which we had just created. Okay, so just add that. And the, Okay, there is only one more thing which I want to add. So here, fragments, it's always a good practice to use lifecycle owner instead of this. So here let's use a view will I'm cycle owner and the here, let's replace those as well, or cane. So we're now, let me just run the app again. And here inside our lawn care, we're going to observe this a log and see if this observer will be triggered that each and every time after we search our database. So as you can see at this moment, when we use our undo function, everything works perfectly fine as expected. Okay? And now let's try and search here something. So now even if we type a single character, our search to database function will be triggered. And as you can see, this log will be printed. But let's see if this observer will be triggered afterwards. So let's close our search view widget, and now let's try and swipe to delete. One of those items are case or now is again see this observer is a no longer triggered. So this observer was triggered that only the first time when we call this Social database function, which is actually each time we type a character inside our search widget. And as you can see now, our undo function is working perfectly fine. Even if we swipe one of those items after we have searched through our search widget. And now everything works perfectly fine. So now our search to database function will be called The only when we query our text inside our surgery widget or when we submit that text and there we have successfully fixed that bug. So I hope you enjoyed this video and that will be all for now. 54. Code Cleanup, Dependency Update + RecyclerView Animation: Hello there and welcome back. So far it's been awhile since I made a video about our to-do application, and now I have decided to make a new video to update all dependencies and also clean up some code in our project as well. So here as you can see, I have already updated the, some dependencies in our Gradle build a file. So let's scroll down below. Alright, so the first code clean up, I want to do, I want to basically remove those dependencies for a data binding because at this point we no longer need them for a data binding to work. You only need to have this data binding to true. So that's all you need for a data binding in their view bindings. So we no longer need those two dependencies and that's why I have removed them. Also, if you check your other grades or build file, then you will see that here we have a warning. So J center repository is now at the end of life and this repository is being shut down. So now we want to remove that. Okay, let's remove that. And then now if we tried to sing the project, we are going to receive an error. So let's run our app and now we're going to receive one error. And that error is basically connected with our RecyclerView animator dependency. So as you already know, this third-party dependency requires a DJ central repository. And since Dre central repository is now at the end of the life, we can remove that repository and also we're going to remove this dependency for RecyclerView animation as well. And now instead of using this dependency for animating our RecyclerView, we're going to manually create animation for our RecyclerView. So what before that, I just want to update our Kotlin standard library from 1.4.32 to 1.5. So let's update death allright perfect. And also I want to update that same version here as well. So 1.5, alright, let's sync our project. All right, So now let's run our application to see if everything will compile and work perfectly fine as before, no. Okay, So inside our list fragment, now we need to remove or a clean up some code for this. All the RecyclerView animate our repository so we need to remove this import, our k. Let's remove that. And down below we need to remove two more lines of code or three. So let's remove that alkane. And then now we're going to create our own a RecyclerView animation. So inside our anim directory, we're going to create a new XML resource file or animation resource file in here. I'm going to name this file from bottom. Because of this animation, we'll basically animate our items are coming from the bottom. So click Okay, and here inside our set element, I'm going to add the translate in here. I'm going to call up from a Y delta. And here I'm going to set the 100% and the two Y delta will be basically 0%. And of course here for the duration we can add 300 milliseconds. Okay, perfect. And that's how our animation for a recycler view will look like. And there is only one more file which we need to create here. So let's add new animation resource file. And I'm going to name this file RecyclerView underscore Anim are here for the roof element. I'm going to add the layout animation here for the delay, I'm going to add 15%. So this delay means that each and every item inside our list will animate with the delay of fitting percent of the whole animation duration. And next for the animation order, I'm going to add just normal n for the animation. I'm going to specify our from bottom animation resource file which we have just created now. Okay, Perfect. And then now we need to open up our list fragment layout. So let's open up our fragment list arcane. And here on our RecyclerView I want to add that one attribute. So our layout animation in here, I'm going to call our RecyclerView anime. So now let's run our app. Okay, so now as you can see, we don't see any animation. And the reason why is because we need to add just one more line of code inside our list fragment. So let's open up our list fragment. And here whenever recall our setData function. After that, we need also to call a RecyclerView. So let's call binding dot RecyclerView dot schedule layout animation. So without this function, our animation will not work. And this line of code that needs to be called the whenever recall our setData function. So now let's run our app and our RecyclerView animation ash would work just fine. Okay, so there we go. Our RecyclerView animation is working at perfectly fine. And of course we can just increase this duration, for example, to 500 or 400 milliseconds. So let's check it out and see how will that look like now. Okay, So I think that for 100 milliseconds for this animation is totally fine. And basically now we have updated our project. We have made some code clean ups as well. We have removed that unnecessary data binding dependency or those two that tenancies. Also, we have removed the data third-party library for animating our RecyclerView. And we should remove the J central repository as well. Now we're using our own animation for a RecyclerView and our project has been updated. So that'll be all for this video. 55. FragmentContainerView: Hello there and welcome back. So why in this video we're going to update the one small part of our project and that is our nav Host Fragment. So I have received a lot of questions from you regarding this fragment container view. So as you can see so far, we have used this fragment XML element, but you can see that the android Studio will always suggest to replace this fragment with a frame and Container View. And whenever we replaced that fragment with this new framing container view, and when we run our application, we're going to receive crash. Okay, so as you can see, let's check our logcat. So there it is. We have received that. It says that our main activity does not have a nav controller setup. And we need to do one more thing in order to make this framing Container View work properly. So let's open up our main activity. And here we're going to add a new variable, nav Host Fragment are, we're going to cast this fragment container view as net host fragments. So you will see first let me just add here a new variable on top of our MainActivity. So I'm going to use the light we need to variable. So we're going to initialize this variable later when we actually call it. So let's create here a nav controller of a type of a nav controller. Okay, and from here I'm going to remove this line of code because we don't need to. Nav controller variables are okay. And here let me just create a new variable name the nav host fragment. And here we're going to use a support fragment manager. Then we're going to call a find fragment by ID. And here we're going to specify the ID of our net Host Fragment. So net Host Fragment, alright, and we need to cast that as a nav Host Fragment, okay? And then down below we need to initialize our nav controller variables. So nav controller, and let's call our nav Host Fragment dot nav controller. Okay, and here we can also pass our nav controller variable. And now let's run our app again, k. So there you go. Now our application is running successfully, and that, that's all I wanted to share with you in this video. So now you know how you can replace this fragment with a fragment container view without your application crashing. And that'll be all for now.