AutoCursor

General

Category
Free
Tag
APT
License
Apache License, Version 2.0
Registered
Jul 15, 2015
Favorites
2
Link
https://github.com/yongjhih/AutoCursor
See also
Bapter
PrefData
Barber
Fragment Creator
RxAnnotations

Additional

Language
Java
Version
1.0.0 (Jun 30, 2015)
Created
Jun 29, 2015
Updated
Jul 16, 2015 (Retired)
Owner
Andrew Chen (yongjhih)
Contributors
Tobias Preuss (johnjohndoe)
Felipe Lima (felipecsl)
Frankie Sardo (frankiesardo)
rock3r
Andrew Chen (yongjhih)
gitter-badger
cranberyxl
7
Activity
Badge
Generate
Download
Source code
APK file

Commercial

AutoCursor

cursor2model/cursor2pojo. Convert cursor to model/POJO 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);
    String data = cursor.getLong(cursor.getColumnIndex(DATA));
    image.setData(data);
    String bucketDisplayName = cursor.getLong(cursor.getColumnIndex(BUCKET_DISPLAY_NAME));
    image.setBucketDisplayName(bucketDisplayName);
    // ...

    images.add(image);
}
public class Image {
    Long id;
    String data;
    String bucketDisplayName;

    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'
}

Sample

yongjhih/RxMediaStore:

TODO

.iterator(Cursor):

for (Image image : Image.iterator(cursor)) {
    System.out.println(image.id());
}

Obseravle<T> T.observable(Cursor):

Image.observable(cursor).forEach(System.out::println);

Integration of RxMediaStore

CursorObseravble.create(cursor).map(c -> Image.create(c));

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.