This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun main(args : Array<String>) { | |
| val text = "With multiple \t whitespace" | |
| println(text) | |
| } | |
| fun replaceMultipleWhiteSpace(value : String) : String { | |
| var regex = Regex("\\s+") | |
| return regex.replace(value, " ") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| binding.imageView.load(url) { | |
| placeholder(R.drawable.ic_placeholder) | |
| crossfade(true) | |
| crossfade(500) | |
| transformations(RoundedCornersTransformation(80f)) | |
| transformations(CircleCropTransformation()) | |
| transformations(GrayscaleTransformation()) //will make image black and white | |
| transformations(BlurTransformation(applicationContext, radius=20f)) | |
| //to have multiple transformation see below |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| A higher-order function is a function that takes functions as parameters or returns a function. | |
| It's a function which can take do two things: | |
| Can take functions as parameters | |
| Can return a function | |
| */ | |
| // 1. A function can take functions as parameters. | |
| fun passMeFunction(abc: () -> Unit) { | |
| // I can take function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private const val SALARY_THRESHOLD = 100 | |
| private val taxCollector = TaxCollector() | |
| //before using lazy | |
| private val accountant = Accountant() | |
| //after using lazy everything by the keyword is delegate, this lazy is used when we want to utilize account | |
| private val accountant by lazy { | |
| Accountant() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // kotlin | |
| implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |
| implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" | |
| implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion" | |
| // architecture components | |
| implementation "androidx.core:core-ktx:$coreVersion" | |
| implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion" | |
| implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion" | |
| implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //*************removing the duplicate strings from an array******************* | |
| // Maintain the original order of items | |
| val devs = arrayOf("Amit", "Ali", "Amit", "Sumit", "Sumit", "Himanshu") | |
| print(devs.distinct()) // [Amit, Ali, Sumit, Himanshu] | |
| // Maintain the original order of items | |
| val devs = arrayOf("Amit", "Ali", "Amit", "Sumit", "Sumit", "Himanshu") | |
| print(devs.toSet()) // [Amit, Ali, Sumit, Himanshu] | |
| // Maintain the original order of items |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //*************************When using with Retrofit please use below converter************************************* | |
| implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0") | |
| //A Retrofit 2 Converter.Factory for Kotlin serialization. | |
| val contentType = "application/json".toMediaType() | |
| val retrofit = Retrofit.Builder() | |
| .baseUrl("https://example.com/") | |
| .addConverterFactory(Json.asConverterFactory(contentType)) | |
| .build() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object Constants { | |
| const val UNSPLASH_IMAGE_TABLE = "unsplash_image_table | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| slide_in_left.xml | |
| */ | |
| <?xml version="1.0" encoding="utf-8"?> | |
| <set xmlns:android="http://schemas.android.com/apk/res/android"> | |
| <translate | |
| android:duration="@android:integer/config_mediumAnimTime" | |
| android:fromXDelta="0" | |
| android:toXDelta="-100%p" /> | |
| </set> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dependencies { | |
| implementation 'com.squareup.logcat:logcat:0.1' | |
| } | |
| *************Install AndroidLogcatLogger in Application.onCreate()****************** | |
| import android.app.Application | |
| import logcat.AndroidLogcatLogger | |
| import logcat.LogPriority.VERBOSE |
NewerOlder