Implementato dynamic load module per VGAlimenti.

Implementato framework per gestire le path.
This commit is contained in:
2019-02-08 19:10:32 +01:00
parent d46a92eecf
commit 996f5978e9
24 changed files with 286 additions and 13 deletions

View File

@@ -80,6 +80,10 @@ android {
lintOptions {
abortOnError false
}
dynamicFeatures = [":dynamic_vgalimenti"]
}
dependencies {
@@ -89,16 +93,16 @@ dependencies {
})
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.orhanobut:logger:2.2.0'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-crash:16.2.1'
implementation 'com.google.firebase:firebase-perf:16.2.3'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'com.google.android.material:material:1.1.0-alpha03'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha01'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha02'
implementation 'androidx.preference:preference:1.1.0-alpha02'
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
@@ -108,8 +112,8 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.lifecycle:lifecycle-common-java8:2.0.0'
kapt "androidx.lifecycle:lifecycle-compiler:2.0.0"
//implementation "com.emreeran.permissionlivedata:permissionlivedata:1.0.4"
//implementation 'com.karumi:dexter:5.0.0'
implementation 'com.danielpuiu:ghostfish:2.0.0'
annotationProcessor "com.danielpuiu:ghostfish-compiler:2.0.0"
//MVVM
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0"
@@ -122,7 +126,6 @@ dependencies {
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
implementation 'br.com.zbra:android-linq:1.1.0'
//FAB
//implementation 'com.getbase:floatingactionbutton:1.10.1'
implementation 'com.github.clans:fab:1.6.4'
//CUSTOM VIEWS
implementation 'com.github.NaimishTrivedi:FBToast:1.0'

View File

@@ -0,0 +1,78 @@
package it.integry.integrywmsnative.core.class_router;
import android.util.Pair;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import it.integry.integrywmsnative.core.class_router.exceptions.MethodParameterTypeNotMatchException;
import it.integry.integrywmsnative.core.class_router.exceptions.MethodParamsCountException;
import it.integry.integrywmsnative.core.class_router.exceptions.MethodPathAlreadyDeclaredException;
import it.integry.integrywmsnative.core.class_router.exceptions.MethodPathNotRegisteredException;
public class BaseRouter {
private static List<Pair<String, MethodDTO>> mRoutePaths = new ArrayList<>();
private static boolean checkIfMethodExists(String path) {
boolean methodAlreadyDeclared = false;
for(int i = 0; i < mRoutePaths.size() && !methodAlreadyDeclared; i++) {
if(mRoutePaths.get(i).first.equalsIgnoreCase(path)) methodAlreadyDeclared = true;
}
return methodAlreadyDeclared;
}
private static int getMethodIndex(String path) {
for(int i = 0; i < mRoutePaths.size(); i++) {
if(mRoutePaths.get(i).first.equalsIgnoreCase(path)) return i;
}
return -1;
}
public static void registerPath(String path, MethodDTO method) throws MethodPathAlreadyDeclaredException {
if(checkIfMethodExists(path)) {
throw new MethodPathAlreadyDeclaredException(path);
}
mRoutePaths.add(new Pair<>(path, method));
}
public static void deregisterPath(String path) {
if(checkIfMethodExists(path)) {
mRoutePaths.remove(getMethodIndex(path));
}
}
public static void invokePath(String path, Object... params) throws MethodPathNotRegisteredException, MethodParamsCountException, MethodParameterTypeNotMatchException, InvocationTargetException, IllegalAccessException {
if(!checkIfMethodExists(path)) {
throw new MethodPathNotRegisteredException(path);
}
MethodDTO methodDTO = mRoutePaths.get(getMethodIndex(path)).second;
Class[] methodParameters = methodDTO.getMethod().getParameterTypes();
if(methodParameters.length != params.length) {
throw new MethodParamsCountException(path);
}
for(int i = 0; i < params.length; i++) {
if(params[i].getClass() != methodParameters[i] && methodParameters[i].cast(params[i]) == null) {
throw new MethodParameterTypeNotMatchException(params[i].getClass().getCanonicalName(), path, methodParameters[i].getCanonicalName());
}
}
methodDTO.getMethod().invoke(null, params);
}
}

View File

@@ -0,0 +1,29 @@
package it.integry.integrywmsnative.core.class_router;
import java.lang.reflect.Method;
public class MethodDTO {
private Method method;
public Method getMethod() {
return method;
}
public MethodDTO setMethod(Method method) {
this.method = method;
return this;
}
public static MethodDTO fromName(Class clazz, String methodName) {
Method[] methods = clazz.getMethods();
for (Method m : methods) {
if (methodName.equals(m.getName())) {
return new MethodDTO().setMethod(m);
}
}
return null;
}
}

View File

@@ -0,0 +1,9 @@
package it.integry.integrywmsnative.core.class_router.exceptions;
public class MethodParameterTypeNotMatchException extends Exception{
public MethodParameterTypeNotMatchException(String path, String type1, String type2) {
super(String.format("The given parameter (%s) to %s don't match the required type %s", type1, path, type2));
}
}

View File

@@ -0,0 +1,9 @@
package it.integry.integrywmsnative.core.class_router.exceptions;
public class MethodParamsCountException extends Exception {
public MethodParamsCountException(String path) {
super(String.format("Given parameters to path %s do not match the real method declaration", path));
}
}

View File

@@ -0,0 +1,11 @@
package it.integry.integrywmsnative.core.class_router.exceptions;
public class MethodPathAlreadyDeclaredException extends Exception {
public MethodPathAlreadyDeclaredException(String path) {
super(String.format("Method %s is already declared in this scope", path));
}
}

View File

@@ -0,0 +1,9 @@
package it.integry.integrywmsnative.core.class_router.exceptions;
public class MethodPathNotRegisteredException extends Exception{
public MethodPathNotRegisteredException(String path){
super(String.format("Method path %s isn't registered at the moment. Please call BaseRouter.registerPath before call invoke.", path));
}
}

View File

@@ -3,21 +3,19 @@ package it.integry.integrywmsnative.core.context;
import android.content.Context;
import com.crashlytics.android.Crashlytics;
import com.danielpuiu.ghostfish.GhostFish;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.Logger;
import java.lang.reflect.Method;
import io.fabric.sdk.android.Fabric;
import it.integry.integrywmsnative.BuildConfig;
import it.integry.integrywmsnative.core.REST.consumers.ColliMagazzinoRESTConsumer;
import it.integry.integrywmsnative.core.REST.model.DistribuzioneColloDTO;
import it.integry.integrywmsnative.core.REST.watcher.ServerStatusChecker;
import it.integry.integrywmsnative.core.barcode_reader.BarcodeManager;
import it.integry.integrywmsnative.core.data_recover.ColliDataRecover;
import it.integry.integrywmsnative.core.model.MtbColt;
import it.integry.integrywmsnative.core.model.secondary.GestioneEnum;
import it.integry.integrywmsnative.core.settings.SettingsManager;
import it.integry.integrywmsnative.core.settings.Stash;
import it.integry.integrywmsnative.core.utility.UtilityExceptions;
import it.integry.integrywmsnative.core.utility.UtilityResources;
import it.integry.integrywmsnative.core.utility.UtilityString;
import it.integry.integrywmsnative.core.utility.UtilityToast;
@@ -47,6 +45,8 @@ public class AppContext {
this.initLogger();
this.initRecoverColli();
this.initReflections();
}
@@ -90,4 +90,27 @@ public class AppContext {
ColliDataRecover.init(mContext);
}
private void initReflections() {
GhostFish.create(mContext);
try {
String initMethod = "init";
Class dynamicContextClass = Class.forName("it.integry.wms.dynamic_customization.DynamicContext");
Method[] methods = dynamicContextClass.getMethods();
for (Method m : methods) {
if (initMethod.equals(m.getName())) {
// for static methods we can use null as instance of class
m.invoke(null);
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@@ -1,8 +1,11 @@
package it.integry.integrywmsnative.core.context;
import android.content.Context;
import android.text.SpannableString;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import it.integry.integrywmsnative.core.class_router.BaseRouter;
import it.integry.integrywmsnative.core.settings.SettingsManager;
import it.integry.integrywmsnative.view.dialogs.DialogSimpleMessageHelper;
@@ -19,6 +22,14 @@ public class MainContext {
this.initDBData(() -> {
onContextInitialized.run();
});
try {
BaseRouter.invokePath("testToast", mContext);
} catch (Exception ex) {
Log.e("PIF", ex.getMessage());
}
}

View File

@@ -182,5 +182,6 @@
<string name="recovering_data">Recovering data</string>
<string name="wait_a_moment">Wait a moment</string>
<string name="title_dynamic_vgalimenti">Personalizzazione VGAlimenti</string>
</resources>