All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mle.android.util.PreferenceImplicits.scala Maven / Gradle / Ivy

The newest version!
package com.mle.android.util

import android.content.SharedPreferences

/**
 *
 * @author mle
 */
object PreferenceImplicits {

  implicit class RichPrefs(val pref: SharedPreferences) extends AnyVal {
    def get(key: String): Option[String] = Option(pref.getString(key, null))

    def put(key: String, value: String) = withEditor(_.putString(key, value))

    def putInt(key: String, value: Int) = withEditor(_.putInt(key, value))

    def putBoolean(key: String, value: Boolean) = withEditor(_.putBoolean(key, value))

    def withEditor(f: SharedPreferences.Editor => SharedPreferences.Editor) =
      f(pref.edit()).apply()
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy