Skip to content

Instantly share code, notes, and snippets.

View virendersran01's full-sized avatar
💻
Working from home

Virender Srxn virendersran01

💻
Working from home
  • India
View GitHub Profile
@virendersran01
virendersran01 / AnimatedTextSwitcher.kt
Created June 29, 2024 06:38 — forked from ardakazanci/AnimatedTextSwitcher.kt
Animated Text in Jetpack Compose
@Composable
fun AnimatedTextSwitcher() {
var isYellowBoxVisibility by remember { mutableStateOf(true) }
LaunchedEffect(Unit) {
while (true) {
delay(3000)
isYellowBoxVisibility = !isYellowBoxVisibility
}
}
@virendersran01
virendersran01 / ExtNavController.kt
Created June 23, 2024 14:41 — forked from ImaginativeShohag/ExtNavController.kt
"MainActivity.kt" example indicates that calling `navigateUp()` multiple times will recreate the `Activity`. To solve the black issue 2 extension function given in "ExtNavController.kt" file.
import android.app.Activity
import android.content.Context
import androidx.lifecycle.Lifecycle
import androidx.navigation.NavController
/**
* Attempts to pop the controller's back stack.
* If the back stack is empty, it will finish the activity.
*
* @param context Activity context.
<application
android:name=".di.Application"
android:icon="${appIcon}"
android:roundIcon="${appIcon}"
....
</aplication>
@virendersran01
virendersran01 / setPlaceHolders.gradle
Created February 5, 2024 01:26 — forked from giovanileitevitor/setPlaceHolders.gradle
Setting a manifestPlaceHolders
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
testCoverageEnabled false
manifestPlaceholders = [
appIcon: "@mipmap/ic_release"
]
}
@virendersran01
virendersran01 / Speedometer.kt
Created October 30, 2023 13:09 — forked from saurabharora90/Speedometer.kt
Speedometer in Jetpack Compose
import androidx.annotation.FloatRange
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Slider
@virendersran01
virendersran01 / ConcurrencyHelpers.kt
Created October 26, 2023 13:05 — forked from objcode/ConcurrencyHelpers.kt
Helpers to control concurrency for one shot requests using Kotlin coroutines.
/* Copyright 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
@virendersran01
virendersran01 / NetworkModule.kt
Created October 8, 2023 13:52 — forked from whytarun/NetworkModule.kt
Including support for TLS/SSL
@Singleton
@Provides
fun provideOkhttpClient(authInterceptor: AuthInterceptor,
certificateHelper: CertificateHelper
) :OkHttpClient{
val trustManagers = certificateHelper.createTrustManagers()
val sslContext = SSLContext.getInstance("TLS")
sslContext.init(null, trustManagers, null)
return OkHttpClient().newBuilder()
.readTimeout(2, TimeUnit.MINUTES)
class CertificateHelper @Inject constructor(@ApplicationContext context: Context) {
private val applicationContext = context
fun createTrustManagers(): Array<TrustManager> {
val certificateInputStream = applicationContext.resources.openRawResource(
R.raw.test)
val certificateFactory = CertificateFactory.getInstance("X.509")
val certificate = certificateFactory.generateCertificate(certificateInputStream)
val trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm())
val keyStore = KeyStore.getInstance(KeyStore.getDefaultType())
@virendersran01
virendersran01 / FileUtils.kt
Created September 30, 2023 08:13 — forked from HasibPrince/FileUtils.kt
Usage of old storage api
val filename = "myFile.txt"
val content = "Hello, World!"
val documentsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS)
val file = File(documentsDir, filename)
file.outputStream().use { outputStream ->
outputStream.write(content.toByteArray())
}