Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Wongxd committed Dec 31, 2019
1 parent a39c692 commit 4f30baf
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 16 deletions.
116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void doMainLogic() {
SpecBean bean = new Gson().fromJson(json, SpecBean.class);


SpecSelectFragment.showDialog(this, "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1282625489,100434574&fm=27&gp=0.jpg", bean)
SpecSelectFragment.showDialog(this, "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1282625489,100434574&fm=27&gp=0.jpg", null,bean,"该规格已无库存!")
.setShowGoodImgListener(new ShowGoodImgListener() {
@Override
public void displayImg(ImageView iv, String imgUrl) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/io/github/wongxd/demo/AtyMainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AtyMainActivity : AppCompatActivity() {
val goodImgUrl = "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1282625489,100434574&fm=27&gp=0.jpg"
Glide.with(this).load(goodImgUrl).placeholder(R.drawable.ic_launcher).into(iv_main)

SpecSelectFragment.showDialog(this, null, defaultAttrList, spec)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void onDestroyView() {
showGoodImgListener = null;
submitSpecCombListener = null;
bean = null;
noStockTip = null;
goodImgPath = null;
checkedComb = null;
super.onDestroyView();
Expand Down Expand Up @@ -395,7 +396,7 @@ public void run() {

//设置点击监听器
for (SkuAdapter adapter : mUiData.getAdapters()) {
ItemClickListener listener = new ItemClickListener(mUiData, adapter);
ItemClickListener listener = new ItemClickListener(mUiData, adapter, noStockTip);
adapter.setOnClickListener(listener);
}
// 初始化按钮
Expand Down Expand Up @@ -450,6 +451,7 @@ public void run() {
}


private static String noStockTip;
private static String goodImgPath;
private static List<ProductModel.AttributesEntity.AttributeMembersEntity> checkedComb = null;
private static SpecBean bean = null;
Expand Down Expand Up @@ -503,9 +505,28 @@ public static SpecSelectFragment showDialog(AppCompatActivity aty, @Nullable Str
* @return
*/
public static SpecSelectFragment showDialog(AppCompatActivity aty, @Nullable String defaultGoodImg,
@Nullable List<ProductModel.AttributesEntity.AttributeMembersEntity> statusRestoreList, @NonNull SpecBean allSpecBean) {
List<ProductModel.AttributesEntity.AttributeMembersEntity> statusRestoreList, @NonNull SpecBean allSpecBean) {
return showDialog(aty, defaultGoodImg, statusRestoreList, allSpecBean, null);
}

/**
* 确认按钮的颜色、规格选中后的颜色 可在 color 中定义 <color name="app_color">#3F51B5</color>,即可实现颜色自定义
* <p>
* <p>
* 可以避免重复
*
* @param aty
* @param defaultGoodImg 商品默认展示的图片,如果不需要选中,传入 null
* @param statusRestoreList 商品默认选中规格,如果不需要选中,传入 null
* @param allSpecBean 规格对象 {@link io.github.wongxd.skulibray.specSelect.bean.SpecBean}
* @param defaultNoStockTip 点击了无库存的规格时,提示信息。如果不需要显示,传入 null
* @return
*/
public static SpecSelectFragment showDialog(AppCompatActivity aty, @Nullable String defaultGoodImg,
List<ProductModel.AttributesEntity.AttributeMembersEntity> statusRestoreList, @NonNull SpecBean allSpecBean, @Nullable String defaultNoStockTip) {

TU.register(aty.getApplicationContext());
noStockTip = defaultNoStockTip;
goodImgPath = defaultGoodImg;
checkedComb = statusRestoreList;
bean = allSpecBean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package io.github.wongxd.skulibray.specSelect.sku;


import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

import io.github.wongxd.skulibray.specSelect.custom.TU;
import io.github.wongxd.skulibray.specSelect.observer.ObserverEventCode;
import io.github.wongxd.skulibray.specSelect.observer.ObserverHolder;

Expand All @@ -19,36 +22,41 @@ public class ItemClickListener implements SkuAdapter.OnClickListener {
private String TAG = getClass().getSimpleName();

private UiData mUiData;
private SkuAdapter currentAdapter;
private SkuAdapter mCurrentAdapter;
private String mNoStockTip;

public ItemClickListener(UiData uiData, SkuAdapter currentAdapter) {
public ItemClickListener(UiData uiData, SkuAdapter currentAdapter, @Nullable String noStockTip) {
mUiData = uiData;
this.currentAdapter = currentAdapter;
mCurrentAdapter = currentAdapter;
mNoStockTip = noStockTip;
}

@Override
public void onItemClickListener(int position) {
onItemClickListener(currentAdapter.getAttributeMembersEntities().get(position));
onItemClickListener(mCurrentAdapter.getAttributeMembersEntities().get(position));
}

@Override
public void onItemClickListener(ProductModel.AttributesEntity.AttributeMembersEntity attributeMembersEntity) {
//屏蔽不可点击
if (attributeMembersEntity.getStatus() == ProductModel.AttributeMemberStatus.UNCHECKABLE) {
if (null != mNoStockTip && !TextUtils.isEmpty(mNoStockTip)) {
TU.t(mNoStockTip);
}
return;
}
// 设置当前单选点击
for (ProductModel.AttributesEntity.AttributeMembersEntity entity : currentAdapter.getAttributeMembersEntities()) {
for (ProductModel.AttributesEntity.AttributeMembersEntity entity : mCurrentAdapter.getAttributeMembersEntities()) {
if (entity.equals(attributeMembersEntity)) {
String key = currentAdapter.groupName;
if (currentAdapter.getCurrentSelectedItem() == null || !currentAdapter.getCurrentSelectedItem().equals(entity)) {
String key = mCurrentAdapter.groupName;
if (mCurrentAdapter.getCurrentSelectedItem() == null || !mCurrentAdapter.getCurrentSelectedItem().equals(entity)) {
entity.setStatus(ProductModel.AttributeMemberStatus.CHECKED);
//添加已经选择的对象
currentAdapter.setCurrentSelectedItem(entity);
mCurrentAdapter.setCurrentSelectedItem(entity);
mUiData.getSelectedMap().put(key, entity);
} else {
entity.setStatus(ProductModel.AttributeMemberStatus.CHECKABLE);
currentAdapter.setCurrentSelectedItem(null);
mCurrentAdapter.setCurrentSelectedItem(null);
mUiData.getSelectedMap().remove(key);
}
} else {
Expand Down

0 comments on commit 4f30baf

Please sign in to comment.