Skip to content

Instantly share code, notes, and snippets.

View jimmyFlash's full-sized avatar
:atom:

Jamal jimmyFlash

:atom:
View GitHub Profile
class ToolbarBehavior : CoordinatorLayout.Behavior<AppBarLayout>() {
/** Consume if vertical scroll because we don't care about other scrolls */
override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout, child: AppBarLayout,
directTargetChild: View, target: View, axes: Int, type: Int): Boolean {
getViews(child)
return axes == ViewCompat.SCROLL_AXIS_VERTICAL ||
super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, axes, type)
}
inline fun getValueAnimator(forward: Boolean = true, duration: Long, interpolator: TimeInterpolator,
crossinline updateListener: (progress: Float) -> Unit
): ValueAnimator {
val a =
if (forward) ValueAnimator.ofFloat(0f, 1f)
else ValueAnimator.ofFloat(1f, 0f)
a.addUpdateListener { updateListener(it.animatedValue as Float) }
a.duration = duration
a.interpolator = interpolator
return a
package com.example
import android.app.Instrumentation
import android.os.Bundle
import android.util.Log
import androidx.test.internal.runner.listener.InstrumentationResultPrinter
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.runner.Description
import org.junit.runner.notification.RunListener
@f3401pal
f3401pal / app\build.gradle.kts
Last active January 5, 2024 13:53
Multi-module Android project with Kotlin DSL for Gradle
plugins {
`android-base-app`
`android-base`
id("io.fabric")
}
android {
defaultConfig {
versionCode = 20
versionName = "1.6.3"
@thehackerish
thehackerish / JavaDeserial.java
Last active April 8, 2024 22:32
Supporting material for the Insecure Deserialization blog post https://thehackerish.com/insecure-deserialization-explained-with-examples
import java.io.*;
public class JavaDeserial{
public static void main(String args[]) throws Exception{
FileInputStream fis = new FileInputStream("/tmp/normalObj.serial");
ObjectInputStream ois = new ObjectInputStream(fis);
NormalObj unserObj = (NormalObj)ois.readObject();
ois.close();
@cbeyls
cbeyls / RecyclerViewExt.kt
Last active February 8, 2024 19:17
Extension function to enforce a single scroll direction for a RecyclerView
package be.digitalia.samples.utils
import android.view.MotionEvent
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener
import kotlin.math.abs
fun RecyclerView.enforceSingleScrollDirection() {
val enforcer = SingleScrollDirectionEnforcer()
addOnItemTouchListener(enforcer)
// domain
sealed class ErrorEntity {
sealed class ApiError: ErrorEntity() {
// .....
}
sealed class FileError: ErrorEntity() {
object NotFound: FileError()
@Suppress("UNCHECKED_CAST")
class ViewModelFactory @Inject constructor(
private val creators: Map<Class<out ViewModel>, Provider<ViewModel>>
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
val creator = creators[modelClass]
?: creators.asIterable().find { (key, _) -> modelClass.isAssignableFrom(key) }?.value
?: throw IllegalArgumentException("Unknown ViewModel class $modelClass")
class OurViewModel(observeGithubReposUseCase: ObserveGithubReposUseCase): ViewModel {
val githubRepos: LiveData<List<GithubRepoItem>>
get() = observeGithubReposUseCase
.observe()
.map { reposList ->
reposList
.sortedByDescending { it.stars }
.map {
@discord-gists
discord-gists / CustomPanelGestureDetection.kt
Last active March 2, 2022 19:16
a simplified code example for how Discord's Android app supports custom panel gesture detection
class OverlappingPanelsLayout : FrameLayout {
private var scrollingSlopPx: Float = 0f
private var velocityTracker: VelocityTracker? = null
private var isScrollingHorizontally = false
private var xFromInterceptActionDown: Float = 0f
private var yFromInterceptActionDown: Float = 0f
... // initialize scrollingSlopPx and VelocityTracker