Skip to content

Instantly share code, notes, and snippets.

View Debdutta-Panda's full-sized avatar

Debdutta Panda Debdutta-Panda

View GitHub Profile
class YourViewModel: ViewModel() {
val uiScope = mutableStateOf<UIScope?>(null)
private val counter = mutableStateOf(0)
fun onButtonClick() {
if((++counter.value)%2==1){
uiScope.scope {
it.toaster?.toast(it.toaster.stringResource(R.string.click_again))
}
}
else{
@Debdutta-Panda
Debdutta-Panda / Composable.kt
Created June 22, 2022 18:16
Put these code at the very first of your composbale function
val owner = LocalLifecycleOwner.current
val context = LocalContext.current
LaunchedEffect(key1 = vm.uiScope.value){
vm.uiScope.forward(
ScopeManager(
navHostController = navController,
owner = owner,
toaster = Toaster(context)
)
)
@Debdutta-Panda
Debdutta-Panda / UIScopeMechanism.kt
Created June 22, 2022 18:13
UI scope mechanism
data class Toaster(
private val context: Context
){
fun toast(message: String, duration: Int = Toast.LENGTH_SHORT){
Toast.makeText(context, message,duration).show()
}
fun stringResource(@StringRes id: Int): String{
return context.getString(id)
}
@Debdutta-Panda
Debdutta-Panda / Processor.kt
Created June 10, 2022 19:16
MyMarker_phase_4_processor
package com.debduttapanda.marker
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.TypeSpec
import java.io.File
import javax.annotation.processing.AbstractProcessor
import javax.annotation.processing.RoundEnvironment
import javax.annotation.processing.SupportedSourceVersion
import javax.lang.model.SourceVersion
import javax.lang.model.element.Element
@Debdutta-Panda
Debdutta-Panda / Processor.kt
Last active June 10, 2022 17:31
MyMarker_phase_3_processor_skeleton
package com.debduttapanda.marker
import javax.annotation.processing.AbstractProcessor
import javax.annotation.processing.RoundEnvironment
import javax.annotation.processing.SupportedSourceVersion
import javax.lang.model.SourceVersion
import javax.lang.model.element.Element
import javax.lang.model.element.TypeElement
@SupportedSourceVersion(SourceVersion.RELEASE_8) // 1
@Debdutta-Panda
Debdutta-Panda / Marker.kt
Created June 10, 2022 15:29
MyMarker_phase_2_Marker
package com.debduttapanda.marker
@Target(
AnnotationTarget.FUNCTION,
AnnotationTarget.CLASS,
AnnotationTarget.FILE,
)
@Retention(AnnotationRetention.SOURCE)
annotation class Mark
@Debdutta-Panda
Debdutta-Panda / MainActivity.kt
Created June 10, 2022 15:16
MyMarker_phase_1_MainActivity
package com.debduttapanda.mymarker
import android.content.Context
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Button
@Debdutta-Panda
Debdutta-Panda / MainActivity.kt
Created June 4, 2022 18:21
Drawer Navigation
package com.debduttapanda.powernavigation
import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.annotation.DrawableRes
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
@Debdutta-Panda
Debdutta-Panda / BottomNavigationScreen.kt
Created June 4, 2022 17:02
Bottom Navigation in jetpack Compose
package com.debduttapanda.powernavigation
import androidx.annotation.StringRes
import androidx.compose.animation.AnimatedContentScope
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
@Debdutta-Panda
Debdutta-Panda / MainActivity.kt
Created June 4, 2022 16:23
Multiple navigation in same page
package com.debduttapanda.powernavigation
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Divider