This file contains 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
/** | |
* Native Mobile Bits Evening Coding Paper @5pm IST | |
* Class, Objects & Primary Constructor | |
*/ | |
class Player constructor(val playerName:String) { | |
} | |
fun main(){ |
This file contains 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
/** | |
* Native Mobile Bits Evening Coding Paper @5pm IST | |
* lateinit in Kotlin | |
*/ | |
class Main { | |
lateinit var name: String | |
fun checkValues() { | |
if (this::name.isInitialized){ | |
println("Value of name is $name") |
This file contains 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
/** | |
* Native Mobile Bits Evening Coding Paper @5pm IST | |
* "Infix - very useful" | |
*/ | |
fun main() { | |
// val result = 20.add(3) Traditional way | |
val result = 20 add 3 //with Infix function | |
println(result) |
This file contains 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
val intent = Intent(this, AlarmReceiver::class.java) | |
val pendingIntent = PendingIntent.getBroadcast( | |
this, | |
ALARM_SERVICE_CODE, | |
intent, | |
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT | |
) | |
val mAlarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager | |
mAlarmManager.setExactAndAllowWhileIdle( |
This file contains 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
val intent = Intent(this, AlarmReceiver::class.java) | |
val pendingIntent = PendingIntent.getBroadcast( | |
this, | |
ALARM_SERVICE_CODE, | |
intent, | |
PendingIntent.FLAG_UPDATE_CURRENT | |
) | |
val mAlarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager | |
mAlarmManager.setExactAndAllowWhileIdle( |
This file contains 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
package com.vs.kotlinserialization | |
import kotlinx.serialization.Serializable | |
//we need to add this annotation | |
@Serializable | |
data class Fruit (val name:String) |
This file contains 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
apply plugin: 'com.android.application' | |
apply plugin: 'kotlin-android' | |
apply plugin: 'kotlin-android-extensions' | |
//Plugin | |
apply plugin: 'kotlinx-serialization' | |
android { | |
defaultConfig { | |
... | |
} |
This file contains 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
buildscript { | |
ext.kotlin_version = "1.4.10" | |
repositories { | |
google() | |
jcenter() | |
} | |
dependencies { | |
classpath "com.android.tools.build:gradle:4.0.1" | |
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" |
This file contains 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
//add this annotation to make it accessible all dependencies from DI Graph created using HILT | |
@AndroidEntryPoint | |
class MainActivity : AppCompatActivity() { | |
//access viewmodel like this | |
private val sampleViewModel: SampleViewModel by viewModels() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) |
This file contains 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
class SampleViewModel @ViewModelInject constructor( | |
private val networkRepository: NetworkRepository | |
) : ViewModel() { | |
//code | |
} |
NewerOlder