Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add value param option to ModelProp for convenience #268

Merged
merged 1 commit into from
Sep 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ enum Option {
/** Specify any {@link Option} values that should be used when generating the model class. */
Option[] options() default {};

/**
* The same as {@link #options()}, but this allows the shortcut of setting an option eg
* "@ModelProp(DoNotHash)".
*/
Option[] value() default {};

/**
* The name of the constant field that should be used as the default value for this prop. The
* default value will be used if the prop value isn't set on the model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class ViewAttributeInfo extends AttributeInfo {
defaultConstant = propAnnotation.defaultValue();
groupKey = propAnnotation.group();
options.addAll(Arrays.asList(propAnnotation.options()));
options.addAll(Arrays.asList(propAnnotation.value()));
} else if (textAnnotation != null) {
options.add(Option.GenerateStringOverloads);
} else if (callbackAnnotation != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ public TestStringOverloadsView(Context context) {
public void setTitle(CharSequence title) {

}

// test setting options via the value param shortcut
@ModelProp(ModelProp.Option.GenerateStringOverloads)
public void setTitleViaValueShortcut(CharSequence title) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Generated file. Do not modify! */
public class TestStringOverloadsViewModel_ extends EpoxyModel<TestStringOverloadsView> implements GeneratedModel<TestStringOverloadsView> {
private final BitSet assignedAttributes_epoxyGeneratedModel = new BitSet(1);
private final BitSet assignedAttributes_epoxyGeneratedModel = new BitSet(2);

private OnModelBoundListener<TestStringOverloadsViewModel_, TestStringOverloadsView> onModelBoundListener_epoxyGeneratedModel;

Expand All @@ -27,10 +27,17 @@ public class TestStringOverloadsViewModel_ extends EpoxyModel<TestStringOverload
* Bitset index: 0 */
private StringAttributeData title_StringAttributeData = new StringAttributeData();

/**
* Bitset index: 1 */
private StringAttributeData titleViaValueShortcut_StringAttributeData = new StringAttributeData();

@Override
public void addTo(EpoxyController controller) {
super.addTo(controller);
addWithDebugValidation(controller);
if (!assignedAttributes_epoxyGeneratedModel.get(1)) {
throw new IllegalStateException("A value is required for setTitleViaValueShortcut");
}
if (!assignedAttributes_epoxyGeneratedModel.get(0)) {
throw new IllegalStateException("A value is required for setTitle");
}
Expand All @@ -45,6 +52,7 @@ public void handlePreBind(final EpoxyViewHolder holder, final TestStringOverload
@Override
public void bind(final TestStringOverloadsView object) {
super.bind(object);
object.setTitleViaValueShortcut(titleViaValueShortcut_StringAttributeData.toString(object.getContext()));
object.setTitle(title_StringAttributeData.toString(object.getContext()));
}

Expand All @@ -57,6 +65,10 @@ public void bind(final TestStringOverloadsView object, EpoxyModel previousModel)
TestStringOverloadsViewModel_ that = (TestStringOverloadsViewModel_) previousModel;
super.bind(object);

if (!titleViaValueShortcut_StringAttributeData.equals(that.titleViaValueShortcut_StringAttributeData)) {
object.setTitleViaValueShortcut(titleViaValueShortcut_StringAttributeData.toString(object.getContext()));
}

if (!title_StringAttributeData.equals(that.title_StringAttributeData)) {
object.setTitle(title_StringAttributeData.toString(object.getContext()));
}
Expand Down Expand Up @@ -166,6 +178,69 @@ public TestStringOverloadsViewModel_ titleQuantityRes(@PluralsRes int pluralRes,
return this;
}

public CharSequence getTitleViaValueShortcut(Context context) {
return titleViaValueShortcut_StringAttributeData.toString(context);
}

/**
* <i>Required.</i>
*
* @see TestStringOverloadsView#setTitleViaValueShortcut(CharSequence)
*/
public TestStringOverloadsViewModel_ titleViaValueShortcut(CharSequence titleViaValueShortcut) {
onMutation();
assignedAttributes_epoxyGeneratedModel.set(1);
if (titleViaValueShortcut == null) {
throw new IllegalArgumentException("titleViaValueShortcut cannot be null");
}
titleViaValueShortcut_StringAttributeData.setValue(titleViaValueShortcut);
return this;
}

/**
* Throws if a value <= 0 is set.
* <p>
* <i>Required.</i>
*
* @see TestStringOverloadsView#setTitleViaValueShortcut(CharSequence)
*/
public TestStringOverloadsViewModel_ titleViaValueShortcut(@StringRes int stringRes) {
onMutation();
assignedAttributes_epoxyGeneratedModel.set(1);
titleViaValueShortcut_StringAttributeData.setValue(stringRes);
return this;
}

/**
* Throws if a value <= 0 is set.
* <p>
* <i>Required.</i>
*
* @see TestStringOverloadsView#setTitleViaValueShortcut(CharSequence)
*/
public TestStringOverloadsViewModel_ titleViaValueShortcut(@StringRes int stringRes,
Object... formatArgs) {
onMutation();
assignedAttributes_epoxyGeneratedModel.set(1);
titleViaValueShortcut_StringAttributeData.setValue(stringRes, formatArgs);
return this;
}

/**
* Throws if a value <= 0 is set.
* <p>
* <i>Required.</i>
*
* @see TestStringOverloadsView#setTitleViaValueShortcut(CharSequence)
*/
public TestStringOverloadsViewModel_ titleViaValueShortcutQuantityRes(@PluralsRes int pluralRes,
int quantity, Object... formatArgs) {
onMutation();
assignedAttributes_epoxyGeneratedModel.set(1);
titleViaValueShortcut_StringAttributeData.setValue(pluralRes, quantity, formatArgs);
return this;
}

@Override
public TestStringOverloadsViewModel_ id(long id) {
super.id(id);
Expand Down Expand Up @@ -244,6 +319,7 @@ public TestStringOverloadsViewModel_ reset() {
onModelUnboundListener_epoxyGeneratedModel = null;
assignedAttributes_epoxyGeneratedModel.clear();
this.title_StringAttributeData = new StringAttributeData();
this.titleViaValueShortcut_StringAttributeData = new StringAttributeData();
super.reset();
return this;
}
Expand All @@ -269,6 +345,9 @@ public boolean equals(Object o) {
if (title_StringAttributeData != null ? !title_StringAttributeData.equals(that.title_StringAttributeData) : that.title_StringAttributeData != null) {
return false;
}
if (titleViaValueShortcut_StringAttributeData != null ? !titleViaValueShortcut_StringAttributeData.equals(that.titleViaValueShortcut_StringAttributeData) : that.titleViaValueShortcut_StringAttributeData != null) {
return false;
}
return true;
}

Expand All @@ -278,13 +357,15 @@ public int hashCode() {
result = 31 * result + (onModelBoundListener_epoxyGeneratedModel != null ? 1 : 0);
result = 31 * result + (onModelUnboundListener_epoxyGeneratedModel != null ? 1 : 0);
result = 31 * result + (title_StringAttributeData != null ? title_StringAttributeData.hashCode() : 0);
result = 31 * result + (titleViaValueShortcut_StringAttributeData != null ? titleViaValueShortcut_StringAttributeData.hashCode() : 0);
return result;
}

@Override
public String toString() {
return "TestStringOverloadsViewModel_{" +
"title_StringAttributeData=" + title_StringAttributeData +
", titleViaValueShortcut_StringAttributeData=" + titleViaValueShortcut_StringAttributeData +
"}" + super.toString();
}

Expand Down