-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 支持 DataBinding 的 BaseActivity 现在独立为 BaseBindingActivity,避免使用非 DataBinding 的用户产生异常; - 废弃 BaseFrameworkSettings.useDataBinding,现在只需要继承对应的 Binding 基础件即可使用 DataBinding 模式;
- Loading branch information
Showing
4 changed files
with
57 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
baseframework/src/main/java/com/kongzue/baseframework/BaseBindingActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.kongzue.baseframework; | ||
|
||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
|
||
import androidx.viewbinding.ViewBinding; | ||
|
||
import com.kongzue.baseframework.util.JumpParameter; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
public abstract class BaseBindingActivity<VB extends ViewBinding> extends BaseActivity{ | ||
|
||
protected VB binding; | ||
|
||
@Override | ||
public void initViews() { | ||
|
||
} | ||
|
||
@Override | ||
public abstract void initDatas(JumpParameter parameter); | ||
|
||
@Override | ||
public abstract void setEvents(); | ||
|
||
@Override | ||
public View resetContentView() { | ||
return userDataBindingCreateLayout(); | ||
} | ||
|
||
private View userDataBindingCreateLayout() { | ||
String className = getClass().getSimpleName(); | ||
if (className.endsWith("Activity")) { | ||
className = className.substring(0, className.length() - 8); | ||
} | ||
String bindingClassName = getPackageName() + ".databinding.Activity" + className + "Binding"; | ||
|
||
try { | ||
// 通过反射实例化Binding对象 | ||
Class<?> bindingClass = Class.forName(bindingClassName); | ||
Method inflateMethod = bindingClass.getMethod("inflate", LayoutInflater.class); | ||
binding = (VB) inflateMethod.invoke(null, getLayoutInflater()); | ||
|
||
return binding.getRoot(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters