Skip to content

This repository contains sample code. Its purpose being, to quickly demonstrate Android and software development in general, clean code, best practices, testing and all those other must know goodies.

License

Notifications You must be signed in to change notification settings

Kdaydin/sample-code-movies

 
 

Repository files navigation

Sample Code: Movies

This repository contains sample code.

Its purpose being, to quickly demonstrate Android, Kotlin and software development in general. More so and amongst others, the main focus of this project is:

  • Setup and Gradle configuration,
  • Gradle modules,
  • Clean architecture,
  • Clean code,
  • Best practices,
  • Testing and
  • All those other must know goodies.

Below is a list of goodies that are being showcased:

  1. Architectural Pattern
    1. Clean Architecture (By employing clean architecture, you can design applications with very low coupling and independent of technical implementation details, such as databases and frameworks. That way, the application becomes easy to maintain and flexible to change. It also becomes intrinsically testable.)
    2. MVVM (Model View ViewModel)
    3. ViewModel (Architecture Components ViewModel Class)
    4. LivaData (Architecture Components LiveData Class)
  2. Libraries
    1. Koin (A pragmatic lightweight dependency injection framework for Kotlin)
    2. Kotlin Coroutines (Coroutines simplify asynchronous programming by putting the complications into libraries. The logic of the program can be expressed sequentially in a coroutine, and the underlying library will figure out the asynchrony for us)
    3. Retrofit (Type-safe HTTP client for Android and Java by Square, Inc.)
    4. GSON (A Java serialization/deserialization library to convert Java Objects into JSON and back)
    5. Glide (An image loading and caching library for Android focused on smooth scrolling)
    6. Timber (A logger with a small, extensible API which provides utility on top of Android's normal Log class)
  3. Android Support
    1. AndroidX (A new package structure to make it clearer which packages are bundled with the Android operating system, and which are packaged with your app's APK)
    2. Android KTX (Android KTX is a set of Kotlin extensions that is part of the Android Jetpack family)
    3. Constraint Layout (A ConstraintLayout is a ViewGroup which allows you to position and size widgets in a flexible way)
    4. Card View (A FrameLayout with a rounded corner background and shadow)
    5. Recycler View (A flexible view for providing a limited window into a large data set)
    6. Shared Element Transition (Activity transitions in material design apps provide visual connections between different states through motion and transformations between common elements)
  4. Code Quality
    1. Android Lint (The lint tool checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization)
    2. Detekt (Static code analysis for Kotlin)
  5. Tests
    1. JUnit (A programmer-oriented testing framework for Java)
    2. Strikt (Strikt is an assertion library for Kotlin intended for use with a test runner such as JUnit or Spek)
    3. MockK (MockK is a mocking library for Kotlin)
    4. Robolectric (Android Unit Testing Framework)
  6. Debug
    1. LeakCanary (A memory leak detection library for Android and Java)
    2. Strict Mode (StrictMode is a developer tool which detects things you might be doing by accident and brings them to your attention so you can fix them)
  7. Build
    1. Gradle Kotlin DSL (Kotlin language support for Gradle build scripts)
    2. Gradle Versions (Gradle plugin to discover dependency updates)
    3. Dexcount Gradle (A Gradle plugin to report the number of method references in your APK on every build)

Screenshots

alt tag

Usage

The first thing that you need to do in order to be able to build this project is to obtain your personal keys and place them under the below config directory:

config/keys/

With the current configuration the build will be completed successful. However, in order for you to play with the app you will need to obtain your personal api key from "The Movie Database" and replace the existing mocked api key with yours within the below property file:

themoviedb_api.properties

For more information on how to obtain your personal TMDB api key visit
The Movie Database API (v3).

After this, you might want to ignore this change and make git forget all about that. In order to do so, run the below git command:

git update-index --assume-unchanged config/keys/themoviedb_api.properties

All set, use the below command to build the project in order to install it on an Android device for demonstration:

gradlew clean build -x check

Or faster yet and targeting a specific build type (in our case the debug build type):

gradlew clean assembleDebug

Open an emulator or connect a physical device to experiment with the sample app, use the below command, which first uninstalls and then installs the sample app:

gradlew uninstallDebug | gradlew installDebug

Or faster yet, target a specific device (in our case an emulator):

adb -s emulator-5554 uninstall io.petros.movies | 
adb -s emulator-5554 install presentation\build\outputs\apk\debug\presentation-debug.apk

Use this command in order to run the static code analysis for the project:

gradlew check -x test

Or if you want to be more specific, run the below commands to run the code quality tool or your choice (in isolation):

gradlew detekt
gradlew lintDebug

Run the project unit tests using this command (this includes Robolectric):

gradlew test

Or if you want to be more specific, run the below commands to run the tests or your choice (per module):

gradlew domain:test
gradlew data:testDebugUnitTest
gradlew presentation:testDebugUnitTest

Future

Below is a list of all those I WISH I HAD MORE TIME TO DO future technical enhancements:

  1. Espresso tests (preferable with the Robot pattern). See MET comment which stands for Missing Espresso Tests
  2. Integration tests (preferable with MockWebServer). See MIT comment which stands for Missing Integration Tests
  3. Add missing Robolectric tests. See MRT comment which stands for Missing Robolectric Tests
  4. Add missing Unit tests. See MUT comment which stands for Missing Unit Tests
  5. Small, medium and large screen considerations.
  6. UI changes during screen rotations (edge cases).
  7. Other lifecycle related edge case events.

Furthermore, below is a wish list of all those I REALLY WANNA DO, AND WILL DO AT SOME POINT future architecture and library enhancements:

  1. #2cb42c DONE Update Gradle to the Latest Version. For more info, see Gradle Release Notes
  2. #2cb42c DONE Update Android Studio to the Latest Canary Version. For more info, see Android Studio Release Updates
  3. #2cb42c DONE Replace current to the new AndroidX Package Structure. For more info, see AndroidX (A new package structure to make it clearer which packages are bundled with the Android operating system, and which are packaged with your app's APK)
  4. #2cb42c DONE Replace Manual Android Extensions with Android KTX. For more info, see Android KTX (Android KTX is a set of Kotlin extensions that is part of the Android Jetpack family)
  5. #2cb42c DONE Replace Gradle Groovy with Kotlin DSL. For more info, see Gradle Kotlin DSL (Kotlin language support for Gradle build scripts)
  6. #2cb42c DONE Replace RxJava with Coroutines. For more info, see Coroutines (Coroutines simplify asynchronous programming by putting the complications into libraries. The logic of the program can be expressed sequentially in a coroutine, and the underlying library will figure out the asynchrony for us)
  7. #2cb42c DONE Replace Dagger with Koin. For more info, see Koin (A pragmatic lightweight dependency injection framework for Kotlin)
  8. #2cb42c DONE Replace AssertJ with Strikt. For more info see Strikt (Strikt is an assertion library for Kotlin intended for use with a test runner such as JUnit or Spek)
  9. #2cb42c DONE Replace Mockito Kotlin with MockK. For more info see MockK (MockK is a mocking library for Kotlin)
  10. #2cb42c DONE Upgrade JUnit4 to SPEK Framework and JUnit5. For more info, see SPEK (A specification framework for Kotlin) and JUnit5 (JUnit 5 is the next generation of JUnit)
  11. Add Code Coverage Reports for Tests with Jacoco. For more info see Jacoco (Java Code Coverage Library)
  12. Modularize the App Horizontally by Features. To get an understanding of Modularization and how to it applies to an Android project, start with this Article Modularization (To take advantage of new distribution features (Instant apps, app bundles) from Google, or even just create a clear separation of concerns to make our project easier to work with— modularizing our applications can help us to achieve all of these things)
  13. Add KtLint as an extra Static Code Analysis Tool. For more info see KtLint (An anti-bikeshedding Kotlin linter with built-in formatter )
  14. Enhance MVVM with MVI. To get an understanding of MVI and how it applies to MVVM (or MVP), start with this Article MVI (Model-View_Intent, is an architecture enhancment that tries to solve the state problem, which most complex application have, especially when the screen complexity grows)
  15. Add Offline Support with Room. For more info, see Room (The Room persistence library provides an abstraction layer over SQLite to allow for more robust database access while harnessing the full power of SQLite)
  16. Integrate Maps into the App. For more info see Maps SDK for Android (With the Maps SDK for Android, you can add maps based on Google Maps data to your application)
  17. Replace Manual Navigation with the Navigation Architecture Component. For more info, see Navigation Architecture Component (The Navigation Architecture Component simplifies the implementation of navigation in an Android app)
  18. Replace Manual Pagination with the Paging Architecture Component. For more info, see Paging Architecture Component (The Paging Library makes it easier for you to load data gradually and gracefully within your app's RecyclerView)
  19. Add Background Support with Work Manager. For more info see Work Manager (The WorkManager API makes it easy to specify deferrable, asynchronous tasks and when they should run)
  20. Add Support for Material Design 2.0. For more info see Material Design 2.0 (Make beautiful products, faster. Material is a design system – backed by open-source code – that helps teams build digital experiences)
  21. Enhance ConstraintLayout with MotionLayout. For more info see MotionLayout (A MotionLayout is a ConstraintLayout which allows you to animate layouts between various states)
  22. Add Support for App Shortcuts. For more info see App Shortcuts (Define shortcuts to perform specific actions in your app. These shortcuts can be displayed in a supported launcher and help your users quickly start common or recommended tasks within your app)
  23. Add Runtime Permissions with Permissions Dispatcher Library. For more info see Permissions Dispatcher (Simple annotation-based API to handle runtime permissions.)
  24. Add Settings Screen. For more info see Settings (Settings allow users to change the functionality and behavior of an application)
  25. Add Support for Firebase Crashlytics. For more info see Firebase Crashlytics (Get clear, actionable insight into app issues with this powerful crash reporting solution for Android and iOS)
  26. Add Support for Firebase Performance Monitoring. For more info see Firebase Performance Monitoring (Gain insight into your app's performance issues)
  27. Add Support for Firebase Remote Config. For more info see Firebase Remote Config (Change the behavior and appearance of your app without publishing an app update, at no cost, for unlimited daily active users.)
  28. Add Support for Firebase Push Notifications. For more info see Firebase Cloud Messaging (Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost)
  29. Create a Continue Integration Environment using GitLab. For more info see GitLab Continuous Integration & Delivery (GitLab has integrated CI/CD pipelines to build, test, deploy, and monitor your code)
  30. Add Support for R8 (ProGuard). For more info see ProGuard and R8: a comparison of optimizers (ProGuard and R8 have three important functions, Shrinking or tree shaking: removes unused classes, fields and methods from the application, Code optimization: makes the code smaller and more efficient at the instruction level, Name obfuscation: renames the remaining classes, fields and methods with short meaningless names. At this point, it mostly reduces the size of the code)
  31. Sing the App. For more info see App Singing (Android requires that all APKs be digitally signed with a certificate before they can be installed. And you need to sign your Android App Bundle before you can upload it to the Play Console.)
  32. Create an Automated Release Process using Gradle Play Publisher Plugin. For more info see Gradle Play Publisher (Gradle plugin to upload your App Bundle or APK and other app details to the Google Play Store)
  33. Convert APK Upload Format to App Bundles. For more info see App Bundles (An Android App Bundle is a new upload format that includes all your app’s compiled code and resources, but defers APK generation and signing to Google Play)
  34. Enable Deep Links and Android App Links. For more info see Android App Links (Set up Android App Links to take users to a link's specific content directly in your app, bypassing the app-selection dialog, also known as the disambiguation dialog)
  35. Add Support for Finger Print Login. For more info see Fingerprint Authentication (New APIs to let you authenticate users by using their fingerprint scans on supported devices)
  36. Add Support for Instant Apps. For more info see Google Play Instant (Google Play Instant enables native apps and games to launch on devices running Android 5.0 (API level 21) without being installed)
  37. Add Support for Slices. For more info see Slices (Slices are UI templates that can display rich, dynamic, and interactive content from your app from within the Google Search app and later in other places like the Google Assistant)
  38. Add AdMob as a Source of App Monetization. For more info see AdMob (AdMob makes earning revenue easy with in-app ads, actionable insights, and powerful, easy-to-use tools that grow your app business)
  39. Add Google Play Billing as a Source of App Monetization. For more info see Google Play Billing Library (Google Play Billing is a service that lets you sell digital content from inside an Android app, or in-app)
  40. Add Support for Machine Learning. For more info see ML Kit (ML Kit beta brings Google’s machine learning expertise to mobile developers in a powerful and easy-to-use package)
  41. Make the App compliant with Android's Accessibility Features and Services. For more info see Accessibility (Accessibility is an important part of any app. Whether you're developing a new app or improving an existing one, consider the accessibility of your app's components)
  42. Convert Imperative to Functional Programming. For more info see Arrow (Functional companion to Kotlin's Standard Library)
  43. Add Kotlin Native Support to Build the iOS equivalent App. For more info see Kotlin Native (Kotlin/Native is a technology for compiling Kotlin code to native binaries, which can run without a virtual machine)
  44. Add Kotlin Multiplatform Support to Share Code between the Android and iOS App. For more info see Kotlin Multiplatform (Kotlin Multiplatform brings the invaluable benefit of reuse for code and expertise, saving the effort for tasks more challenging than implementing everything twice or multiple times)
  45. Last but not least, Convert the whole thing to Flutter. For more info see Flutter (JUST KIDDING 😛 ...OR AM I!)

THANK YOU

About

This repository contains sample code. Its purpose being, to quickly demonstrate Android and software development in general, clean code, best practices, testing and all those other must know goodies.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 100.0%