Skip to content

Commit dcb503e

Browse files
author
Mohammad Hamdan
committed
Support custom code
1 parent 0d2fa0c commit dcb503e

4 files changed

Lines changed: 29 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ annotationProcessor 'com.github.mnayef.AutoAdapter:compiler:v1.0.2'
3939
* Visibility
4040
* Click
4141
* LongClick
42+
* Code
4243
* LinkPreview ([AndroidLinkPreview](https://github.com/mnayef/AndroidLinkPreview))
4344

4445
### How to use? ###
@@ -80,6 +81,7 @@ public class MixModel {
8081
@Image(value = R.id.image, library = ImageLibraries.FRESCO, progressId = R.id.image_progress, source = ImageSource.URL)
8182
private String image = "";
8283
84+
@Code("if (holder.title.getText().toString().isEmpty()) {\nholder.title.setVisibility(android.view.View.GONE);\n}\n")
8385
public String getTitle() {
8486
return title;
8587
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.mnayef.annotations;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* AutoAdapter-master
10+
* Created by Mohamed Hamdan on 2017-Jul-10.
11+
*/
12+
@Target(ElementType.METHOD)
13+
@Retention(RetentionPolicy.CLASS)
14+
public @interface Code {
15+
String value();
16+
}

app/src/main/java/com/mnayef/autoadapter/model/MixModel.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.mnayef.annotations.Adapter;
88
import com.mnayef.annotations.Click;
9+
import com.mnayef.annotations.Code;
910
import com.mnayef.annotations.Image;
1011
import com.mnayef.annotations.LongClick;
1112
import com.mnayef.annotations.Text;
@@ -22,6 +23,7 @@
2223
public class MixModel {
2324

2425
private int id;
26+
2527
@Text(R.id.title)
2628
private String title = "";
2729
@Text(R.id.date)
@@ -31,6 +33,7 @@ public class MixModel {
3133
@Image(value = R.id.image, library = ImageLibraries.FRESCO, progressId = R.id.image_progress, source = ImageSource.URL)
3234
private String image = "";
3335

36+
@Code("if (holder.title.getText().toString().isEmpty()) {\nholder.title.setVisibility(android.view.View.GONE);\n}\n")
3437
public String getTitle() {
3538
return title;
3639
}

compiler/src/main/java/com/mnayef/compiler/AdapterProcessor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.mnayef.annotations.Adapter;
55
import com.mnayef.annotations.Check;
66
import com.mnayef.annotations.Click;
7+
import com.mnayef.annotations.Code;
78
import com.mnayef.annotations.Image;
89
import com.mnayef.annotations.Link;
910
import com.mnayef.annotations.LongClick;
@@ -58,6 +59,7 @@ public final class AdapterProcessor extends AbstractProcessor {
5859
Radio.class,
5960
Check.class,
6061
Visibility.class,
62+
Code.class,
6163
Link.class
6264
);
6365

@@ -120,6 +122,9 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
120122
Visibility visibility = enclosedElement.getAnnotation(Visibility.class);
121123
if (visibility != null) fields.put(enclosedElement, visibility);
122124

125+
Code code = enclosedElement.getAnnotation(Code.class);
126+
if (code != null) fields.put(enclosedElement, code);
127+
123128
Link link = enclosedElement.getAnnotation(Link.class);
124129
if (link != null) fields.put(enclosedElement, link);
125130
}
@@ -280,6 +285,9 @@ private void findViewById(MethodSpec.Builder builder, Element element, Annotatio
280285
} else {
281286
BindingUtil.bindVisibilityView(onBindViewHolder, createdFields.get(String.valueOf(field.value())), fieldSpec.name);
282287
}
288+
} else if (baseField instanceof Code) {
289+
Code code = (Code) baseField;
290+
onBindViewHolder.addCode(code.value());
283291
} else if (baseField instanceof Link) {
284292
Link field = (Link) baseField;
285293
fieldSpec = FieldSpec.builder(ClassesNames.LINK_PREVIEW, element.getSimpleName().toString(), Modifier.PRIVATE).build();

0 commit comments

Comments
 (0)