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.
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:
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.
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: firstname.lastname@example.org.
Camposha is a website dedicated to bringing you high quality tutorials, projects and libraries to aid your programming skills development and help you learn faster.