diff --git a/README.md b/README.md index 317221c..1ef5cb4 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ dependencies { // ... // declare memo version - def memo_version = "1.0.0" + def memo_version = "x.y.z" // Memo Library implementation("com.zeoflow:memo:$memo_version") @@ -88,6 +88,212 @@ Memo.init(context) .build(); ``` +### 3. Injector +#### 3.1 Build MemoEntity Class +```java +/** + * the entity generated will be named UserProfile_MemoEntity + * it was annotated with @MemoEntity("UserProfile") + * + * the entity will be encrypted using the "G15y3aV9M8d" key + * it was annotated with @EncryptEntity("G15y3aV9M8d") + */ +@MemoEntity("UserProfile") +@EncryptEntity("G15y3aV9M8d") +public class User +{ + + /** + * the default value will be "zeoflow" + * + * generated field will be named username + * + * this field is observable + * it was annotated with @Observable + */ + @KeyName("username") + @Observable + protected final String userUsername = "zeoflow"; + + /** + * generated field name will be login - lowerCamel + * + * this field will have its own onChangedListener + * it was annotated with @Listener + */ + @Listener + protected final boolean login = false; + + /* the default value will be 1 */ + @KeyName("views") + protected final int viewsCount = 1; + + /* the default value will be null */ + @KeyName("userinfo") + protected PrivateInfo privateInfo; + + /** + * preference putter function for userUsername. + * + * @param userUsername function in + * + * @return function out + */ + @MemoFunction("username") + public String putUserUsernameFunction(String userUsername) + { + return "Hello, " + userUsername; + } + + /** + * preference getter function for userUsername. + * + * @param userUsername function in + * + * @return function out + */ + @MemoFunction("username") + public String getUserUsernameFunction(String userUsername) + { + return userUsername + "!!!"; + } + + /** + * preference putter function example for visitCount's auto increment. + * + * @param count function in + * + * @return function out + */ + @MemoFunction("views") + public int putVisitCountFunction(int count) + { + return ++count; + } + + /** + * preference getter compound function for following fields. + * + * Params declared inside @MemoCompoundFunction's annotation + * @param username function in + * @param views function in + * + * @return $username $views + */ + @MemoCompoundFunction(values = {"username", "views"}) + public String getUserViews(String username, int views) + { + return username + " " + views; + } + + /** + * preference getter compound function for following fields. + * + * Params declared inside @MemoCompoundFunction's annotation + * @param userinfo function in + * + * @return $first_name $last_name + */ + @MemoCompoundFunction(values = {"userinfo"}) + public String getFullName(PrivateInfo userinfo) + { + return userinfo.getFirstName() + " " + userinfo.getLastName(); + } + + /** + * preference getter compound function for following fields. + * + * Params declared inside @MemoCompoundFunction's annotation + * @param userinfo function in + * @param views function in + * + * @return $first_name $last_name, views count $views + */ + @MemoCompoundFunction(values = {"userinfo", "views"}) + public String getFullNameAndViews(PrivateInfo userinfo, int views) + { + return userinfo.getFirstName() + " " + userinfo.getLastName() + ", views count: " + views; + } + +} +``` + +#### 3.2 Helper Class for Memo's injector +Create injector class +```java +/** + * Component that integrates memo entities; it must be an interface + * and annotated with @MemoComponent. The generated class will end in + * $_Memo (generated class for this interface will be AppStorage_Memo + * + * inside this Memo manager, the following MemoEntities are injected: + * - User + * - Country + */ +@MemoComponent(entities = {User.class, Country.class}) +public interface AppStorage +{ + + /** + * declare dependency injection target MaiActivity. + */ + void inject(MainActivity mainActivity); + + /** + * declare dependency injection target LoginActivity. + */ + void inject(LoginActivity loginActivity); + +} +``` + +Create variables that needs to be injected by the `AppStorage_Memo` +```java +@InjectPreference +public AppStorage_Memo component; +@InjectPreference +public UserProfile_MemoEntity userProfile; +``` + +Inject `MainActivity` in the `AppStorage_Memo` +```java +AppStorage_Memo.getInstance().inject((MainActivity) this); +``` + +Access MemoEntity from Memo Component +```java +component.userProfile(); +``` + +Put value inside `userProfile` +```java +userProfile.putUsername(inputUsername); +``` + +Add change listener for login +```java +userProfile.addLoginListeners(new UserProfile_MemoEntity.LoginIOnChangedListener() +{ + @Override + public void onChanged(boolean login) + { + // do something + } +}); +``` + +Add observable for the username field +```java +component.userProfile().usernameObserver((LifecycleOwner) this, new Observer() +{ + @Override + public void onChanged(String username) + { + // do something here + } +}); +``` + ## License Copyright (C) 2021 ZeoFlow S.R.L. diff --git a/demo/src/main/java/com/zeoflow/demo/components/AppStorage.java b/demo/src/main/java/com/zeoflow/demo/components/AppStorage.java index a691e4f..9e28854 100644 --- a/demo/src/main/java/com/zeoflow/demo/components/AppStorage.java +++ b/demo/src/main/java/com/zeoflow/demo/components/AppStorage.java @@ -23,17 +23,26 @@ import com.zeoflow.memo.annotation.MemoComponent; /** - * Component integrates entities. + * Component that integrates memo entities; it must be an interface + * and annotated with @MemoComponent. The generated class will end in + * $_Memo (generated class for this interface will be AppStorage_Memo + * + * inside this Memo manager, the following MemoEntities are injected: + * - User + * - Country */ @MemoComponent(entities = {User.class, Country.class}) public interface AppStorage { /** - * declare dependency injection targets. + * declare dependency injection target MaiActivity. */ void inject(MainActivity mainActivity); + /** + * declare dependency injection target LoginActivity. + */ void inject(LoginActivity loginActivity); } diff --git a/demo/src/main/java/com/zeoflow/demo/entities/User.java b/demo/src/main/java/com/zeoflow/demo/entities/User.java index 7469a2e..9506a91 100644 --- a/demo/src/main/java/com/zeoflow/demo/entities/User.java +++ b/demo/src/main/java/com/zeoflow/demo/entities/User.java @@ -8,55 +8,75 @@ import com.zeoflow.memo.annotation.MemoFunction; import com.zeoflow.memo.annotation.Observable; +/** + * the entity generated will be named UserProfile_MemoEntity + * it was annotated with @MemoEntity("UserProfile") + * + * the entity will be encrypted using the "G15y3aV9M8d" key + * it was annotated with @EncryptEntity("G15y3aV9M8d") + */ @MemoEntity("UserProfile") -@EncryptEntity("G15y3aV9M8dHbmV4vC9EZmDxRgAoWd") +@EncryptEntity("G15y3aV9M8d") public class User { + /** + * the default value will be "zeoflow" + * + * generated field will be named username + * + * this field is observable + * it was annotated with @Observable + */ @KeyName("username") @Observable - protected final String userNickName = "zeoflow"; + protected final String userUsername = "zeoflow"; /** - * key value will be 'login'. (login's camel lowercase) + * generated field name will be login - lowerCamel + * + * this field will have its own onChangedListener + * it was annotated with @Listener */ @Listener protected final boolean login = false; + /* the default value will be 1 */ @KeyName("views") protected final int viewsCount = 1; + /* the default value will be null */ @KeyName("userinfo") protected PrivateInfo privateInfo; /** - * preference putter function about userNickName. + * preference putter function for userUsername. * - * @param nickname function in + * @param userUsername function in * * @return function out */ @MemoFunction("username") - public String putUserNickFunction(String nickname) + public String putUserUsernameFunction(String userUsername) { - return "Hello, " + nickname; + return "Hello, " + userUsername; } /** - * preference getter function about userNickName. + * preference getter function for userUsername. * - * @param nickname function in + * @param userUsername function in * * @return function out */ @MemoFunction("username") - public String getUserNickFunction(String nickname) + public String getUserUsernameFunction(String userUsername) { - return nickname + "!!!"; + return userUsername + "!!!"; } /** - * preference putter function example about visitCount's auto increment. + * preference putter function example for visitCount's auto increment. * * @param count function in * @@ -68,18 +88,44 @@ public int putVisitCountFunction(int count) return ++count; } + /** + * preference getter compound function for following fields. + * + * Params declared inside @MemoCompoundFunction's annotation + * @param username function in + * @param views function in + * + * @return $username $views + */ @MemoCompoundFunction(values = {"username", "views"}) - public String getUserFullName(String username, int views) + public String getUserViews(String username, int views) { return username + " " + views; } + /** + * preference getter compound function for following fields. + * + * Params declared inside @MemoCompoundFunction's annotation + * @param userinfo function in + * + * @return $first_name $last_name + */ @MemoCompoundFunction(values = {"userinfo"}) public String getFullName(PrivateInfo userinfo) { return userinfo.getFirstName() + " " + userinfo.getLastName(); } + /** + * preference getter compound function for following fields. + * + * Params declared inside @MemoCompoundFunction's annotation + * @param userinfo function in + * @param views function in + * + * @return $first_name $last_name, views count $views + */ @MemoCompoundFunction(values = {"userinfo", "views"}) public String getFullNameAndViews(PrivateInfo userinfo, int views) { diff --git a/docs/README.md b/docs/README.md index 317221c..1ef5cb4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -23,7 +23,7 @@ dependencies { // ... // declare memo version - def memo_version = "1.0.0" + def memo_version = "x.y.z" // Memo Library implementation("com.zeoflow:memo:$memo_version") @@ -88,6 +88,212 @@ Memo.init(context) .build(); ``` +### 3. Injector +#### 3.1 Build MemoEntity Class +```java +/** + * the entity generated will be named UserProfile_MemoEntity + * it was annotated with @MemoEntity("UserProfile") + * + * the entity will be encrypted using the "G15y3aV9M8d" key + * it was annotated with @EncryptEntity("G15y3aV9M8d") + */ +@MemoEntity("UserProfile") +@EncryptEntity("G15y3aV9M8d") +public class User +{ + + /** + * the default value will be "zeoflow" + * + * generated field will be named username + * + * this field is observable + * it was annotated with @Observable + */ + @KeyName("username") + @Observable + protected final String userUsername = "zeoflow"; + + /** + * generated field name will be login - lowerCamel + * + * this field will have its own onChangedListener + * it was annotated with @Listener + */ + @Listener + protected final boolean login = false; + + /* the default value will be 1 */ + @KeyName("views") + protected final int viewsCount = 1; + + /* the default value will be null */ + @KeyName("userinfo") + protected PrivateInfo privateInfo; + + /** + * preference putter function for userUsername. + * + * @param userUsername function in + * + * @return function out + */ + @MemoFunction("username") + public String putUserUsernameFunction(String userUsername) + { + return "Hello, " + userUsername; + } + + /** + * preference getter function for userUsername. + * + * @param userUsername function in + * + * @return function out + */ + @MemoFunction("username") + public String getUserUsernameFunction(String userUsername) + { + return userUsername + "!!!"; + } + + /** + * preference putter function example for visitCount's auto increment. + * + * @param count function in + * + * @return function out + */ + @MemoFunction("views") + public int putVisitCountFunction(int count) + { + return ++count; + } + + /** + * preference getter compound function for following fields. + * + * Params declared inside @MemoCompoundFunction's annotation + * @param username function in + * @param views function in + * + * @return $username $views + */ + @MemoCompoundFunction(values = {"username", "views"}) + public String getUserViews(String username, int views) + { + return username + " " + views; + } + + /** + * preference getter compound function for following fields. + * + * Params declared inside @MemoCompoundFunction's annotation + * @param userinfo function in + * + * @return $first_name $last_name + */ + @MemoCompoundFunction(values = {"userinfo"}) + public String getFullName(PrivateInfo userinfo) + { + return userinfo.getFirstName() + " " + userinfo.getLastName(); + } + + /** + * preference getter compound function for following fields. + * + * Params declared inside @MemoCompoundFunction's annotation + * @param userinfo function in + * @param views function in + * + * @return $first_name $last_name, views count $views + */ + @MemoCompoundFunction(values = {"userinfo", "views"}) + public String getFullNameAndViews(PrivateInfo userinfo, int views) + { + return userinfo.getFirstName() + " " + userinfo.getLastName() + ", views count: " + views; + } + +} +``` + +#### 3.2 Helper Class for Memo's injector +Create injector class +```java +/** + * Component that integrates memo entities; it must be an interface + * and annotated with @MemoComponent. The generated class will end in + * $_Memo (generated class for this interface will be AppStorage_Memo + * + * inside this Memo manager, the following MemoEntities are injected: + * - User + * - Country + */ +@MemoComponent(entities = {User.class, Country.class}) +public interface AppStorage +{ + + /** + * declare dependency injection target MaiActivity. + */ + void inject(MainActivity mainActivity); + + /** + * declare dependency injection target LoginActivity. + */ + void inject(LoginActivity loginActivity); + +} +``` + +Create variables that needs to be injected by the `AppStorage_Memo` +```java +@InjectPreference +public AppStorage_Memo component; +@InjectPreference +public UserProfile_MemoEntity userProfile; +``` + +Inject `MainActivity` in the `AppStorage_Memo` +```java +AppStorage_Memo.getInstance().inject((MainActivity) this); +``` + +Access MemoEntity from Memo Component +```java +component.userProfile(); +``` + +Put value inside `userProfile` +```java +userProfile.putUsername(inputUsername); +``` + +Add change listener for login +```java +userProfile.addLoginListeners(new UserProfile_MemoEntity.LoginIOnChangedListener() +{ + @Override + public void onChanged(boolean login) + { + // do something + } +}); +``` + +Add observable for the username field +```java +component.userProfile().usernameObserver((LifecycleOwner) this, new Observer() +{ + @Override + public void onChanged(String username) + { + // do something here + } +}); +``` + ## License Copyright (C) 2021 ZeoFlow S.R.L. diff --git a/docs/getting-started.md b/docs/getting-started.md index 15ac76c..13178c1 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -27,7 +27,7 @@ dependencies { // ... // declare memo version - def memo_version = "1.0.0" + def memo_version = "x.y.z" // Memo Library implementation("com.zeoflow:memo:$memo_version") @@ -92,6 +92,212 @@ Memo.init(context) .build(); ``` +### 3. Injector +#### 3.1 Build MemoEntity Class +```java +/** + * the entity generated will be named UserProfile_MemoEntity + * it was annotated with @MemoEntity("UserProfile") + * + * the entity will be encrypted using the "G15y3aV9M8d" key + * it was annotated with @EncryptEntity("G15y3aV9M8d") + */ +@MemoEntity("UserProfile") +@EncryptEntity("G15y3aV9M8d") +public class User +{ + + /** + * the default value will be "zeoflow" + * + * generated field will be named username + * + * this field is observable + * it was annotated with @Observable + */ + @KeyName("username") + @Observable + protected final String userUsername = "zeoflow"; + + /** + * generated field name will be login - lowerCamel + * + * this field will have its own onChangedListener + * it was annotated with @Listener + */ + @Listener + protected final boolean login = false; + + /* the default value will be 1 */ + @KeyName("views") + protected final int viewsCount = 1; + + /* the default value will be null */ + @KeyName("userinfo") + protected PrivateInfo privateInfo; + + /** + * preference putter function for userUsername. + * + * @param userUsername function in + * + * @return function out + */ + @MemoFunction("username") + public String putUserUsernameFunction(String userUsername) + { + return "Hello, " + userUsername; + } + + /** + * preference getter function for userUsername. + * + * @param userUsername function in + * + * @return function out + */ + @MemoFunction("username") + public String getUserUsernameFunction(String userUsername) + { + return userUsername + "!!!"; + } + + /** + * preference putter function example for visitCount's auto increment. + * + * @param count function in + * + * @return function out + */ + @MemoFunction("views") + public int putVisitCountFunction(int count) + { + return ++count; + } + + /** + * preference getter compound function for following fields. + * + * Params declared inside @MemoCompoundFunction's annotation + * @param username function in + * @param views function in + * + * @return $username $views + */ + @MemoCompoundFunction(values = {"username", "views"}) + public String getUserViews(String username, int views) + { + return username + " " + views; + } + + /** + * preference getter compound function for following fields. + * + * Params declared inside @MemoCompoundFunction's annotation + * @param userinfo function in + * + * @return $first_name $last_name + */ + @MemoCompoundFunction(values = {"userinfo"}) + public String getFullName(PrivateInfo userinfo) + { + return userinfo.getFirstName() + " " + userinfo.getLastName(); + } + + /** + * preference getter compound function for following fields. + * + * Params declared inside @MemoCompoundFunction's annotation + * @param userinfo function in + * @param views function in + * + * @return $first_name $last_name, views count $views + */ + @MemoCompoundFunction(values = {"userinfo", "views"}) + public String getFullNameAndViews(PrivateInfo userinfo, int views) + { + return userinfo.getFirstName() + " " + userinfo.getLastName() + ", views count: " + views; + } + +} +``` + +#### 3.2 Helper Class for Memo's injector +Create injector class +```java +/** + * Component that integrates memo entities; it must be an interface + * and annotated with @MemoComponent. The generated class will end in + * $_Memo (generated class for this interface will be AppStorage_Memo + * + * inside this Memo manager, the following MemoEntities are injected: + * - User + * - Country + */ +@MemoComponent(entities = {User.class, Country.class}) +public interface AppStorage +{ + + /** + * declare dependency injection target MaiActivity. + */ + void inject(MainActivity mainActivity); + + /** + * declare dependency injection target LoginActivity. + */ + void inject(LoginActivity loginActivity); + +} +``` + +Create variables that needs to be injected by the `AppStorage_Memo` +```java +@InjectPreference +public AppStorage_Memo component; +@InjectPreference +public UserProfile_MemoEntity userProfile; +``` + +Inject `MainActivity` in the `AppStorage_Memo` +```java +AppStorage_Memo.getInstance().inject((MainActivity) this); +``` + +Access MemoEntity from Memo Component +```java +component.userProfile(); +``` + +Put value inside `userProfile` +```java +userProfile.putUsername(inputUsername); +``` + +Add change listener for login +```java +userProfile.addLoginListeners(new UserProfile_MemoEntity.LoginIOnChangedListener() +{ + @Override + public void onChanged(boolean login) + { + // do something + } +}); +``` + +Add observable for the username field +```java +component.userProfile().usernameObserver((LifecycleOwner) this, new Observer() +{ + @Override + public void onChanged(String username) + { + // do something here + } +}); +``` + Visit [MVN Repository](https://mvnrepository.com/artifact/com.zeoflow/memo) to find the latest version of the library.