Skip to content

Instantly share code, notes, and snippets.

Avatar

Fredrik H. Larsen frel

View GitHub Profile
@frel
frel / TinyThumbDecoder.kt
Last active Aug 15, 2021
AirBrush Medium article example
View TinyThumbDecoder.kt
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 Aug 15, 2021
AirBrush Medium article example
View TinyThumbDataFetcher.kt
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 Aug 15, 2021
AirBrush Medium article example
View TinyThumbLoader.kt
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 Aug 15, 2021
AirBrush Medium article example
View ImageLoader.kt
val thumbnail = TinyThumb(base64 = "...")
requestManager
.load(imageUrl)
.thumbnail(requestManager.load(thumbnail))
.transition(DrawableTransitionOptions().crossFade(750))
.into(imageView)
@frel
frel / GlideModule.kt
Created Aug 15, 2021
AirBrush Medium article example
View GlideModule.kt
@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(
View FragmentExt.kt
/*
* 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 / MainActivity.kt
Last active Oct 23, 2018
This is an example of how log events can be defined using android resources files.
View MainActivity.kt
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() {
View tus-js-client-upload-example.js
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) {