詹子聪 пре 5 година
родитељ
комит
771a066b0f

+ 1 - 4
mvp/src/main/java/com/miekir/mvp/presenter/BasePresenter.java

@@ -36,10 +36,7 @@ public abstract class BasePresenter<V extends IView> extends ViewModel {
     private ViewHandler mViewHandler;
     public V getCallbackView() {
         mViewHandler.setView(getView());
-        return  (V) Proxy.newProxyInstance(
-                mViewHandler.getClazz().getClassLoader(),
-                mViewHandler.getClazz().getInterfaces(),
-                mViewHandler);
+        return (V) mViewHandler.getProxyObject();
     }
 
     private V getView() {

+ 13 - 6
mvp/src/main/java/com/miekir/mvp/view/ViewHandler.java

@@ -4,23 +4,30 @@ import com.miekir.common.utils.LogTool;
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 
+/**
+ * @author Miekir
+ */
 public class ViewHandler implements InvocationHandler {
     private Object mView;
-    private Class mClazz;
+    private Class<?> mClazz;
 
-    public ViewHandler(Class clazz) {
+    public ViewHandler(Class<?> clazz) {
         mClazz = clazz;
     }
 
-    public Class getClazz() {
-        return mClazz;
-    }
-
     public void setView(Object view) {
         mView = view;
     }
 
+    /**
+     * @return 获取代理对象
+     */
+    public Object getProxyObject() {
+        return Proxy.newProxyInstance(mClazz.getClassLoader(), mClazz.getInterfaces(), this);
+    }
+
     @Override
     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
         Object invoke = null;