Skip to content

Commit 5c0616a

Browse files
authored
Fixes complications (#39)
* Fixes complications Fixes issue #38 and Regex removing symbols from the class names that may be required to identify the component. * Fixes build error * Fixes improper class name * Let's try again * Modify invalid component error
1 parent facb5df commit 5c0616a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/com/yusufcihan/DynamicComponents/DynamicComponents.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
helpUrl = "https://github.com/ysfchn/DynamicComponents-AI2/blob/main/README.md",
4747
iconName = "aiwebres/icon.png",
4848
nonVisible = true,
49-
version = 7,
50-
versionName = "2.2.0"
49+
version = 8,
50+
versionName = "2.2.1"
5151
)
5252
@SimpleObject(external = true)
5353
public class DynamicComponents extends AndroidNonvisibleComponent {
@@ -84,6 +84,21 @@ public boolean exists(Component component) {
8484
public boolean exists(String id) {
8585
return COMPONENTS.containsKey(id);
8686
}
87+
88+
public String getClassName(Object componentName) {
89+
String regex = "[^.$@a-zA-Z0-9]";
90+
String componentNameString = componentName.toString().replaceAll(regex, "");
91+
92+
if (componentName instanceof String && componentNameString.contains(".")) {
93+
return componentNameString;
94+
} else if (componentName instanceof String) {
95+
return BASE + componentNameString;
96+
} else if (componentName instanceof Component) {
97+
return componentName.getClass().getName().replaceAll(regex, "");
98+
} else {
99+
throw new YailRuntimeError("Component is invalid.", "DynamicComponents");
100+
}
101+
}
87102

88103
public Method getMethod(Method[] methods, String name, int parameterCount) {
89104
name = name.replaceAll("[^a-zA-Z0-9]", "");
@@ -188,11 +203,10 @@ public void ChangeId(String id, String newId) {
188203

189204
@SimpleFunction(description = "Creates a new dynamic component.")
190205
public void Create(final AndroidViewComponent in, Object componentName, final String id) throws Exception {
191-
componentName = componentName.toString().replaceAll("[^a-zA-Z0-9]", "");
192206
if (!COMPONENTS.containsKey(id)) {
193207
lastUsedId = id;
194208

195-
String mClassName = BASE + componentName;
209+
String mClassName = UTIL_INSTANCE.getClassName(componentName);
196210
Class<?> mClass = Class.forName(mClassName);
197211
final Constructor<?> mConstructor = mClass.getConstructor(ComponentContainer.class);
198212

0 commit comments

Comments
 (0)