Skip to content

Instantly share code, notes, and snippets.

View raghunandankavi2010's full-sized avatar
🤵‍♂️
Android dev looking to learn new technologies and always open for a new job.

Raghunandan Kavi raghunandankavi2010

🤵‍♂️
Android dev looking to learn new technologies and always open for a new job.
View GitHub Profile
@raghunandankavi2010
raghunandankavi2010 / BounceScrollView
Created February 15, 2020 11:43
A scrollview that is animated off screen if you touch, move is greater than 50% of screen height
import android.animation.Animator
import android.animation.ObjectAnimator
import android.animation.ValueAnimator.AnimatorUpdateListener
import android.content.Context
import android.content.res.Resources
import androidx.core.widget.NestedScrollView
import android.util.AttributeSet
import android.util.Log
import android.view.MotionEvent
import android.view.View
@raghunandankavi2010
raghunandankavi2010 / AsyncDiffUtil
Created March 17, 2020 17:06
AsyncDiffUtil using kotlin coroutnes
package me.raghu.mvpassignment.util
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListUpdateCallback
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel.Factory.CONFLATED
import kotlinx.coroutines.channels.actor
import java.util.*
@raghunandankavi2010
raghunandankavi2010 / environ.text
Created March 31, 2020 10:01
Adding to environment variable ubuntu
// edit /home/.bashrc and add the following lines
JAVA_HOME='/home/raghu/jdk1.8.0_241'
export JAVA_HOME
export PATH=$PATH:$JAVA_HOME/bin
FLUTTER_HOME='/home/raghu/flutter'
export FLUTTER_HOME
export PATH=$PATH:$FLUTTER_HOME/bin
ANDROID_SDK_ROOT='/home/raghu/Android/Sdk'
suspend fun <T> retryIO(
times: Int = Int.MAX_VALUE,
initialDelay: Long = 100, // 0.1 second
maxDelay: Long = 1000, // 1 second
factor: Double = 2.0,
block: suspend () -> T): T
{
var currentDelay = initialDelay
repeat(times - 1) {
try {
public class InputStreamRequestBody extends RequestBody {
private final MediaType contentType;
private final ContentResolver contentResolver;
private final Uri uri;
public InputStreamRequestBody(MediaType contentType, ContentResolver contentResolver, Uri uri) {
if (uri == null) throw new NullPointerException("uri == null");
this.contentType = contentType;
this.contentResolver = contentResolver;
this.uri = uri;
@raghunandankavi2010
raghunandankavi2010 / Sharedpreferences
Created August 18, 2020 06:35
SharedPreferences edit inline function
// SharedPreferences extension function
// SharedPreferences.Editor.() - lambda with receiver
// call edit for the editor
// perform the action and apply edit.
inline fun SharedPreferences.edit(action: Sharedpreferenes.Editor.()->Unit) {
val edit = edit()
action.edit()
edit.apply()
}
inline fun <refied T: Any> Context.openActivity(noinline init: Intent.()-> Unit = {}){
val intent == newIntent<T>(this)
intent.init()
startActivity(intent)
}
inline <refied T: Any> fun newIntent(context: Context): Int{
Intent(context.T::class.kava)
@raghunandankavi2010
raghunandankavi2010 / gist:c7daf3b869b364e92de239fe1fb4dd64
Created October 27, 2020 08:11
Custom Circular Progress view with percentage text in center.
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.*
import android.util.AttributeSet
import android.view.View
import androidx.core.content.ContextCompat
import bg.dihanov.customviewexamples.R
import bg.dihanov.customviewexamples.px
import kotlin.math.max
import kotlin.math.min
@raghunandankavi2010
raghunandankavi2010 / Flow.txt
Created January 14, 2021 03:48
rxjava equivalent in kotlin flow
flow<String> {
// suspending call here
emit("Foo")
}
.onStart { // show loading }
.onCompletion { // hide loading }
.catch { // exception handling }
.onEach { // equivalent to rx onNext }
.launchIn(yourScope)
@raghunandankavi2010
raghunandankavi2010 / Git
Created January 14, 2021 04:50
adding remote repo as upstream
# Add a new remote upstream repository
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
# Sync your fork
git fetch upstream
git checkout master
git merge upstream/master