autoprefs-processor

APT processor for autoprefs library

License

License

Categories

Categories

Auto Application Layer Libs Code Generators
GroupId

GroupId

com.dpforge
ArtifactId

ArtifactId

autoprefs-processor
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

autoprefs-processor
APT processor for autoprefs library
Project URL

Project URL

https://github.com/int02h/autoprefs
Source Code Management

Source Code Management

https://github.com/int02h/autoprefs

Download autoprefs-processor

How to add to project

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

Dependencies

runtime (2)

Group / Artifact Type Version
com.dpforge : autoprefs-annotation jar 1.0.2
com.squareup : javapoet jar 1.11.0

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-core jar 2.18.3
org.codehaus.groovy : groovy-all jar 2.4.12

Project Modules

There are no modules declared in this project.

autoprefs

Build Status Latest release

Autoprefs library based on compile-time code generation lets you eliminate boilerplate code for working with Android SharedPreferences. Generated code is fast as if you would wrote it by yourself. Only one reflection call is used to create instance of generated class.

Example

You need to declare interface annotated with @AutoPrefs annotation to work with SharedPreferences:

@AutoPrefs("current-user")
interface User {
    @DefaultLong(-1L)
    LongPref id();
    
    @DefaultString("")
    StringPref name();
    
    IntPref age();
    
    @PrefKey("access-token")
    StringPref accessToken();
    
    BooleanPref loggedIn();
}

Then get the instance:

User user = PrefsProvider.get(User.class);

and start to use SharedPreferences representing some user.

Preferences name

You are able to specify preferences name with @AutoPrefs annotation argument. By default the name of the interface (without package name) will be used. So keep in mind that two interfaces with the same name but in different packages will represent the same preferences instance.

Preferences keys

Method name defines preference key. You can change it with @PrefKey annotation.

Default values

There are six annotations that can be used to set up preference default value. Each for corresponding data type:

  • DefaultBoolean
  • DefaultFloat
  • DefaultInt
  • DefaultLong
  • DefaultString
  • DefaultStringSet

Clear preferences

Declare void method without arguments and place @ClearMethod annotation on it. When called this method will clear all values in SharedPreferences.

Download

To use latest version of the library just add the following code to your Gradle build script:

implementation 'com.dpforge:autoprefs:1.0.2'
implementation 'com.dpforge:autoprefs-annotation:1.0.2'
annotationProcessor 'com.dpforge:autoprefs-processor:1.0.2'

License

Copyright (c) 2018 Daniil Popov

Licensed under the MIT License.

Versions

Version
1.0.2
1.0.1
1.0.0