Skip to content

Instantly share code, notes, and snippets.

View devrath's full-sized avatar
💭
I'm grateful when for one drop in glass. Since I knw exactly what to do with it

Devrath devrath

💭
I'm grateful when for one drop in glass. Since I knw exactly what to do with it
View GitHub Profile
@devrath
devrath / Age.kt
Created September 30, 2022 15:54
Data object class is same as normal object class
data object Age {
private const val default : Int = 0
fun printDefaultAge(): Int {
return default
}
}
@devrath
devrath / MainActivity.kt
Created September 30, 2022 15:44
Sealed class implementation
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
println(User.Name)
println(User.Age)
}
}
@devrath
devrath / KotlinLanguageVersion.gradle
Created September 30, 2022 15:18
Kotlin options
kotlinOptions {
jvmTarget = '1.8'
languageVersion = '1.8'
}
@devrath
devrath / settings.gradle
Created September 30, 2022 15:08
kotlin version
'org.jetbrains.kotlin.android' version '1.7.20'
@devrath
devrath / CustomBackgroundThread.kt
Created September 19, 2022 13:34
demo describing using handler in android to process runnables
class CustomBackgroundThread : Thread() {
private var handler: Handler? = null
override fun run() {
super.run()
Looper.prepare() // Prepare the looper and associate with current thread
handler = Handler()
Looper.loop() // Start the thread so that it can keep the thread active
}
@devrath
devrath / HandlerOne.kt
Created September 18, 2022 17:40
Sample showing how the handler thread is used to publish something from separate background thread to android main thread
class HandlerOne(handlerTag: String) : HandlerThread(handlerTag) {
private lateinit var handler : Handler
init {
start()
handler = Handler(looper)
}
fun execute( runnable: Runnable) : HandlerOne {
@devrath
devrath / CustomRunnableOne.kt
Last active September 17, 2022 17:42
This snippet contains code on how to use a class that implementing runnable class to achieve threading in android
class CustomRunnableOne : Runnable {
override fun run() {
try {
val TAG_ONE = "one"
for (i in 0 until 5) {
Thread.sleep(500L)
println(TAG_NARUTO.plus("--$i--").plus("Current Runnable-->$TAG_ONE"))
}
}catch (ex:InterruptedException){
@devrath
devrath / CustomThreadOne.kt
Last active September 17, 2022 16:28
This snippet contains code on how to use a class that extends thread class to achieve threading in android
class CustomThreadOne : Thread() {
override fun run() {
try {
val TAG_ONE = "one"
for (i in 0 until 5) {
Thread.sleep(500L)
println(TAG_SASUKE.plus("--$i--").plus(name).plus("--").plus(TAG_ONE))
}
}catch (ex:InterruptedException){
println(TAG_SASUKE.plus("--").plus("Thread named").plus("--").plus(name).plus("--").plus("is interrupted"))
@devrath
devrath / AbstractSealedClass.kt
Created August 9, 2022 10:50
Defining the sealed class
sealed class Animal {
object Cat : Animal() // We can define a Object classes like this
data class Dog(val name: String) : Animal() // We can define data classes like this
}
@devrath
devrath / FakeUser.kt
Created August 3, 2022 15:01
Adding a fake user
data class FakeUser(
override val id: String = "",
override val firstName: String = "",
override val lastName: String = "",
override val email: String = "",
override val image: String = "",
override val mobile: Long = 0,
override val gender: String = "",
override val profileCompleted: Int = 0
) : UserAbstract(id,firstName,lastName,email,image,mobile,gender,profileCompleted)