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 / 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())
}
@virendersran01
virendersran01 / FileUtils.kt
Created September 30, 2023 08:12 — forked from HasibPrince/FileUtils.kt
Usage of MediaStore API
val contentResolver = this.contentResolver
val contentValues = ContentValues().apply {
put(MediaStore.MediaColumns.DISPLAY_NAME, "applounge")
put(MediaStore.MediaColumns.MIME_TYPE, "text/plain")
put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOCUMENTS)
}
val uri = contentResolver.insert(MediaStore.Files.getContentUri("external"), contentValues)
uri?.let {
contentResolver.openOutputStream(it)?.use { outputStream ->
@virendersran01
virendersran01 / AnimatedBorderCard.kt
Created September 25, 2023 17:32 — forked from stevdza-san/AnimatedBorderCard.kt
Card with Animated Border built with Jetpack Compose.
@Composable
fun AnimatedBorderCard(
modifier: Modifier = Modifier,
shape: Shape = RoundedCornerShape(size = 0.dp),
borderWidth: Dp = 2.dp,
gradient: Brush = Brush.sweepGradient(listOf(Color.Gray, Color.White)),
animationDuration: Int = 10000,
onCardClick: () -> Unit = {},
content: @Composable () -> Unit
) {
@virendersran01
virendersran01 / Circles.kt
Created September 21, 2023 08:07 — forked from nirbhayph/Circles.kt
Google Maps and Jetpack Compose
@Composable
fun CircleMap() {
// Define the coordinates for circle centers and their associated information
val circleData = listOf(
CircleInfo("Park A", LatLng(37.7749, -122.4194), "This is Park A"),
CircleInfo("Park B", LatLng(36.7783, -119.4179), "This is Park B"),
CircleInfo("Park C", LatLng(34.0522, -118.2437), "This is Park C")
)
// Create a mutable state to track the selected circle
@virendersran01
virendersran01 / better-url-intent.kt
Created September 13, 2023 13:04 — forked from jack-webb/better-url-intent.kt
A better way to open a link in the user's browser
val url = Uri.parse("https://www.asos.com/")
val browserSelectorIntent = Intent()
  .setAction(Intent.ACTION_VIEW)
  .addCategory(Intent.CATEGORY_BROWSABLE)
  .setData(Uri.parse("http:"))
val targetIntent = Intent()
  .setAction(Intent.ACTION_VIEW)
  .addCategory(Intent.CATEGORY_BROWSABLE)
@virendersran01
virendersran01 / .kt
Created August 24, 2023 03:19 — forked from ZaqueuLima3/Fixture.kt
Fixture
import kotlin.random.Random
import kotlin.reflect.KClass
import kotlin.reflect.KFunction
import kotlin.reflect.KType
/**
* You can find the method explanation here on this post:
* https://zaqueusantos.medium.com/an-easy-way-to-create-fixture-or-dummy-classes-for-your-android-tests-with-kotlin-9d6c619237d4
*/
@virendersran01
virendersran01 / LocationService.kt
Created July 23, 2023 14:40 — forked from oussama-dz/LocationService.kt
A Location service class that get the current user location, and handle any exceptions that maybe thrown.
class LocationService {
@SuppressLint("MissingPermission")
suspend fun getCurrentLocation(context: Context): Location {
if (!context.hasPermissions(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
)
) {