Skip to content

Instantly share code, notes, and snippets.

View projectdelta6's full-sized avatar

Bradley Duck projectdelta6

View GitHub Profile
@projectdelta6
projectdelta6 / LazyGridPagingExtensions.kt
Last active February 24, 2025 20:51
Helper Extensions for using AndroidX Paging with Compose LazyList & LazyGrid
package //your.package
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridItemScope
import androidx.compose.foundation.lazy.grid.LazyGridItemSpanScope
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.paging.LoadState
@projectdelta6
projectdelta6 / LazyPagerExtensions.kt
Last active February 24, 2025 20:53
Androidx Paging 3 extensiopns for LazyList (LazyColumn and LazyRow) and LazyGrid. I had seen these `items(...)` extensions for Paging3 mentioned in a tutorial somewhere but then couldn't actually find them so I made my own.
//package ...
import androidx.compose.foundation.lazy.LazyItemScope
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.grid.GridItemSpan
import androidx.compose.foundation.lazy.grid.LazyGridItemScope
import androidx.compose.foundation.lazy.grid.LazyGridItemSpanScope
import androidx.compose.foundation.lazy.grid.LazyGridScope
import androidx.compose.runtime.Composable
import androidx.paging.compose.LazyPagingItems
@projectdelta6
projectdelta6 / RegulatedTouchTextView.kt
Last active October 15, 2024 16:10
An Android AppCompatTextView with a touch listener that repeats an actoin on an interval while the view is touched and stops when it is released
//package your.package.here
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import android.view.View.OnTouchListener
import androidx.appcompat.widget.AppCompatTextView
@projectdelta6
projectdelta6 / HapticScrollListAdapter.kt
Last active March 23, 2023 09:01
An implementation of androidx.recyclerview.widget.ListAdapter<T, VH> that provides haptic feedback on scrolling.
//package com.example.app.util
import android.view.HapticFeedbackConstants
import androidx.annotation.CallSuper
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
abstract class HapticScrollListAdapter<T, VH : RecyclerView.ViewHolder>(diffCallback: DiffUtil.ItemCallback<T>) : ListAdapter<T, VH>(diffCallback) {
protected var isScrolling: Boolean = false
@projectdelta6
projectdelta6 / SetupHandler.kt
Last active February 8, 2023 11:06
SetupHandler construct to handle waiting for 2 async tasks to complete before triggering its action
import android.os.Handler
import android.os.Looper
import android.os.Message
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.lang.ref.WeakReference
import java.util.concurrent.atomic.AtomicBoolean
//package ...
import android.content.Context
import android.view.GestureDetector
import android.view.MotionEvent
import android.view.View
import androidx.recyclerview.widget.RecyclerView
fun RecyclerView.setOnItemClickListener(onItemClickListener: (itemView: View, position: Int) -> Unit) {
addOnItemTouchListener(
@projectdelta6
projectdelta6 / APIResponse.kt
Last active May 13, 2021 12:43
API Response sealed class
//package ...
import java.net.UnknownHostException
sealed class APIResponse<T>(val success: Boolean) {
class APISuccess<T>(val data: T) : APIResponse<T>(true)
sealed class APIFail<T>(val message: String) : APIResponse<T>(false) {
class APIUnsuccessful<T>(val code: Int, message: String) : APIFail<T>(message) {
constructor(other: APIUnsuccessful<out Any>) : this(other.code, other.message)
}
@projectdelta6
projectdelta6 / extensions.kt
Last active June 30, 2021 15:51
Android kotlin common extensions
/**
* Home for useful extension functions.
*/
//package ...
import android.content.Context
import android.content.Intent
import android.text.Editable
import android.text.Spannable
import android.text.SpannableString
@projectdelta6
projectdelta6 / BitmapUtil.kt
Last active July 7, 2022 12:12
Android kotlin Bitmap rotation correction
//package ...
import android.content.ContentResolver
import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.ImageDecoder
import android.graphics.Matrix
import android.net.Uri
import android.os.Build