Last active
November 10, 2016 09:00
-
-
Save LouisCAD/c1b484bcc7ffe8427c9c370e225da5c9 to your computer and use it in GitHub Desktop.
A simple LoaderCallbacks implementation for kotlin and it's lambdas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Bundle | |
import android.support.v4.app.LoaderManager | |
import android.support.v4.content.Loader | |
class LoadListener<D, out L : Loader<D>>(private val createLoader: () -> L, | |
private val onLoadDone: (loader: L, data: D) -> Unit) | |
: LoaderManager.LoaderCallbacks<D> { | |
override fun onCreateLoader(id: Int, args: Bundle?) = createLoader() | |
@Suppress("UNCHECKED_CAST") | |
override fun onLoadFinished(loader: Loader<D>?, data: D) = onLoadDone(loader as L, data) | |
override fun onLoaderReset(loader: Loader<D>?) = Unit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment