Skip to content

Android Studio Templates

Yuri Shmakov edited this page Aug 15, 2017 · 2 revisions

We've introduced you into Moxy - mvp framework for spliting application into logic layers and lifecycle managing. Now it's time to to reduce boilerplate via Android Studio Templates

Project structure

Firstly we should immobilize project structure
  • model
  • presentation
    • presenter
    • view
  • ui
    • activity
    • fragment

Presenter, view, activity and fragment packages consist of logic modules. These models are often the application's sections (f.e. intro, offers, feed) Check example with two Activity (CarActivity and HomeActivity) and one fragment (CarDetailsFragment) belowarDetailsFragment)

Activity template

Our goal is generate this class set using Android Studio Templates

Template settings

Adding Moxy templates to Android Studio:

  • Download templates for Java from Github or directly using link
  • Or download templates for Kotlin from Github
  • Copy files to ANDROID_STUDIO_DIR/plugins/android/lib/templates/activities
  • Restart Android Studio

Managing hot keys for templates quick access:

  • Open settings-> Keymap
  • Enter "Moxy" to search box
  • Add key combination (A prefer Alt + A for Moxy Activity and Alt + F for Moxy Fragment)

Activity template

Temlates using

  • Click your ROOT package and then press Alt + A.
  • In Activity Name box enter "MyFirstMoxyActivity"

Other fields will fill automaticly

Activity template

Finaly print in the Package Name field yoor subpackage name (f.e. first) and press Finish.

Attention while your Android Studio upgrading all the custom templates can be delayed. In this case it is necessary to import them again

Links

Templates also available from other repositories in kotlin and java

[Kotlin] from REDMADROBOT View REDMAD templates repo

[Java] from Ribot View Ribot templates repo