Skip to content

Instantly share code, notes, and snippets.

@senamit2708
senamit2708 / Employee.kt
Created July 6, 2023 09:10
Sealed Class Learning
package com.example.coroutinelearning.entity
sealed class Employee //there is no need of {}, its optional
//if you use {}, u have to call class with use of Employee class, like Employee.Manager from fragment/activity. else u will be
//able to directly call it.
data class Manager(val name: String, val age: Int, val team: List<String>) : Employee()
class SeniorDev(val name: String, val age: Int, val project: String) : Employee()
object JuniorDev : Employee()
@senamit2708
senamit2708 / SealedLearningFrag.kt
Created July 6, 2023 09:02
multiple button with "when"
class SealedLearningFrag: Fragment(), View.OnClickListener{
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.btnEmployee.setOnClickListener(this)
binding.btnManager.setOnClickListener(this)
binding.btnJuniorDev.setOnClickListener(this)
}
package com.example.coroutinelearning.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import com.example.coroutinelearning.databinding.NewUserEntryBinding
@senamit2708
senamit2708 / ByDelegateFragment.kt
Created July 5, 2023 09:25
By - delegates basic learning
package com.example.coroutinelearning.fragments
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.coroutinelearning.databinding.ByDelegateLearningBinding
package com.example.coroutinelearning.viewModels.learning
import android.app.Application
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.example.coroutinelearning.repositories.MyRepositoryTwo
import java.lang.IllegalArgumentException
class MyAndroidViewModelFactoryFour(
private val application: Application,
package com.example.coroutinelearning.database
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.coroutinelearning.entity.User
@Database(entities = [User::class], version = 1, exportSchema = false)
abstract class AppDatabase: RoomDatabase() {
//fragment
private lateinit var binding: DashboardBinding
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
class MainActivity : AppCompatActivity() {
private lateinit var navHostFragment: NavHostFragment
private lateinit var appBarConfiguration: AppBarConfiguration
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
package basics
/*
1. structure equality -> == or equals -> both are same here -> value comp -> equality of 2 object in terms of value
2. reference equality -> === -> memory location comparison -> two reference variable points to same object
negative of == -> !=
negative of === -> !==
@senamit2708
senamit2708 / basicScope.kt
Created June 30, 2023 10:31
scope function learning
/*
there are five types of scope functions: makes your code clear, concise and more readable
with
let
run
apply
also
two main difference between them
1. the way to refer the context object -> either this or it