Skip to content

Instantly share code, notes, and snippets.

View jishindev's full-sized avatar
🏠

Jishin Dev jishindev

🏠
View GitHub Profile
@jishindev
jishindev / UriPath.kt
Last active July 5, 2019 11:21
Extensions to resolve file paths from uri on Android
fun isExternalStorageDocument(uri: Uri) = "com.android.externalstorage.documents" == uri.authority
fun isDownloadsDocument(uri: Uri) = "com.android.providers.downloads.documents" == uri.authority
fun isMediaDocument(uri: Uri) = "com.android.providers.media.documents" == uri.authority
/**
* Get a file path from a Uri. This will get the the path for Storage Access
* Framework Documents, as well as the _data field for the MediaStore and
* other file-based ContentProviders.
@jishindev
jishindev / ArrayListAdapter.kt
Last active September 18, 2021 12:26
Kotlin | Moshi Type converters and adapters for common use cases. Will be updated with new ones.
@Suppress("UNCHECKED_CAST")
class ArrayListAdapter<T>(private val adapter: JsonAdapter<T>) : JsonAdapter<ArrayList<T>>() {
@Throws(IOException::class)
override fun fromJson(reader: JsonReader): ArrayList<T>? {
val arrayList = arrayListOf<T>()
reader.beginArray()
while (reader.hasNext()) {
(adapter.fromJson(reader))?.let { arrayList.add(it) }
@jishindev
jishindev / AwsDataFetcher.kt
Created July 2, 2019 06:30
Data fetcher that can be registered with a Glide module to load data from AWS S3 Storage
class AwsDataFetcher(private val s3Client: AmazonS3Client, private val awsImage: AwsImage) : DataFetcher<InputStream> {
override fun getDataClass() = InputStream::class.java
override fun loadData(priority: Priority, callback: DataFetcher.DataCallback<in InputStream>) {
callback.onDataReady(
s3Client.getObject(
GetObjectRequest(
awsImage.bucket,
typealias NetworkCall<R> = suspend () -> Response<R>
typealias DbCall<R> = suspend () -> R
typealias DbSave<R> = suspend (R) -> Unit
open class BaseRepo {
suspend inline fun <R : Any, reified E> loadData(
noinline dbCall: DbCall<R>? = null,
noinline dbSave: DbSave<R>? = null,
noinline networkCall: NetworkCall<R>? = null