├── .gradle └── 2.14.1 │ ├── taskArtifacts │ ├── cache.properties │ ├── cache.properties.lock │ ├── fileHashes.bin │ ├── fileSnapshots.bin │ ├── fileSnapshotsToTreeSnapshotsIndex.bin │ └── taskArtifacts.bin │ └── tasks │ ├── _SkuLib_compileReleaseJavaWithJavac │ ├── localClassSetAnalysis │ │ ├── localClassSetAnalysis.bin │ │ └── localClassSetAnalysis.lock │ └── localJarClasspathSnapshot │ │ ├── localJarClasspathSnapshot.bin │ │ └── localJarClasspathSnapshot.lock │ └── _app_compileDebugJavaWithJavac │ ├── localClassSetAnalysis │ ├── localClassSetAnalysis.bin │ └── localClassSetAnalysis.lock │ └── localJarClasspathSnapshot │ ├── localJarClasspathSnapshot.bin │ └── localJarClasspathSnapshot.lock ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── libraries │ ├── animated_vector_drawable_24_2_1.xml │ ├── animated_vector_drawable_25_0_1.xml │ ├── appcompat_v7_24_2_1.xml │ ├── appcompat_v7_25_0_1.xml │ ├── design_25_0_1.xml │ ├── espresso_core_2_2_2.xml │ ├── espresso_idling_resource_2_2_2.xml │ ├── exposed_instrumentation_api_publish_0_5.xml │ ├── hamcrest_core_1_3.xml │ ├── hamcrest_integration_1_3.xml │ ├── hamcrest_library_1_3.xml │ ├── javawriter_2_1_1.xml │ ├── javax_annotation_api_1_2.xml │ ├── javax_inject_1.xml │ ├── jsr305_2_0_1.xml │ ├── junit_4_12.xml │ ├── recyclerview_v7_25_0_1.xml │ ├── rules_0_5.xml │ ├── runner_0_5.xml │ ├── support_annotations_24_2_1.xml │ ├── support_annotations_25_0_1.xml │ ├── support_compat_24_2_1.xml │ ├── support_compat_25_0_1.xml │ ├── support_core_ui_24_2_1.xml │ ├── support_core_ui_25_0_1.xml │ ├── support_core_utils_24_2_1.xml │ ├── support_core_utils_25_0_1.xml │ ├── support_fragment_24_2_1.xml │ ├── support_fragment_25_0_1.xml │ ├── support_media_compat_24_2_1.xml │ ├── support_media_compat_25_0_1.xml │ ├── support_v4_24_2_1.xml │ ├── support_v4_25_0_1.xml │ ├── support_vector_drawable_24_2_1.xml │ ├── support_vector_drawable_25_0_1.xml │ └── transition_25_0_1.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── Sku.iml ├── SkuLib ├── .gitignore ├── SkuLib.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── sennie │ │ └── skulib │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── sennie │ │ │ └── skulib │ │ │ ├── Sku.java │ │ │ └── model │ │ │ └── BaseSkuModel.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── sennie │ └── skulib │ └── ExampleUnitTest.java ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── sennie │ │ └── sku │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── sennie │ │ │ └── sku │ │ │ ├── ItemClickListener.java │ │ │ ├── MainActivity.java │ │ │ ├── ProductModel.java │ │ │ ├── UiData.java │ │ │ └── adapter │ │ │ └── SkuAdapter.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── bottom_sheet.xml │ │ ├── bottom_sheet_group.xml │ │ └── sku_item_layout.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── sennie │ └── sku │ └── ExampleUnitTest.java ├── build.gradle ├── build ├── generated │ └── mockable-android-24.jar ├── intermediates │ └── dex-cache │ │ └── cache.xml └── jrebel │ └── timings.json ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── local.properties └── settings.gradle /.gradle/2.14.1/taskArtifacts/cache.properties: -------------------------------------------------------------------------------- 1 | #Thu Nov 24 14:34:30 CST 2016 2 | -------------------------------------------------------------------------------- /.gradle/2.14.1/taskArtifacts/cache.properties.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesignPCode/Sku/e128a99c4cb4131babe5dd9c8cc150fa2cfccd5f/.gradle/2.14.1/taskArtifacts/cache.properties.lock -------------------------------------------------------------------------------- /.gradle/2.14.1/taskArtifacts/fileHashes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesignPCode/Sku/e128a99c4cb4131babe5dd9c8cc150fa2cfccd5f/.gradle/2.14.1/taskArtifacts/fileHashes.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/taskArtifacts/fileSnapshots.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesignPCode/Sku/e128a99c4cb4131babe5dd9c8cc150fa2cfccd5f/.gradle/2.14.1/taskArtifacts/fileSnapshots.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/taskArtifacts/fileSnapshotsToTreeSnapshotsIndex.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesignPCode/Sku/e128a99c4cb4131babe5dd9c8cc150fa2cfccd5f/.gradle/2.14.1/taskArtifacts/fileSnapshotsToTreeSnapshotsIndex.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/taskArtifacts/taskArtifacts.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesignPCode/Sku/e128a99c4cb4131babe5dd9c8cc150fa2cfccd5f/.gradle/2.14.1/taskArtifacts/taskArtifacts.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/tasks/_SkuLib_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesignPCode/Sku/e128a99c4cb4131babe5dd9c8cc150fa2cfccd5f/.gradle/2.14.1/tasks/_SkuLib_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/tasks/_SkuLib_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesignPCode/Sku/e128a99c4cb4131babe5dd9c8cc150fa2cfccd5f/.gradle/2.14.1/tasks/_SkuLib_compileReleaseJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock -------------------------------------------------------------------------------- /.gradle/2.14.1/tasks/_SkuLib_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesignPCode/Sku/e128a99c4cb4131babe5dd9c8cc150fa2cfccd5f/.gradle/2.14.1/tasks/_SkuLib_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/tasks/_SkuLib_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesignPCode/Sku/e128a99c4cb4131babe5dd9c8cc150fa2cfccd5f/.gradle/2.14.1/tasks/_SkuLib_compileReleaseJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock -------------------------------------------------------------------------------- /.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesignPCode/Sku/e128a99c4cb4131babe5dd9c8cc150fa2cfccd5f/.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesignPCode/Sku/e128a99c4cb4131babe5dd9c8cc150fa2cfccd5f/.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock -------------------------------------------------------------------------------- /.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesignPCode/Sku/e128a99c4cb4131babe5dd9c8cc150fa2cfccd5f/.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin -------------------------------------------------------------------------------- /.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DesignPCode/Sku/e128a99c4cb4131babe5dd9c8cc150fa2cfccd5f/.gradle/2.14.1/tasks/_app_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/libraries/animated_vector_drawable_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/animated_vector_drawable_25_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/appcompat_v7_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/libraries/appcompat_v7_25_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/libraries/design_25_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/libraries/espresso_core_2_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/espresso_idling_resource_2_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/exposed_instrumentation_api_publish_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/hamcrest_integration_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/hamcrest_library_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/javawriter_2_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/javax_annotation_api_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/javax_inject_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/jsr305_2_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/recyclerview_v7_25_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/libraries/rules_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/libraries/runner_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/libraries/support_annotations_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/support_annotations_25_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/support_compat_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_compat_25_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_core_ui_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_core_ui_25_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_core_utils_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/support_core_utils_25_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_fragment_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_fragment_25_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_media_compat_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_media_compat_25_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_v4_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/support_v4_25_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/libraries/support_vector_drawable_24_2_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/support_vector_drawable_25_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/transition_25_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sku 2 | Sku算法,Android实现,淘宝Sku实现 3 | -------------------------------------------------------------------------------- /Sku.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /SkuLib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /SkuLib/SkuLib.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /SkuLib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar']) 26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 27 | exclude group: 'com.android.support', module: 'support-annotations' 28 | }) 29 | compile 'com.android.support:appcompat-v7:24.2.1' 30 | testCompile 'junit:junit:4.12' 31 | } 32 | -------------------------------------------------------------------------------- /SkuLib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/niesen918/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /SkuLib/src/androidTest/java/com/sennie/skulib/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.sennie.skulib; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.sennie.skulib.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SkuLib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /SkuLib/src/main/java/com/sennie/skulib/Sku.java: -------------------------------------------------------------------------------- 1 | package com.sennie.skulib; 2 | 3 | import android.text.TextUtils; 4 | 5 | import com.sennie.skulib.model.BaseSkuModel; 6 | 7 | import java.util.ArrayList; 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | /** 12 | * 项目名称:Sku算法 13 | * 类描述: 14 | * 创建人:N.Sun 15 | * 创建时间:2016/11/3 下午2:32 16 | * 修改人:N.Sun 17 | * 修改时间:2016/11/3 下午2:32 18 | * 修改备注: 19 | */ 20 | 21 | public class Sku { 22 | 23 | /** 24 | * 算法入口 25 | * 26 | * @param initData 所有库存的hashMap组合 27 | * @return 拆分所有组合产生的所有情况(生成客户端自己的字典) 28 | */ 29 | public static Map skuCollection(Map initData) { 30 | //用户返回数据 31 | HashMap result = new HashMap<>(); 32 | // 遍历所有库存 33 | for (String subKey : initData.keySet()) { 34 | BaseSkuModel skuModel = initData.get(subKey); 35 | //根据;拆分key的组合 36 | String[] skuKeyAttrs = subKey.split(";"); 37 | 38 | //获取所有的组合 39 | ArrayList> combArr = combInArray(skuKeyAttrs); 40 | 41 | // 对应所有组合添加到结果集里面 42 | for (int i = 0; i < combArr.size(); i++) { 43 | add2SKUResult(result, combArr.get(i), skuModel); 44 | } 45 | 46 | // 将原始的库存组合也添加进入结果集里面 47 | String key = TextUtils.join(";", skuKeyAttrs); 48 | result.put(key, skuModel); 49 | } 50 | return result; 51 | } 52 | 53 | /** 54 | * 获取所有的组合放到ArrayList里面 55 | * 56 | * @param skuKeyAttrs 单个key被; 拆分的数组 57 | * @return ArrayList 58 | */ 59 | private static ArrayList> combInArray(String[] skuKeyAttrs) { 60 | if (skuKeyAttrs == null || skuKeyAttrs.length <= 0) 61 | return null; 62 | int len = skuKeyAttrs.length; 63 | ArrayList> aResult = new ArrayList<>(); 64 | for (int n = 1; n < len; n++) { 65 | ArrayList aaFlags = getCombFlags(len, n); 66 | for (int i = 0; i < aaFlags.size(); i++) { 67 | Integer[] aFlag = aaFlags.get(i); 68 | ArrayList aComb = new ArrayList<>(); 69 | for (int j = 0; j < aFlag.length; j++) { 70 | if (aFlag[j] == 1) { 71 | aComb.add(skuKeyAttrs[j]); 72 | } 73 | } 74 | aResult.add(aComb); 75 | } 76 | } 77 | return aResult; 78 | } 79 | 80 | /** 81 | * 算法拆分组合 用1和0 的移位去做控制 82 | * (这块需要你打印才能看的出来) 83 | * 84 | * @param len 85 | * @param n 86 | * @return 87 | */ 88 | private static ArrayList getCombFlags(int len, int n) { 89 | if (n <= 0) { 90 | return new ArrayList<>(); 91 | } 92 | ArrayList aResult = new ArrayList<>(); 93 | Integer[] aFlag = new Integer[len]; 94 | boolean bNext = true; 95 | int iCnt1 = 0; 96 | //初始化 97 | for (int i = 0; i < len; i++) { 98 | aFlag[i] = i < n ? 1 : 0; 99 | } 100 | aResult.add(aFlag.clone()); 101 | while (bNext) { 102 | iCnt1 = 0; 103 | for (int i = 0; i < len - 1; i++) { 104 | if (aFlag[i] == 1 && aFlag[i + 1] == 0) { 105 | for (int j = 0; j < i; j++) { 106 | aFlag[j] = j < iCnt1 ? 1 : 0; 107 | } 108 | aFlag[i] = 0; 109 | aFlag[i + 1] = 1; 110 | Integer[] aTmp = aFlag.clone(); 111 | aResult.add(aTmp); 112 | if (!TextUtils.join("", aTmp).substring(len - n).contains("0")) { 113 | bNext = false; 114 | } 115 | break; 116 | } 117 | if (aFlag[i] == 1) { 118 | iCnt1++; 119 | } 120 | } 121 | } 122 | return aResult; 123 | } 124 | 125 | /** 126 | * 添加到数据集合 127 | * 128 | * @param result 129 | * @param newKeyList 130 | * @param skuModel 131 | */ 132 | private static void add2SKUResult(HashMap result, ArrayList newKeyList, BaseSkuModel skuModel) { 133 | String key = TextUtils.join(";", newKeyList); 134 | if (result.keySet().contains(key)) { 135 | result.get(key).setStock(result.get(key).getStock() + skuModel.getStock()); 136 | result.get(key).setPrice(skuModel.getPrice()); 137 | } else { 138 | result.put(key, new BaseSkuModel(skuModel.getPrice(), skuModel.getStock())); 139 | } 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /SkuLib/src/main/java/com/sennie/skulib/model/BaseSkuModel.java: -------------------------------------------------------------------------------- 1 | package com.sennie.skulib.model; 2 | 3 | /** 4 | * 项目名称:Sku 5 | * 类描述:Sku基本模型数据 6 | * 创建人:N.Sun 7 | * 创建时间:2016/11/24 下午3:27 8 | * 修改人:N.Sun 9 | * 修改时间:2016/11/24 下午3:27 10 | * 修改备注: 11 | */ 12 | public class BaseSkuModel { 13 | 14 | //base 属性 15 | private double price;//价格 16 | private long stock;//库存 17 | 18 | public BaseSkuModel(double price, long stock) { 19 | this.price = price; 20 | this.stock = stock; 21 | } 22 | 23 | public double getPrice() { 24 | return price; 25 | } 26 | 27 | public void setPrice(double price) { 28 | this.price = price; 29 | } 30 | 31 | public long getStock() { 32 | return stock; 33 | } 34 | 35 | public void setStock(long stock) { 36 | this.stock = stock; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /SkuLib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SkuLib 3 | 4 | -------------------------------------------------------------------------------- /SkuLib/src/test/java/com/sennie/skulib/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.sennie.skulib; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.2" 6 | defaultConfig { 7 | applicationId "com.sennie.sku" 8 | minSdkVersion 14 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:24.2.1' 28 | testCompile 'junit:junit:4.12' 29 | compile 'com.android.support:recyclerview-v7:25.0.1' 30 | compile project(':SkuLib') 31 | compile 'com.android.support:design:25.0.1' 32 | } 33 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/niesen918/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/sennie/sku/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.sennie.sku; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.sennie.sku", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/sennie/sku/ItemClickListener.java: -------------------------------------------------------------------------------- 1 | package com.sennie.sku; 2 | 3 | import android.util.Log; 4 | 5 | import com.sennie.sku.adapter.SkuAdapter; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | import static android.content.ContentValues.TAG; 11 | 12 | /** 13 | * 项目名称:Sku 14 | * 类描述: 15 | * 创建人:N.Sun 16 | * 创建时间:2016/11/24 下午5:22 17 | * 修改人:N.Sun 18 | * 修改时间:2016/11/24 下午5:22 19 | * 修改备注: 20 | */ 21 | public class ItemClickListener implements SkuAdapter.OnClickListener { 22 | 23 | UiData mUiData; 24 | SkuAdapter currentAdapter; 25 | 26 | public ItemClickListener(UiData uiData, SkuAdapter currentAdapter) { 27 | mUiData = uiData; 28 | this.currentAdapter = currentAdapter; 29 | } 30 | 31 | @Override 32 | public void onItemClickListener(int position) { 33 | //屏蔽不可点击 34 | if (currentAdapter.getAttributeMembersEntities().get(position).getStatus() == 2) { 35 | return; 36 | } 37 | // 设置当前单选点击 38 | for (ProductModel.AttributesEntity.AttributeMembersEntity entity : currentAdapter.getAttributeMembersEntities()) { 39 | if (entity.equals(currentAdapter.getAttributeMembersEntities().get(position))) { 40 | entity.setStatus(1); 41 | //添加已经选择的对象 42 | currentAdapter.setCurrentSelectedItem(entity); 43 | } else { 44 | entity.setStatus(entity.getStatus() == 2 ? 2 : 0); 45 | } 46 | } 47 | //存放当前被点击的按钮 48 | mUiData.getSelectedEntities().clear(); 49 | for (int i = 0; i < mUiData.getAdapters().size(); i++) { 50 | if (mUiData.getAdapters().get(i).getCurrentSelectedItem() != null) { 51 | mUiData.getSelectedEntities().add(mUiData.getAdapters().get(i).getCurrentSelectedItem()); 52 | } 53 | } 54 | //处理未选中的按钮 55 | for (int i = 0; i < mUiData.getAdapters().size(); i++) { 56 | for (ProductModel.AttributesEntity.AttributeMembersEntity entity : mUiData.getAdapters().get(i).getAttributeMembersEntities()) { 57 | // 处理没有数据和没有库存(检测单个) 58 | if (mUiData.getResult().get(entity.getAttributeMemberId() + "") == null || mUiData.getResult().get(entity.getAttributeMemberId() + "").getStock() <= 0) { 59 | entity.setStatus(2); 60 | } else if (entity.equals(mUiData.getAdapters().get(i).getCurrentSelectedItem())) { 61 | entity.setStatus(1); 62 | } else { 63 | entity.setStatus(0); 64 | } 65 | // 冒泡排序 66 | List cacheSelected = new ArrayList<>(); 67 | cacheSelected.add(entity); 68 | cacheSelected.addAll(mUiData.getSelectedEntities()); 69 | for (int j = 0; j < cacheSelected.size() - 1; j++) { 70 | for (int k = 0; k < cacheSelected.size() - 1 - j; k++) { 71 | ProductModel.AttributesEntity.AttributeMembersEntity cacheEntity; 72 | if (cacheSelected.get(k).getAttributeGroupId() > cacheSelected.get(k + 1).getAttributeGroupId()) { 73 | //交换数据 74 | cacheEntity = cacheSelected.get(k); 75 | cacheSelected.set(k, cacheSelected.get(k + 1)); 76 | cacheSelected.set(k + 1, cacheEntity); 77 | } 78 | } 79 | } 80 | for (int j = 0; j < cacheSelected.size() - 1; j++) { 81 | for (int k = 0; k < cacheSelected.size() - 1 - j; k++) { 82 | if (cacheSelected.get(k).getAttributeGroupId() == cacheSelected.get(k + 1).getAttributeGroupId()) { 83 | cacheSelected.remove(k + 1); 84 | } 85 | } 86 | } 87 | StringBuffer buffer = new StringBuffer(); 88 | for (ProductModel.AttributesEntity.AttributeMembersEntity selectedEntity : cacheSelected) { 89 | buffer.append(selectedEntity.getAttributeMemberId() + ";"); 90 | } 91 | Log.e(TAG, "key = " + buffer.substring(0, buffer.length() - 1)); 92 | //TODO 检查数据 93 | if (mUiData.getResult().get(buffer.substring(0, buffer.length() - 1)) != null && mUiData.getResult().get(buffer.substring(0, buffer.length() - 1)).getStock() > 0) { 94 | entity.setStatus(entity.getStatus() == 1 ? 1 : 0); 95 | } else { 96 | entity.setStatus(2); 97 | } 98 | } 99 | mUiData.getAdapters().get(i).notifyDataSetChanged(); 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /app/src/main/java/com/sennie/sku/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.sennie.sku; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.BottomSheetBehavior; 5 | import android.support.design.widget.BottomSheetDialog; 6 | import android.support.design.widget.CoordinatorLayout; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.GridLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.util.Log; 11 | import android.view.Gravity; 12 | import android.view.View; 13 | import android.widget.Button; 14 | import android.widget.LinearLayout; 15 | import android.widget.TextView; 16 | 17 | import com.sennie.sku.adapter.SkuAdapter; 18 | import com.sennie.skulib.Sku; 19 | import com.sennie.skulib.model.BaseSkuModel; 20 | 21 | public class MainActivity extends AppCompatActivity { 22 | 23 | private Button btnBottom; 24 | 25 | private ProductModel testData; 26 | 27 | UiData mUiData; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_main); 33 | btnBottom = (Button) findViewById(R.id.btn_bottom); 34 | mUiData = new UiData(); 35 | // 设置模拟数据 36 | testData = new ProductModel(); 37 | testData.getProductStocks().put("1;4", new BaseSkuModel(13, 20)); 38 | testData.getProductStocks().put("1;5", new BaseSkuModel(14, 10)); 39 | testData.getProductStocks().put("1;7", new BaseSkuModel(13, 40)); 40 | testData.getProductStocks().put("2;4", new BaseSkuModel(16, 70)); 41 | testData.getProductStocks().put("2;6", new BaseSkuModel(17, 30)); 42 | testData.getProductStocks().put("2;7", new BaseSkuModel(12, 22)); 43 | testData.getProductStocks().put("3;5", new BaseSkuModel(11, 25)); 44 | testData.getProductStocks().put("3;6", new BaseSkuModel(19, 21)); 45 | testData.getProductStocks().put("3;7", new BaseSkuModel(10, 29)); 46 | // 设置对应的品种和规格 47 | ProductModel.AttributesEntity group01 = new ProductModel.AttributesEntity(); 48 | group01.setName("颜色"); 49 | group01.getAttributeMembers().add(0, new ProductModel.AttributesEntity.AttributeMembersEntity(1, 1, "红色")); 50 | group01.getAttributeMembers().add(1, new ProductModel.AttributesEntity.AttributeMembersEntity(1, 2, "白色")); 51 | group01.getAttributeMembers().add(2, new ProductModel.AttributesEntity.AttributeMembersEntity(1, 3, "绿色")); 52 | testData.getAttributes().add(0, group01);//第一组 53 | 54 | ProductModel.AttributesEntity group02 = new ProductModel.AttributesEntity(); 55 | group02.setName("尺寸"); 56 | group02.getAttributeMembers().add(0, new ProductModel.AttributesEntity.AttributeMembersEntity(2, 4, "80cm")); 57 | group02.getAttributeMembers().add(1, new ProductModel.AttributesEntity.AttributeMembersEntity(2, 5, "90cm")); 58 | group02.getAttributeMembers().add(2, new ProductModel.AttributesEntity.AttributeMembersEntity(2, 6, "100cm")); 59 | group02.getAttributeMembers().add(3, new ProductModel.AttributesEntity.AttributeMembersEntity(2, 7, "110cm")); 60 | testData.getAttributes().add(1, group02);//第二组 61 | 62 | } 63 | 64 | protected void bottomClick(View view) { 65 | //显示Sku 66 | showBottomSheetDialog(testData); 67 | } 68 | 69 | private void showBottomSheetDialog(ProductModel productModel) { 70 | if (mUiData.getBottomSheetDialog() == null) { 71 | mUiData.getSelectedEntities().clear(); 72 | mUiData.getAdapters().clear(); 73 | View view = getLayoutInflater().inflate(R.layout.bottom_sheet, null); 74 | LinearLayout llList = (LinearLayout) view.findViewById(R.id.ll_list);//列表 75 | //添加list组 76 | for (int i = 0; i < testData.getAttributes().size(); i++) { 77 | View viewList = getLayoutInflater().inflate(R.layout.bottom_sheet_group, null); 78 | TextView tvTitle = (TextView) viewList.findViewById(R.id.tv_title); 79 | RecyclerView recyclerViewBottom = (RecyclerView) viewList.findViewById(R.id.recycler_bottom); 80 | SkuAdapter skuAdapter = new SkuAdapter(testData.getAttributes().get(i).getAttributeMembers()); 81 | mUiData.getAdapters().add(skuAdapter); 82 | int item = 4;//设置列数 83 | GridLayoutManager gridLayoutManager = new GridLayoutManager(this, item); 84 | recyclerViewBottom.setLayoutManager(gridLayoutManager); 85 | recyclerViewBottom.setAdapter(skuAdapter); 86 | llList.addView(viewList); 87 | } 88 | // SKU 计算 89 | mUiData.setResult(Sku.skuCollection(testData.getProductStocks())); 90 | for (String key : mUiData.getResult().keySet()) { 91 | Log.d("SKU Result", "key = " + key + " value = " + mUiData.getResult().get(key)); 92 | } 93 | //设置点击监听器 94 | for (SkuAdapter adapter : mUiData.getAdapters()) { 95 | ItemClickListener listener = new ItemClickListener(mUiData, adapter); 96 | adapter.setOnClickListener(listener); 97 | } 98 | // 初始化按钮 99 | for (int i = 0; i < mUiData.getAdapters().size(); i++) { 100 | for (ProductModel.AttributesEntity.AttributeMembersEntity entity : mUiData.getAdapters().get(i).getAttributeMembersEntities()) { 101 | if (mUiData.getResult().get(entity.getAttributeMemberId() + "") == null || mUiData.getResult().get(entity.getAttributeMemberId() + "").getStock() <= 0) { 102 | entity.setStatus(2); 103 | } 104 | } 105 | } 106 | //设置价格 107 | mUiData.setBottomSheetDialog(new BottomSheetDialog(this)); 108 | mUiData.getBottomSheetDialog().setContentView(view); 109 | View parent = (View) view.getParent();//获取ParentView 110 | BottomSheetBehavior behavior = BottomSheetBehavior.from(parent); 111 | view.measure(0, 0); 112 | behavior.setPeekHeight(view.getMeasuredHeight()); 113 | CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) parent.getLayoutParams(); 114 | params.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; 115 | parent.setLayoutParams(params); 116 | mUiData.getBottomSheetDialog().show(); 117 | } else { 118 | mUiData.getBottomSheetDialog().show(); 119 | } 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /app/src/main/java/com/sennie/sku/ProductModel.java: -------------------------------------------------------------------------------- 1 | package com.sennie.sku; 2 | 3 | import com.sennie.skulib.model.BaseSkuModel; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | /** 11 | * 项目名称:Sku 12 | * 类描述: 13 | * 创建人:N.Sun 14 | * 创建时间:2016/11/24 下午4:17 15 | * 修改人:N.Sun 16 | * 修改时间:2016/11/24 下午4:17 17 | * 修改备注: 18 | */ 19 | public class ProductModel { 20 | 21 | //存储所有录入的库存情况 22 | private Map productStocks = new HashMap<>(); 23 | 24 | //记录规格的种类 25 | private List attributes = new ArrayList<>(); 26 | 27 | public Map getProductStocks() { 28 | return productStocks; 29 | } 30 | 31 | public void setProductStocks(Map productStocks) { 32 | this.productStocks = productStocks; 33 | } 34 | 35 | public List getAttributes() { 36 | return attributes; 37 | } 38 | 39 | public void setAttributes(List attributes) { 40 | this.attributes = attributes; 41 | } 42 | 43 | public static class AttributesEntity { 44 | 45 | private int id; 46 | private String name; 47 | private List attributeMembers = new ArrayList<>(); 48 | 49 | public int getId() { 50 | return id; 51 | } 52 | 53 | public void setId(int id) { 54 | this.id = id; 55 | } 56 | 57 | public String getName() { 58 | return name; 59 | } 60 | 61 | public void setName(String name) { 62 | this.name = name; 63 | } 64 | 65 | public List getAttributeMembers() { 66 | return attributeMembers; 67 | } 68 | 69 | public void setAttributeMembers(List attributeMembers) { 70 | this.attributeMembers = attributeMembers; 71 | } 72 | 73 | public static class AttributeMembersEntity { 74 | 75 | private int attributeGroupId; 76 | private int attributeMemberId; 77 | private String name; 78 | private int status; 79 | 80 | public AttributeMembersEntity(int attributeGroupId, int attributeMemberId, String name) { 81 | this.attributeGroupId = attributeGroupId; 82 | this.attributeMemberId = attributeMemberId; 83 | this.name = name; 84 | } 85 | 86 | @Override 87 | public boolean equals(Object obj) { 88 | if (!(obj instanceof AttributeMembersEntity)) 89 | return false; 90 | AttributeMembersEntity entity = (AttributeMembersEntity) obj; 91 | return entity.getName().equals(name) && entity.getAttributeGroupId() == attributeGroupId && entity.getAttributeMemberId() == attributeMemberId; 92 | } 93 | 94 | public int getStatus() { 95 | return status; 96 | } 97 | 98 | public void setStatus(int status) { 99 | this.status = status; 100 | } 101 | 102 | public int getAttributeGroupId() { 103 | return attributeGroupId; 104 | } 105 | 106 | public void setAttributeGroupId(int attributeGroupId) { 107 | this.attributeGroupId = attributeGroupId; 108 | } 109 | 110 | public int getAttributeMemberId() { 111 | return attributeMemberId; 112 | } 113 | 114 | public void setAttributeMemberId(int attributeMemberId) { 115 | this.attributeMemberId = attributeMemberId; 116 | } 117 | 118 | public String getName() { 119 | return name; 120 | } 121 | 122 | public void setName(String name) { 123 | this.name = name; 124 | } 125 | 126 | } 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /app/src/main/java/com/sennie/sku/UiData.java: -------------------------------------------------------------------------------- 1 | package com.sennie.sku; 2 | 3 | import android.support.design.widget.BottomSheetDialog; 4 | 5 | import com.sennie.sku.adapter.SkuAdapter; 6 | import com.sennie.skulib.model.BaseSkuModel; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | /** 13 | * 项目名称:ZHIZHEN 14 | * 类描述: 15 | * 创建人:N.Sun 16 | * 创建时间:2016/11/21 下午5:06 17 | * 修改人:N.Sun 18 | * 修改时间:2016/11/21 下午5:06 19 | * 修改备注: 20 | */ 21 | public class UiData { 22 | 23 | BottomSheetDialog mBottomSheetDialog; 24 | 25 | // 保存多组adapter 26 | List adapters = new ArrayList<>(); 27 | 28 | //存放被选中的按钮对应的数据 29 | List selectedEntities = new ArrayList<>(); 30 | 31 | //存放计算结果 32 | Map result; 33 | 34 | public List getAdapters() { 35 | return adapters; 36 | } 37 | 38 | public void setAdapters(List adapters) { 39 | this.adapters = adapters; 40 | } 41 | 42 | public Map getResult() { 43 | return result; 44 | } 45 | 46 | public void setResult(Map result) { 47 | this.result = result; 48 | } 49 | 50 | public BottomSheetDialog getBottomSheetDialog() { 51 | return mBottomSheetDialog; 52 | } 53 | 54 | public void setBottomSheetDialog(BottomSheetDialog bottomSheetDialog) { 55 | mBottomSheetDialog = bottomSheetDialog; 56 | } 57 | 58 | public List getSelectedEntities() { 59 | return selectedEntities; 60 | } 61 | 62 | public void setSelectedEntities(List selectedEntities) { 63 | this.selectedEntities = selectedEntities; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/sennie/sku/adapter/SkuAdapter.java: -------------------------------------------------------------------------------- 1 | package com.sennie.sku.adapter; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import com.sennie.sku.ProductModel; 10 | import com.sennie.sku.R; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * 项目名称:Sku 16 | * 类描述: 17 | * 创建人:N.Sun 18 | * 创建时间:2016/11/24 下午4:38 19 | * 修改人:N.Sun 20 | * 修改时间:2016/11/24 下午4:38 21 | * 修改备注: 22 | */ 23 | public class SkuAdapter extends RecyclerView.Adapter { 24 | 25 | private List mAttributeMembersEntities; 26 | OnClickListener mOnClickListener; 27 | private ProductModel.AttributesEntity.AttributeMembersEntity currentSelectedItem; 28 | 29 | public SkuAdapter(List attributeMembersEntities) { 30 | this.mAttributeMembersEntities = attributeMembersEntities; 31 | } 32 | 33 | public ProductModel.AttributesEntity.AttributeMembersEntity getCurrentSelectedItem() { 34 | return currentSelectedItem; 35 | } 36 | 37 | public void setCurrentSelectedItem(ProductModel.AttributesEntity.AttributeMembersEntity currentSelectedItem) { 38 | this.currentSelectedItem = currentSelectedItem; 39 | } 40 | 41 | public List getAttributeMembersEntities() { 42 | return mAttributeMembersEntities; 43 | } 44 | 45 | public OnClickListener getOnClickListener() { 46 | return mOnClickListener; 47 | } 48 | 49 | public void setOnClickListener(OnClickListener onClickListener) { 50 | mOnClickListener = onClickListener; 51 | } 52 | 53 | @Override 54 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 55 | View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.sku_item_layout, parent, false); 56 | return new ViewHolder(v); 57 | } 58 | 59 | @Override 60 | public void onBindViewHolder(ViewHolder holder, int position) { 61 | holder.setData(mAttributeMembersEntities.get(position)); 62 | holder.setClick(position); 63 | } 64 | 65 | @Override 66 | public int getItemCount() { 67 | return mAttributeMembersEntities.size(); 68 | } 69 | 70 | class ViewHolder extends RecyclerView.ViewHolder { 71 | 72 | private TextView mTextView; 73 | 74 | public ViewHolder(View itemView) { 75 | super(itemView); 76 | mTextView = (TextView) itemView.findViewById(R.id.tv); 77 | } 78 | 79 | public void setData(ProductModel.AttributesEntity.AttributeMembersEntity entity) { 80 | mTextView.setText(entity.getName()); 81 | switch (entity.getStatus()) { 82 | case 0: 83 | mTextView.setAlpha(1f); 84 | mTextView.setBackgroundResource(android.R.color.darker_gray); 85 | break; 86 | case 1: 87 | mTextView.setAlpha(1f); 88 | mTextView.setBackgroundResource(android.R.color.holo_red_light); 89 | break; 90 | case 2: 91 | mTextView.setAlpha(0.4f); 92 | mTextView.setBackgroundResource(android.R.color.darker_gray); 93 | break; 94 | } 95 | } 96 | 97 | public void setClick(final int position) { 98 | mTextView.setOnClickListener(new View.OnClickListener() { 99 | @Override 100 | public void onClick(View v) { 101 | if (mOnClickListener != null) 102 | mOnClickListener.onItemClickListener(position); 103 | } 104 | }); 105 | } 106 | } 107 | 108 | public interface OnClickListener { 109 | void onItemClickListener(int position); 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 |