Created
November 30, 2016 19:36
-
-
Save johncordeiro/48376bdfe9c6f128f87b2fa76b0b09ad to your computer and use it in GitHub Desktop.
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
package br.com.ilhasoft.clickcondo.helpers | |
import br.com.ilhasoft.support.core.preferences.BasePreferences | |
import kotlin.reflect.KProperty | |
/** | |
* Created by john-mac on 11/23/16. | |
*/ | |
class PreferenceFieldDelegate<T>(val defaultValue: T?) { | |
@Suppress("UNCHECKED_CAST") | |
operator fun getValue(basePreferences: BasePreferences, propertyMetadata: KProperty<*>): T? { | |
return basePreferences.getValue(propertyMetadata.name, defaultValue) | |
} | |
operator fun setValue(basePreferences: BasePreferences, propertyMetadata: KProperty<*>, a: Any?) { | |
if (a != null) { | |
basePreferences.setValue(propertyMetadata.name, a) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Talvez fosse mais interessante usar assim
a?.let { basePreferences.setValue(propertyMetadata.name, it) }
, vai dar no mesmo no fim das contas.