Skip to content

Latest commit

 

History

History
125 lines (105 loc) · 4.01 KB

README.md

File metadata and controls

125 lines (105 loc) · 4.01 KB

prefstore

Security SharedPreferences support min sdk 21+

🏃 Library Setup

1. Add the repository

build.gradle

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

2. Add the dependency

build.gradle

  • Read and Write key-value
dependencies {
    implementation("com.github.developersancho.prefstore:prefstore:1.0.0")
}
  • Read and Write key-value, Support Moshi Serialize-Deserialize
dependencies {
    implementation("com.github.developersancho.prefstore:prefstore-moshi:1.0.0")
}
  • Read and Write key-value, Support Gson Serialize-Deserialize
dependencies {
    implementation("com.github.developersancho.prefstore:prefstore-gson:1.0.0")
}
  • Read and Write key-value, Support Both of Moshi-Gson Serialize-Deserialize
dependencies {
    implementation("com.github.developersancho.prefstore:prefstore-core:1.0.0")
}

💻 Usage

Example

data class Student(
        val id: Int,
        val name: String,
)

Just read and write value

val pref = PrefStore(context = this, prefFileName = "prefFileName")
pref.write(key = "KEY", "default")
pref.read(key = "KEY", defaultValue = "")

Just read and write value via moshi

val prefMoshi = MoshiPrefStore(context = this, prefFileName = "prefFileName_moshi")
prefMoshi.write(key = "KEY_MOSHI", "developersancho")
prefMoshi.read(key = "KEY_MOSHI", defaultValue = "")
prefMoshi.writeObject(key = "KEY_MOSHI_OBJECT", value = Student(id = 1, name = "moshi"))
prefMoshi.readObject<Student>(key = "KEY_MOSHI_OBJECT")
prefMoshi.readListObject<Student>(key = "KEY_MOSHI_LIST_OBJECT")

Just read and write value via gson

val prefGson = GsonPrefStore(context = this, prefFileName = "prefFileName_gson")
prefGson.write(key = "KEY_GSON", "gson")
prefGson.read(key = "KEY_GSON", defaultValue = "")
prefGson.writeObject(key = "KEY_GSON_OBJECT", value = Student(id = 1, name = "gson"))
prefGson.readObject<Student>(key = "KEY_GSON_OBJECT")
prefGson.readListObject<Student>(key = "KEY_GSON_LIST_OBJECT")

Also you can use extension methods

✍️ Author

👤 Mr.Sanchez

Feel free to ping me 😉

🤝 Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Open an issue first to discuss what you would like to change.
  2. Fork the Project
  3. Create your feature branch (git checkout -b feature/amazing-feature)
  4. Commit your changes (git commit -m 'Add some amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a pull request

Please make sure to update tests as appropriate.

☑️ TODO

  • Unit Testing
  • Support more libraries

📝 License

Copyright © 2021 - developersancho

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.