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
@giovanileitevitor
giovanileitevitor / setPlaceHolders.gradle
Created January 9, 2023 20:48
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"
]
}
import android.graphics.Matrix
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
@ercnksgl
ercnksgl / DisallowParentSwipeOnItemTouchListener.kt
Created November 20, 2022 18:49
ViewPager inside RecyclerView Scroll issue
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,
@Vaibhav2002
Vaibhav2002 / FlowWithExtension.kt
Created November 9, 2022 14:11
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) }
}
@stevdza-san
stevdza-san / MainScreen.kt
Created October 20, 2022 06:31
New Photo Picker on Android 13/API Level 33 - Backwards Compatible
// 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.*
suspend fun LazyListState.getFirstVisibleAsState(index: (Int) -> Unit) {
this.interactionSource.interactions.collectLatest {
index(this.firstVisibleItemIndex)
}
}
data class WeeklyStat(
val earning: Float = 0.0f
)
@thenishchalraj
thenishchalraj / TextWatcherForInputBox.kt
Created August 15, 2022 10:24
Text watcher that will take care of input fields in CreateInputFieldsInInputBox.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
@thenishchalraj
thenishchalraj / CreateInputFieldsInInputBox.kt
Last active September 8, 2022 13:22
Function to create input fields inside flexbox dynamically.
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 / Kotlin Extension Functions
Last active March 17, 2023 08:31
Kotlin Extension Functions
/*
finds and colors all urls contained in a string
@param linkColor color for the url default is blue
@param linkClickAction action to perform when user click that link
*/
fun String.linkify(linkColor:Int = Color.BLUE,linkClickAction:((link:String) -> Unit)? = null): SpannableStringBuilder {
val builder = SpannableStringBuilder(this)
val matcher = Patterns.WEB_URL.matcher(this)
while(matcher.find()){
import android.app.Activity
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat.shouldShowRequestPermissionRationale
import androidx.fragment.app.Fragment
object PermissionUtil {