Giter Site home page Giter Site logo

skulib's Introduction

skuLib

quickly implement product SKU on Android.

快速实现商品规格选择。

实现类似淘宝规格选择的效果。

源码有较为详细的注释,更多信息请查看源码。

演示


###添加依赖

 // 你的项目中一定要使用recycleview
implementation 'com.android.support:recyclerview-v7:x.x.x'

// 加入本依赖库
// x.y.z 替换成具体的release版本号 如:0.0.7
implementation('com.github.Wongxd:skuLib:x.y.z') { 
	exclude group: 'com.android.support'
}

###使用方式

kotlin:

	 SpecSelectFragment.showDialog(this, null, defaultAttrList, spec)
                    .setShowGoodImgListener { iv, imgUrl ->
                        Log.e(TAG, "商品图片地址= $imgUrl    iv对象--$iv")
                        Glide.with(this).load(imgUrl).placeholder(R.drawable.ic_launcher).centerCrop().into(iv)

                    }
                    .setSubmitSpecCombListener { combBean, num, statusRestoreList ->
                        defaultAttrList = statusRestoreList
                        Log.e(TAG, " 描述---${combBean.desc}      数量---$num")
                        tv.text = " 描述---${combBean.desc}---数量---$num"
                    }

java:

	SpecSelectFragment.showDialog(this, "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1282625489,100434574&fm=27&gp=0.jpg", bean)
                    .setShowGoodImgListener(new ShowGoodImgListener() {
                        @Override
                        public void displayImg(ImageView iv, String imgUrl) {
                            Glide.with(AtyJavaActivity.this).load(imgUrl)
                                    .placeholder(R.drawable.ic_launcher).into(iv);
                        }
                    })
                    .setSubmitSpecCombListener(new SubmitSpecCombListener() {
                        @Override
                        public void onSubmit(SpecBean.CombsBean combBean, int num, List<ProductModel.AttributesEntity.AttributeMembersEntity> statusRestoreList) {
                            tv.setText("描述" + combBean.getDesc() + "----数量" + num);
                        }
                    });

参考1--Android DialogFragment实现底部弹出菜单效果

参考2-- 利用观察者模式(发布/订阅模式)制作一个“代替”广播的通知类

参考3--Sku算法--商城(品种,规格,参数等选择)

skulib's People

Contributors

wongxd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

skulib's Issues

选中状态恢复

你好,首先十分感谢你的分享,刚好最近也在开发sku商品选择功能,对此我这边还有一个需求,请问下一次打开弹框的时候如何恢复上一次选中的状态呢?

你好,关于SKU算法的一点建议

算法入口 skuCollection 不应该遍历initData的key去获取组合列表,遇到initData库存组合过多的情况,这种方法效率不是很理想。

建议:
skuCollection 新增参数String[][] lables 标签类目。如 : [["蓝色,“红色"],[“XL”,"L"],["优质","一般"]];

skuCollection(String[][] lables , Map<String, BaseSkuModel> initData ){ ...}

由lables 去建立一次组合数,获取所有的组合列表Map<String, BaseSkuModel> result。

`initData遍历key去设置result的库存以及价格信息,如此可以减少每次去获取组合列表的耗时。

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.