Giter Site home page Giter Site logo

Comments (4)

shiweibsw avatar shiweibsw commented on August 17, 2024

List可以直接通过bundle传递,List 可以通过Parcelable

from ddcomponentforandroid.

leobert-lan avatar leobert-lan commented on August 17, 2024

DDComp这边代码很久没有维护过了,记忆中,在使用Autowired的时候,当时提供的功能并不是很多。
在JIMU那边最新的代码里,我也仅提供了这些支持:

// Primitive
        if (typeMirror.getKind().isPrimitive()) {
            return element.asType().getKind().ordinal();
        }

        switch (typeMirror.toString()) {
            case Constants.BYTE:
                return Type.BYTE.ordinal();
            case Constants.SHORT:
                return Type.SHORT.ordinal();
            case Constants.INTEGER:
                return Type.INT.ordinal();
            case Constants.LONG:
                return Type.LONG.ordinal();
            case Constants.FLOAT:
                return Type.FLOAT.ordinal();
            case Constants.DOUBEL:
                return Type.DOUBLE.ordinal();
            case Constants.BOOLEAN:
                return Type.BOOLEAN.ordinal();
            case Constants.STRING:
                return Type.STRING.ordinal();
            default:    // Other side, maybe the PARCELABLE or OBJECT.
                if (types.isSubtype(typeMirror, parcelableType)) {  // PARCELABLE
                    return Type.PARCELABLE.ordinal();
                }
//                else if (types.isSubtype(typeMirror, serializableType)) {
//                    return Type.SERIALIZABLE.ordinal(); 暂不支持需要做转型
//                }
                else {    // For others
                    return Type.OBJECT.ordinal();
                }

显然,这边只会走到OBJECT的处理逻辑中,也就是利用json工具做序列化/反序列化.即使用Bundle#putParcelableArrayList(String key, ArrayList<? extends Parcelable> value)的形式去传递,也无法用Autowired取出来并赋值。只能自己去Intent的Bundle中读取。或者用一个对象类去包裹一下这个List(注意需要去泛化)


PS:经过长时间的考虑,我越发觉得UI路由是个有点花里胡哨的功能。但是自动取值还是比较有意义的,在我另一个项目中,是尝试过对绝大多数Bundle中支持的数据做智能推断的。目前可以支持这么多(根据名字推测一下):
image
有空的话我会考虑下扩展自动取值注入的功能,代码应该会在JIMU仓库提交。

from ddcomponentforandroid.

xiaojinzi123 avatar xiaojinzi123 commented on August 17, 2024

// UI transfer with Bundle
private void goToShareActivityWithBundle() {
Author author = new Author();
author.setName("Margaret Mitchell");
author.setCounty("USA");
Bundle bundle = new Bundle();
bundle.putString("bookName", "Gone with the Wind");
bundle.putString("author", JsonService.Factory.getInstance().create().toJsonString(author));
UIRouter.getInstance().openUri(getActivity(), "DDComp://share/shareBook", bundle);
}

这是 Demo 中的数据传递,如果传递 List 数据,怎么传递?
@Autowired
List author;
接收数据时,这么写,编译报错:错误: 需要<标识符>

@OverRide
public void inject(Object target) {
jsonService = JsonService.Factory.getInstance().create();
SecondActivity substitute = (SecondActivity)target;
if (null != jsonService) {
substitute.children = jsonService.parseObject(substitute.getIntent().getStringExtra("children"), List.class);
} else {
Log.e("AutowiredProcessor", "You want automatic inject the field 'children' in class 'SecondActivity' , but JsonService not found in Router");
}
substitute.title = substitute.getIntent().getStringExtra("title");
}

这是编译生成的类,List.class 这个地方编译不通过,Cannot select from parameterized type

DDComponent 很久没维护了,其实问题还是挺多的,建议使用下面的方案,持续更新,框架贴近系统,不使用晦涩难懂的配置,并且功能强大
Component

from ddcomponentforandroid.

xiaojinzi123 avatar xiaojinzi123 commented on August 17, 2024

DDComp这边代码很久没有维护过了,记忆中,在使用Autowired的时候,当时提供的功能并不是很多。
在JIMU那边最新的代码里,我也仅提供了这些支持:

// Primitive
        if (typeMirror.getKind().isPrimitive()) {
            return element.asType().getKind().ordinal();
        }

        switch (typeMirror.toString()) {
            case Constants.BYTE:
                return Type.BYTE.ordinal();
            case Constants.SHORT:
                return Type.SHORT.ordinal();
            case Constants.INTEGER:
                return Type.INT.ordinal();
            case Constants.LONG:
                return Type.LONG.ordinal();
            case Constants.FLOAT:
                return Type.FLOAT.ordinal();
            case Constants.DOUBEL:
                return Type.DOUBLE.ordinal();
            case Constants.BOOLEAN:
                return Type.BOOLEAN.ordinal();
            case Constants.STRING:
                return Type.STRING.ordinal();
            default:    // Other side, maybe the PARCELABLE or OBJECT.
                if (types.isSubtype(typeMirror, parcelableType)) {  // PARCELABLE
                    return Type.PARCELABLE.ordinal();
                }
//                else if (types.isSubtype(typeMirror, serializableType)) {
//                    return Type.SERIALIZABLE.ordinal(); 暂不支持需要做转型
//                }
                else {    // For others
                    return Type.OBJECT.ordinal();
                }

显然,这边只会走到OBJECT的处理逻辑中,也就是利用json工具做序列化/反序列化.即使用Bundle#putParcelableArrayList(String key, ArrayList<? extends Parcelable> value)的形式去传递,也无法用Autowired取出来并赋值。只能自己去Intent的Bundle中读取。或者用一个对象类去包裹一下这个List(注意需要去泛化)

PS:经过长时间的考虑,我越发觉得UI路由是个有点花里胡哨的功能。但是自动取值还是比较有意义的,在我另一个项目中,是尝试过对绝大多数Bundle中支持的数据做智能推断的。目前可以支持这么多(根据名字推测一下):
image
有空的话我会考虑下扩展自动取值注入的功能,代码应该会在JIMU仓库提交。

使用这个吧,你不会失望的
Component

from ddcomponentforandroid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.