Skip to content

Instantly share code, notes, and snippets.

Avatar
💻
Working from home

Virender Sran virendersran01

💻
Working from home
  • India
View GitHub Profile
@virendersran01
virendersran01 / FlowWithExtension.kt
Created Nov 24, 2022 — forked from Vaibhav2002/FlowWithExtension.kt
Collecting flows by using an extension function
View FlowWithExtension.kt
/** 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) }
}
View DisallowParentSwipeOnItemTouchListener.kt
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 Nov 10, 2022 — forked from mksantoki/MainActivity.java
FileChooser in Android webview
View MainActivity.java
/*
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;
View PermissionHandler.kt
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 Oct 31, 2022 — forked from dzolnai/View.kt
Expandable TextView with clickable '...read more'
View View.kt
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
@virendersran01
virendersran01 / MainScreen.kt
Created Oct 20, 2022 — forked from stevdza-san/MainScreen.kt
New Photo Picker on Android 13/API Level 33 - Backwards Compatible
View MainScreen.kt
// Coil
// implementation("io.coil-kt:coil-compose:2.2.2")
import android.util.Log
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
View FragmentViewBindingDelegate.kt
// https://github.com/Zhuinden/fragmentviewbindingdelegate-kt
import android.view.View
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.viewbinding.ViewBinding
import kotlin.properties.ReadOnlyProperty
View BarChart.kt
suspend fun LazyListState.getFirstVisibleAsState(index: (Int) -> Unit) {
this.interactionSource.interactions.collectLatest {
index(this.firstVisibleItemIndex)
}
}
data class WeeklyStat(
val earning: Float = 0.0f
)
@virendersran01
virendersran01 / CreateInputFieldsInInputBox.kt
Created Sep 8, 2022 — forked from thenishchalraj/CreateInputFieldsInInputBox.kt
Function to create input fields inside flexbox dynamically.
View CreateInputFieldsInInputBox.kt
private val mTextMap: HashMap<Int, TextMapModel> = HashMap()
private val mTextIdArray: ArrayList<Int> = ArrayList()
private fun createInputFieldsInInputBox(actualText: String) {
val textLength = actualText.length
val flexboxLayout = mBinding.flexboxLayoutInput
flexboxLayout.flexDirection = FlexDirection.ROW
val filterArray = arrayOfNulls<InputFilter>(1)
filterArray[0] = InputFilter.LengthFilter(1)
@virendersran01
virendersran01 / TextWatcherForInputBox.kt
Created Sep 8, 2022 — forked from thenishchalraj/TextWatcherForInputBox.kt
Text watcher that will take care of input fields in CreateInputFieldsInInputBox.kt
View TextWatcherForInputBox.kt
private fun setTextWatcher(editText: EditText?) {
editText?.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (s.toString() != "") {
mTextMap[editText.id] = TextMapModel(s.toString(), editText)
val indexOfNext = mTextIdArray.indexOf(editText.id) + 1