Skip to content

msoftware/AutoCursor

 
 

Repository files navigation

AutoCursor

Android Arsenal Download JitPack Build Status Join the chat at https://gitter.im/yongjhih/AutoCursor

Convert Cursor to model by annotations.

Usage

Before:

List<Image> images = new ArrayList<>();

while (cursor.moveToNext()) {
    Image image = new Image();
    
    Long id = cursor.getLong(cursor.getColumnIndex(_ID));
    image.setId(id);
    
    // ...
    
    images.add(id);
}
public class Image {
    Long id;

    public void setId(Long id) {
        this.id = id;
    }

    // ...
}

After:

List<Image> images = new ArrayList<>();

while (cursor.moveToNext()) {
    images.add(Image.create(cursor));
}
@AutoCursor
public abstract class Image implements Parcelable {
    @Nullable
    @AutoCursor.Column(name = _ID)
    public abstract Long id();

    @Nullable
    @AutoCursor.Column(name = DATA)
    public abstract String data();
 
    @Nullable
    @AutoCursor.Column(name = BUCKET_DISPLAY_NAME)
    public String bucketDisplayName();

    @Nullable
    @AutoCursor.Column(name = BUCKET_ID)
    public Long bucketId();

    // ...

    public static Image create(Cursor cursor) {
        return new AutoCursor_Image(cursor);
    }
}

Installation

via jcenter:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

apply plugin: 'com.neenbedankt.android-apt'

repositories {
    jcenter()
}

dependencies {
    compile 'com.infstory:auto-cursor:1.0.0'
    apt 'com.infstory:auto-cursor-processor:1.0.0'
}

via jitpack.io:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

apply plugin: 'com.neenbedankt.android-apt'

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

dependencies {
    compile 'com.github.yongjhih.AutoCursor:auto-cursor:-SNAPSHOT'
    apt 'com.github.yongjhih.AutoCursor:auto-cursor-processor:-SNAPSHOT'
}

License

Copyright 2015 8tory, Inc.

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.

Packages

No packages published

Languages

  • Java 100.0%