Comments (14)
The idea of a ContentValuesBuilder
might be simplified by simply adding a toContentValues()
method to the generated class, so you could use it like this:
ContentValues values = User.builder()
.id(id)
.name(name)
.email(email)
.build()
.toContentValues();
The @ContentValuesBuilder
seems inflexible in that the user would have to add both Builder
and ContentValuesBuilder
inner classes in order to use it. I wonder if the auto-value-cursor
generated class could simply override the $AutoValue_User.Builder
class to add a public ContentValues asContentValues()
method so that, if the class has an @AutoValue.Builder
inner class, the ContentValues addition can be added with no extra code.
My suspicion is the the extension support in AutoValue will have to be extended to the Builder in order to accommodate this type of functionality.
from auto-value-cursor.
I'll add support for that, but I'm currently a bit busy. Maybe this or next weekend. If you want to give it a try before that I'm happy about pull requests 😃
from auto-value-cursor.
Can confirm this is working great. Thanks again for your help.
from auto-value-cursor.
Yes it is possible.
It would even be possible to generate a ContentValues Builder class similar AutoValue Builders for ContentValues. Something like this:
@AutoValue public abstract class User {
abstract String id();
abstract String name();
abstract String email();
@ContentValuesBuilder
abstract static class ContentValuesBuilder {
abstract ContentValuesBuilder id(String id);
abstract ContentValuesBuilder name(String name);
abstract ContentValuesBuilder email(String email);
abstract ContentValues build();
}
// returns ContentValuesBuilder with values from current object
abstract ContentValuesBuilder toContentValuesBuilder();
public static User create(Cursor cursor) {
return AutoValue_User.createFromCursor(cursor);
}
}
from auto-value-cursor.
Re: the toContentValues
method, you could simply check the class for an abstract method returning ContentValues
, and implement that to convert the class to ContentValues
and return it.
from auto-value-cursor.
Yeah a regular toContentValues()
should definitely be done and is super easy to implement.
I just thought that it might be nice to have the ContentValuesBuilder
on top of that. One major advantage of having it would be that you can use it for partial updates like only updating name and email. That would only work with either a separate Builder or extending the default Builder, because build().toContentValues()
would do null checks.
from auto-value-cursor.
@laurencedawson The latest 0.3.0-SNAPSHOT
will now generate a toContentValues()
if you add an abstract one to your class.
from auto-value-cursor.
@gabrielittner Fantastic thanks!
from auto-value-cursor.
@gabrielittner sorry but can you provide a quick example? Thanks
from auto-value-cursor.
You just need to change the dependency to the snapshot version and add public abstract ContentValues toContentValues()
to your AutoValue class.
from auto-value-cursor.
Have you published the snapshot or do you mean built it and add locally?
from auto-value-cursor.
Snapshots are published to a different repository. You have to add
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
to the repositories block in your build.gradle file.
from auto-value-cursor.
Aha thanks!
from auto-value-cursor.
I created another issue but I think it's probably best discussed in here.
If a custom class is defined and setup with the @CursorAdapter annotation, the toContentValues method will cause the build to fail throwing the following error message:
Error:Property "Y" has type "X" that can't be put into ContentValues
Would it be possible to add along side the CursorAdapterFactory (containing createFromCursor) a method to saveToCursorValues?
Thanks
from auto-value-cursor.
Related Issues (20)
- Annotation to avoid a property being filled in ContentValues HOT 4
- Consider putNull support for foreign key ID values HOT 1
- Check for null in createFromCursor HOT 3
- Autogeneration of createFromCursor not occuring . HOT 6
- Improvement: reusable CursorAdapter class with different column name HOT 2
- Improvement: fillContentValues HOT 2
- @ColumnAdapter class can't be found at runtime HOT 2
- toContentValues is not generated HOT 3
- Default support for Optional without a custom type adapter HOT 2
- Improvement: Provide dependency in ColumnTypeAdapter
- Annotation @Nullable not handled correctly
- Special handling for autogenerated _id columns? HOT 4
- @AutoValue dependencies issue? HOT 1
- Improvement: Register global ColumnAdapters HOT 3
- Improvement: support ColumnTypeAdapters with identical names HOT 8
- Improvement: Support to ignore fields HOT 2
- set default value if a item in cursor is null HOT 1
- Improvement: Support to ignore fields
- auto-value-cursor 2.0.0-rc1 still does not support incremental build.
- auto-value-cursor 2.0.0 does not include shadow HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from auto-value-cursor.