




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、一、 商铺界面1 界面分析1.1 整体布局1.2 BottomSheetLayout 的布局1.3 购物车布局1.4 引入 BottomSheet 库/底部弹出窗体compile com.flipboamons:1.5.1compile com.flipboard:bottomsheet-core:1.5.12 初始化标题信息/获取商家的 id Bundundle = getent().getExtras(); seller = (Seller) bundle.getSerializable(seller);/设置标题 tvTitle.setText(seller.getName(); /设置
2、配送费 tvSendPrietText(另需配送费+seller.gedPrice()+¥); /设置起送金额 tvDeliveryFee.setText(¥+seller.gedPrice()+元起送);3 TabLayout 添加 Tabprivate String tabTitles = new String商品, 评价, 商家;/* * 创建 Tab */private void createTabs() for ( i = 0; i tabTitles.length; i+) tabs.addTab(tabs.newTab().setText(tabTitlesi);4 Vieger
3、 增加页面注意:整个项目整体采用的是V4 支持包的 Fragment 一套 APIFragmentActivityFragmentFragmentPagerAdapter/准备 Viger 的数据List listFragment = createFragmentList();BusinesivityVpAdapter vpAdapter = new BusinesivityVpAdapter(getSupportFragmentManager(), listFragment);vp.setAdapter(vpAdapter);public List listFragment = new Ar
4、rayList();/* * 创建 Fragment */privaist createFragmentList() for ( i = 0; i tabTitles.length; i+) Fragment fragment = null;switch (i) case 0:fragment = new GoodsFragment();break;case 1:fragment = new CommentFragment();break;case 2:fragment = new BusinessFragment();break;Bundle args = new Bundle();args
5、.putString(title, tabTitlesi);args.putSerializable(seller,seller);fragment.setArguments(args);listFragment.add(fragment);return listFragment;5 TableLayout 和 Vieger 进行关联tabs.setupWithVieger(vp);注意FragmentPagerAdapter 一定要重写Overridereturn listFragment.get(ition).getArguments().getString(title);6 页面滑动处理
6、vp.addOnPageChangeListener(new MyOnPageChangeListener();private class MyOnPageChangeListener implements Vieger.OnPageChangeListener public CharSequence getPageTitle(ition) Override itionOffsetPixels) Overrideif (ition = 0) bottom.setVisibility(View.VISIBLE); else bottom.setVisibility(View.GONE);Over
7、ridepublic void onPageScrollSeChanged( se) 二、 联网获取商铺的商品信息1 创建 GoodsFragment 的布局/带浮动分栏的 ListViewcompile se.emilsjolander:stickylistheaders:2.7.0public void onPageSelected(ition) public void onPageScrolled(ition, float itionOffset, InjectView(R.id.rv_goods_type) RecyclerView rvGoodsType; InjectView(R.
8、id.slhlv) StickyListHeadersListView slhlv;private RecyclerView.LayoutManager typeLm; Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstane) View view = inflater.inflate(R.layout.fragment_goods, container, false);ButterKnife.inject(this, view);/设置布局管理器type
9、Lm = new LinearLayoutManager(getActivity();rvGoodsType.setLayoutManager(typeLm);/添加RecyclerView 的分割线rvGoodsType.addItemDecoration(new RecycleViewDivider(this.getContext(),LinearLayoutManager.HORIZONTAL);return view;2 使用 Dagger 分离 GoodsFragment 的业务2.1 创建 GoodsFragmengPresenterpublic class GoodsFragme
10、ntPresenter extends BasePresenterprivate GoodsFragment goodsFragment;Injectpublic GoodsFragmentPresenter(GoodsFragment goodsFragment) this.goodsFragment = goodsFragment;2.2 在 GoodsFragment 里面注入public class GoodsFragment extends BaseFragment Injectpublic GoodsFragmentPresenter goodsFragmentPresenter;
11、2.3 创建 GoodsFragmentModuleModulepublic class GoodsFragmentModule GoodsFragment goodsFragment;public GoodsFragmentModule(GoodsFragment goodsFragment) this.goodsFragment = goodsFragment;ProvidesGoodsFragment providerGoodsFragment()return goodsFragment;2.4 创建ponentComponent(modules = GoodsFragmentModul
12、e.class)publicerfaceponet void in(GoodsFragment goodsFragment);2.5 Build- ReBuild Project2.6 在 GoodsFragment 里面编写代码protected voidponet() Daggponet.builder().goodsFragmentModule(new GoodsFragmentModule(this).build().his);3 根据 SellerId 获取商品的商品信息Overridepublic void getData() Call responseInfoCall = res
13、ponseInfoApi.getBussinessInfo(business,goodsFragment.seller.getId();responseInfoCall.enqueue(callback);Overrideprotected void parseDestInfo(String json) BusinessInfo businessInfo = gson.fromJson(json,BusinessInfo.class);dealData(businessInfo.getList();4 根据返回的数据类型设计 bean 模型4.1 BusinessInfopublic clas
14、s BusinessInfo privaist list; 4.2 GoodsTypeInfopublic class GoodsTypeInfo String name;/商品类型名称String info;/特价信息List list;/商品列表private typeCount; 4.3 GoodsInfopublic class GoodsInfo String name;/商品名称String icon;/商品String form;/组成float newPrice;/新价oldPrice;/ isNew;/是否是新产品 bargainPrice;/特价 monthSaleNum;
15、/月销售量 id;/商品 id id;/商品类型 idprivate number;private typeId;private String typeName;private sellerId; 5数据封装数据成集合public List businessInfos;public List goodsInfos;public void dealData(List businessInfos)this.businessInfos = businessInfos;goodsInfos = new ArrayList();for (GoodsTypeInfo info:businessInfos)
16、 List spList = info.getList();for (GoodsInfo goods:spList)goods.setSellerId(goodsFragment.seller.getId();goods.setTypeId(info.getId();goods.setTypeName(info.getName();goodsInfos.addAll(spList);/的数量6 处理商品类型列表6.1 GoodsFragmentTypeAdapterpublic GoodsFragmentTypeAdapter typeAdapter;typeAdapter = new Goo
17、dsFragmentTypeAdapter(this, getActivity(), null);rvGoodsType.setAdapter(typeAdapter);使用 Dagger后 Fragment 只会负责界面的修改部分,所以 FragmentPresenter 直接给Adapter 设置数据。goodsFragment.typeAdapter.setBusinessInfos(businessInfos);goodsFragment.goodsAdapter.setInfos(goodsInfos);6.2 选择的条目变灰ViewHolder 里面的操作public select
18、edition = 0;public void setition(final ition)/设置条目点击事件 itemView.setOnClickListener(new View.OnClickListener() Overridepublic void onClick(View v) GoodsFragmentTypeAdapter.this.notifyDataSetChanged(););onBindViewHolder(RecyclerView.ViewHolder holder, finalition)if(selectedition =ition)viewHolder.item
19、View.setBackgroundColor(Color.WHITE);viewHolder.type.setTypeface(Typeface.DEFAULT_BOLD);/粗体elseviewHolder.itemView.setBackgroundColor(Color.parseColor(#b9dedcdc);viewHolder.type.setTypeface(Typeface.DEFAULT);/正常字体7 商品列表7.1 界面selectedition =ition;7.2 头布局7.3 条目布局holder.tvOldprice.getPa().setFlags(Pa.
20、STRIKE_THRU_TEXT_FLAG );7.4 点击类型列表条目商品条码移动至顶部fragment.onClickType(typeId);/告知 Fragment/* * 商品类型条目点击 * param typeId */public void onClickType( typeId) slhlv.setSelection(ition);/* * 通过商品类型id 获取第一条商品类型的 id * param typeId * return */private getGoodsition( typeId) for (i = 0; i goodsFragmentPresenter.go
21、odsInfos.size(); i+) ition = getGoodsition(typeId);if (goodsFragmentPresenter.goodsInfos.get(i).getTypeId() = typeId) return i;return 0;7.5 滑动商品条目滑动商品条目到新的商品类型,让商品类型条目自动选中,并且自动滑动思路:1 设置滑动2 滑动的时候获取第一个条目的类型 id3 获取类型条目当前选中的类型 id4 两个类型 id 进行对比5 当两个类型 id 不相同的时候,去修改类型列表的 selectedition6 刷新界面/* * 成功获取数据后设置
22、*/public void setListener() /设置滑动slhlv.setOnScrollListener(new MyOnScrollListener();private class MyOnScrollListener implements AbsListView.OnScrollListener Overridepublic void onScrollSeChanged(AbsListView view, scrollSe) Overridepublic void onScroll(AbsListView view, VisibleItem, visibleItemCount,
23、 totalItemCount) if (typeId != selectTypeId) selectedition = getTypeListition(typeId); selectTypeId = getTypeListSelectedTypeId(); typeId = goodsFragmentPresenter.goodsInfos.get(VisibleItem).getTypeId();typeAdapter.notifyDataSetChanged();/滑动到要选择的条目rvGoodsType.smoothScrollToition(selectedition);/通过类型
24、id 获取应该选择类型的下标private getTypeListition( typeId) for ( i = 0; i ReBuild1.6 在 Businesivity 编写/设置组件private voidponet() DaggerBponet.builder().businesivityModule(newBusinesivityModule(this).build().his);2 更新购物车选购商品数量商品列表条目的+号和-号会影响购物车的数量。(Businesivity)fragment.getActivity().businesivityPresenter.updateC
25、artUI();/* * 更新购物车界面 */public void updateCartUI()GoodsFragment goodsFragment = (GoodsFragment) businesivity.listFragment.get(0);List goodsInfos = goodsFragment.goodsFragmentPresenter.goodsInfos;double countPrice = 0;for (GoodsInfo info:goodsInfos)if(info.getNumber() != 0)countPrice+=info.getNumber()
26、*info.getNewPrice();countGoods+=info.getNumber();businesivity.updateCartUI(countGoods,countPrice);/* * 更新购物车界面 */public void updateCartUI( countGoods,double countPrice)if(countGoods = 0)tvSelectNum.setVisibility(View.GONE);tvSubmit.setVisibility(View.GONE); countGoods = 0;tvCountPrietText(¥0);elsetv
27、SelectNum.setVisibility(View.VISIBLE);tvSelectNum.setText(countGoods+);if(countPrice = startDispatchPrice)tvSubmit.setVisibility(View.VISIBLE);tvSendPrietVisibility(View.GONE);tvCountPrietText(NumberFormatUtils.formatDigits(countPrice);public claumberFormatUtils private NumberFormatUtils()/格式化数据保留两位
28、小数并且带¥public sic String formatDigits(double data)NumberFormat nf = NumberFormat.getCurrencyInstance();nf.setumFractionDigits(2);return nf.format(data);tvSendPrietVisibility(View.VISIBLE);3 购物车列表界面加载public View bottomSheet;public void showBottomSheet() if (bottomSheet = null) bottomSheet = createBott
29、omSheet();if(bottomSheetLayout.isSheetShowing()bottomSheetLayout.dismissSheet();elseif(businesivityPresenter.getCartGoodsInfo().size() != 0)bottomSheetLayout.showWithSheetView(bottomSheet);private View createBottomSheet() View view = LayoutInflater.from(this).inflate(R.layoart, (ViewGroup) getWindow
30、().getDecorView(), false);return view;4 购物车数据的获取/* * 获取购物车里面的数据 * return */public List getCartGoodsInfo()List infos = new ArrayList();List goodsInfos = (GoodsFragment) businesivity.listFragment.get(0).goodsFragmentPresenter.goodsInfos;if(goodsInfos != null)for ( i =0; igoodsInfos.size();i+)GoodsInfo
31、 info = goodsInfos.get(i);if(info != null & info.getNumber() != 0)infos.add(info);return infos;5 购物车列表显示RecyclerView rvCart = (RecyclerView) view.findViewById(R.id.rvCart); rvCart.setLayoutManager(new LinearLayoutManager(this);rvCart.addItemDecoration(new RecycleViewDivider(this,LinearLayoutManager.
32、HORIZONTAL);cartAdapter = new CartAdapter(this,businesivityPresenter.getCartGoodsInfo();rvCart.setAdapter(cartAdapter);public class CartAdapter extends RecyclerView.Adapter private Context context;privaist infos;6 清空购物车TextView tvClear = (TextView) view.findViewById(R.id.tvClear);tvClear.setOnClickL
33、istener(new View.OnClickListener() Overridepublic void onClick(View v) new AlertDialog.Builder(Businesivity.this).setMessage(清空购物车).setNegativeButton(取消,null)Overridepublic void onClick(Dialogerface dialog, which) businesivityPresenter.clearCart();).show(););/* * 清空购物车 */public void clearCart()Goods
34、Fragment goodsFragment = (GoodsFragment) businesivity.listFragment.get(0);List goodsInfos = goodsFragment.goodsFragmentPresenter.goodsInfos;for( i =0;igoodsInfos.size();i+)GoodsInfo info = goodsInfos.get(i);if(info.getNumber() != 0)info.setNumber(0);businesivity.hideCartList();goodsFragment.typeAdap
35、ter.clearTypeNumber();goodsFragment.goodsAdapter.clearSelectedGoodsNumber();updateCartUI();7 购物车列表的+号和 -号操作class ViewHolder extends RecyclerView.ViewHolder ition;.setitiveButton(确定, new Dialogerface.OnClickListener() this.ition = ition;ViewHolder(View view) super(view);ButterKnife.inject(this, view)
36、;OnClick(R.id.ib_minus, R.id.ib_add)public void onClick(View view) switch (view.getId() case R.id.ib_minus:doMinus(ition);operator = Constant.MINUSOPERATOR;break;case R.id.ib_add:doAdd(ition);operator = Constant.ADDOPERATOR;break;GoodsFragment goodsFragment = (GoodsFragment) (Businesivity) context).
37、listFragment.get(0);goodsFragment.selectedTypeDhange(typeId,operator);goodsFragment.goodsAdapter.notifyDataSetChanged();private void doMinus(ition)GoodsInfo goodsInfo = infos.get(ition);goodsInfo.setNumber(goodsInfo.getNumber()-1);Businesivity activity = (Businesivity)context;MyApplication app = (My
38、Application) activity.getApplication(); typeId = infos.get(ition).getTypeId(); operator = 0;public void setition(ition) if(goodsInfo.getNumber() = 0)if(getItemCount() = 1)/隐藏购物车列表activity.hideCartList();private void doAdd(ition)GoodsInfo goodsInfo = infos.get(ition);goodsInfo.setNumber(goodsInfo.get
39、Number()+1);Businesivity activity = (Businesivity)context;MyApplication app = (MyApplication) activity.getApplication();四、 选购商品内存缓存1 选择缓存的位置public class MyApplication extends Application/解决迭代删除异常public CopyOnWriteArrayList cacheSelectedInfos;Overridepublic void onCreate() super.onCreate();cacheSelec
40、tedInfos = new CopyOnWriteArrayList();/* 获取在该商家选购的商品数量* param sellerId* return*/public getCacheSelectedCountBySellerId( sellerId)count = 0;CacheSelectedInfo cacheSelectedInfo = cacheSelectedInfos.get(i);if(cacheSelectedInfo.getSellerId() = sellerId)count += cacheSelectedInfo.getCount();return count;
41、public getCacheSelectedGoodsTypeCountBySellerIdAndTypeId( sellerId, typeId)for ( i = 0; i cacheSelectedInfos.size(); i+) CacheSelectedInfo cacheSelectedInfo = cacheSelectedInfos.get(i);if(cacheSelectedInfo.getSellerId() = sellerId & cacheSelectedInfo.getGoodsTypeId() = typeId)count += cacheSelectedInfo.getCount();return count;public getCacheSelectedGoodsCountByGoodsId( sellerId, typeId, goodsId)for ( i = 0; i cacheSelectedInfos.size(); i+) Ca
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 炸药生产自动化设备应用考核试卷
- 下肢深静脉血栓的预防和护理新进展
- 二年级数学口算题
- 2-3逻辑运算的电路实现-开关特性
- 九江理工职业学院《中药学》2023-2024学年第二学期期末试卷
- 江苏省无锡市惠山区七校2024-2025学年初三下学期第一次在线考试含解析
- 四川大学附中2025年高三综合题(三)历史试题(文史类)试题含解析
- 辽宁财贸学院《工程建设监理》2023-2024学年第一学期期末试卷
- 道路损毁及抢修抢建分级
- 江苏省苏州市姑苏区振华校2024-2025学年初三化学试题第一次统练(一模)试题含解析
- 煤炭行业煤层气开发与利用考核试卷
- 2024年8月CCAA注册审核员OHSMS职业健康安全管理体系基础知识考试题目含解析
- 《工程建设标准强制性条文》(水利工程部分)
- 《PBR次世代游戏建模技术》(微课版)课件 0课程导引
- 后所村城中村改造建设项目节能评估报告
- 中小学班主任工作指南
- DB35∕T 2174-2024 改良酸性土壤专用有机肥料通 用技术要求
- 北师大版数学五年级下册《确定位置》课件教学课件
- 辽宁葫芦岛协作校2025届高三第二次联考生物试卷含解析
- DL∕T 1396-2014 水电建设项目文件收集与档案整 理规范
- 2024年纪检监察综合业务知识考试题库及参考答案(完整版)
评论
0/150
提交评论