Skip to content

Commit

Permalink
7.0.6
Browse files Browse the repository at this point in the history
- 新增 DataCarrier,解决 Java 无法返回多个数据的问题;
- 修正了一个错误,可能导致 BaseBindingFragment 无法正常初始化 ViewBinding;
  • Loading branch information
kongzue committed Dec 4, 2024
1 parent 2f24d8b commit 08b39a7
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
minSdkVersion 15
targetSdkVersion 30
versionCode 141
versionName "7.0.5"
versionName "7.0.6"
}
buildTypes {
release {
Expand Down
2 changes: 1 addition & 1 deletion baseframework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
minSdkVersion 15
targetSdkVersion 34
versionCode 141
versionName "7.0.5"
versionName "7.0.6"
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private View userDataBindingCreateLayout() {
Type superclass = getClass().getGenericSuperclass();
if (superclass instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) superclass;
Type type = parameterizedType.getActualTypeArguments()[0];
Type type = parameterizedType.getActualTypeArguments()[1];
try {
Class<VB> clazz = (Class<VB>) type;
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.kongzue.baseframework.util;

/**
* 解决 Java 无法返回多个数据的问题
* return 时可以使用 DataCarrier 来完成:return newCarrier("text", true, 3);
* 获取对应索引的值:result.value(0) 或 if (result.value(1)){ ... }
* 参与计算:result.intValue(2) + 5
*/
public class DataCarrier {
Object[] data;

public DataCarrier(Object... data) {
this.data = data;
}

public static DataCarrier newCarrier(Object... data) {
return new DataCarrier(data);
}

public <T> T value(int index) {
return (T) data[index];
}

public int intValue(int index) {
return (int) value(index);
}

public String stringValue(int index) {
return (String) value(index);
}

public boolean booleanValue(int index) {
return (boolean) value(index);
}

public double doubleValue(int index) {
return (double) value(index);
}

public short shortValue(int index) {
return (short) value(index);
}

public float floatValue(int index) {
return (float) value(index);
}

//eg.举例
// public DataCarrier cc() { //有一个方法 cc() 需要同时返回多个数据
// return newCarrier("text", true, 3); //使用 DataCarrier 承载多个数据
// }
//
// public void dd(){
// DataCarrier result = cc();
// String a = result.value(0); //获取第一个数据文本
// boolean a2 = result.value(1); //获取第二个布尔数据
// if (result.value(1)){ //直接参与判断
// //do something...
// }
// int d = result.intValue(2) + 5; //参与计算可以获取对应类型的值
// }
}

0 comments on commit 08b39a7

Please sign in to comment.