Coder Social home page Coder Social logo

koreference's Introduction

Koreference

Circle CI

Android SharedPreference delegate property for Kotlin

Installation

In your build.gradle

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    compile 'com.github.takuji31.Koreference:koreference:2.0.0'
    // optional: gson support
    compile 'com.github.takuji31.Koreference:koreference-gson:2.0.0'
    // optional: RxJava2 observable support
    compile 'com.github.takuji31.Koreference:koreference-observable:2.0.0'
}

Get started

Create your preference model

class MyPreferences(context : Context) : KoreferenceModel(context = context, name = "my_preferences") {
	var name : String by stringPreference("noname")
	var age : int by intPreference(17)
}

You can also use other constructors

class MyPreferences(sharefPreferences : SharedPreferences) : KoreferenceModel(sharefPreferences = sharefPreferences)
// or
class MyPreferences(context : Context) : KoreferenceModel(context = context, name = "my_preferences", mode = Context.MODE_PRIVATE)

Create model instance and set/get value

val pref = MyPreferences(context = this)

// set values
pref.name = "takuji31"
pref.age = 28

// this is same
pref.bulk {
    name = "takuji31"
    age = 28
}

val name = pref.name //takuji31
val age = pref.age //28

Preference delegate properies

Koreference has basic delegate properties

public class PreferenceModel(sharefPreferences : SharedPreferences) : KoreferenceModel(sharedPreferences = sharefPreferences) {
  var stringValue : String by stringPreference("default value")
  var intValue : Int by intPreference(256)
  var longValue : Long by longPreference(256L)
  var floatValue : Float by floatPreference(12.34f)
  var boolValue : Boolean by booleanPreference(true)
  var stringSetValue : Set<String> by stringSetPreference(setOf())
  
  // Nullable support
  var stringValue : String? by nullableStringPreference()
  var stringSetValue : Set<String>? by nullableStringSetPreference()
}

Custom properties

You can create custom properties.

Default properties are example.

//TODO write sample codes

License

Copyright (C) 2015 Takuji Nishibayashi

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
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

koreference's People

Contributors

azure-pipelines[bot] avatar pine avatar takuji31 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

pine douncoding

koreference's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.