|
@@ -8,6 +8,8 @@ import android.view.View;
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
import androidx.viewbinding.ViewBinding;
|
|
|
|
|
|
+import com.kongzue.dialogx.R;
|
|
|
+
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
public abstract class OnBindingView<D, VB extends ViewBinding> extends OnBindView<D> {
|
|
@@ -16,26 +18,38 @@ public abstract class OnBindingView<D, VB extends ViewBinding> extends OnBindVie
|
|
|
|
|
|
public OnBindingView(VB binding) {
|
|
|
super(binding.getRoot());
|
|
|
+ this.binding = binding;
|
|
|
}
|
|
|
|
|
|
public OnBindingView(Class viewBindingClass) {
|
|
|
- super(getViewBindingRootView(viewBindingClass.getSimpleName()));
|
|
|
+ super(getBindingRootView(getViewBinding(viewBindingClass.getSimpleName())));
|
|
|
+ this.binding = (VB) getCustomView().getTag(R.id.dialogx_view_binding_tag_key);
|
|
|
}
|
|
|
|
|
|
public OnBindingView(String viewBindingClassName) {
|
|
|
- super(getViewBindingRootView(viewBindingClassName));
|
|
|
+ super(getBindingRootView(getViewBinding(viewBindingClassName)));
|
|
|
+ this.binding = (VB) getCustomView().getTag(R.id.dialogx_view_binding_tag_key);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static View getBindingRootView(ViewBinding viewBinding) {
|
|
|
+ if (viewBinding == null) {
|
|
|
+ return new View(BaseDialog.getContext());
|
|
|
+ }
|
|
|
+ View view = viewBinding.getRoot();
|
|
|
+ view.setTag(R.id.dialogx_view_binding_tag_key, viewBinding);
|
|
|
+ return view;
|
|
|
}
|
|
|
|
|
|
- private static View getViewBindingRootView(String bindingClassName) {
|
|
|
+ private static ViewBinding getViewBinding(String bindingClassName) {
|
|
|
try {
|
|
|
Class<?> bindingClass = Class.forName(bindingClassName);
|
|
|
Method inflateMethod = bindingClass.getMethod("inflate", LayoutInflater.class);
|
|
|
- return ((ViewBinding) inflateMethod.invoke((Object)null, LayoutInflater.from(BaseDialog.getContext()))).getRoot();
|
|
|
+ return (ViewBinding) inflateMethod.invoke((Object) null, LayoutInflater.from(BaseDialog.getContext()));
|
|
|
} catch (Exception var5) {
|
|
|
error("DialogX: OnBindingView初始化异常,未能根据bindingClassName找到对应的ViewBinding,请尝试指定ViewBinding实例");
|
|
|
var5.printStackTrace();
|
|
|
}
|
|
|
- return new View(BaseDialog.getContext());
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
public OnBindingView(int layoutResId) {
|