Skip to content

Instantly share code, notes, and snippets.

View frel's full-sized avatar

Fredrik H. Larsen frel

View GitHub Profile
/*
* Based on https://gist.github.com/jamiesanson/d1a3ed0910cd605e928572ce245bafc4
*
* Refactored to use the preferred `DefaultLifecycleObserver` which does not rely on the annotation processor.
* See https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle#init
*
* Usage:
* `private var binding: TheViewBinding by viewLifecycle()`
*/
@frel
frel / TinyThumbDecoder.kt
Last active August 15, 2021 10:57
AirBrush Medium article example
class TinyThumbDecoder(
private var context: Context,
private val bitmapPool: BitmapPool,
private val blurProvider: (source: Bitmap, options: BlurOptions?) -> Bitmap
) : ResourceDecoder<TinyThumb, BitmapDrawable> {
override fun handles(source: TinyThumb, options: Options) = source.base64.isNotEmpty()
override fun decode(
source: TinyThumb,
@frel
frel / TinyThumbDataFetcher.kt
Created August 15, 2021 10:46
AirBrush Medium article example
class TinyThumbDataFetcher(private val thumb: TinyThumb) : DataFetcher<TinyThumb> {
override fun loadData(
priority: Priority,
callback: DataFetcher.DataCallback<in TinyThumb>
) = callback.onDataReady(thumb)
override fun getDataClass(): Class<TinyThumb> = TinyThumb::class.java
override fun getDataSource(): DataSource = DataSource.LOCAL
override fun cleanup() { /* Do nothing */ }
@frel
frel / TinyThumbLoader.kt
Created August 15, 2021 10:41
AirBrush Medium article example
class TinyThumbLoader : ModelLoader<TinyThumb, TinyThumb> {
override fun buildLoadData(
model: TinyThumb,
width: Int,
height: Int,
options: Options
) = ModelLoader.LoadData(
ObjectKey(model.toString()),
TinyThumbDataFetcher(model)
)
@frel
frel / ImageLoader.kt
Created August 15, 2021 10:24
AirBrush Medium article example
val thumbnail = TinyThumb(base64 = "...")
requestManager
.load(imageUrl)
.thumbnail(requestManager.load(thumbnail))
.transition(DrawableTransitionOptions().crossFade(750))
.into(imageView)
@frel
frel / GlideModule.kt
Created August 15, 2021 10:17
AirBrush Medium article example
@GlideModule
class GlideModule : AppGlideModule() {
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
// Register a ModelLoaderFactory for TinyThumb allowing the type to be loaded using Glide
registry.append(TinyThumb::class.java, TinyThumb::class.java, TinyThumbLoader.Factory())
// Register a ResourceDecoder for TinyThumb. Specifying the input and output type.
// Note that the tailing lambda is the blur provider. If we wanted to use another blur
// implementation we could replace it here.
registry.append(
@frel
frel / MainActivity.kt
Last active October 23, 2018 21:21
This is an example of how log events can be defined using android resources files.
package com.subgarden.eventlogging
import android.os.Bundle
import android.support.annotation.IntegerRes
import android.support.v7.app.AppCompatActivity
import android.util.Log
import java.util.*
class MainActivity : AppCompatActivity() {
var fs = require("fs");
var tus = require("tus-js-client");
const ENDPOINT = "http://"
const FILE_NAME = "video.MOV"
const X_AUTH_KEY = ""
const file = fs.readFileSync( __dirname + "/"+ FILE_NAME)
if (file.err) {