Expense Manager App - Part 23 | Retrieve Expense Data
Estimated read time: 1:20
Summary
In this episode, Furqan Yasin guides us through the process of retrieving expense data for our app, integrating it into a RecyclerView. Following a methodical approach, Furqan parallels the setup in the Income fragment, ensuring a seamless data flow from Firebase to the app’s UI. The episode highlights key coding practices, including setting up database references, creating view holders, and managing layout changes. By the end, users will have a dynamically updating expense list, complete with an accurate summation feature for better financial tracking.
Highlights
- Introduction to integrating expense data into RecyclerView 🎬
- Setting up Firebase database references 🔗
- Copying and modifying the Income fragment for expenses 🔄
- Crafting view holders and layout managers 🔨
- Running and testing the updated app 🔍
- Summing up expenses dynamically for real-time updates 💡
Key Takeaways
- Learn how to reuse and modify existing code to handle similar functionalities in different parts of an app. 🤓
- Understand the importance of accurate data referencing to ensure seamless data retrieval from Firebase. 🔗
- Gain insights into structuring RecyclerViews and their adapters for displaying dynamic data. 📱
- Master techniques to compute and display aggregated data, like total expenses, in a user-friendly manner. 💵
- Realize the significance of testing and fine-tuning your app for enhanced user experience and performance. 🚀
Overview
In episode 23 of building the Expense Manager App, Furqan Yasin continues with integrating expense data within our app's UI. Drawing parallels from the Income fragment code, Furqan shows how to set up Firebase references and populate data in a RecyclerView. This approach not only ensures data consistency but also empowers developers to draw from established templates, making the build process faster and more efficient.
The crux of this session is about setting up RecyclerViews properly. With detailed guidance, Furqan illustrates how to craft view holders, manage adapters, and configure layout managers to display expense data dynamically. The steps covered ensure that users can see real-time updates to their financial data, directly fetched from Firebase, through an engaging and intuitive interface.
Furqan wraps up with a deep dive into adding new functionalities, like summing expenses. This feature, integrated with onDataChange listeners, helps in rendering accurate totals within the expense fragment. Through continuous development, testing and fine-tuning, the episode highlights how developers can enrich user experience by providing reliable and up-to-date financial insights, right at their fingertips.
Chapters
- 00:00 - 01:00: Introduction and Setup In this chapter, we focus on setting up the RecyclerView for displaying expense data in our application. Initially, we modify the return view by creating a 'my view' class and update our return statement accordingly. Then, we turn our attention towards integrating Firebase database. Specifically, we instantiate a private Firebase authentication mode, mirroring the steps previously taken for the income fragment setup. This sets the foundation for managing and displaying data within the app.
- 01:00 - 03:00: Firebase Database Integration The chapter titled 'Firebase Database Integration' provides a detailed explanation on how to integrate Firebase into an application to handle user data. It starts with setting a reference to the database using 'Firebase.getInstance()', then retrieves the current authenticated user with 'auth.getCurrentUser()'. It concludes by demonstrating how to capture the user's unique ID with 'user.getUID()' to manage the database records pertinent to the specific user.
- 03:00 - 05:00: Recyclerview Setup for Expense Fragment The chapter covers the setup of a RecyclerView for the Expense Fragment. It involves obtaining an instance and reference to a specific database child. The chapter emphasizes ensuring that the correct expense database name is added, following the correct structure that includes a user ID (UID). The primary focus is on configuring the RecyclerView in the context of Firebase, which is essential for this setup.
- 05:00 - 09:00: ViewHolder and Data Binding The chapter discusses incorporating a design for the 'expense manager' in an Android application. It begins with opening a fragment and copying design elements from an existing income fragment to maintain consistency across the app. These elements are pasted into the expense fragment, and adjustments are made to integrate it into a linear layout. This process ensures that all necessary fields are visible and functional within the expense manager interface.
- 09:00 - 14:00: Adapter Setup and Data Retrieval This chapter focuses on the setup process for a new adapter and the corresponding data retrieval. It starts with duplicating a fragment from the income section and adapting it for the expense section, highlighting the similarity in regional settings. Changes are implemented by duplicating the card view from the income fragment and adapting it for expenses. Similarly, a recycler view is repurposed and redesigned for income functionality, then reused for expenses. The chapter further elaborates on modifications in the fragment IDs to ensure that the specific identifiers for income are correctly replaced with those for expense, particularly noting adjustments in text view identifiers.
- 14:00 - 18:30: Summing Expense Data The chapter titled 'Summing Expense Data' discusses modifying identifiers in a codebase. Specifically, it addresses changing an ID name to 'expense text result' and for recycling purposes, opting for 'recycle' as an identifier. It emphasizes using the same idea with slight modifications and includes opening an 'expense fragment'. The use of 'recyclerview' is highlighted, with it being equated to 'my few dot find view by ID r dot ID dot recycle our ID expense non-linear loud'.
- 18:30 - 20:00: Testing and Verification The chapter titled 'Testing and Verification' discusses setting up a layout manager using the Linear Layout Manager in a programmatic environment. It covers how to configure the layout manager's properties, such as stack from end and reverse layout options. Additionally, it addresses the implementation details for a RecyclerView, including setting a fixed size and designating the layout manager for it.
Expense Manager App - Part 23 | Retrieve Expense Data Transcription
- 00:00 - 00:30 hello guys we'll come back once again in this part we will retire our expense data and said inside our recyclerview so first change this return and add view class is equal to my view and now we need to return our my view now in here we need to add our firebase database so private firebase auth is going to be a mode in here you need to do exactly same that we did for our income fragment so private database
- 00:30 - 01:00 reference is going to be M expenses data database and in here we can add a mod is equal to firebase earth dot get instance and now in this firebase user and create em user is equal to this auth dot and get current user and now created a string variable E string new ID is going to be M user dot get UID now this MX panetta base 5 is database
- 01:00 - 01:30 don't get instance don't get reference dot child and in here we need to add our expense database name so make sure that we added the same name and dot child and this child is going to be our UID and to know at Firebirds recyclerview now we need to secular view
- 01:30 - 02:00 so open up our fragment and who need same design for our expense manager for our expert for our expense fragment so copy from income fragment and paste it here and add it to it linear layout and now we can see all this required field so now at one particle and now we can see so we
- 02:00 - 02:30 just need to copy from our income income fragment and paste it to our expense fragment cause we need to add same region so we added a card few and we added a recycle of you okay that we'll design for our income fragment and inside this expression track man we can see we can change this ID an instead of income you need to call it expense and for second text view and
- 02:30 - 03:00 change the ID name to expense text result and for recycle I will change the ID name we can call you recycle an idea expensive we can use same idea but I just want to change it and now again open expense fragment now recycle our view recyclerview is going to be recyclerview and this recycle our view is equal to my few dot find view by ID r dot ID dot recycle our ID expense non-linear loud
- 03:00 - 03:30 manager layout manager is equal to new linear lab manager and to get activity and layout manager dot set stock from int true and layout manager dot set reverse layout and for a secular view we need to add recyclerview Dorset has fixed size true and recyclerview dot set layout manager
- 03:30 - 04:00 and this layout manager is going to be our layout manager that is the object of linear layout manager so set layout manager is going to be layout manager and I think we added all this filled all this required field now we need to open our own instead method and insert an upper debt we can create a class so private a static class and we can call it my few holder exchange recycle our
- 04:00 - 04:30 view dot view holder and now create a constructor of this class and again you need to add our view plus so view and create object of view em view and this mu is going to be is equal to item view and now we need to add our method so private white set that we can call it a string in debt at text view is going to be M debt is equal to MU dot fine view by ID
- 04:30 - 05:00 I DDOT that takes expense now these M did not set text to this debt the method for private Boyd said type and parameter is string easting is going to be type as it takes view and this time is M type is equal to M view . fine view by ID r dot ID dot app texts expense no m-type Dorset text
- 05:00 - 05:30 is going to be this type and private poet set not easting note and textview is going to be M naught is equal to MU dot fine view by ID r dot ID dot no text expense and this M naught is going to be set text is going to be not
- 05:30 - 06:00 until we need to add another method for our amount so private white set amount and we can call it as parameter integer and amount at textview and we can call it m amount is equal to MU dot fine view by ID r dot ID dot Emin text expense
- 06:00 - 06:30 and this M amount dot first we need to convert this to on twisting so easting so sting dot value value of an hour amount and now we can set our data so mm on dot set text and this one for DZ sting amount so we converted our integer to
- 06:30 - 07:00 our esteem because we want to set this inside our text view now we need to add our recycle of fire Jay Sekulow adapter inside our honest turd method so now fibrous recycle adapter first parameter is our modeling class in data and second one is our class name and create object I can call it adapter and new 5s recycle our adapter and now in here and now we can write here our model class
- 07:00 - 07:30 name second parameter is going to be r dot layout dot our expense recycle our data and last one is going to be our class and last one is going to be our database name and this pew hole that dot get dead is going to be modeled on cadet mu holder dot set type is going to be modeled or to get type
- 07:30 - 08:00 and this beholder dot set amount set node is going to be model lodge yet not and this viewholder dot said amount is going to be model dot and get amount so we said all this method inside our beholder and now we can set our recycle of you you can set this adapter without a circular view so recycle of your daughter set adapter adapter so now I
- 08:00 - 08:30 think all done hopefully we will be able to see our data so now hit this Run button so here is our F and inside our income so this is a dashboard and the income fragment we can see five data and inexpensive eke an see only one data that means we successfully retrieve our expense data from firebase database but we did not count all these expensive so we need to add so we need to count it so let's add some
- 08:30 - 09:00 more data so we can call it amount 50 type is going to be you can call it random text and click Save and if we click if you have an expansion that we can see our data
- 09:00 - 09:30 so here's our income and this one is our expense fragment so now we need to so we need to add summation of all these expensive so first we need to add our text view where we want to where we want to set
- 09:30 - 10:00 our data so private textview is going to be expense some result and we need to connect it so expense some result is equal to
- 10:00 - 10:30 my view dot find uber ID our dot I dot you and to what was the item ID name was
- 10:30 - 11:00 open this fragment explains and torrid enemies who is on his already name and to open this ID coppy we can copy decide so copy this ID
- 11:00 - 11:30 and best it here you now in hell we need to add advil even listener so MX means database dot add value even listener
- 11:30 - 12:00 . advil even listener knew hello even listener you and it will give us to Matata one is on data chance and one it on cancer so we need to work with own data chance
- 12:00 - 12:30 and in her we need to we need to do for his loop for retrieved and for count all this amount of experience database so how can you do it in our because we saw already did so for and it is not short
- 12:30 - 13:00 so for data stuff showed and we can call it and and we can call it to my snapshot so my snapshot and this did a snapshot dot get chilly and you need to add a snapshot children
- 13:00 - 13:30 and first create a object of our model class so data is going to be data is equal to my snapshot dot get value my snapshot dot get below you so we can call it my snapshot
- 13:30 - 14:00 get value and okay we need to add a channel to get children so that is not short get children okay now I think you start set an insert this gate value parameter you need to add our model class so data dot class so data dot plus-- now we need to create a integer variable
- 14:00 - 14:30 and inside our integer variable who you list on our amount of expense one by one so you can call it expense some is a cult Oh I would like to study it from zero and then we will count all this data one
- 14:30 - 15:00 by one so now this explains some now this expansion plus is equal to plus is a call you end and we can call data dot get em on so we are getting all these
- 15:00 - 15:30 salmon from our model class from our firebase database and we store all this data one by one inside our integer variable and we started it count from zero so fast pillow will be get zero then we led to one more one more one more and this way to does harm will count and it will restore inside this integer variable now we need to change this is integer to a string because we need to set this extreme hello set this amount inside our text view so create a string variable we can call it string
- 15:30 - 16:00 STR it expense I can call it a string expense sum is equal to a string dot value of and we can call it this explains some and now we can set this easting data to
- 16:00 - 16:30 our textview why we want to show total result so what was the name of this textview you now this expense um result dot set text
- 16:30 - 17:00 it's going to be easier experience um you so we said our data now run these apps once again
- 17:00 - 17:30 and to open it again so very sore elves one is for our income fragment and you can see and you stack time course maybe native slow so go to - book fragment and go to income fragment and you go to expense fragment but we can see our data maybe
- 17:30 - 18:00 we need to wait so now we can see our income data and total sum and we can see our expense data and our total sum so 850 is going to be 850 and we can see our data in recyclerview so we can add a few more expense data and we can add amount I can get 50 and we can add
- 18:00 - 18:30 and we can add or not and SIV so this one is all income no changes here and if you open our expense fragment then we can see our data is changed and that I knew that I said and all samisen and our Sammis increase so if you open from here or income and if we open here we can see our dashboard so I think all functionality done perfectly