动画播放进购物车再进订单
来源:互联网 发布:历年网络作家富豪榜 编辑:程序博客网 时间:2024/06/06 11:04
public class CartModel { private ICartPresenter iCartPresenter; public CartModel(ICartPresenter iCartPresenter) { this.iCartPresenter = iCartPresenter; } public void getCartData(final String cartUrl) { //获取数据 OkHttp3Util.doGet(cartUrl, new Callback() { @Override public void onFailure(okhttp3.Call call, IOException e) { Log.e(cartUrl,e.getLocalizedMessage()); } @Override public void onResponse(okhttp3.Call call, Response response) throws IOException { if (response.isSuccessful()){ final String json = response.body().string(); CommonUtils.runOnUIThread(new Runnable() { @Override public void run() { /*if ("null".equals(json)){ Toast.makeText(DashApplication.getAppContext(),"购物车为空,请添加",Toast.LENGTH_SHORT).show(); }else {*/ Gson gson = new Gson(); CartBean cartBean = gson.fromJson(json, CartBean.class); //返回数据到主线程 iCartPresenter.getSuccessCartJson(cartBean); //} } }); } } }); }}----------------------------------------public interface ICartPresenter { void getSuccessCartJson(CartBean cartBean);}-------------------------------------------** * Created by Dash on 2017/12/12. */public class CartPresenter implements ICartPresenter { private final CartModel cartModel; private IMainActivity iMainActivity; public CartPresenter(IMainActivity iMainActivity) { this.iMainActivity = iMainActivity; cartModel = new CartModel(this); } public void getCartData(String cartUrl) { cartModel.getCartData(cartUrl); } @Override public void getSuccessCartJson(CartBean cartBean) { //回调给view iMainActivity.getSuccessCartData(cartBean); } public void destroy(){ if(iMainActivity!=null) { iMainActivity=null; } }}-----------------------------------------------public class ApiUtil { public static final String cartUrl = "https://www.zhaoapi.cn/product/getCarts?uid=4084"; public static final String addCartUrl = "https://www.zhaoapi.cn/product/addCart";//uid,pid public static final String deleteCartUrl = "https://www.zhaoapi.cn/product/deleteCart";//uid,pid //?uid=71&sellerid=1&pid=1&selected=0&num=10 public static final String updateCartUrl = "https://www.zhaoapi.cn/product/updateCarts"; public static final String createCartUrl = "https://www.zhaoapi.cn/product/createOrder";}----------------------------------------------public class CommonUtils { public static final String TAG = "Dash";//sp文件的xml名称 private static SharedPreferences sharedPreferences; /** * DashApplication.getAppContext()可以使用,但是会使用系统默认的主题样式,如果你自定义了某些样式可能不会被使用 * @param layoutId * @return */ public static View inflate(int layoutId) { View view = View.inflate(DashApplication.getAppContext(), layoutId, null); return view; } /** * dip---px * * @param dip 设备独立像素device independent px....1dp = 3px 1dp = 2px 1dp = 1.5px * @return */ public static int dip2px(int dip) { //获取像素密度 float density = DashApplication.getAppContext().getResources().getDisplayMetrics().density; // int px = (int) (dip * density + 0.5f);//100.6 return px; } /** * px-dip * * @param px * @return */ public static int px2dip(int px) { //获取像素密度 float density = DashApplication.getAppContext().getResources().getDisplayMetrics().density; // int dip = (int) (px / density + 0.5f); return dip; } /** * 获取资源中的字符串 * @param stringId * @return */ public static String getString(int stringId) { return DashApplication.getAppContext().getResources().getString(stringId); } public static Drawable getDrawable(int did) { return DashApplication.getAppContext().getResources().getDrawable(did); } public static int getDimens(int id) { return DashApplication.getAppContext().getResources().getDimensionPixelSize(id); } /** * sp存入字符串类型的值 * @param flag * @param str */ public static void saveSp(String flag, String str) { if (sharedPreferences == null) { sharedPreferences = DashApplication.getAppContext().getSharedPreferences(TAG, DashApplication.getAppContext().MODE_PRIVATE); } SharedPreferences.Editor edit = sharedPreferences.edit(); edit.putString(flag, str); edit.commit(); } public static String getSp(String flag) { if (sharedPreferences == null) { sharedPreferences = DashApplication.getAppContext().getSharedPreferences(TAG, DashApplication.getAppContext().MODE_PRIVATE); } return sharedPreferences.getString(flag, ""); } public static boolean getBoolean(String tag) { if (sharedPreferences == null) { sharedPreferences = DashApplication.getAppContext().getSharedPreferences(TAG, DashApplication.getAppContext().MODE_PRIVATE); } return sharedPreferences.getBoolean(tag, false); } public static void putBoolean(String tag, boolean content) { if (sharedPreferences == null) { sharedPreferences = DashApplication.getAppContext().getSharedPreferences(TAG, DashApplication.getAppContext().MODE_PRIVATE); } SharedPreferences.Editor edit = sharedPreferences.edit(); edit.putBoolean(tag, content); edit.commit(); } /** * 清除sp数据 * @param tag */ public static void clearSp(String tag) { if (sharedPreferences == null) { sharedPreferences = DashApplication.getAppContext().getSharedPreferences(TAG, DashApplication.getAppContext().MODE_PRIVATE); } SharedPreferences.Editor edit = sharedPreferences.edit(); edit.remove(tag); edit.commit(); } /** * 自己写的运行在主线程的方法 * 如果是主线程,执行任务,否则使用handler发送到主线程中去执行 * * * @param runable */ public static void runOnUIThread(Runnable runable) { //先判断当前属于子线程还是主线程 if (android.os.Process.myTid() == DashApplication.getMainThreadId()) { runable.run(); } else { //子线程 DashApplication.getAppHanler().post(runable); } }}------------------------------------------------------/** * Created by Dash on 2017/12/12. */public class CartExpanableListview extends ExpandableListView { public CartExpanableListview(Context context) { super(context); } public CartExpanableListview(Context context, AttributeSet attrs) { super(context, attrs); } public CartExpanableListview(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, height); }}----------------------------------------------public class StatusFragment extends Fragment{ List<DingDanBean.DataBean> list; private ListView lv; Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); if(msg.what==1) { getDataFromNetQuan(); for(int i=0;i<3;i++) { getDataFromNet(i+""); } } } }; private String name; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.status_layout, container, false); lv = view.findViewById(R.id.lv); return view; } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); name = getArguments().getString("name",""); if(name.equals("待支付")) { name ="0"; }else if(name.equals("全部")){ getDataFromNetQuan(); } else if(name.equals("已支付")){ name ="1"; } else if(name.equals("已取消")){ name ="2"; } getDataFromNet(name); } private void getDataFromNet(final String name) { list = new ArrayList<>(); Map<String, String> parmas=new HashMap<>(); parmas.put("uid",4084+""); parmas.put("page",1+""); parmas.put("status",name); parmas.put("source","android"); OkHttp3Util.doPost("https://www.zhaoapi.cn/product/getOrders", parmas, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { final String json = response.body().string(); CommonUtils.runOnUIThread(new Runnable() { @Override public void run() { DingDanBean dingDanBean = new Gson().fromJson(json, DingDanBean.class); List<DingDanBean.DataBean> data = dingDanBean.getData(); if (data!=null) { list.clear(); list.addAll(data); Map<String, String> parmas=new HashMap<>(); parmas.put("uid",4084+""); parmas.put("page",2+""); parmas.put("status",name); parmas.put("source","android"); OkHttp3Util.doPost("https://www.zhaoapi.cn/product/getOrders", parmas, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { final String json = response.body().string(); CommonUtils.runOnUIThread(new Runnable() { @Override public void run() { DingDanBean dingDanBean = new Gson().fromJson(json, DingDanBean.class); List<DingDanBean.DataBean> data = dingDanBean.getData(); if (data!=null) { list.addAll(data); Map<String, String> parmas=new HashMap<>(); parmas.put("uid",4084+""); parmas.put("page",3+""); parmas.put("status",name); parmas.put("source","android"); OkHttp3Util.doPost("https://www.zhaoapi.cn/product/getOrders", parmas, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { final String json = response.body().string(); CommonUtils.runOnUIThread(new Runnable() { @Override public void run() { DingDanBean dingDanBean = new Gson().fromJson(json, DingDanBean.class); List<DingDanBean.DataBean> data = dingDanBean.getData(); if (data!=null) { list.addAll(data); //设置适配器... lv.setAdapter(new DingDanAdapter(getActivity(),list,handler)); }else { //设置适配器... lv.setAdapter(new DingDanAdapter(getActivity(),list,handler)); } } }); } }); }else { //设置适配器... lv.setAdapter(new DingDanAdapter(getActivity(),list,handler)); } } }); } }); }else { Toast.makeText(getActivity(),"没有订单,快去下单吧!",Toast.LENGTH_SHORT).show(); } } }); } }); } private void getDataFromNetQuan() { list = new ArrayList<>(); Map<String, String> parmas=new HashMap<>(); parmas.put("uid",4084+""); parmas.put("page",1+""); parmas.put("source","android"); OkHttp3Util.doPost("https://www.zhaoapi.cn/product/getOrders", parmas, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { final String json = response.body().string(); CommonUtils.runOnUIThread(new Runnable() { @Override public void run() { DingDanBean dingDanBean = new Gson().fromJson(json, DingDanBean.class); List<DingDanBean.DataBean> data = dingDanBean.getData(); if (data!=null) { list.addAll(data); Map<String, String> parmas=new HashMap<>(); parmas.put("uid",4084+""); parmas.put("page",2+""); parmas.put("source","android"); OkHttp3Util.doPost("https://www.zhaoapi.cn/product/getOrders", parmas, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { final String json = response.body().string(); CommonUtils.runOnUIThread(new Runnable() { @Override public void run() { DingDanBean dingDanBean = new Gson().fromJson(json, DingDanBean.class); List<DingDanBean.DataBean> data = dingDanBean.getData(); if (data!=null) { list.addAll(data); Map<String, String> parmas=new HashMap<>(); parmas.put("uid",4084+""); parmas.put("page",3+""); parmas.put("source","android"); OkHttp3Util.doPost("https://www.zhaoapi.cn/product/getOrders", parmas, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { final String json = response.body().string(); CommonUtils.runOnUIThread(new Runnable() { @Override public void run() { DingDanBean dingDanBean = new Gson().fromJson(json, DingDanBean.class); List<DingDanBean.DataBean> data = dingDanBean.getData(); if (data!=null) { list.addAll(data); //设置适配器... lv.setAdapter(new DingDanAdapter(getActivity(),list,handler)); }else { //设置适配器... lv.setAdapter(new DingDanAdapter(getActivity(),list,handler)); } } }); } }); }else { //设置适配器... lv.setAdapter(new DingDanAdapter(getActivity(),list,handler)); } } }); } }); }else { Toast.makeText(getActivity(),"这一类为空哦~",Toast.LENGTH_SHORT).show(); } } }); } }); }}------------------------------------------------public interface IMainActivity { void getSuccessCartData(CartBean cartBean);}---------------------------------------public class DingDanAdapter extends BaseAdapter{ private Handler handler; Context context; private List<DingDanBean.DataBean> list; public DingDanAdapter(Context context, List<DingDanBean.DataBean> list, Handler handler) { this.context = context; this.list = list; this.handler=handler; } @Override public int getCount() { return list.size(); } @Override public Object getItem(int position) { return list.get(position); } @Override public long getItemId(int position) { return position; } @Override public int getViewTypeCount() { return 2; } @Override public View getView(final int i, View view, ViewGroup viewGroup) { final TextHolder holder; if (view == null){ view = View.inflate(context, R.layout.item_text_layout,null); holder = new TextHolder(); holder.textView = view.findViewById(R.id.text_title); holder.price = view.findViewById(R.id.text_price); holder.status = view.findViewById(R.id.status); holder.text_time=view.findViewById(R.id.text_time); holder.btn= view.findViewById(R.id.btn); view.setTag(holder); }else { holder = (TextHolder) view.getTag(); } holder.textView.setText(list.get(i).getTitle()+"订单号为:"+list.get(i).getOrderid()); holder.text_time.setText(list.get(i).getCreatetime()); holder.price.setText(list.get(i).getPrice()+""); if(list.get(i).getStatus()==0){ holder.status.setTextColor(Color.RED); holder.status.setText("待支付"); holder.btn.setText("取消订单"); }else if(list.get(i).getStatus()==1) { holder.status.setTextColor(Color.BLACK); holder.status.setText("已支付"); holder.btn.setText("查看订单"); }else if(list.get(i).getStatus()==2) { holder.btn.setText("查看订单"); holder.status.setTextColor(Color.BLACK); holder.status.setText("已取消"); } holder.btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Map<String, String> pramas=new HashMap<String, String>(); pramas.put("uid",4084+""); pramas.put("status",2+""); pramas.put("orderId",list.get(i).getOrderid()+""); Log.d("AAAAAA",list.get(i).getOrderid()+""); OkHttp3Util.doPost("https://www.zhaoapi.cn/product/updateOrder", pramas, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { Message msg=Message.obtain(); msg.arg1=list.get(i).getStatus(); msg.what=1; handler.sendMessage(msg); } }); } }); return view; } private class TextHolder{ TextView textView; TextView price; TextView status; Button btn; TextView text_time; }}-------------------------------------------------------------public class MyAdapter extends BaseExpandableListAdapter { private RelativeLayout relative_progress; private CartPresenter cartPresenter; private Handler handler; private CartBean cartBean; private Context context; private int size; private int childI; private int allSize; private int index; public MyAdapter(Context context, CartBean cartBean, Handler handler, CartPresenter cartPresenter, RelativeLayout relative_progress) { this.context = context; this.cartBean = cartBean; this.handler = handler; this.cartPresenter = cartPresenter; this.relative_progress = relative_progress; } @Override public int getGroupCount() { return cartBean.getData().size(); } @Override public int getChildrenCount(int groupPosition) { return cartBean.getData().get(groupPosition).getList().size(); } @Override public Object getGroup(int groupPosition) { return cartBean.getData().get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { return cartBean.getData().get(groupPosition).getList().get(childPosition); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public boolean hasStableIds() { return true; } @Override public View getGroupView(int groupPosition, boolean b, View view, ViewGroup viewGroup) { final GroupHolder holder; if (view == null){ view = View.inflate(context, R.layout.group_item_layout,null); holder = new GroupHolder(); holder.check_group = view.findViewById(R.id.check_group); holder.text_group = view.findViewById(R.id.text_group); view.setTag(holder); }else { holder = (GroupHolder) view.getTag(); } final CartBean.DataBean dataBean = cartBean.getData().get(groupPosition); //赋值 holder.check_group.setChecked(dataBean.isGroupChecked()); holder.text_group.setText(dataBean.getSellerName()); //组的点击事件...也要去请求更新的接口 holder.check_group.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { relative_progress.setVisibility(View.VISIBLE);//显示 size = dataBean.getList().size(); childI = 0; updateAllInGroup(holder.check_group.isChecked(),dataBean); } }); return view; } /** * 更新一组的状态 * @param checked * @param dataBean */ private void updateAllInGroup(final boolean checked, final CartBean.DataBean dataBean) { CartBean.DataBean.ListBean listBean = dataBean.getList().get(childI);//0 //?uid=71&sellerid=1&pid=1&selected=0&num=10 Map<String, String> params = new HashMap<>(); params.put("uid","4084"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(checked ? 1:0)); params.put("num", String.valueOf(listBean.getNum())); OkHttp3Util.doPost(ApiUtil.updateCartUrl, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()){ childI = childI+1;//0,1,2...3 if (childI <size){ updateAllInGroup(checked,dataBean); }else { //所有的条目已经更新完成....再次请求查询购物车的数据 cartPresenter.getCartData(ApiUtil.cartUrl); } } } }); } @Override public View getChildView(int groupPosition, int childPosition, boolean b, View view, ViewGroup viewGroup) { ChildHolder holder; if (view == null){ view = View.inflate(context, R.layout.child_item_layout,null); holder = new ChildHolder(); holder.text_add = view.findViewById(R.id.text_add); holder.text_num = view.findViewById(R.id.text_num); holder.text_jian = view.findViewById(R.id.text_jian); holder.text_title = view.findViewById(R.id.text_title); holder.text_price = view.findViewById(R.id.text_price); holder.image_good = view.findViewById(R.id.image_good); holder.check_child = view.findViewById(R.id.check_child); holder.text_delete = view.findViewById(R.id.text_delete); view.setTag(holder); }else { holder = (ChildHolder) view.getTag(); } //赋值 final CartBean.DataBean.ListBean listBean = cartBean.getData().get(groupPosition).getList().get(childPosition); holder.text_num.setText(listBean.getNum()+"");//......注意 holder.text_price.setText("¥"+listBean.getBargainPrice()); holder.text_title.setText(listBean.getTitle()); //listBean.getSelected().....0false,,,1true //设置checkBox选中状态 holder.check_child.setChecked(listBean.getSelected()==0? false:true); /*implementation 'com.github.bumptech.glide:glide:4.4.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.4.0'*/ Glide.with(context).load(listBean.getImages().split("\\|")[0]).into(holder.image_good); holder.text_delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Map<String, String> params=new HashMap<String, String>(); params.put("uid",4084+""); params.put("pid",listBean.getPid()+""); params.put("source","android"); OkHttp3Util.doPost("https://www.zhaoapi.cn/product/deleteCart", params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if(response.isSuccessful()) { Message msg=Message.obtain(); msg.what=2; handler.sendMessage(msg); } } }); } }); //点击事件 holder.check_child.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //点击的时候 更新当前条目选中的状态,,,更新完之后,请求查询购物车,重新展示数据 updateChildChecked(listBean); } }); //加号 holder.text_add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //请求更新的接口 updateChildNum(listBean,true); } }); //减号 holder.text_jian.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (listBean.getNum() == 1){ return; } //更新数量,,,减 updateChildNum(listBean,false); } }); return view; } /** * 更新数量 * @param listBean * @param */ private void updateChildNum(CartBean.DataBean.ListBean listBean, boolean isAdded) { //一旦执行更新的操作,,,progressBar显示 relative_progress.setVisibility(View.VISIBLE); //?uid=71&sellerid=1&pid=1&selected=0&num=10 Map<String, String> params = new HashMap<>(); params.put("uid","4084"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(listBean.getSelected())); if (isAdded){ params.put("num", String.valueOf(listBean.getNum() + 1)); }else { params.put("num", String.valueOf(listBean.getNum() - 1)); } OkHttp3Util.doPost(ApiUtil.updateCartUrl, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { //更新成功之后...网络上的数据发生了改变...再次请求购物车的接口进行数据的展示 if (response.isSuccessful()){ cartPresenter.getCartData(ApiUtil.cartUrl); } } }); } /** * 更新子条目 网络上的状态 * @param listBean */ private void updateChildChecked(CartBean.DataBean.ListBean listBean) { //一旦执行更新的操作,,,progressBar显示 relative_progress.setVisibility(View.VISIBLE); //?uid=71&sellerid=1&pid=1&selected=0&num=10 Map<String, String> params = new HashMap<>(); params.put("uid","4084"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(listBean.getSelected() == 0? 1:0)); params.put("num", String.valueOf(listBean.getNum())); OkHttp3Util.doPost(ApiUtil.updateCartUrl, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { //更新成功之后...网络上的数据发生了改变...再次请求购物车的接口进行数据的展示 if (response.isSuccessful()){ cartPresenter.getCartData(ApiUtil.cartUrl); } } }); } @Override public boolean isChildSelectable(int i, int i1) { return true; } /** * 计算价格和数量 并发送显示 */ public void sendPriceAndCount() { double price = 0; int count = 0; //通过判断二级列表是否勾选,,,,计算价格数量 for (int i=0;i<cartBean.getData().size();i++){ for (int j = 0;j<cartBean.getData().get(i).getList().size();j++){ if (cartBean.getData().get(i).getList().get(j).getSelected() == 1){ //价格是打折的价格........... price += cartBean.getData().get(i).getList().get(j).getNum() * cartBean.getData().get(i).getList().get(j).getBargainPrice(); count += cartBean.getData().get(i).getList().get(j).getNum(); } } } //精准的保留double的两位小数 DecimalFormat decimalFormat = new DecimalFormat("#.00"); String priceString = decimalFormat.format(price); CountPriceBean countPriceBean = new CountPriceBean(priceString, count); //发送...显示 Message msg = Message.obtain(); msg.what = 0; msg.obj = countPriceBean; handler.sendMessage(msg); } /** * 根据全选的状态,,,,跟新每一个子条目的状态,,,全部更新完成后,查询购物车的数据进行展示 * @param checked */ public void setAllChildState(boolean checked) { //创建一个集合 装所有的子条目 List<CartBean.DataBean.ListBean> allList = new ArrayList<>(); for (int i=0;i<cartBean.getData().size();i++){ for (int j=0;j<cartBean.getData().get(i).getList().size();j++){ allList.add(cartBean.getData().get(i).getList().get(j)); } } relative_progress.setVisibility(View.VISIBLE); allSize = allList.size(); index = 0; //通过 递归 更新所有子条目的选中 updateAllChild(allList,checked); } /** * 根据全选 跟新所有的子条目 * @param allList * @param checked */ private void updateAllChild(final List<CartBean.DataBean.ListBean> allList, final boolean checked) { CartBean.DataBean.ListBean listBean = allList.get(index);//0 //跟新的操作 //?uid=71&sellerid=1&pid=1&selected=0&num=10 Map<String, String> params = new HashMap<>(); params.put("uid","4084"); params.put("sellerid", String.valueOf(listBean.getSellerid())); params.put("pid", String.valueOf(listBean.getPid())); params.put("selected", String.valueOf(checked ? 1:0)); params.put("num", String.valueOf(listBean.getNum())); OkHttp3Util.doPost(ApiUtil.updateCartUrl, params, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()){ index = index +1;//0,1,2......3 if (index < allSize){ updateAllChild(allList,checked); }else { //查询购物车 cartPresenter.getCartData(ApiUtil.cartUrl); } } } }); } private class GroupHolder{ CheckBox check_group; TextView text_group; } private class ChildHolder{ CheckBox check_child; ImageView image_good; TextView text_title; TextView text_price; TextView text_jian; TextView text_num; TextView text_add; TextView text_delete; }}--------------------------------------public class DingDanStatusActivity extends AppCompatActivity { private List<String> list; private ViewPager vb; private TabLayout tabLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ding_dan_status); tabLayout = (TabLayout) findViewById(tab); vb = (ViewPager) findViewById(R.id.vp); list=new ArrayList<>(); list.add("全部"); list.add("待支付"); list.add("已支付"); list.add("已取消"); runOnUiThread(new Runnable() { @Override public void run() { } }); StatusFragment fragment = new StatusFragment(); Bundle bundle = new Bundle(); bundle.putString("name",list.get(0)); fragment.setArguments(bundle); Log.d("AAAAAA",list.toString()); vb.setOffscreenPageLimit(list.size()); vb.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public CharSequence getPageTitle(int position) { return list.get(position); } @Override public Fragment getItem(int position) { StatusFragment fragment = new StatusFragment(); Bundle bundle = new Bundle(); bundle.putString("name",list.get(position)); fragment.setArguments(bundle); return fragment; } @Override public int getCount() { return list.size(); } }); tabLayout.setupWithViewPager(vb); }}------------------------------------------------public class DongHuaActivity extends AppCompatActivity { private ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_dong_hua); imageView = (ImageView) findViewById(R.id.img); ObjectAnimator y = ObjectAnimator.ofFloat(imageView, "y", 0, 10, 200, 250, 500,600, 800); ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", 0.5f, 2); ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, "scaleY", 0.5f, 2); ObjectAnimator alpha = ObjectAnimator.ofFloat(imageView, "alpha", 2.0f, 1.0f); ObjectAnimator rotationX = ObjectAnimator.ofFloat(imageView, "rotationX", 0, 360); ObjectAnimator rotationY = ObjectAnimator.ofFloat(imageView, "rotationY", 0, 360); AnimatorSet animatorSet = new AnimatorSet(); //设置 /*animatorSet.play(y).before(scaleX); animatorSet.play(scaleX).with(scaleY); animatorSet.play(alpha).with(scaleY); animatorSet.play(rotationX).with(alpha).with(rotationY);*/ animatorSet.play(y).with(scaleX).with(scaleY).with(alpha).with(rotationX); animatorSet.setDuration(3000); animatorSet.start(); animatorSet.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { Intent intent=new Intent(DongHuaActivity.this,ShangPinXiangQingActivity.class); startActivity(intent); DongHuaActivity.this.finish(); } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); }}-------------------------------------------public class MainActivity extends AppCompatActivity implements IMainActivity,View.OnClickListener{ private CartExpanableListview expanableListview; private CartPresenter cartPresenter; private CheckBox check_all; private TextView text_total; private TextView text_buy; private CartBean cartBean; private RelativeLayout relative_progress; private MyAdapter myAdapter; private LinearLayout linear_bottom; private Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { if (msg.what == 0){ countPriceBean = (CountPriceBean) msg.obj; text_total.setText("合计:¥"+ countPriceBean.getPriceString()); text_buy.setText("去结算("+ countPriceBean.getCount()+")"); }else if(msg.what==2) { relative_progress.setVisibility(View.VISIBLE); //请求数据 cartPresenter.getCartData(ApiUtil.cartUrl); } } }; private CountPriceBean countPriceBean; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); check_all = (CheckBox) findViewById(R.id.check_all); text_total = (TextView) findViewById(R.id.text_total); text_buy = (TextView) findViewById(R.id.text_buy); expanableListview = (CartExpanableListview) findViewById(R.id.expanable_listview); relative_progress = (RelativeLayout) findViewById(R.id.relative_progress); linear_bottom = (LinearLayout) findViewById(R.id.linear_layout); //去掉默认的指示器 expanableListview.setGroupIndicator(null); cartPresenter = new CartPresenter(this); //1.点击全选:选中/未选中...调用适配器中的方法...myAdapter.setIsCheckAll(true);来设置所有的一级和二级是否选中,计算 check_all.setOnClickListener(this); text_buy.setOnClickListener(this); } @Override protected void onResume() { super.onResume(); relative_progress.setVisibility(View.VISIBLE); //请求数据 cartPresenter.getCartData(ApiUtil.cartUrl); } @Override public void getSuccessCartData(CartBean cartBean) { relative_progress.setVisibility(View.GONE); this.cartBean = cartBean; if (cartBean != null){ //显示下面的 linear_bottom.setVisibility(View.VISIBLE); //1.根据组中子条目是否选中,,,决定该组是否选中...初始化一下每一组中isGroupCheck这个数据 for (int i = 0;i<cartBean.getData().size();i++){ if (isAllChildInGroupSelected(i)){ //更改i位置 组的选中状态 cartBean.getData().get(i).setGroupChecked(true); } } //2.根据每一个组是否选中的状态,,,初始化全选是否选中 check_all.setChecked(isAllGroupChecked()); //设置适配器 myAdapter = new MyAdapter(MainActivity.this, cartBean,handler,cartPresenter,relative_progress); expanableListview.setAdapter(myAdapter); //展开 for (int i= 0;i<cartBean.getData().size();i++){ expanableListview.expandGroup(i); } //3.根据子条目是否选中 初始化价格和数量 myAdapter.sendPriceAndCount(); }else { //隐藏下面的全选.... 等 linear_bottom.setVisibility(View.GONE); //显示去逛逛,,,添加购物车 Toast.makeText(MainActivity.this,"购物车为空,去逛逛",Toast.LENGTH_SHORT).show(); } } /** * 所有的一级列表是否选中 */ private boolean isAllGroupChecked() { for (int i =0;i<cartBean.getData().size();i++){ if (! cartBean.getData().get(i).isGroupChecked()){//代表一级列表有没选中的 return false; } } return true; } /** * 判断当前组里面所有的子条目是否选中 * @param groupPosition * @return */ private boolean isAllChildInGroupSelected(int groupPosition) { for (int i= 0;i<cartBean.getData().get(groupPosition).getList().size();i++){ //只要有一个没选中就返回false if (cartBean.getData().get(groupPosition).getList().get(i).getSelected() ==0){ return false; } } return true; } @Override public void onClick(View view) { switch (view.getId()){ case R.id.check_all: myAdapter.setAllChildState(check_all.isChecked()); break; case R.id.text_buy://去结算...试一下创建订单 Intent intent = new Intent(MainActivity.this, QueRenOrderActivity.class); intent.putExtra("order",countPriceBean); startActivity(intent); break; } } @Override protected void onDestroy() { super.onDestroy(); if(cartPresenter!=null){ cartPresenter.destroy(); } }}-----------------------------------public class QueRenOrderActivity extends AppCompatActivity { private TextView text_kuai; private TextView text_order; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_que_ren_order); final CountPriceBean countPriceBean= (CountPriceBean) getIntent().getSerializableExtra("order"); text_kuai = (TextView) findViewById(R.id.text_kuan); text_order = (TextView) findViewById(R.id.text_order); text_kuai.setText("实付款:¥"+countPriceBean.getPriceString()); text_order.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { OkHttp3Util.doGet("https://www.zhaoapi.cn/product/createOrder?uid=4084&price=" + countPriceBean.getPriceString(), new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { final String json = response.body().string(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(QueRenOrderActivity.this, json,Toast.LENGTH_SHORT).show(); Intent intent=new Intent(QueRenOrderActivity.this,DingDanStatusActivity.class); startActivity(intent); } }); } }); } }); }}-------------------------------------------public class ShangPinXiangQingActivity extends AppCompatActivity implements XBanner.XBannerAdapter{ private TextView price; private TextView bargainPrice; private TextView name; private ShangPinXiangQingBean shangPinbean; private ImageView vp; private List<ImageView> images; private String uid; private String pid; private XBanner banner_1; private List<String> list; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_shang_pin_xiang_qing); price = (TextView) findViewById(R.id.price); bargainPrice = (TextView) findViewById(R.id.bargainPrice); name = (TextView) findViewById(R.id.name); // vp = (ImageView) findViewById(R.id.vp); banner_1 = (XBanner) findViewById(R.id.banner_1); xingqing(); banner_1.setmAutoPlayAble(false); } //获取网络商品 private void xingqing() { Map<String,String> map=new HashMap<>(); map.put("pid", 37+""); OkHttp3Util.doPost("https://www.zhaoapi.cn/product/getProductDetail", map, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { String json = response.body().string(); shangPinbean = new Gson().fromJson(json, ShangPinXiangQingBean.class); runOnUiThread(new Runnable() { @Override public void run() { String code = shangPinbean.getCode(); if("0".equals(code)) { price.setText(shangPinbean.getData().getPrice()+""); bargainPrice.setText(shangPinbean.getData().getBargainPrice()+""); name.setText(shangPinbean.getData().getTitle()); String[] split = shangPinbean.getData().getImages().split("\\|"); list = new ArrayList<String>(); for (String a: split) { list.add(a); } banner_1.setData(list); runOnUiThread(new Runnable() { @Override public void run() { banner_1.setmAdapter(ShangPinXiangQingActivity.this); } }); // ImageLoader.getInstance().displayImage(shangPinbean.getData().getImages().split("\\|")[0],vp, ImageLoaderUtil.getDefaultOption()); }else { Toast.makeText(ShangPinXiangQingActivity.this, shangPinbean.getMsg(),Toast.LENGTH_SHORT).show(); } } }); } }); } //加入购物车 public void addcar(View view) { Map<String,String> map=new HashMap<>(); map.put("uid",4084+""); map.put("pid",37+""); OkHttp3Util.doPost("https://www.zhaoapi.cn/product/addCart", map, new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { String json = response.body().string(); final JiaBean yonghu = new Gson().fromJson(json, JiaBean.class); runOnUiThread(new Runnable() { @Override public void run() { String code = yonghu.getCode(); if("0".equals(code)) { Toast.makeText(ShangPinXiangQingActivity.this,yonghu.getMsg(),Toast.LENGTH_SHORT).show(); }else { Toast.makeText(ShangPinXiangQingActivity.this,yonghu.getMsg(),Toast.LENGTH_SHORT).show(); } } }); } }); } public void gocar(View view){ Intent intent=new Intent(ShangPinXiangQingActivity.this,MainActivity.class); startActivity(intent); } @Override public void loadBanner(XBanner banner, View view, int position) { Glide.with(ShangPinXiangQingActivity.this).load(list.get(position)).into((ImageView) view); }}
阅读全文
0 0
- 动画播放进购物车再进订单
- 属性动画 购物车 订单列表
- 属性动画+购物车+下订单
- 购物车/订单
- 购物车和订单
- 购物车+订单
- 购物车之订单
- 购物车订单布局
- 购物网站23:FORM----订单
- Angularjs购物车订单强化
- angular购物车增加订单
- angularJS实现购物车订单
- 购物车之订单列表
- 商品详情,购物车,订单
- 购物网站15:订单action---订单分页列表----订单管理----订单信息查看
- 购物网站9:Service订单---订单---订单项
- mvc购物车项目--提交订单并创建订单
- 从订单状态谈电子商务购物体验
- windows下带超时的telnet探测IP和端口
- 依赖
- 多选框选中是否删除,显示错误内容
- 前端页面利用Blob对象创建文件进行下载
- 如何离线安装ansible
- 动画播放进购物车再进订单
- win server 2012 r2 sqlserver 2008 r2 部署
- fsck命令
- Angular 购物车
- 希尔排序 c++实现
- 购物车适配器
- Linux下动态链接库管理
- webservice结合spring实现restful风格
- Tomcat开启APR运行模式,优化并发性能