Skip to content

Instantly share code, notes, and snippets.

View runo280's full-sized avatar
🀨

runo280 runo280

🀨
  • ‍‍‍~
View GitHub Profile
@BhavyaRattan
BhavyaRattan / ScaleItemOnTouchListener.kt
Created September 26, 2020 14:21
Magic Touch Recycler
class ScaleItemOnTouchListener : RecyclerView.OnItemTouchListener {
private var previousX = 0f
private var previousY = 0f
private var previousMotionX = 0f
private var previousMotionY = 0f
private object Constants {
const val SCALE_DEFAULT = 1f
@BasetEsmaeili
BasetEsmaeili / InfiniteScrollExtensions.kt
Last active January 3, 2021 08:24
Add Infinite Scroll to RecyclerView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
fun RecyclerView.attachInfiniteScroll(onLoadMoreListener: OnLoadMoreListener) {
if (layoutManager != null)
setInfiniteScrollGrid(this, layoutManager!!, onLoadMoreListener)
else throw RuntimeException("Layout Manager is Not Set")
}
@DHosseiny
DHosseiny / DeleteBuildFolders.bat
Last active June 8, 2020 11:25
Runnable Kotlin Script example with windows batch(double click .bat file to run) -- This example Searches all neighbor folders for android projects and deletes project and it's modules "build" folders(For reducing disk size). *need one time set "kotlinc" enviroment variable(See comments for guidance).
%kotlinc% -script DeleteBuildFolders.kts -- -dir .
:: "." is default path you can change it to any folder you want to work on that folder ^
:: (script workes on current folder without "-dir" argument)"
:: "^" can be used for multiline commands
@tonnylitao
tonnylitao / AndroidViewModelFactory.kt
Last active December 12, 2020 16:48
Android ViewModel with Variable Arguments
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import kotlin.reflect.full.primaryConstructor
class AndroidViewModelFactory(private vararg val args: Any) :
ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>) =
modelClass.kotlin.primaryConstructor?.call(*args)
?: throw IllegalArgumentException("$modelClass primaryConstructor is null")
@zach-klippenstein
zach-klippenstein / DrawLayerDemo.kt
Last active October 21, 2021 10:59
Interactive demo of the drawLayer composable function. (screencap in comments)
import androidx.animation.PhysicsBuilder
import androidx.animation.Spring.DampingRatioHighBouncy
import androidx.animation.Spring.StiffnessLow
import androidx.compose.Composable
import androidx.compose.Model
import androidx.compose.remember
import androidx.ui.animation.animate
import androidx.ui.core.DrawClipToBounds
import androidx.ui.core.Text
import androidx.ui.core.drawLayer
@DHosseiny
DHosseiny / BasePreferencesDataSource.kt
Created February 23, 2020 12:43
Delegates for SharedPreferences(Copy paste usage) (Maybe add some other delegates for other types soon)
import android.content.SharedPreferences
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
abstract class BasePreferencesDataSource {
protected abstract val preferences : SharedPreferences
protected class StringPrefProperty(private val key: String) : ReadWriteProperty<BasePreferencesDataSource, String> {
@raulraja
raulraja / TwitterHandle.kt
Created February 20, 2020 12:16
Type Refinements with Type Proofs in Kotlin
/* Coming up ~ April 2020 */
package test
import arrow.*
inline class TwitterHandle(val handle: String) {
companion object : Refined<String> {
override val validate: String.() -> Map<String, Boolean> = {
mapOf(
"Should start with '@'" to startsWith("@"),
@MRezaNasirloo
MRezaNasirloo / Ganjeh.kt
Last active October 9, 2021 13:17
Share ViewModels across LifecycleOwners
package com.mrezanasirloo.ganjeh
import android.util.SparseArray
import androidx.activity.ComponentActivity
import androidx.annotation.MainThread
import androidx.fragment.app.Fragment
import androidx.fragment.app.createViewModelLazy
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelLazy
# This is for ATV only
alias adb-dev-options='adb shell am start -n com.android.tv.settings/.system.development.DevelopmentActivity'
# For mobile use:
#alias adb-dev-options='adb shell am start -n com.android.settings/.DevelopmentSettings'
# Animations
alias animations-off='adb shell settings put global animator_duration_scale 0'
alias animations-slow='adb shell settings put global animator_duration_scale 10'
alias animations-normal='adb shell settings put global animator_duration_scale 1'
alias animations-fast='adb shell settings put global animator_duration_scale 0.5'
@DHosseiny
DHosseiny / FileUtils.java
Last active January 9, 2020 12:12
Open any type of file
public class FileUtils {
/**
* @return The MIME type for the given file.
*/
public static String getMimeType(File file) {
String extension = getExtension(file.getName()).toLowerCase();
if (!TextUtils.isEmpty(extension) && extension.length() > 1)