Hi, Oclemy here. Talk to me: firstname.lastname@example.org
Kotlin Retrofit MySQL MVVM Full CRUD with Disk Caching(Java also available)
Do you want to learn how to create an offline first Retrofit Full CRUD app with disk caching? Do you want to learn how to use Model View ViewModel design pattern in a full app with Retrofit? Do you want to learn how to perform CRUD operations against MySQL database from an android app using Java?
ABOUT THIS PROJECT
This project is designed for students to help them learn create a full android app based on Retrofit as the HTTP Client and MySQL as the database. We use Java as the programming language. PHP is our server side language and data will be transmitted in JSON format via HTTP. GSON will be used to parse the JSON but this will be done automatically via Retrofit.
Our HTTP Client is Retrofit, the most popular HTTP library for android. It is simple, clean and scalable and beginner friendly yet powerful.
We will store our data in MySQL database, the most popular RDBMS solution. We use PHP as our server side language. PHP is also the most popular server side language and that’s why we chose it.
We have two projects: one written in Kotlin and another in Java.
HTTP Requests will be made asynchronously thus freeing up our UI thread. We will handle different states of our response like the progress state, error state and success state cleanly.
After much research, we’ve chosen to use RedbeanPHP as it’s one of the best PHP ORMs. It is extremely simple, encourages Object Oriented programming and can even generate for us our database and table just based on the design our classes.
ACTIVITIES AND FRAGMENTS
We use activities as our pages. We also have fragments in our listing page. These activities are easy to customize and very independent. All of them share one base class. That base class includes properties and methods common to most or all the other activities. Those properties get derived via Inheritance.
The listings page will include wipe tabs. We achieve this using viewpager. We show our tabs in a tablayout. The first tab will show data only from our hard disk cache. The other tab will show data from our cache as well but it also allows us to refresh our data.
PULL TO REFRESH
If you pull the recyclerview in the second tab in our listings page. Data will be automatically refreshed. This is courtesy of the SwipeRefreshLayout which we wrap around our recyclerview.
LOAD MORE PAGINATION
Our data is downloaded in chunks from the server. Only around 7-10 items get downloaded at a time. This makes the app super fast and efficient. Data is downloaded as the user scrolls. All downlaoded data are added to the cache so that we won’t have to re-download them again.
Users can search filter. We include a dialog fragment to provide a complete search experience with highlighted searh results.
In case of any problem, we are available to provide you with full support. Just contact us via the Contacts Form or through my email: email@example.com.
MVVM(Model View ViewModel)
LRU Hard Disk Caching
What You'll Learn
Here are the operations this project teaches you to perform:
(a). POSTING DATA
Say you have a BigThinker/Product/Person etc object that you want to post to database. Well we teach you how to do so via Retrofit. The item will be saved in a mysql database. The advantage of this as opposed to saving locally in SQLite is that that object now becomes available to all users who download the app.
(b). UPDATING DATA
What is the essence of posting data if you can’t update it? Well you can update the database directly at the backend but this isn’t suitable. A better solution is to allow for updating the database directly from the app. We include this capability in this app. The already posted data can be safely edited and updated via a nice UI in the app.
(c). RETRIEVING DATA
Of course retrieving data is a must. Normally when you learn Retrofit using those online courses or projects by other instructors, they always only include this capability. For example fetching data from a movie api allows you to only retrieve content. That isn’t a complete solution especially if you want to master creating a full app. Our data is coming from mysql database and we include other capabilities as well.
(d). DELETING DATA
We also have the ability to delete data. Users can delete data directly from the app. You select the item you want to delete from a recyclerview. You will first be taken to the detail page. From the editing page you can navigate to the delete page where you can easily delete an item.
(e). SEARCHING DATA
We include the capability to search data. We implement the toolbar search pattern. As user types the search term we filter data and highlight search results. You can easily change the highlight color in our adapter class. Searches occur in a dialog fragment this you don’t need to take users to a different page just to search. If the user clicks the result then he/she is taken to the detail page.
(f). PAGINATING DATA
If your app starts getting thousands of people per day and you have thousands of products or items in your database. We don’t your app to crash your database causing you downtime. Pagination can always be tricky so we have implemented one for you. All you need to do is change the number of items you want to be rendered per page. We use the most common technique called Load more pagination.
(g). HARD DISK CACHING
One of the main motivations for creating this project has been to teach how to design an offline first app. Data in this case is to be stored in Hard Disk temporarily and only get downloaded when a change has occured. This is super important as you will probably paying for some hosting resources if you were to release your app to users. Moreover your users probably prefer to save their precious bandwidth. Data will be cached in the disk and users can view already downloaded data without having to redownload them every time they open your app. However if a user adds new item or updates or deletes an existing item, the next time a user visits the listing page we will automatically connect to the server and redownload fresh data to update our cache. Users can also pull on the recyclerview to refresh data.
(h). CREATING BEAUTIFUL REUSABLE PAGES
For example here are the pages we create in this app:
- Splash Screen – We animate a logo and textviews to show your app brand.
- Dashboard Screen – Is like the central navigation activity in the project. You can change the color of the cards, the images,the texts etc, You can even add more cards.
- About-Us Screen – Use it to show info about you like email and other contact info.
- CRUD Screen – Will be intelligently re-used for three important operations: Posting data, Updating data and deleting data. Saves us from creating a lot of pages.
- Listing Screen – Very important. Will host three fragments. The first two will be shown in tabs and can be swiped left and right via ViewPager. The other one will be a dialog fragment used to allow us search filter data.
- Search Screen – To be used to search filter data with highlights shown.
- Detail Screen – To be used to show details of a single item. Will have a beautiful collapsing toolbar with a banner image that can be changed.
We use a combination of activities, fragments and dialog fragments to create those pages.
Well the app has a lot of features and techiniques you will need to create a full app. You can use it as a template.
First thanks very much for purchasing this project. Am available to assist you all through the way.
RUNNING THE PROJECT
1. In you android studio import the project
2. Then sync to download dependencies.
When you run the project, we will use a demo mysql database we host online.
SETTING UP YOUR DATABASE
1. In XAMPP/WAMP server root directory create a folder named PHP.
2. Inside this PHP extract the stars.zip file.
3. In the code go and comment this line:
R::setup( ‘mysql:host=localhost;dbname=projectsdb’, ‘demo’, ‘9AmaFn6jpmNe8DN6’ );
The above line is the user credentials for our online mysql database. We comment it if we want to use
Uncomment the following line:
R::setup( ‘mysql:host=localhost;dbname=camposha_demos_db’, ‘root’, ” );
In the above line we are using the default root superuser.
4. That’s it.
You don’t have to create a database. We are using Redbean PHP which will automatically create for us
a database and a table based the data we are trying to save. However you have to attempt to save data
first. For example go to the CRUD page of the app then choose an image, fill all the fields and click
upload. ReadbeanPHP will create a database table based on those fields.
For queries contact me: firstname.lastname@example.org
HOW TO OBTAIN YOUR IP ADDRESS
- Connect to a wifi network.
- Type ipconfig in the cmd
- The IPv4 Addess will be listed. It is your ip address
Look at the image below:
Demo and APK
You need to know what you are buying, don’t you? Well here is the APK demo. Just install it and run. We have a hosted online database to use for demo purposes.
We have written a public article associated with this project. READ IT HERE.
We continue updating all our projects, fixing bugs, releasing more features and improving code quality. If you buy the project we will continue sending you the updates via email.
Here are the update history so far:
3rd March 2020(Major Update)
- Fixed Pagination issue with the Kotlin Project
- Redesigned Model class to prevent null pointer exceptions by assigning default values using elvis operator.
- Simplified method for making our HTTP requests to perform CRUD by re-using the same method.
- Replaced most of our if-statements with the much cleaner when statements.
- Added lots of comments.
25th February 2020
- Updated Java Code.
- Fixed bugs.
1st February 2020
- Published Java Project
22nd January 2020
- Published Kotlin Project.
We provide lifetime support exclusively by email address. I always reply as soon as I receive the email. However this will be within a 24 hour window.
My email address: email@example.com
Let’s address some of the questions you may have. Remember you can ask us any question, even those not related to this project via my email address: firstname.lastname@example.org.
Why do you Charge for Projects, why don’t you just offer them for Free?
Well we have more than 5oo free mini-projects and tutorials, and almost 1000 free coding videos in YouTube.
However alot of students kept asking us to make full projects. We looked online and saw that indeed it was difficult to find full, easy to understand, supported and high quality projects geared towards students. So we decided to fill this void. However it takes alot of time and effort so we charge for sustainablity. We also provide lifetime support and updates to our projects. Thankfully, we are getting good feedback of this decision.
What if I buy the Project and it doesn’t work?
Well we thoroughly test our projects across many devices and only publish them once we are sure they work. However if there is a problem, probably in some devices you can contact us and we will provide a fix. However we only provide fixes related to the project and not general or apps you have created. We can do that but in a separate plan.
Can You Help me customize this Project and add more features?
Yeah. However again this is a different plan. Feel free to email us the features you want and we will talk.
Will You be sending me Updates?
Yeah. We will be sending updates to your email address. We provide lifetime updates.
Do Projects help me learn Faster?
Absolutely. People learn coding by coding. Reading is good but it’s slow and you won’t get far just by reading. Projects force you to work with several concepts even if you may not understand them in detail at first. Getting a project designed for students will ease you in. Try this, read a book or articles for one month and document what you can do, then get a good project and attempt to customize it for one month, then compare the improvements you made between those two months.