https://github.com/agamkoradiya/Android-Live-Templates
A curated android live templates to make your android development more fast🚀 and easy✨. Import all of them within a minute⌛
https://github.com/agamkoradiya/Android-Live-Templates
androdistudio android android-studio-live-templates androidstudiotemplate live-templates livetemplate
Last synced: 6 months ago
JSON representation
A curated android live templates to make your android development more fast🚀 and easy✨. Import all of them within a minute⌛
- Host: GitHub
- URL: https://github.com/agamkoradiya/Android-Live-Templates
- Owner: agamkoradiya
- License: apache-2.0
- Created: 2021-05-15T03:18:57.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-26T18:07:46.000Z (about 2 years ago)
- Last Synced: 2024-07-27T10:32:22.221Z (10 months ago)
- Topics: androdistudio, android, android-studio-live-templates, androidstudiotemplate, live-templates, livetemplate
- Homepage:
- Size: 11.3 MB
- Stars: 292
- Watchers: 6
- Forks: 28
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: contributing.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - agamkoradiya/Android-Live-Templates - A curated android live templates to make your android development more fast🚀 and easy✨. Import all of them within a minute⌛ (Misc)
README
![]()
![]()
![]()
![]()
![]()
![]()
# Content :notebook:
- [What is live template? 😮](#what-is-live-template-)
- [Demo 💻](#demo-)
- [How to *import all live templates* in 1 minute? 💥](#how-to-import-all-live-templates-in-1-minute-)
- [CheatSheet for this repository 📄](#cheatsheet-)
- [Adapter](#adapters)
- [View binding](#view-binding)
- [Retrofit library](#retrofit-library)
- [Room database](#room-database)
- [Dependency Injection](#dependency-injection)
- [Drawable](#drawable)
- [XML](#xml)
- [Util](#util)
- [Gradle dependency](#gradle-dependencies)
- [How to create your own live templates? 💡](#how-to-create-your-own-live-templates-)
- [Suggest me! ✒️](#suggest-me)
- [Contribute ❤️](#contribute)## What is live template? 😮
Live Templates are code snippets that you can insert into your code by typing their abbreviation and pressing tab.
By using them, you can quickly and intelligently add frequently used code patterns and constructs to your code, letting the IDE do the tedious work for you.## Demo 💻
![]()
## How to import all live templates in 1 minute? 💥
1. Download AndroidLiveTemplates.zip file
2. Then follow below video tutorial
![]()
## CheatSheet 📄
Write Only :keyboard:
You will get :sparkles:
:diamonds: Adapters :diamonds:
adapter list```kotlin
class $FILE_NAME$ : androidx.recyclerview.widget.ListAdapter<$TYPE$, $FILE_NAME$.$HOLDER_NAME$ViewHolder>(DiffCallback()) {override fun onCreateViewHolder(parent: android.view.ViewGroup, viewType: Int): $HOLDER_NAME$ViewHolder {
val binding =
$BINDING$.inflate(
android.view.LayoutInflater.from(parent.context),
parent,
false
)
return $HOLDER_NAME$ViewHolder(binding)
}override fun onBindViewHolder(holder: $HOLDER_NAME$ViewHolder, position: Int) {
val currentItem = getItem(position)
}inner class $HOLDER_NAME$ViewHolder(private val binding: $BINDING$) :
androidx.recyclerview.widget.RecyclerView.ViewHolder(binding.root) {}class DiffCallback : androidx.recyclerview.widget.DiffUtil.ItemCallback<$TYPE$>() {
override fun areItemsTheSame(oldItem: $TYPE$, newItem: $TYPE$) =
oldItem.id == newItem.idoverride fun areContentsTheSame(oldItem: $TYPE$, newItem: $TYPE$) =
oldItem == newItem
}
}
```
adapter normal
```kotlin
class $FILE_NAME$ : androidx.recyclerview.widget.RecyclerView.Adapter<$FILE_NAME$.MyViewHolder>() {class MyViewHolder(itemView: android.view.View) : androidx.recyclerview.widget.RecyclerView.ViewHolder(itemView) {}
override fun onCreateViewHolder(parent: android.view.ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(
android.view.LayoutInflater.from(parent.context).inflate(R.layout.$LAYOUT$, parent, false)
)
}override fun getItemCount(): Int {
TODO("Not yet implemented")
}override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
TODO("Not yet implemented")
}
}
```
:diamonds: View Binding :diamonds:
binding activity
```kotlin
class $FILE_NAME$ : androidx.appcompat.app.AppCompatActivity() {private lateinit var binding: $BINDING_LAYOUT$
override fun onCreate(savedInstanceState: android.os.Bundle?) {
super.onCreate(savedInstanceState)
binding = $BINDING_LAYOUT$.inflate(layoutInflater)
val view = binding.root
setContentView(view)
}
}
```
binding fragment
```kotlin
class $FILE_NAME$ : androidx.fragment.app.Fragment() {private var _binding: $BINDING_LAYOUT$? = null
private val binding get() = _binding!!override fun onCreateView(
inflater: android.view.LayoutInflater,
container: android.view.ViewGroup?,
savedInstanceState: android.os.Bundle?
): android.view.View {
_binding = $BINDING_LAYOUT$.inflate(inflater, container, false)
return binding.root
}override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
```
:diamonds: Retrofit Library :diamonds:
retrofit instance
```kotlin
class $FILE_NAME$ {companion object {
private val retrofit by lazy {
val logging = okhttp3.logging.HttpLoggingInterceptor()
logging.setLevel(okhttp3.logging.HttpLoggingInterceptor.Level.$TYPE$)
val client = okhttp3.OkHttpClient.Builder()
.addInterceptor(logging)
.build()
retrofit2.Retrofit.Builder()
.baseUrl($BASE_URL$)
.addConverterFactory(retrofit2.converter.gson.GsonConverterFactory.create())
.client(client)
.build()
}val api by lazy {
retrofit.create($API_NAME$::class.java)
}
}
}
```
:diamonds: Room Database :diamonds:
room db
```kotlin
@androidx.room.Database(
entities = [$TABLE_NAME$::class],
version = 1,
exportSchema = false
)
@androidx.room.TypeConverters($CONVERTER_NAME$::class)
abstract class $FILE_NAME$ : androidx.room.RoomDatabase() {abstract fun $DAO_NAME$(): $DAO_TYPE$
}
```
room db with singleton
```kotlin
@androidx.room.Database(
entities = [$TABLE_NAME$::class],
version = 1,
exportSchema = false
)
@androidx.room.TypeConverters($CONVERTER_NAME$::class)
abstract class $FILE_NAME$ : androidx.room.RoomDatabase() {abstract fun $DAO_NAME$(): $DAO_TYPE$
companion object {
@Volatile
private var INSTANCE: $FILE_NAME$? = null
private val LOCK = Any()fun getDatabase(context: android.content.Context): $FILE_NAME$ =
INSTANCE ?: synchronized(LOCK) {
INSTANCE
?: buildDatabase(context).also { INSTANCE = it }
}private fun buildDatabase(context: android.content.Context) =
androidx.room.Room.databaseBuilder(
context.applicationContext,
$FILE_NAME$::class.java, "$DB_NAME$.db"
).build()
}
}
```
room dao
```kotlin
import androidx.room.*@Dao
interface $FILE_NAME$ {@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert$TABLE_NAME$($VAR_NAME$: $TABLE_NAME$)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll$TABLE_NAME$(vararg $VAR_NAME$s: $TABLE_NAME$)@Update
suspend fun update($VAR_NAME$: $TABLE_NAME$)@Delete
suspend fun delete($VAR_NAME$: $TABLE_NAME$)@Query("SELECT * FROM $VAR_NAME$")
fun getAll$TABLE_NAME$(): List<$TABLE_NAME$>}
```
room converter for list of string
```kotlin
// List <-> String
@androidx.room.TypeConverter
fun fromList(list: List): String {
return com.google.gson.Gson().toJson(list)
}@androidx.room.TypeConverter
fun toList(string: String): List {
return com.google.gson.Gson().fromJson(string, object : com.google.gson.reflect.TypeToken>() {}.type)
}
```
room converter for date
```kotlin
// Date <-> Long
@androidx.room.TypeConverter
fun fromTimestamp(value: Long?): java.util.Date? {
return value?.let { java.util.Date(it) }
}@androidx.room.TypeConverter
fun dateToTimestamp(date: java.util.Date?): Long? {
return date?.time?.toLong()
}
```
room converter for bitmap
```kotlin
// Bitmap <-> ByteArray
@androidx.room.TypeConverter
fun fromBitmap(bitmap: android.graphics.Bitmap): ByteArray {
val outputStream = java.io.ByteArrayOutputStream()
bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100, outputStream)
return outputStream.toByteArray()
}@androidx.room.TypeConverter
fun toBitmap(byteArray: ByteArray): android.graphics.Bitmap {
return android.graphics.BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size)
}
```
:diamonds: Dependency Injection :diamonds:
di hilt app
```kotlin
@dagger.hilt.android.HiltAndroidApp
class $FILE_NAME$ : android.app.Application() {
}
```
di retrofit module
```kotlin
@javax.inject.Singleton
@dagger.Provides
fun provideRetrofit(): retrofit2.Retrofit =
retrofit2.Retrofit.Builder()
.baseUrl($BASE_URL$)
.addConverterFactory(retrofit2.converter.gson.GsonConverterFactory.create())
.build()@javax.inject.Singleton
@dagger.Provides
fun provide$API_NAME$(retrofit: retrofit2.Retrofit): $API$ =
retrofit.create($API$::class.java)
```
di room module
```kotlin
@javax.inject.Singleton
@dagger.Provides
fun provideDatabase(
@dagger.hilt.android.qualifiers.ApplicationContext context: android.content.Context
) = androidx.room.Room.databaseBuilder(
context,
$DATABASE_CLASS$::class.java,
"$DATABASE_NAME$"
).build()@javax.inject.Singleton
@dagger.Provides
fun provideDao(database: $DATABASE_CLASS$) = database.$METHOD$
```
:diamonds: Drawable :diamonds:
shape bubble
```kotlin
```
shape halfcircle
```kotlin
```
shape line
```kotlin
```
shape oval
```kotlin
```
shape ractangle
```kotlin
```
shape ring
```kotlin
```
shape round
```kotlin
```
state list
```kotlin
```
:diamonds: XML :diamonds:
center_horizontal
```kotlin
app:layout_constraintEnd_toStartOf="@+id/$VIEWIDSTART$"
app:layout_constraintStart_toEndOf="@+id/$VIEWIDEND$"
```
center_horizontal_parent
```kotlin
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
```
center_parent
```kotlin
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
```
center_vartical
```kotlin
app:layout_constraintBottom_toTopOf="@+id/$VIEWIDTOP$"
app:layout_constraintTop_toBottomOf="@+id/$VIEWIDBOTTOM$"
```
center_vartical_parent
```kotlin
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
```
xml_menu
```kotlin
```
:diamonds: Util :diamonds:
util resource
```kotlin
sealed class Resource(val data: T?, val message: String?) {
class Success(data: T) : Resource(data, null)
class Error(message: String) : Resource(null, message)
}
```
util toast
```kotlin
fun android.content.Context.toast(message: CharSequence) =
android.widget.Toast.makeText(this, message, android.widget.Toast.$LENGTH$).show()
```
:diamonds: Dependencies :diamonds:
view and data binding
```kotlin
buildFeatures {
viewBinding true
dataBinding true
}
```
view binding
```kotlin
buildFeatures {
viewBinding true
}
```
## How to create your own live templates? 💡
[Official documentation](https://www.jetbrains.com/help/idea/creating-and-editing-live-templates.html)
[Live template variables](https://www.jetbrains.com/help/idea/template-variables.html)
## Suggest me
If you have any suggestion or you want to add any other templates than ping me on![]()
## Contribute
Contributions are always welcome!😇
Please read the [contribution guidelines](contributing.md) first.