├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── io │ │ └── github │ │ └── wongxd │ │ └── demo │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── wongxd │ │ │ └── demo │ │ │ ├── AtyJavaActivity.java │ │ │ └── AtyMainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── aty_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── io │ └── github │ └── wongxd │ └── demo │ └── ExampleUnitTest.kt ├── art └── demo.gif ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── skulibray ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── io │ │ └── github │ │ └── wongxd │ │ └── skulibray │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── wongxd │ │ │ └── skulibray │ │ │ └── specSelect │ │ │ ├── SpecSelectFragment.java │ │ │ ├── bean │ │ │ └── SpecBean.java │ │ │ ├── custom │ │ │ ├── DensityUtil.java │ │ │ ├── SkuLooper.java │ │ │ ├── SpaceItemDecoration.java │ │ │ ├── SpecLayoutManager.java │ │ │ └── TU.java │ │ │ ├── listener │ │ │ ├── ShowGoodImgListener.java │ │ │ └── SubmitSpecCombListener.java │ │ │ ├── observer │ │ │ ├── EventObservable.java │ │ │ ├── IObservable.java │ │ │ ├── IObserver.java │ │ │ ├── ObserverEventCode.java │ │ │ └── ObserverHolder.java │ │ │ └── sku │ │ │ ├── ItemClickListener.java │ │ │ ├── ProductModel.java │ │ │ ├── SkuAdapter.java │ │ │ ├── UiData.java │ │ │ └── skuLib │ │ │ ├── Sku.java │ │ │ └── model │ │ │ └── BaseSkuModel.java │ └── res │ │ ├── anim │ │ ├── bottomview_anim_enter.xml │ │ └── bottomview_anim_exit.xml │ │ ├── drawable │ │ ├── add.png │ │ ├── check_un.png │ │ ├── checked_bg.xml │ │ ├── close.png │ │ ├── ic_launcher.png │ │ ├── normal_bg.xml │ │ ├── reduce.png │ │ └── unclickable_bg.xml │ │ ├── layout │ │ ├── bottom_sheet_group.xml │ │ ├── fgt_spec_select.xml │ │ └── sku_item_layout.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── io │ └── github │ └── wongxd │ └── skulibray │ └── ExampleUnitTest.java └── testJson.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 |
116 |
-------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 至东至西至清溪 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # skuLib 2 | 3 | quickly implement product SKU on Android. 4 | 5 | 快速实现商品规格选择。 6 | 7 | 实现类似淘宝规格选择的效果。 8 | 9 | 10 | 源码有较为详细的注释,更多信息请查看源码。 11 | 12 | 13 | ![演示](/art/demo.gif) 14 | 15 | *** 16 | 17 | ###添加依赖 18 | 19 | [![](https://jitpack.io/v/Wongxd/skuLib.svg)](https://jitpack.io/#Wongxd/skuLib) 20 | 21 | // 你的项目中一定要使用recycleview 22 | implementation 'com.android.support:recyclerview-v7:x.x.x' 23 | 24 | // 加入本依赖库 25 | // x.y.z 替换成具体的release版本号 如:0.0.7 26 | implementation('com.github.Wongxd:skuLib:x.y.z') { 27 | exclude group: 'com.android.support' 28 | } 29 | 30 | 31 | 32 | 33 | 34 | *** 35 | ###使用方式 36 | 37 | kotlin: 38 | 39 | SpecSelectFragment.showDialog(this, null, defaultAttrList, spec) 40 | .setShowGoodImgListener { iv, imgUrl -> 41 | Log.e(TAG, "商品图片地址= $imgUrl iv对象--$iv") 42 | Glide.with(this).load(imgUrl).placeholder(R.drawable.ic_launcher).centerCrop().into(iv) 43 | 44 | } 45 | .setSubmitSpecCombListener { combBean, num, statusRestoreList -> 46 | defaultAttrList = statusRestoreList 47 | Log.e(TAG, " 描述---${combBean.desc} 数量---$num") 48 | tv.text = " 描述---${combBean.desc}---数量---$num" 49 | } 50 | 51 | 52 | 53 | java: 54 | 55 | 56 | SpecSelectFragment.showDialog(this, "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1282625489,100434574&fm=27&gp=0.jpg", bean) 57 | .setShowGoodImgListener(new ShowGoodImgListener() { 58 | @Override 59 | public void displayImg(ImageView iv, String imgUrl) { 60 | Glide.with(AtyJavaActivity.this).load(imgUrl) 61 | .placeholder(R.drawable.ic_launcher).into(iv); 62 | } 63 | }) 64 | .setSubmitSpecCombListener(new SubmitSpecCombListener() { 65 | @Override 66 | public void onSubmit(SpecBean.CombsBean combBean, int num, List statusRestoreList) { 67 | tv.setText("描述" + combBean.getDesc() + "----数量" + num); 68 | } 69 | }); 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | [参考1--Android DialogFragment实现底部弹出菜单效果](http://blog.csdn.net/wbwjx/article/details/50507344) 92 | 93 | [参考2-- 利用观察者模式(发布/订阅模式)制作一个“代替”广播的通知类](http://blog.csdn.net/chengliang0315/article/details/53381539) 94 | 95 | [参考3--Sku算法--商城(品种,规格,参数等选择)](http://blog.csdn.net/u012589795/article/details/53304287) 96 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 26 9 | defaultConfig { 10 | applicationId "io.github.wongxd.demo" 11 | minSdkVersion 19 12 | targetSdkVersion 26 13 | versionCode 1 14 | versionName "1.0" 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(include: ['*.jar'], dir: 'libs') 27 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 28 | implementation 'com.android.support:appcompat-v7:26.1.0' 29 | testImplementation 'junit:junit:4.12' 30 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 31 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 32 | implementation project(':skulibray') 33 | implementation 'com.android.support:recyclerview-v7:26.1.0' 34 | // implementation('com.github.Wongxd:skuLib:v0.0.5') { 35 | // exclude group: 'com.android.support' 36 | // } 37 | // implementation 'com.github.Wongxd:skuLib:v0.0.7' 38 | implementation 'com.google.code.gson:gson:2.8.2' 39 | implementation 'com.github.bumptech.glide:glide:3.7.0' 40 | } 41 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/io/github/wongxd/demo/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.wongxd.demo 2 | 3 | import android.support.test.InstrumentationRegistry 4 | import android.support.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("io.github.wongxd.demo", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/wongxd/demo/AtyJavaActivity.java: -------------------------------------------------------------------------------- 1 | package io.github.wongxd.demo; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.widget.ImageView; 8 | import android.widget.TextView; 9 | 10 | import com.bumptech.glide.Glide; 11 | import com.google.gson.Gson; 12 | 13 | import java.util.List; 14 | 15 | import io.github.wongxd.skulibray.specSelect.SpecSelectFragment; 16 | import io.github.wongxd.skulibray.specSelect.bean.SpecBean; 17 | import io.github.wongxd.skulibray.specSelect.listener.ShowGoodImgListener; 18 | import io.github.wongxd.skulibray.specSelect.listener.SubmitSpecCombListener; 19 | import io.github.wongxd.skulibray.specSelect.sku.ProductModel; 20 | 21 | /** 22 | * Created by wongxd on 2018/2/8. 23 | */ 24 | 25 | public class AtyJavaActivity extends AppCompatActivity { 26 | 27 | 28 | private TextView tv; 29 | private ImageView ivMain; 30 | 31 | @Override 32 | protected void onCreate(@Nullable Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.aty_main); 35 | tv = findViewById(R.id.tv); 36 | ivMain = findViewById(R.id.iv_main); 37 | findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() { 38 | @Override 39 | public void onClick(View v) { 40 | doMainLogic(); 41 | } 42 | }); 43 | 44 | Glide.with(AtyJavaActivity.this) 45 | .load("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1282625489,100434574&fm=27&gp=0.jpg") 46 | .placeholder(R.drawable.ic_launcher) 47 | .into(ivMain); 48 | } 49 | 50 | public void doMainLogic() { 51 | SpecBean bean = new Gson().fromJson(json, SpecBean.class); 52 | 53 | 54 | SpecSelectFragment.showDialog(this, "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1282625489,100434574&fm=27&gp=0.jpg", null,bean,"该规格已无库存!") 55 | .setShowGoodImgListener(new ShowGoodImgListener() { 56 | @Override 57 | public void displayImg(ImageView iv, String imgUrl) { 58 | Glide.with(AtyJavaActivity.this).load(imgUrl) 59 | .placeholder(R.drawable.ic_launcher).into(iv); 60 | } 61 | }) 62 | .setSubmitSpecCombListener(new SubmitSpecCombListener() { 63 | @Override 64 | public void onSubmit(SpecBean.CombsBean combBean, int num, List statusRestoreList) { 65 | tv.setText("描述" + combBean.getDesc() + "----数量" + num); 66 | } 67 | }); 68 | } 69 | 70 | 71 | String json = "{\n" + 72 | " \"attrs\": [\n" + 73 | " {\n" + 74 | " \"key\": \"颜色\",\n" + 75 | " \"value\": [\n" + 76 | " {\n" + 77 | " \"id\": 3,\n" + 78 | " \"name\": \"红色\",\n" + 79 | " \"ownId\": 1\n" + 80 | " },\n" + 81 | " {\n" + 82 | " \"id\": 4,\n" + 83 | " \"name\": \"蓝色\",\n" + 84 | " \"ownId\": 1\n" + 85 | " }\n" + 86 | " ]\n" + 87 | " },\n" + 88 | " {\n" + 89 | " \"key\": \"重量\",\n" + 90 | " \"value\": [\n" + 91 | " {\n" + 92 | " \"id\": 5,\n" + 93 | " \"name\": \"10KG\",\n" + 94 | " \"ownId\": 2\n" + 95 | " },\n" + 96 | " {\n" + 97 | " \"id\": 6,\n" + 98 | " \"name\": \"20KG\",\n" + 99 | " \"ownId\": 2\n" + 100 | " },\n" + 101 | " {\n" + 102 | " \"id\": 7,\n" + 103 | " \"name\": \"30KG\",\n" + 104 | " \"ownId\": 2\n" + 105 | " }\n" + 106 | " ]\n" + 107 | " },\n" + 108 | " {\n" + 109 | " \"key\": \"产地\",\n" + 110 | " \"value\": [\n" + 111 | " {\n" + 112 | " \"id\": 24,\n" + 113 | " \"name\": \"江油\",\n" + 114 | " \"ownId\": 22\n" + 115 | " },\n" + 116 | " {\n" + 117 | " \"id\": 23,\n" + 118 | " \"name\": \"绵阳\",\n" + 119 | " \"ownId\": 22\n" + 120 | " },\n" + 121 | " {\n" + 122 | " \"id\": 31,\n" + 123 | " \"name\": \"四川绵阳市涪城区的撒啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊\",\n" + 124 | " \"ownId\": 22\n" + 125 | " }\n" + 126 | " ]\n" + 127 | " },\n" + 128 | " {\n" + 129 | " \"key\": \"尺寸\",\n" + 130 | " \"value\": [\n" + 131 | " {\n" + 132 | " \"id\": 20,\n" + 133 | " \"name\": \"30cm\",\n" + 134 | " \"ownId\": 14\n" + 135 | " },\n" + 136 | " {\n" + 137 | " \"id\": 19,\n" + 138 | " \"name\": \"20cm\",\n" + 139 | " \"ownId\": 14\n" + 140 | " },\n" + 141 | " {\n" + 142 | " \"id\": 18,\n" + 143 | " \"name\": \"10cm\",\n" + 144 | " \"ownId\": 14\n" + 145 | " }\n" + 146 | " ]\n" + 147 | " }\n" + 148 | " ],\n" + 149 | " \"combs\": [\n" + 150 | " {\n" + 151 | " \"comb\": \"4,6,23,20\",\n" + 152 | " \"desc\": \"蓝色-20KG-绵阳-30cm\",\n" + 153 | " \"id\": 10,\n" + 154 | " \"price\": 1.0,\n" + 155 | " \"productId\": 5,\n" + 156 | " \"stock\": 2,\n" + 157 | " \"specImg\":\"http://ww3.sinaimg.cn/mw600/0073ob6Pgy1fo91049t9mj30lc0w0dnh.jpg\"\n" + 158 | " },\n" + 159 | " {\n" + 160 | " \"comb\": \"4,5,23,19\",\n" + 161 | " \"desc\": \"蓝色-10KG-绵阳-20cm\",\n" + 162 | " \"id\": 8,\n" + 163 | " \"price\": 22.0,\n" + 164 | " \"productId\": 5,\n" + 165 | " \"stock\": 333,\n" + 166 | " \"specImg\":\"http://wx4.sinaimg.cn/mw600/0072bW0Xly1fo908gkyqjj30en0miabp.jpg\"\n" + 167 | " },\n" + 168 | " {\n" + 169 | " \"comb\": \"4,5,24,19\",\n" + 170 | " \"desc\": \"蓝色-10KG-江油-20cm\",\n" + 171 | " \"id\": 9,\n" + 172 | " \"price\": 1.0,\n" + 173 | " \"productId\": 5,\n" + 174 | " \"stock\": 2,\n" + 175 | " \"specImg\":\"http://wx1.sinaimg.cn/mw600/0072bW0Xly1fo8zz4znwyj30hq0qoabz.jpg\"\n" + 176 | " },\n" + 177 | " {\n" + 178 | " \"comb\": \"3,6,24,18\",\n" + 179 | " \"desc\": \"红色-20KG-江油-10\",\n" + 180 | " \"id\": 11,\n" + 181 | " \"price\": 1.0,\n" + 182 | " \"productId\": 5,\n" + 183 | " \"stock\": 2,\n" + 184 | " \"specImg\":\"http://wx2.sinaimg.cn/mw600/0072bW0Xly1fo8zf0pn15j30ia0tzdox.jpg\"\n" + 185 | " }\n" + 186 | " ]\n" + 187 | "}"; 188 | } 189 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/wongxd/demo/AtyMainActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.wongxd.demo 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import android.support.v7.app.AppCompatActivity 6 | import android.util.Log 7 | import android.view.View 8 | import com.bumptech.glide.Glide 9 | import com.google.gson.Gson 10 | import io.github.wongxd.skulibray.specSelect.SpecSelectFragment 11 | import io.github.wongxd.skulibray.specSelect.bean.SpecBean 12 | import io.github.wongxd.skulibray.specSelect.sku.ProductModel 13 | import kotlinx.android.synthetic.main.aty_main.* 14 | 15 | class AtyMainActivity : AppCompatActivity() { 16 | 17 | companion object { 18 | val TAG: String = AtyMainActivity::class.java.simpleName 19 | } 20 | 21 | override fun onCreate(savedInstanceState: Bundle?) { 22 | super.onCreate(savedInstanceState) 23 | setContentView(R.layout.aty_main) 24 | btn_java.visibility = View.VISIBLE 25 | btn_java.setOnClickListener { startActivity(Intent(this, AtyJavaActivity::class.java)) } 26 | 27 | btn.setOnClickListener { doLogic() } 28 | } 29 | 30 | private var defaultAttrList: List? = null 31 | 32 | private fun doLogic() { 33 | val goodImgUrl = "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1282625489,100434574&fm=27&gp=0.jpg" 34 | Glide.with(this).load(goodImgUrl).placeholder(R.drawable.ic_launcher).into(iv_main) 35 | 36 | SpecSelectFragment.showDialog(this, null, defaultAttrList, spec, "该规格已无库存!") 37 | .setShowGoodImgListener { iv, imgUrl -> 38 | Log.e(TAG, "商品图片地址= $imgUrl iv对象--$iv") 39 | Glide.with(this).load(imgUrl).placeholder(R.drawable.ic_launcher).centerCrop().into(iv) 40 | 41 | } 42 | .setSubmitSpecCombListener { combBean, num, statusRestoreList -> 43 | defaultAttrList = statusRestoreList 44 | Log.e(TAG, " 描述---${combBean.desc} 数量---$num") 45 | tv.text = " 描述---${combBean.desc}---数量---$num" 46 | } 47 | } 48 | 49 | val spec: SpecBean by lazy { Gson().fromJson(json, SpecBean::class.java) } 50 | 51 | val json = """ 52 | { 53 | "attrs": [ 54 | { 55 | "key": "颜色", 56 | "value": [ 57 | { 58 | "id": 3, 59 | "name": "红色", 60 | "ownId": 1 61 | }, 62 | { 63 | "id": 4, 64 | "name": "蓝色", 65 | "ownId": 1 66 | } 67 | ] 68 | }, 69 | { 70 | "key": "重量", 71 | "value": [ 72 | { 73 | "id": 5, 74 | "name": "10KG", 75 | "ownId": 2 76 | }, 77 | { 78 | "id": 6, 79 | "name": "20KG", 80 | "ownId": 2 81 | }, 82 | { 83 | "id": 7, 84 | "name": "30KG", 85 | "ownId": 2 86 | } 87 | ] 88 | }, 89 | { 90 | "key": "产地", 91 | "value": [ 92 | { 93 | "id": 24, 94 | "name": "江油", 95 | "ownId": 22 96 | }, 97 | { 98 | "id": 23, 99 | "name": "绵阳", 100 | "ownId": 22 101 | }, 102 | { 103 | "id": 31, 104 | "name": "四川绵阳市涪城区的撒啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊", 105 | "ownId": 22 106 | } 107 | ] 108 | }, 109 | { 110 | "key": "尺寸", 111 | "value": [ 112 | { 113 | "id": 20, 114 | "name": "30cm", 115 | "ownId": 14 116 | }, 117 | { 118 | "id": 19, 119 | "name": "20cm", 120 | "ownId": 14 121 | }, 122 | { 123 | "id": 18, 124 | "name": "10cm", 125 | "ownId": 14 126 | } 127 | ] 128 | } 129 | ], 130 | "combs": [ 131 | { 132 | "comb": "4,6,23,20", 133 | "desc": "蓝色-20KG-绵阳-30cm", 134 | "id": 10, 135 | "price": "1.0(可抵扣)", 136 | "productId": 5, 137 | "stock": 2, 138 | "specImg":"http://ww3.sinaimg.cn/mw600/0073ob6Pgy1fo91049t9mj30lc0w0dnh.jpg" 139 | }, 140 | { 141 | "comb": "4,5,23,19", 142 | "desc": "蓝色-10KG-绵阳-20cm", 143 | "id": 8, 144 | "price": "22.0(可抵扣)", 145 | "productId": 5, 146 | "stock": 333, 147 | "specImg":"http://wx4.sinaimg.cn/mw600/0072bW0Xly1fo908gkyqjj30en0miabp.jpg" 148 | }, 149 | { 150 | "comb": "4,5,24,19", 151 | "desc": "蓝色-10KG-江油-20cm", 152 | "id": 9, 153 | "price": "1.0(可抵扣)", 154 | "productId": 5, 155 | "stock": 2, 156 | "specImg":"http://wx1.sinaimg.cn/mw600/0072bW0Xly1fo8zz4znwyj30hq0qoabz.jpg" 157 | }, 158 | { 159 | "comb": "3,6,24,18", 160 | "desc": "红色-20KG-江油-10", 161 | "id": 11, 162 | "price": "1.0(可抵扣)", 163 | "productId": 5, 164 | "stock": 2, 165 | "specImg":"http://wx2.sinaimg.cn/mw600/0072bW0Xly1fo8zf0pn15j30ia0tzdox.jpg" 166 | } 167 | ] 168 | } 169 | """.trimIndent() 170 | } 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/aty_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 20 | 21 |