Catchflicks is a sample project after completing Android Development Online Course For Professionals by MindOrks.
This app shows the popular movies, upcoming movies and the ongoing movies in theatre from the movie db API. The goal of this sample project is to implement most of the learning from the Bootcamp. Also, this project works as a kitchen sink project where anyone can play with any new Android API's and concepts.
Project consist of multiple packages in order to achieve MVVM architecture.
- data
- di
- ui
- utils
This project use multiple libraries to bring easy way of implementation
- Dagger2 - Dependency Injection Framework
- Retrofit - Used for Networking
- Timber - Helps in logging
- Glide - use to load image
- RxJava - to perform asynchronous work
- GSON - use to serialize and deserialize Java objects to JSON
- Lifecycle - manage activity and fragment lifecycle
- LiveData - observable data holder
- AndroidX - android library for core functionalities
- ViewModel - manage data in lifecycle aware fashion
- Material Components for Android - Modular and customizable Material Design UI components for Android
- Data Binding - helps to bind UI with data source
- Palette API - dynamically change app color scheme
This project uses the TMDb API to fetch movies data.
To begin with the setup, firstly you need to create an API key.
- Create an account at themoviedb.org
- Go to settings from the profile icon
- Click on API
- Click on create
# Insert at ~/.gradle/gradle.properties or catchflicks/gradle.properties
API_KEY=<insert>
This project uses the Dagger2 for dependency Injection. After opening this project in your Android Studio you might get some error which is due unavailability of few classes. You need to make project
or try to build the project, this will generate all the required classes for dagger.
I had created a custom ViewModelProviderFactory
class because I need to pass arguments in my View Model class constructor.
- Default ->
ViewModelProviders.of(this).get(MyViewModel.class);
ViewModelProviders.of
, this depends upon aViewModelStore
and aViewModelFactory
return new ViewModelProvider(activity.getViewModelStore(), factory);
getViewModelStore()
under the hood usesonRetainNonConfigurationInstance()
method andSavedStateRegistryController
class which callsperformRestore()
andperformSave()
method ofSavedStateRegistry
class.ViewModelStore
store view model usingHashMap<String, ViewModel>
- So, if we have arguments in our view model class constructor then we create custom
ViewModelProviderFactory
.
class ViewModelProviderFactory<T : ViewModel>(
private val kClass: KClass<T>,
private val creator: () -> T
) : ViewModelProvider.NewInstanceFactory() {
@Suppress("UNCHECKED_CAST")
@Throws(IllegalArgumentException::class)
override fun <T : ViewModel> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(kClass.java)) return creator() as T
throw IllegalArgumentException("Unknown class name")
}
}
ViewModelProviders.of(activity, ViewModelProviderFactory(MainViewModel::class){
// MainViewModel(PARAM_1,PARAM_2)
}).get(MainViewModel::class.java)
- We are extending our custom class with
ViewModelProvider.NewInstanceFactory()
. - This is used to create the instance of the given class.
- This by default returns class object with empty argument list.
return modelClass.newInstance();
- KClass is the holder of a class of type ViewModel that needs to be injected.
- Instances of KClass class are obtainable by the
::class
syntax. - This is the Lambda function, this is provided by the ActivityModule/FragmentModule, when creator lambda is called then that module creates and return the instance of ViewModel.
- Search feature
- Unit Testing
- UI Testing, using espresso and mockito
- Update Region option
- Update Language option
- Try Pagination API
- Dark Mode
- Try Navigation Component
- Coroutine
- Better UI
- Bookmark Movie
Let's connect here -> anandwana001.github.io
MIT License
Copyright (c) 2020 Akshay Nandwana
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.