This repository contains live and file templates to be used in Android Studio during the development of an Android Application.
Many of live and file templates are linked with InitiateAndroid. InitiateAndroid is a library and a gradle plugin to kick start the development of Android application. It makes use of some of the templates here to generate files and code to support some of the functionality in it. More information about how to use the templates along with the library is found here.
-
fileTemplates
This folder contains the kotlin files for file templates
-
options
This folder contains an xml file with settings added for file templates
-
templates
This folder contains xml files of live templates
-
Live-File-Templates.zip
This file is generated using 'Export Settings...' option in Android Studio (File -> Manage IDE Settings). All the above folders are got when this file is unzipped. But to import the settings in Android Studio, unzipping is not necessary. Check the Setup section to get the steps.
To import the live and file templates, follow the steps listed below,
- Download the zip file 'Live-File Templates.zip'. This file is present at the top level directory of this repository.
- In Android Studio, go to File -> Manage IDE Settings -> Import Settings ...
- Choose the zip file downloaded when window is prompted to choose location.
- Select all the options
- File Templates
- File Templates (schemes)
- Live templates (schemes)
- Click on 'OK'
Now the live and file templates are imported into your Android Studio
To import classes directly, enable 'Add unambiguous imports on the fly' in 'Settings -> Editor -> General -> Auto Import -> Kotlin'
- Adds provides function for shared preferences and PreferenceRepository in Module class of Dagger Hilt.
- PreferenceRepository is added by using 'InitiateSharedPreferences' file template.
- Adds 'app:layout_constraintBottom_toBottomOf=""' in xml.
- Adds 'app:layout_constraintTop_toTopOf=""' in xml.
- Adds 'app:layout_constraintStart_toStartOf=""' in xml.
- Adds 'app:layout_constraintEnd_toEndOf=""' in xml.
- Adds 'app:layout_constraintBottom_toTopOf=""' in xml.
- Adds 'app:layout_constraintTop_toBottomOf=""' in xml.
- Adds 'app:layout_constraintStart_toEndOf=""' in xml.
- Adds 'app:layout_constraintEnd_toStartOf=""' in xml.
- Adds 'app:layout_constraintBottom_toBottomOf="parent"' in xml.
- Adds 'app:layout_constraintTop_toTopOf="parent"' in xml.
- Adds 'app:layout_constraintStart_toStartOf="parent"' in xml.
- Adds 'app:layout_constraintEnd_toEndOf="parent"' in xml.
- Adds 'app:layout_constraintBottom_toTopOf="parent"' in xml.
- Adds 'app:layout_constraintTop_toBottomOf="parent"' in xml.
- Adds 'app:layout_constraintStart_toEndOf="parent"' in xml.
- Adds 'app:layout_constraintEnd_toStartOf="parent"' in xml.
- Adds provides function for database builder in Module class of Dagger Hilt.
- Room Database dependencies should be added and classes used are generated using 'InitiateRoomDatabase' file template.
Live Templates - Dependent on InitiateAndroid
- Adds parameter for ConnectionRepository in ViewModel.
- Declare variables in ViewModel.
- Select a block of code and enclose it with this live template to run whenever internet connectivity changes.
- Select a block of code and enclose it with this live template to run whenever internet connectivity changes only a certain number of times.
- Adds two provides functions in Module class of Dagger Hilt.
- Functions are for Retrofit Builder and NetworkRepository.
- Files required for this are generated using 'InitiateRetrofit' file template and depends on classes in 'InitiateAndroid'.
- Adds provides function for ConnectivityRepository in Module class of Dagger Hilt.
- Creates a ListAdapter Class with inputs given
- Binding File: ViewBinding should enabled and binding file of item layout should be given as input.
- Adapter Name: Add only description of adapter in field 'Adapter Name'. For example, if the input to field is 'Test', then class name would be 'TestAdapter' and view holder name would be 'TestViewHolder'
- Item Type: Add the class name of item
- Creates a ListAdapter Class with inputs given
- Binding File: ViewBinding should enabled and binding file of item layout should be given as input.
- Adapter Name: Add only description of adapter in field 'Adapter Name'. For example, if the input to field is 'Test', then class name would be 'TestAdapter' and view holder name would be 'TestViewHolder'
- Item Type: Add the class name of item
- This should be called from base package and all the files are created in 'data/local/room' package
- It creates three files
- A sample entity class in 'data/local/room/entity' package
- A sample dao class in 'data/local/room/dao' package
- An AppDatabase class extending RoomDatabase with table defined in entity file, in 'data/local/room' package.
- This should be called from base package and all the files are created in 'data/local/preferences' package
- It creates three files
- An object class 'PreferenceKeys' to store key values
- An interface 'PreferenceRepository' which contains 'get' and 'put' functions for String, Int and Boolean
- An implementation class 'PreferenceRepository' which contains implementations of 'get' and 'put' functions
- Creates an interface with the name provided and a class with the suffix 'Impl' and implementing the interface
- Creates Module class for Dagger-Hilt with inputs,
- Initiate Retrofit : If 'InitiateRetrofit' file template has already been called, then add the value 'true' and if not, leave it blank.
- Initiate Room Database : If 'InitiateRoomDatabase' file template has already been called, then add the value 'true' and if not, leave it blank.
- Initiate Shared Preferences : If 'InitiateSharedPreferences' file template has already been called, then add the value 'true' and if not, leave it blank.
File Templates - Dependent on InitiateAndroid
- Creates a fragment extending ViewBindingFragment from InitiateAndroid
- File Name: Name of fragment
- Layout Binding: ViewBinding should enabled and binding file of item layout should be given as input.