Instagram-Clone-Clean-Architecture is my portfolio project that implemented with clean architecture approach. The projects that I referenced while developing can be see in Reference section.
The objective of this project is to learn how to handle large project when developing Android application. Particularly with clean-architecture approach, making it easy to expand, build and test.
While it takes longer to setup a project, after setting-up, the workflow is less-error-prone. Making the application much reliable and confident to develop.
- File -> New -> Project from Version Control
- Pass "https://github.com/kyleliao321/instagram-clone-clean-architecture.git" into URL block.
git clone https://github.com/kyleliao321/instagram-clone-clean-architecture.git
- Build -> Make Project
- Run - Run 'app'
- Login process
- Remember login process
- Search user and follow/unfollow process
- Check post and like process
- Add post process
While it is not the first android project I developed, I still learn a lot and strengthen some of the best-practice concept with it.
- Modularization with Features using dynamic feature.
- Presentation/Domain/Data dependency rule.
- Setup Base Library Module to organize common utility class/function.
- Separation of Concern with Model-View-ViewModel.
- Repository Pattern with Local/Cache/Remote data source.
- Error Handling, especially for network fail.
- Dependency Injection with Kodein-DI.
- Using Gradle-Kotlin-DSL.
- Using buildSrc to organize library/plugin dependency and android configuration.
- Configure build variant through build types and flavors.
- Using Mockk. (kotlin-version of Mockito)
- Utilize class/function's testability with dependency injection.
- Test with Kotlin-Coroutine.
- Using Shared Preference to store key-value data.
- Take photo from camera/gallery.
- Load image file with ImageDecoder.
- Bitmap data processing.
- Styling with theme/style.
- Material-Design-Components.
- Data-Binding.
- Using LeakCanary for memory leak detection.
- Using EncryptedSharedPreferences to store sensitive user data
- Using Paging 3 to paginate large data sequence
- Inline function with reified type parameter.
- Coroutine context/dispatcher.
- Extension function.
- Using Network Security Configuration
- Using OkHttp Interceptor for Json-Web-Token authorization
- Using Retrofit with complex query
Reference projects/articles provides solid foundation for me to build this project, but there are some outdated dependency issues or special scenario that required other approaches. Here are some of the issues that I think is worth mentioning :
Since Gradle6.0, buildSrc is no longer visible from gradle's setting file anymore:
As a result, developers have to make sure plugin-version and modules are synchronized between gradle setting and buildSrc. (More on the this issue)
When navigating between features, safe-args navigation is not possible:
One approach mention in this article is to use common-android module to store destination ids, but there are some drawbacks (See more on the article). My approach is to let navigation's action have the id that is the same as its destination. This way, I can use the following code to capture the exception and re-navigate in traditional-way:
try {
navController.navigate(navDir)
} catch (e: Exception) {
if (e is java.lang.IllegalArgumentException) {
navController.navigate(navDir.actionId, navDir.arguments)
} else {
throw e
}
}
Potential memory leak when reference Activity/Application:
In some case, the class have to use activity/application context. For example, LocalDataSource have to get SharedPreference from application context. And this lead to other class has reference on Activity/Application, a classic-way to trigger memory leak.
To prevent from memory leak, I use WeakReference to get Activity/Application context. So when the Activity/Application is destroyed, GC can reclaim the memory.
Replace MockRemoteDataSource with actual API that get/upload data to/from server.Detect memory leak.Encrypt user data in SharedPreference.- Fix Lint error.
- Android-Showcase by Igor Wojda
- Android-CleanArchitecture-Kotlin by Fernando Cejas