Skip to content

Instantly share code, notes, and snippets.

View limkhashing's full-sized avatar
:octocat:
When there is a challenge, there is an opportunity

Lim Kha Shing limkhashing

:octocat:
When there is a challenge, there is an opportunity
View GitHub Profile
/*
* Copyright (C) 2017 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@limkhashing
limkhashing / Result.kt
Last active March 31, 2024 08:35
Wrapper class for ViewModel -> View as Event state
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith
import androidx.compose.runtime.Composable
sealed class Result<out Data, out Error> {
data object Idle: Result<Nothing, Nothing>()
data object InProgress: Result<Nothing, Nothing>()
"enable_black_navigation_bar": false,
"enable_old_player_background": true,
"enable_save_playback_speed": true,
"remember_repeat_state": false
"default_playback_speed": 2,
"default_video_quality_mobile": 720,
"default_video_quality_wifi": 2160,
"disable_default_playback_speed_live": false,
"enable_default_playback_speed_shorts": true,
"enable_save_playback_speed": true,
"enable_swipe_brightness": false,
"enable_swipe_volume": false,
"force_fullscreen": true,
"hide_auto_player_popup_panels": false,
@limkhashing
limkhashing / PullToRefreshLazyColumn.kt
Created March 27, 2024 16:46
PullToRefreshLazyColumn in JetpackCompose
@file:OptIn(ExperimentalMaterial3Api::class)
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
// Producer is covariant in T
// Class body can only return T, not take T as parameter
class Producer<out T> {
fun produce() : T // ok
fun consume(item: T) // compile error
}
// Then it's possible to:
fun covariantExample(x: Producer<String>) {
val y: Producer<Any> = x // Allowed, producer is covariant in T
@limkhashing
limkhashing / BiometricPromptManager.kt
Last active March 20, 2024 17:29
Sample Biometric feature on Android
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import androidx.biometric.BiometricManager
import androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG
import androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL
import androidx.biometric.BiometricPrompt
import androidx.biometric.BiometricPrompt.PromptInfo
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.receiveAsFlow
@limkhashing
limkhashing / SwipeToDeleteCompose.kt
Created February 4, 2024 12:58
Swipe To Delete in Jetpack Compose
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
SwipeToDeleteComposeTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
@limkhashing
limkhashing / dependabot_branch.md
Last active January 29, 2024 09:57
Dependabot branch for environment protection rules

List of dependabot branches

  1. dependabot/actions/*
  2. dependabot/github_actions/actions/*
  3. dependabot/github_actions/github/*
  4. dependabot/github_actions/gradle/*
  5. dependabot/gradle/*