Androidx Preferences Annotations

Maintenance

Лицензия

Лицензия

Группа

Группа

co.windly
Идентификатор

Идентификатор

androidxpreferences-annotations
Последняя версия

Последняя версия

1.0.6
Дата

Дата

Тип

Тип

jar
Описание

Описание

Androidx Preferences Annotations
Maintenance
Ссылка на сайт

Ссылка на сайт

https://github.com/tommus/androidx-prefs
Система контроля версий

Система контроля версий

https://github.com/tommus/androidx-prefs

Скачать androidxpreferences-annotations

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/co.windly/androidxpreferences-annotations/ -->
<dependency>
    <groupId>co.windly</groupId>
    <artifactId>androidxpreferences-annotations</artifactId>
    <version>1.0.6</version>
</dependency>
// https://jarcasting.com/artifacts/co.windly/androidxpreferences-annotations/
implementation 'co.windly:androidxpreferences-annotations:1.0.6'
// https://jarcasting.com/artifacts/co.windly/androidxpreferences-annotations/
implementation ("co.windly:androidxpreferences-annotations:1.0.6")
'co.windly:androidxpreferences-annotations:jar:1.0.6'
<dependency org="co.windly" name="androidxpreferences-annotations" rev="1.0.6">
  <artifact name="androidxpreferences-annotations" type="jar" />
</dependency>
@Grapes(
@Grab(group='co.windly', module='androidxpreferences-annotations', version='1.0.6')
)
libraryDependencies += "co.windly" % "androidxpreferences-annotations" % "1.0.6"
[co.windly/androidxpreferences-annotations "1.0.6"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

AndroidX Preferences

This library uses annotation processing to ensure the compile time verification for user-defined shared preferences.

Usage

  1. Add dependencies.

Add dependencies to the Java-based project:

dependencies {
    implementation "co.windly:androidxpreferences:1.0.6"
    annotationProcessor "co.windly:androidxpreferences-compiler:1.0.6"
}

Add dependencies to the Kotlin-based project:

dependencies {
    implementation "co.windly:androidxpreferences:1.0.6"
    kapt "co.windly:androidxpreferences-compiler:1.0.6"
}
  1. Define shared preferences.

Use the @Prefs annotation on any POJO. All (non static) fields will be considered a preference.

For example:

@Prefs(value = "UserCachePreferences", fileMode = MODE_PRIVATE)
public class UserCache {

    //region Basic

    @DefaultLong(0L)
    Long id;

    @DefaultString("")
    String firstName;

    @DefaultString("")
    String lastName;

    @DefaultString("")
    String password;

    @DefaultBoolean(true)
    Boolean active;

    //endregion
}

Accepted shared preference field types are:

  • Boolean
  • Float
  • Integer
  • Long
  • String
  • Set<String>
  1. Use generated wrapper class.

A class named <YourClassName>Prefs will be generated in the same package (at compile time). Use it like this:

    final UserCachePrefs cache = UserCachePrefs.get(this);

    // Put a single value (apply() is automatically called).
    cache
      .putId(1L);

    // Put several values in one transaction.
    cache
      .edit()
      .putFirstName("John")
      .putLastName("Snow")
      .putPassword("WinterIsComing")
      .putActive(true)
      .apply();

    // Check if a value is set.
    if (cache.containsFirstName()) {
      Log.d(TAG, "First name is set.");
    };

    // Access preferences one by one.
    Log.d(TAG, "id -> " + cache.getId());
    Log.d(TAG, "first name -> " + cache.getFirstName());
    Log.d(TAG, "last name -> " + cache.getLastName());
    Log.d(TAG, "password -> " + cache.getPassword());
    Log.d(TAG, "active -> " + cache.isActive());

    // Access all preferences.
    Log.d(TAG, "cache -> " + cache.getAll());

    // Remove a value.
    cache.removeFirstName();

    // Clear all preferences.
    cache.clear();

Версии библиотеки

Версия
1.0.6
1.0.5