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
val visitId = savedStateHandle.get<Int>("visitId")
val agentDetail: StateFlow<VisitingDetailUiState>? =
visitId?.let {
useCase.getDetailAgentVisitFullResponseFlow(id = it).map { visitDetail ->
Log.d("MYTAG", ": got exec")
when (visitDetail) {
is SallyResponseResource.Loading -> {
VisitingDetailUiState.Loading
}
override fun onViewCreated() {
observeVisitDetail()
}
private fun observeVisitDetail() {
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.agentDetail?.collect { visitingUiState ->
when (visitingUiState) {
is VisitingDetailUiState.Success -> {
@virendersran01
virendersran01 / CounterButtonSample.kt
Created June 8, 2023 08:15 — forked from landomen/CounterButtonSample.kt
Animated counter button sample implemented in Jetpack Compose
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
CounterButtonTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
@virendersran01
virendersran01 / build.gradle
Created December 28, 2022 12:02 — forked from maxirosson/build.gradle
Versioning Android apps
apply plugin: 'com.android.application'
ext.versionMajor = 1
ext.versionMinor = 2
ext.versionPatch = 3
ext.versionClassifier = null
ext.isSnapshot = true
ext.minimumSdkVersion = 19
android {
apply plugin: 'com.android.application'
ext.versionMajor = 1
ext.versionMinor = 2
ext.versionPatch = 3
ext.versionClassifier = null
ext.isSnapshot = true
android {
defaultConfig {
@virendersran01
virendersran01 / FlowWithExtension.kt
Created November 24, 2022 13:10 — forked from Vaibhav2002/FlowWithExtension.kt
Collecting flows by using an extension function
/** Making this extension function cleans out the code a lot by removing the repetitive
flowWithLifecycle() or repeatOnLifecycle()
**/
fun <T> Flow<T>.safeCollect(
owner: LifecycleOwner,
block: (T.() -> Unit)? = null
) = owner.lifecycleScope.launch {
flowWithLifecycle(owner.lifecycle).collectLatest { block?.invoke(it) }
}
package com.ercnksgl.testapp.util
import android.view.MotionEvent
import androidx.recyclerview.widget.RecyclerView
import kotlin.math.abs
class DisallowParentSwipeOnItemTouchListener : RecyclerView.OnItemTouchListener {
var startPoint = 0f
override fun onInterceptTouchEvent(
rv: RecyclerView,
@virendersran01
virendersran01 / MainActivity.java
Created November 10, 2022 13:04 — forked from mksantoki/MainActivity.java
FileChooser in Android webview
/*
reference link ->https://www.opengeeks.me/2015/08/filechooser-and-android-webview/
https://github.com/OpenGeeksMe/Android-File-Chooser
*/
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
fun Fragment.isGranted(permission: AppPermission) = run {
context?.let {
(PermissionChecker.checkSelfPermission(it, permission.permissionName
) == PermissionChecker.PERMISSION_GRANTED)
} ?: false
}
fun Fragment.shouldShowRationale(permission: AppPermission) = run {
shouldShowRequestPermissionRationale(permission.permissionName)
}
@virendersran01
virendersran01 / View.kt
Created October 31, 2022 04:11 — forked from dzolnai/View.kt
Expandable TextView with clickable '...read more'
import android.annotation.SuppressLint
import android.content.Context
import android.text.Layout
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.StaticLayout
import android.text.TextPaint
import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan