Skip to content

Instantly share code, notes, and snippets.

@ksharma-xyz
ksharma-xyz / gen-kotlin.yaml
Created July 6, 2024 11:51
Generate Kotlin files and push them to new repository by creating a PR
name: Generate Kotlin
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
@ksharma-xyz
ksharma-xyz / wire-build.gradle.kts
Created July 6, 2024 11:41
How to add Wire Plugin to Gradle File
// In libs.versions.toml
wire = { id = "com.squareup.wire", version.ref = "wire"}
// In build.gradle.kts (module level)
plugins {
alias(libs.plugins.wire)
}
@ksharma-xyz
ksharma-xyz / user.proto
Created July 6, 2024 11:33
Protobuf for User
syntax = "proto3";
option java_package = "xyz.ksharma.user";
option java_outer_classname = "User";
message User {
string id = 1;
string name = 2;
int32 age = 3;
}
@ksharma-xyz
ksharma-xyz / User.kt
Created July 6, 2024 11:32
Kotlin Class generated from proto using wire plugin
// Code generated by Wire protocol buffer compiler, do not edit.
// Source: User in xyz/ksharma/pokemon/user.proto
@file:Suppress("DEPRECATION")
package xyz.ksharma.user
import com.squareup.wire.FieldEncoding
import com.squareup.wire.Message
import com.squareup.wire.ProtoAdapter
import com.squareup.wire.ProtoReader
@ksharma-xyz
ksharma-xyz / .zshrc
Last active June 3, 2024 10:04
android - adb commands with alias
## Read Blog - https://www.ksharma.xyz/android-adb-shortcuts-for-productivity
## A11y - Talkback
alias TalkbackOn="adb shell settings put secure enabled_accessibility_services com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService"
alias TalkbackOff="adb shell settings put secure enabled_accessibility_services com.android.talkback/com.google.android.marvin.talkback.TalkBackService"
## A11y - FontSize
alias LargeFontSize="adb shell settings put system font_scale 2.0" # Largest font size for android devices
alias MediumFontSize="adb shell settings put system font_scale 1.5"
@ksharma-xyz
ksharma-xyz / TinkCryptoManager.kt
Last active May 24, 2024 11:16
Encryption and Decryption using Google Tink and managing keys using AndroidKeystore
import androidx.security.crypto.MasterKeys
import com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm
object TinkCryptoManager {
// Get / Create Keys using Android Keystore
private val aesKeystore =
AndroidKeystoreAesGcm(MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC))
fun encrypt(plainText: String): ByteArray =
@ksharma-xyz
ksharma-xyz / build.gradle.kts
Created May 24, 2024 09:10
Adding Google Tink dependency in Android project
dependencies {
implementation("com.google.crypto.tink:tink-android:1.13.0") // check latest version
}
@ksharma-xyz
ksharma-xyz / SecureScreen.kt
Last active May 13, 2024 01:00
Listen to changes in android Lifecycle in Composable and set and clear secure flag in onStart / onStop.
import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import android.view.WindowManager.LayoutParams.FLAG_SECURE
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
@ksharma-xyz
ksharma-xyz / ComposableLifeCycleListener.kt
Created May 12, 2024 11:00
Listener for Composable Lifecycle
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
@Composable
fun ComposableLifecycleListener(
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,