Slide 1

Slide 1 text

Writing a modular Android Application - Karan Trehan Android @ m.Paani @karntrehan

Slide 2

Slide 2 text

What? What is a modular Android Application? How? How do I go about making my app modular? Why? Why do I or my users need it? 2

Slide 3

Slide 3 text

“ 3 What? Modular programming is a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality. -https://en.wikipedia.org/wiki/Modular_programming

Slide 4

Slide 4 text

4 Default structure Drawbacks: ▪ No shared utils ▪ Cumbersome code navigation ▪ No Instant Apps ▪ Slow gradle builds

Slide 5

Slide 5 text

5 Modular structure Advantages: ▪ Faster gradle builds ▪ Re-usability of common functionality ▪ Easily “Instant” your apps ▪ Better teamwork (Ownership) ▪ Smoother Git Flows

Slide 6

Slide 6 text

Initial doubts with a modular Android App ▪ What architecture do I use? ▪ Is my choice of language going to impact me? ▪ How do I define my modules? ▪ What is a core module? ▪ How do I use 3rd party libraries? ▫ Room? ▫ Dagger 2? 6

Slide 7

Slide 7 text

Architecture Which one do I choose? MVP Presenter communicates between the view and the model 7 MVVM Viewmodel communicates between the view and the model Clean Like MVP, the model contains use cases which can be shared across multiple models MVI For each user action an intent is dispatched by the View and observed by the Presenter Reductor Redux inspired to make state mutations easier to read, write and reason about Custom Your custom implementation

Slide 8

Slide 8 text

CHOOSE ANY! Your architecture choices in no way impact the modular-ness of your app! Better, you can have different architectures in different modules. 8

Slide 9

Slide 9 text

9 Language Which one do I write my modules in? VS

Slide 10

Slide 10 text

But, please, give Kotlin a try! Again, CHOOSE ANY! 10

Slide 11

Slide 11 text

11 Modules What goes in which module? ▪ Identify app flows ▪ Create feature modules ▪ Non-UI modules ▪ Examples: ▫ authentication ▫ onboarding ▫ settings ▫ account ▫ notification

Slide 12

Slide 12 text

12 Core Module Why do I need one? ▪ Utility classes and extension functions ▪ Global classes and callbacks ▪ Initiate libraries ▪ Provides global dependencies to dependency injection framework

Slide 13

Slide 13 text

13 core stores rewards home notification authentication dependent’s build.gradle Module dependency structure

Slide 14

Slide 14 text

14 3rd Party Libraries Where do I add them and initialize them? core’s build.gradle core’s CoreApp.kt

Slide 15

Slide 15 text

15 Room How do I use this awesome library? ▪ New db into each feature module ▪ Migrations are modularized ▪ Instant apps contain only those tables they need ▪ Queries will be faster

Slide 16

Slide 16 text

16 Dagger 2 How do I handle my dependencies?

Slide 17

Slide 17 text

Actual Code Implementation! ▪ Modular ▪ Kotlin ▪ Rx ▪ Retrofit ▪ LiveData ▪ ViewModel ▪ Tests https://github.com/karntrehan/posts Place your screenshot here 17 @karntrehan

Slide 18

Slide 18 text

THANK YOU! Have fun modularizing your apps! @karntrehan Template from: Mowbray, Link: https://goo.gl/XVJRqH