Commit 21ce32a3 by llxqb

购物车界面-部分

parent c9af29b6
......@@ -2,57 +2,135 @@ package com.freemud.app.facepay;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.freemud.app.facepay.adapter.CartGoodsAdapter;
import com.freemud.app.facepay.adapter.ShoppingBagAdapter;
import com.freemud.app.facepay.entity.Goods;
import com.freemud.app.facepay.entity.ShoppingBag;
import com.freemud.app.facepay.views.CustomPopWindow;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
public static String TAG = "MainActivity";
private RecyclerView mMainRecyclerView;
private CartGoodsAdapter mCartGoodsAdapter;
private List<Goods> mGoodsList;
private LinearLayout mMainLlAddbag;
private CustomPopWindow mCustomPopWindow;
private List<ShoppingBag> shoppingBagList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_goods);
initView();
initData();
initRecycler();
}
private void initView() {
TextView mCommonTvLeft = findViewById(R.id.common_tv_left);
TextView mMainBarcodeHands = findViewById(R.id.main_barcode_hands);
mMainRecyclerView = findViewById(R.id.main_recyclerView);
LinearLayout mMainLlAddbag = findViewById(R.id.main_ll_addbag);
mMainLlAddbag = findViewById(R.id.main_ll_addbag);
mCommonTvLeft.setOnClickListener(v -> {
});
mMainBarcodeHands.setOnClickListener(v -> {
});
mMainLlAddbag.setOnClickListener(v -> {
mCommonTvLeft.setOnClickListener(this);
mMainBarcodeHands.setOnClickListener(this);
mMainLlAddbag.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.common_tv_left://退出
Toast.makeText(MainActivity.this, "退出", Toast.LENGTH_SHORT).show();
break;
case R.id.main_barcode_hands://手动输入条形码
break;
case R.id.main_ll_addbag://添加购物袋
initPopWindow(v);
break;
}
}
private void initPopWindow(View view) {
initBagData();
View contentView = LayoutInflater.from(this).inflate(R.layout.popwindow_bag, null);
//处理popWindow 显示内容
handleListView(contentView);
//创建并显示popWindow
mCustomPopWindow = new CustomPopWindow.PopupWindowBuilder(this)
.setView(contentView)
.enableBackgroundDark(true)
// .size(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)//显示大小
.create();
mCustomPopWindow.showAsDropDown(mMainLlAddbag, 40, -(mMainLlAddbag.getHeight() + mCustomPopWindow.getHeight() + 60));
}
private void initBagData() {
shoppingBagList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
ShoppingBag shoppingBag = new ShoppingBag();
if (i == 0) {
shoppingBag.name = "小号购物袋";
shoppingBag.price = 0.2;
}
if (i == 1) {
shoppingBag.name = "中号购物袋";
shoppingBag.price = 0.30;
}
if (i == 2) {
shoppingBag.name = "大号购物袋";
shoppingBag.price = 0.40;
}
shoppingBagList.add(shoppingBag);
}
}
private void handleListView(View contentView) {
RecyclerView recyclerView = contentView.findViewById(R.id.item_popwindow_recyclerView);
LinearLayoutManager manager = new LinearLayoutManager(this);
manager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(manager);
recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
ShoppingBagAdapter mShoppingBagAdapter = new ShoppingBagAdapter(shoppingBagList);
recyclerView.setAdapter(mShoppingBagAdapter);
mShoppingBagAdapter.setOnItemClickListener((adapter, view, position) -> {
ShoppingBag shoppingBag = (ShoppingBag) adapter.getItem(position);
if (shoppingBag != null) {
Toast.makeText(MainActivity.this, "item" + position, Toast.LENGTH_SHORT).show();
}
});
}
private void initData() {
mGoodsList = new ArrayList<>();
for (int i = 0; i < 10; i++) {
for (int i = 1; i <= 10; i++) {
Goods goods = new Goods();
goods.name = "养生大宝粥" + i + "味";
goods.originalPrice = 8.90;
......@@ -66,6 +144,30 @@ public class MainActivity extends AppCompatActivity {
mMainRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mCartGoodsAdapter = new CartGoodsAdapter(mGoodsList);
mMainRecyclerView.setAdapter(mCartGoodsAdapter);
mCartGoodsAdapter.setOnItemChildClickListener((adapter, view, position) -> {
Goods goods = (Goods) adapter.getItem(position);
if (goods != null) {
switch (view.getId()) {
case R.id.item_cartgoods_btn_delete:
Toast.makeText(MainActivity.this, "已删除", Toast.LENGTH_SHORT).show();
adapter.remove(position);
break;
case R.id.item_cartgoods_iv_reduceNum:
if (goods.count > 1) {
goods.count--;
mCartGoodsAdapter.setData(position, goods);
} else {
Toast.makeText(MainActivity.this, "商品数量不能小于1", Toast.LENGTH_SHORT).show();
}
break;
case R.id.item_cartgoods_iv_addNum:
goods.count++;
mCartGoodsAdapter.setData(position, goods);
break;
}
}
});
}
......@@ -74,4 +176,5 @@ public class MainActivity extends AppCompatActivity {
context.startActivity(intent);
}
}
......@@ -7,6 +7,7 @@ import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.freemud.app.facepay.R;
import com.freemud.app.facepay.entity.Goods;
import com.freemud.app.facepay.utils.ValueUtil;
import java.util.List;
......@@ -25,8 +26,11 @@ public class CartGoodsAdapter extends BaseQuickAdapter<Goods, BaseViewHolder> {
protected void convert(BaseViewHolder holder, Goods goods) {
if (goods == null) return;
holder.setText(R.id.item_cartgoods_tv_name, goods.name);
holder.setText(R.id.item_cartgoods_tv_originalPrice, String.valueOf(goods.originalPrice));
holder.setText(R.id.item_cartgoods_tv_discountPrice, String.valueOf(goods.discountPrice));
holder.setText(R.id.item_cartgoods_tv_originalPrice, "¥" + ValueUtil.getDoublle(goods.originalPrice));
holder.setText(R.id.item_cartgoods_tv_discountPrice, "¥" + ValueUtil.getDoublle(goods.discountPrice));
holder.setText(R.id.item_cartgoods_tv_num, goods.count != 0.0 ? String.valueOf(goods.count) : String.valueOf(0));
holder.addOnClickListener(R.id.item_cartgoods_btn_delete).addOnClickListener(R.id.item_cartgoods_iv_reduceNum)
.addOnClickListener(R.id.item_cartgoods_iv_addNum);
}
}
package com.freemud.app.facepay.adapter;
import android.support.annotation.Nullable;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.freemud.app.facepay.R;
import com.freemud.app.facepay.entity.Goods;
import com.freemud.app.facepay.entity.ShoppingBag;
import com.freemud.app.facepay.utils.ValueUtil;
import java.util.List;
/**
* Created by li.liu on 2018/4/10.
* ShoppingBagAdapter 加载数据
*/
public class ShoppingBagAdapter extends BaseQuickAdapter<ShoppingBag, BaseViewHolder> {
public ShoppingBagAdapter(@Nullable List<ShoppingBag> data) {
super(R.layout.item_adapter_popwindow_bag, data);
}
@Override
protected void convert(BaseViewHolder holder, ShoppingBag shoppingBag) {
if (shoppingBag == null) return;
holder.setText(R.id.item_bag_name, shoppingBag.name);
holder.setText(R.id.item_bag_price, "¥" + ValueUtil.getDoublle(shoppingBag.price));
}
}
package com.freemud.app.facepay.entity;
/**
* Created by li.liu on 2018/8/13.
* 购物袋 实体
*/
public class ShoppingBag {
public String name;
public double price;
}
package com.freemud.app.facepay.utils;
/**
* Created by li.liu on 2018/8/13.
*/
public class ValueUtil {
/**
* 把数字转换为2位小数格式
*/
public static String getDoublle(double s) {
if (s == 0) {
return "0.00";
}
return String.format("%.2f", s);
}
}
......@@ -4,18 +4,16 @@
<item android:state_pressed="true">
<shape>
<solid android:color="@color/main_gopay_pressed" />
<corners android:radius="2dp" />
<corners android:radius="4dp" />
</shape>
<corners android:radius="2dp" />
</item>
<!-- 普通状态 -->
<item android:state_pressed="false">
<shape android:shape="rectangle">
<!--android:endColor="@color/write" android:startColor="@color/write" -->
<gradient android:angle="270" android:endColor="@color/main_gopay_normal" android:startColor="@color/main_gopay_normal" android:type="linear" />
<corners android:radius="2dp" />
<corners android:radius="4dp" />
</shape>
<corners android:radius="2dp" />
</item>
<!-- 禁用状态 -->
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="4dp" />
<solid android:color="@color/colorFA" />
<stroke
android:width="1dp"
android:color="@color/colorFA" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.freemud.app.facepay.views.SwipeMenuView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/height_130px"
android:paddingEnd="@dimen/height_30px"
android:paddingStart="@dimen/height_30px">
android:layout_height="@dimen/height_130px">
<LinearLayout
android:id="@+id/item_cartgoods_ll_num"
android:layout_width="wrap_content"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:gravity="center"
android:orientation="horizontal">
android:paddingEnd="@dimen/height_30px"
android:paddingStart="@dimen/height_30px">
<ImageView
android:id="@+id/item_cartgoods_iv_reduceNum"
android:layout_width="@dimen/height_44px"
android:layout_height="@dimen/height_44px"
android:src="@drawable/reduce_normal" />
<TextView
android:id="@+id/item_cartgoods_tv_num"
<LinearLayout
android:id="@+id/item_cartgoods_ll_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/height_28px"
android:layout_marginStart="@dimen/height_28px"
android:text="1"
android:textColor="@color/color4D"
android:textSize="@dimen/sp_30px" />
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/item_cartgoods_iv_addNum"
android:layout_width="@dimen/height_44px"
android:layout_height="@dimen/height_44px"
android:src="@drawable/add_normal" />
</LinearLayout>
<ImageView
android:id="@+id/item_cartgoods_iv_reduceNum"
android:layout_width="@dimen/height_44px"
android:layout_height="@dimen/height_44px"
android:src="@drawable/reduce_normal" />
<TextView
android:id="@+id/item_cartgoods_tv_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/height_28px"
android:layout_marginStart="@dimen/height_28px"
android:text="1"
android:textColor="@color/color4D"
android:textSize="@dimen/sp_30px" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/height_30px"
android:layout_toStartOf="@id/item_cartgoods_ll_num"
android:gravity="center_vertical">
<ImageView
android:id="@+id/item_cartgoods_iv_addNum"
android:layout_width="@dimen/height_44px"
android:layout_height="@dimen/height_44px"
android:src="@drawable/add_normal" />
</LinearLayout>
<TextView
android:id="@+id/item_cartgoods_tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:text="养生大保粥C味"
android:textColor="@color/black"
android:textSize="@dimen/sp_30px" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/height_30px"
android:layout_toStartOf="@id/item_cartgoods_ll_num"
android:gravity="center_vertical">
<TextView
android:id="@+id/item_cartgoods_tv_discountPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/item_cartgoods_tv_name"
android:layout_marginTop="@dimen/height_10px"
android:singleLine="true"
android:text="¥6.20"
android:textColor="@color/app_color"
android:textSize="@dimen/sp_30px" />
<TextView
android:id="@+id/item_cartgoods_tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:textColor="@color/black"
android:textSize="@dimen/sp_30px" />
<TextView
android:id="@+id/item_cartgoods_tv_originalPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/item_cartgoods_tv_name"
android:layout_marginStart="@dimen/height_10px"
android:layout_marginTop="@dimen/height_16px"
android:layout_toEndOf="@id/item_cartgoods_tv_discountPrice"
android:text="¥6.80"
android:textColor="@color/colorAAA"
android:textSize="@dimen/sp_20px" />
</RelativeLayout>
<TextView
android:id="@+id/item_cartgoods_tv_discountPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/item_cartgoods_tv_name"
android:layout_marginTop="@dimen/height_10px"
android:singleLine="true"
android:textColor="@color/app_color"
android:textSize="@dimen/sp_30px" />
<TextView
android:id="@+id/item_cartgoods_tv_originalPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/item_cartgoods_tv_name"
android:layout_marginStart="@dimen/height_10px"
android:layout_marginTop="@dimen/height_20px"
android:layout_toEndOf="@id/item_cartgoods_tv_discountPrice"
android:textColor="@color/colorAAA"
android:textSize="@dimen/sp_20px" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.4dp"
android:layout_alignParentBottom="true"
android:background="@color/line_color" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.4dp"
android:layout_alignParentBottom="true"
android:background="@color/line_color" />
</RelativeLayout>
<Button
android:id="@+id/item_cartgoods_btn_delete"
android:layout_width="@dimen/height_140px"
android:layout_height="match_parent"
android:background="@color/item_cartgoods_delete_bg"
android:text="@string/item_cartgoods_delete"
android:textColor="@android:color/white" />
</com.freemud.app.facepay.views.SwipeMenuView>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/height_188px"
android:layout_height="@dimen/height_100px"
android:layout_margin="@dimen/height_8px"
android:background="@drawable/app_btn_main_click_selector"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/item_bag_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/color4C"
android:textSize="@dimen/sp_26px" />
<TextView
android:id="@+id/item_bag_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/color4C"
android:textSize="@dimen/sp_26px" />
</LinearLayout >
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/item_popwindow_recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/app_popwindow_bg" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SwipeMenuView">
<attr name="swipeEnable" format="boolean"/>
<attr name="ios" format="boolean"/>
<attr name="leftSwipe" format="boolean"/>
</declare-styleable>
</resources>
......@@ -16,6 +16,7 @@
<color name="colorAAA">#AAAAAA</color>
<color name="colorF7">#F7F7F7</color>
<color name="colorF8">#F8F8F8</color>
<color name="colorFA">#FAFAFA</color>
<color name="colorDE">#DEDEDE</color>
<color name="app_gray">#F1F1F1</color>
<color name="hint_red_color">#F76260</color>
......@@ -23,5 +24,7 @@
<color name="line_color">#E5E5E5</color>
<color name="color4D">#4D4D4D</color>
<color name="colorD2">#D2D2D2</color>
<color name="color4C">#4C4C4C</color>
<color name="item_cartgoods_pressed_bg">#F2F7F2</color>
<color name="item_cartgoods_delete_bg">#F12C20</color>
</resources>
......@@ -41,6 +41,7 @@
<dimen name="height_86px">43dp</dimen>
<dimen name="height_88px">44dp</dimen>
<dimen name="height_90px">45dp</dimen>
<dimen name="height_92px">46dp</dimen>
<dimen name="height_100px">50dp</dimen>
<dimen name="height_102px">51dp</dimen>
<dimen name="height_114px">57dp</dimen>
......@@ -49,15 +50,19 @@
<dimen name="height_128px">64dp</dimen>
<dimen name="height_130px">65dp</dimen>
<dimen name="height_140px">70dp</dimen>
<dimen name="height_150px">75dp</dimen>
<dimen name="height_160px">80dp</dimen>
<dimen name="height_172px">86dp</dimen>
<dimen name="height_173px">86.5dp</dimen>
<dimen name="height_174px">87dp</dimen>
<dimen name="height_180px">90dp</dimen>
<dimen name="height_188px">94dp</dimen>
<dimen name="height_240px">120dp</dimen>
<dimen name="height_220px">110dp</dimen>
<dimen name="height_270px">135dp</dimen>
<dimen name="height_210px">105dp</dimen>
<dimen name="height_216px">108dp</dimen>
<dimen name="height_282px">141dp</dimen>
<dimen name="height_300px">150dp</dimen>
<dimen name="height_310px">155dp</dimen>
<dimen name="height_326px">163dp</dimen>
......
......@@ -25,6 +25,8 @@
<!--main-->
<string name="main_hint_title">请在下方扫描区扫描商品条码</string>
<string name="main_barcode_hands">扫描有问题?手动输条码</string>
<string name="item_popwindow_small_bag">小号购物袋</string>
<string name="item_cartgoods_delete">删除</string>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment