Skip to content

Instantly share code, notes, and snippets.

View smokelaboratory's full-sized avatar
🎵

Sumeet Rukeja smokelaboratory

🎵
View GitHub Profile
@smokelaboratory
smokelaboratory / EntryModule.kt
Created October 31, 2021 13:03
Entry module navigation - Jetpack Compose
object Entry : Route() {
override val label: String = "entrymodule"
override val arguments: List<String>? = null
override val optionalArguments: List<String>? = null
object Login : Route() {
override val label: String = "login"
override val arguments: List<String>? = null
override val optionalArguments: List<String>? = null
}
@smokelaboratory
smokelaboratory / NavHelperImplementation.kt
Created October 31, 2021 12:58
NavHelper navigation implementation - Jetpack Compose
NavHost(navController = navController, startDestination = Entry.route) {
navigation(Entry.Login.route, Entry.route) {
composable(Entry.Login.route) {
LoginScreen {
navController.navigate(
Entry.Signup.address(
mapOf(
Entry.Signup.Arguments.EMAIL.name to "sumeetrukeja@gmail.com",
@smokelaboratory
smokelaboratory / ClassicImplementation.kt
Created October 31, 2021 12:52
Classic navigation implementation - Jetpack Compose
NavHost(navController = navController, startDestination = "entryModule") {
navigation("login", "entryModule") {
composable("login") {
LoginScreen {
navController.navigate("signup/sumeetrukeja@gmail.com/123456?birthdate=23-Sep-1994")
}
}
@smokelaboratory
smokelaboratory / Route.kt
Created October 31, 2021 11:49
Route in NavHelper - Jetpack Compose
abstract class Route {
abstract val label: String
abstract val arguments: List<String>?
abstract val optionalArguments: List<String>?
val route: String by lazy {
StringBuilder(label).apply {
arguments?.let {
it.forEach {
append("/{$it}")
}
@smokelaboratory
smokelaboratory / DataStoreUtil.kt
Created April 29, 2021 18:11
DataStore Utility
class DataStoreUtil {
/**
* serializes data type into string
* performs encryption
* stores encrypted data in DataStore
*/
private suspend inline fun <reified T> DataStore<Preferences>.secureEdit(
value: T,
crossinline editStore: (MutablePreferences, String) -> Unit
@smokelaboratory
smokelaboratory / SecurityUtil.kt
Created April 29, 2021 18:00
Security Utility class
class SecurityUtil
@Inject
constructor() {
private val provider = "AndroidKeyStore"
private val cipher by lazy {
Cipher.getInstance("AES/GCM/NoPadding")
}
private val charset by lazy {
charset("UTF-8")
setIsStrongBoxBacked(true)
@smokelaboratory
smokelaboratory / user_authentication.kt
Created March 16, 2020 04:24
Custom key user authentication
setUserAuthenticationRequired(true)
setUserAuthenticationValidityDurationSeconds(5)
@smokelaboratory
smokelaboratory / master_key_obj.kt
Created March 16, 2020 04:22
Master Key object
val masterKey = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
@smokelaboratory
smokelaboratory / jet_sec.gradle
Created March 16, 2020 04:14
JetSec dependency
implementation 'androidx.security:security-crypto:1.0.0-alpha02'