Skip to content

Instantly share code, notes, and snippets.

Avatar
🔱

Akshay Chordiya AkshayChordiya

🔱
View GitHub Profile
@ch4vi
ch4vi / LiveDataPromise.kt
Last active Feb 1, 2019
Concatenate LiveData
View LiveDataPromise.kt
fun <T, R> LiveData<T>.then(callback: (T) -> LiveData<R>): LiveData<R> {
return Transformations.switchMap(this, {
result(it)
})
}
@magneticflux-
magneticflux- / LiveDataUtils.kt
Last active Sep 18, 2020
Helpful Android-Kotlin LiveData utilities
View LiveDataUtils.kt
//--------------------------------
// CHECK THE COMMENTS FOR UPDATES!
//--------------------------------
/*
* Copyright (C) 2017 Mitchell Skaggs, Keturah Gadson, Ethan Holtgrieve, Nathan Skelton, Pattonville School District
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
View BaseDao.kt
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
View ContextExtensions.kt
import android.app.Activity
import android.app.Service
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.Intent.EXTRA_SUBJECT
import android.content.Intent.EXTRA_TEXT
import android.net.Uri
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KClass
@rharter
rharter / SharedPreferenceLiveData.kt
Last active Feb 7, 2021
Creates LiveData objects that observe a value in SharedPreferences while they have active listeners.
View SharedPreferenceLiveData.kt
import android.arch.lifecycle.LiveData
import android.content.SharedPreferences
abstract class SharedPreferenceLiveData<T>(val sharedPrefs: SharedPreferences,
val key: String,
val defValue: T) : LiveData<T>() {
private val preferenceChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
if (key == this.key) {
value = getValueFromPreferences(key, defValue)
View CollapsingTitleLayout.java
/*
* Copyright 2014 Chris Banes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software