All Projects → agamkoradiya → Android-Live-Templates

agamkoradiya / Android-Live-Templates

Licence: Apache-2.0 license
A curated android live templates to make your android development more fast🚀 and easy✨.

Projects that are alternatives of or similar to Android-Live-Templates

Hacktoberfest-2021
An Open Source repository to Teach people How to contribute to open sources.
Stars: ✭ 98 (-50.25%)
Mutual labels:  code, hacktoberfest-accepted
tempat-kontributor
Merupakan tempat bagi kalian untuk berkontributor bersama kami
Stars: ✭ 33 (-83.25%)
Mutual labels:  code, hacktoberfest-accepted
HacktoberFest21
A beginner friendly repository for HacktoberFest 2021
Stars: ✭ 45 (-77.16%)
Mutual labels:  code, hacktoberfest-accepted
Hacktoberfest-2021
This repository aims to help code beginners with their first successful pull request and open source contribution. 🥳🎯🚀
Stars: ✭ 24 (-87.82%)
Mutual labels:  code, hacktoberfest-accepted
c-future
Small beginner C programs.
Stars: ✭ 23 (-88.32%)
Mutual labels:  hacktoberfest-accepted
Hacktoberfest2021
Make your first Pull Request on Hacktoberfest 2022. Don't forget to spread love and if you like give us a ⭐️
Stars: ✭ 1,320 (+570.05%)
Mutual labels:  hacktoberfest-accepted
code-art
🌈 Collect beautiful art text, never bug. 收集好看的艺术代码,佛祖保佑,永无 Bug。找好看的注释,看这里。
Stars: ✭ 38 (-80.71%)
Mutual labels:  code
Mat-O-Wahl
🇩🇪 Mat-O-Wahl - Ein einfach zu bedienender, freier Open Source Wahl-O-Mat Klon fuer jedermann ### 🇬🇧 🇺🇸 A simple to handle, free "Voting Advice Application" / "Electoral Compass" alternative
Stars: ✭ 27 (-86.29%)
Mutual labels:  code
vscode-in-docker
Run VSCode inside of a Docker Container
Stars: ✭ 22 (-88.83%)
Mutual labels:  code
Aec-Library-Website
This is an Open-Source Library Website in which you get Resources to learn different topics, Donate book section to donate your old books, and a Book issue section to keep a record of all the books issued. -HacktoberFest Accepted
Stars: ✭ 52 (-73.6%)
Mutual labels:  hacktoberfest-accepted
codetime-web
Statistical analysis and presentation of programming time.
Stars: ✭ 22 (-88.83%)
Mutual labels:  code
Hacktoberfest2021
No description or website provided.
Stars: ✭ 15 (-92.39%)
Mutual labels:  hacktoberfest-accepted
noiiice
a serverless blog built on NuxtJS, AWS, serverless framework, and irrational exuberance.
Stars: ✭ 42 (-78.68%)
Mutual labels:  hacktoberfest-accepted
code-run
一个代码在线编辑预览工具,类似codepen、jsbin、jsfiddle等。
Stars: ✭ 325 (+64.97%)
Mutual labels:  code
Hacktoberfest-2021
Participate in Hacktoberfest by contributing to any Open Source project on GitHub! Here is a starter project for first time contributors. #hacktoberfest
Stars: ✭ 1 (-99.49%)
Mutual labels:  hacktoberfest-accepted
R edu
Facebook
Stars: ✭ 18 (-90.86%)
Mutual labels:  code
linec
🍬一个高颜值命令行统计代码行数的计数器。(counts lines of code)
Stars: ✭ 121 (-38.58%)
Mutual labels:  code
he4rtconf-landing
No description or website provided.
Stars: ✭ 11 (-94.42%)
Mutual labels:  hacktoberfest-accepted
Unity3D-Cars
A project built for a Renaissance Coders tutorial to introduce vehicle physics.
Stars: ✭ 60 (-69.54%)
Mutual labels:  code
code-examples
Example Code that I use for Referencing when needed
Stars: ✭ 14 (-92.89%)
Mutual labels:  code

Android-Live-Templates

Awesome Badge Star Badge Instagram Badge
A curated list of Android Live Templates

Poster

Star Badge Fork Badge Issues Badge PR Badge Contributors Badge License Badge

Checkout master branch for unzip folder


Content


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 How to import all live templates

How to import all live templates in 1 minute? 💥

  1. Download AndroidLiveTemplates.zip file
  2. Then follow below video tutorial

How to import all live templates


CheatSheet 📄

📌 Adapter


adapter list

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.id

        override fun areContentsTheSame(oldItem: $TYPE$, newItem: $TYPE$) =
            oldItem == newItem
    }
}

adapter normal

  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")
    }
}

📌 View Binding


binding activity

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

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
    }
}

📌 Retrofit Library


retrofit instance

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)
        }
    }
    
}

📌 Room Database


room db

@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

@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

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

// List<String> <-> String
@androidx.room.TypeConverter
fun fromList(list: List<String>): String {
    return com.google.gson.Gson().toJson(list)
}

@androidx.room.TypeConverter
fun toList(string: String): List<String> {
    return com.google.gson.Gson().fromJson(string, object : com.google.gson.reflect.TypeToken<List<String>>() {}.type)
}

room converter for date

// 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

// 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)
}

📌 Dependency Injection


di hilt app

@dagger.hilt.android.HiltAndroidApp
class $FILE_NAME$ : android.app.Application() {
}

di retrofit module

@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

@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$

📌 Drawable


shape bubble

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners
        android:bottomRightRadius="10dp"
        android:radius="40dp" />

    <stroke
        android:width="1dp"
        android:color="@color/$STROKE_COLOR$" />

    <size
        android:width="50dp"
        android:height="50dp" />
        
    <solid android:color="@color/$SOLID_COLOR$" />

</shape>

shape halfcircle

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners
        android:topLeftRadius="60dp"
        android:topRightRadius="60dp" />

    <size
        android:width="120dp"
        android:height="60dp" />

    <solid android:color="@color/$SOLID_COLOR$" />

</shape>

shape line

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">

    <stroke
        android:width="3dp"
        android:color="@color/$STROKE_COLOR$" />

    <size android:height="1dp" />

</shape>

shape oval

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <stroke
        android:width="3dp"
        android:color="@color/$STROKE_COLOR$" />

    <solid android:color="@color/$SOLID_COLOR$" />

</shape>

shape ractangle

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners android:radius="10dp" />

    <stroke
        android:width="3dp"
        android:color="@color/$STROKE_COLOR$" />

    <solid android:color="@color/$SOLID_COLOR$" />

</shape>

shape ring

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="ring"
    android:thickness="5dp"
    android:useLevel="false">
    
    <solid android:color="@color/$SOLID_COLOR$" />

</shape>

shape round

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="0dp"
    android:shape="ring"
    android:thickness="100dp"
    android:useLevel="false">

    <solid android:color="@color/$SOLID_COLOR$" />

</shape>

state list

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/$DRAWABLE1$" android:state_pressed="true" /> <!-- pressed -->
    <item android:drawable="@drawable/$DRAWABLE2$" android:state_focused="true" /> <!-- focused -->
    <item android:drawable="@drawable/$DRAWABLE3$" android:state_hovered="true" /> <!-- hovered -->
    <item android:drawable="@drawable/$DRAWABLE4$" android:state_selected="true" /> <!-- selected -->
    <item android:drawable="@drawable/$DRAWABLE5$" android:state_checkable="true" /> <!-- checkable -->
    <item android:drawable="@drawable/$DRAWABLE6$" android:state_checked="true" /> <!-- checked -->
    <item android:drawable="@drawable/$DRAWABLE7$" android:state_enabled="true" /> <!-- enabled -->
    <item android:drawable="@drawable/$DRAWABLE8$" android:state_activated="true" /> <!-- activated -->
    <item android:drawable="@drawable/$DRAWABLE9$" android:state_window_focused="true" /> <!-- window_focused -->
    <item android:drawable="@drawable/$DRAWABLE$" /> <!-- default -->
</selector>

📌 XML


center_horizontal

        app:layout_constraintEnd_toStartOf="@+id/$VIEWIDSTART$"
        app:layout_constraintStart_toEndOf="@+id/$VIEWIDEND$"

center_horizontal_parent

        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"

center_parent

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"

center_vartical

        app:layout_constraintBottom_toTopOf="@+id/$VIEWIDTOP$"
        app:layout_constraintTop_toBottomOf="@+id/$VIEWIDBOTTOM$"

center_vartical_parent

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"

xml_menu

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/menu_$ID1$"
        android:icon="@drawable/$ICON1$"
        android:title="@string/$TITLE1$"
        app:showAsAction="$ACTION1$" />

    <item
        android:id="@+id/menu_$ID2$"
        android:icon="@drawable/$ICON2$"
        android:title="@string/$TITLE2$"
        app:showAsAction="$ACTION2$" />
        
    <item
        android:id="@+id/menu_$ID3$"
        android:icon="@drawable/$ICON3$"
        android:title="@string/$TITLE3$"
        app:showAsAction="$ACTION3$" />
        
        <item
        android:id="@+id/menu_$ID4$"
        android:icon="@drawable/$ICON4$"
        android:title="@string/$TITLE4$"
        app:showAsAction="$ACTION4$" />
        
    <item
        android:id="@+id/menu_$ID5$"
        android:icon="@drawable/$ICON5$"
        android:title="@string/$TITLE5$"
        app:showAsAction="$ACTION5$" />
        
</menu>

📌 Util


util resource

sealed class Resource<T>(val data: T?, val message: String?) {
    class Success<T>(data: T) : Resource<T>(data, null)
    class Error<T>(message: String) : Resource<T>(null, message)
}

util toast

fun android.content.Context.toast(message: CharSequence) =
    android.widget.Toast.makeText(this, message, android.widget.Toast.$LENGTH$).show()

📌 Gradle dependency


coil depen

// Coil Image Loading Library
    implementation "io.coil-kt:coil:1.2.1"

coroutines depen

// Coroutines Dependency
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3"

data binding

apply plugin: 'kotlin-kapt'

buildFeatures {
    dataBinding true
}

datastore depen

// Data store
// Typed DataStore (Typed API surface, such as Proto)
    implementation "androidx.datastore:datastore:1.0.0-beta01"
// Preferences DataStore (SharedPreferences like APIs)
    implementation "androidx.datastore:datastore-preferences:1.0.0-beta01"

easy permission depen

// Easy permission library
    implementation 'com.vmadalin:easypermissions-ktx:1.0.0'

glide depen

// Glide Image Loading Library
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

hilt classpath

classpath "com.google.dagger:hilt-android-gradle-plugin:2.35"

hilt depen

// Hilt Dependency Injection
    implementation "com.google.dagger:hilt-android:2.35"
    kapt "com.google.dagger:hilt-compiler:2.35"

hilt plugin

id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'

lifecycle depen

// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1"

// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1"

// Lifecycles only (without ViewModel or LiveData)
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"

// Saved state module for ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.1"

// Annotation processor
kapt "androidx.lifecycle:lifecycle-compiler:2.3.1"

// alternately - if using Java8, use the following instead of lifecycle-compiler
implementation "androidx.lifecycle:lifecycle-common-java8:2.3.1"

navigation depen

// Navigation Component
    implementation "androidx.navigation:navigation-fragment-ktx:2.3.5"
    implementation "androidx.navigation:navigation-ui-ktx:2.3.5"

paging depen

// Paging 3
    implementation "androidx.paging:paging-runtime-ktx:3.0.0"

retrofit depen

// Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation "com.squareup.okhttp3:okhttp:4.9.0"
    implementation "com.squareup.okhttp3:logging-interceptor:4.5.0"

room depen

// Room
    // kapt plugin: cut it and paste in plugins
    id 'kotlin-kapt'
    
    implementation "androidx.room:room-runtime:2.3.0"
    // To use Kotlin annotation processing tool (kapt)
    kapt "androidx.room:room-compiler:2.3.0"
    // optional - Kotlin Extensions and Coroutines support for Room
    implementation "androidx.room:room-ktx:2.3.0"

safeargs classpath

classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"

safeargs plugin

id 'androidx.navigation.safeargs.kotlin'

view and data binding

buildFeatures {
    viewBinding true
    dataBinding true
}
id 'kotlin-kapt'

view binding

buildFeatures {
    viewBinding true
}

How to create your own live templates? 💡


Official documentation

Live template variables

Suggest me


If you have any suggestion or you want to add any other templates than ping me on Instagram Badge

Contribute

Contributions are always welcome!😇 Please read the contribution guidelines first.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].