|
|
|
@ -47,32 +47,28 @@ public class ShoppingCartFragment extends Fragment implements View.OnClickListen
|
|
|
|
|
private ProductFragment productFragment;
|
|
|
|
|
private GridView productGridView;
|
|
|
|
|
private TextView usernameText;
|
|
|
|
|
ImageView left_l,right_r;
|
|
|
|
|
ImageView left_l,right_r,delete;
|
|
|
|
|
private RecyclerView recyclerView;
|
|
|
|
|
CheckBox checkBox;
|
|
|
|
|
int listNum=0;
|
|
|
|
|
private Integer userId=13;
|
|
|
|
|
private List<CatProductPack> catProductList= new ArrayList<>();
|
|
|
|
|
Handler h=null;
|
|
|
|
|
public ShopAdapter shopAdapter=null;
|
|
|
|
|
static int o;
|
|
|
|
|
private boolean isGetData = false;
|
|
|
|
|
CheckBox checkBox;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
//给购物车集合赋值,用以判断界面的展示
|
|
|
|
|
cartList=IndexActivity.cartList;
|
|
|
|
|
Log.d("ShoppingCartFragment onCrate init cartList",""+cartList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
|
@Override
|
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
|
View view;
|
|
|
|
|
cartList=IndexActivity.cartList;
|
|
|
|
|
Log.d("cartList---------",""+cartList.size());
|
|
|
|
|
if (cartList.size() > 0) {
|
|
|
|
|
if(IndexActivity.cartList!=null)
|
|
|
|
|
listNum=IndexActivity.cartList.size();
|
|
|
|
|
if (listNum > 0) {
|
|
|
|
|
//有商品
|
|
|
|
|
view = LayoutInflater.from(getActivity()).inflate(R.layout.cart_have_product, container, false);
|
|
|
|
|
linkHttp(view);
|
|
|
|
@ -88,10 +84,10 @@ public class ShoppingCartFragment extends Fragment implements View.OnClickListen
|
|
|
|
|
*/
|
|
|
|
|
private void init(View view) {
|
|
|
|
|
usernameText=view.findViewById(R.id.username);
|
|
|
|
|
checkBox=view.findViewById(R.id.checkbox);
|
|
|
|
|
productGridView = view.findViewById(R.id.cart_productList);
|
|
|
|
|
if (cartList.size() > 0) {
|
|
|
|
|
|
|
|
|
|
if (listNum > 0) {
|
|
|
|
|
productGridView = view.findViewById(R.id.cart_productList);
|
|
|
|
|
checkBox=view.findViewById(R.id.checkbox);
|
|
|
|
|
delete=view.findViewById(R.id.delete);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
walkButton = view.findViewById(R.id.random_search);
|
|
|
|
@ -101,32 +97,31 @@ public class ShoppingCartFragment extends Fragment implements View.OnClickListen
|
|
|
|
|
}
|
|
|
|
|
private void setData() {
|
|
|
|
|
Bundle bundle = getArguments();
|
|
|
|
|
// usernameText.setText(String.format("用户名:%s", bundle.getString("username")));
|
|
|
|
|
usernameText.setText(String.format("用户名:%s", bundle.getString("username")));
|
|
|
|
|
userId=(Integer)bundle.getInt("id");
|
|
|
|
|
System.out.println(userId);
|
|
|
|
|
}
|
|
|
|
|
// @Override
|
|
|
|
|
// public void onClick(View v) {
|
|
|
|
|
// if (cartList.size() > 0) {
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// else {
|
|
|
|
|
// switch (v.getId()) {
|
|
|
|
|
// case R.id.random_search:
|
|
|
|
|
// //开启事务,fragment的控制是由事务来实现的
|
|
|
|
|
// FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
|
|
|
|
// if (productFragment == null) {
|
|
|
|
|
// Bundle bundle = getArguments();
|
|
|
|
|
// productFragment.setArguments(bundle);
|
|
|
|
|
// productFragment = new ProductFragment();
|
|
|
|
|
// bundle.putInt("id",userId);
|
|
|
|
|
// }
|
|
|
|
|
// transaction.replace(R.id.main_content0, productFragment);
|
|
|
|
|
// transaction.commit();
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
if (listNum > 0) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
switch (v.getId()) {
|
|
|
|
|
case R.id.random_search:
|
|
|
|
|
//开启事务,fragment的控制是由事务来实现的
|
|
|
|
|
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
|
|
|
|
if (productFragment == null) {
|
|
|
|
|
productFragment = new ProductFragment();
|
|
|
|
|
Bundle bundle = getArguments();
|
|
|
|
|
productFragment.setArguments(bundle);
|
|
|
|
|
bundle.putInt("id",userId);
|
|
|
|
|
}
|
|
|
|
|
transaction.replace(R.id.main_content0, productFragment);
|
|
|
|
|
transaction.commit();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -143,34 +138,8 @@ public class ShoppingCartFragment extends Fragment implements View.OnClickListen
|
|
|
|
|
// recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false));
|
|
|
|
|
// shopAdapter=new ShopAdapter(getActivity(),catProductList,cartList);
|
|
|
|
|
// recyclerView.setAdapter(shopAdapter);
|
|
|
|
|
ShoppingCartAdapter shoppingCartAdapter=new ShoppingCartAdapter(getActivity(),catProductList,cartList);
|
|
|
|
|
ShoppingCartAdapter shoppingCartAdapter=new ShoppingCartAdapter(getActivity(),catProductList,cartList,userId);
|
|
|
|
|
productGridView.setAdapter(shoppingCartAdapter);
|
|
|
|
|
|
|
|
|
|
productGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
|
Bundle bundle = getArguments();
|
|
|
|
|
//usernameText.setText(String.format("用户名:%s", bundle.getString("username")));
|
|
|
|
|
int i=(Integer)bundle.getInt("id");
|
|
|
|
|
int p=cartList.get(position).getId();
|
|
|
|
|
System.out.println(""+1111111+"----"+p+"---"+i);
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
@SuppressLint("HandlerLeak")
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
OkHttpShoppingcart okHttpShoppingcart=new OkHttpShoppingcart();
|
|
|
|
|
try {
|
|
|
|
|
okHttpShoppingcart.deleteShoppingCart(i,p);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}).start();
|
|
|
|
|
Toast.makeText(getContext(), "delete", Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
@ -179,12 +148,12 @@ public class ShoppingCartFragment extends Fragment implements View.OnClickListen
|
|
|
|
|
public void run() {
|
|
|
|
|
OkHttpShoppingcart okHttpShoppingcart=new OkHttpShoppingcart();
|
|
|
|
|
try {
|
|
|
|
|
// recyclerView=view.findViewById(R.id.recyclerview);
|
|
|
|
|
productGridView = view.findViewById(R.id.cart_productList);
|
|
|
|
|
left_l=view.findViewById(R.id.left);
|
|
|
|
|
right_r=view.findViewById(R.id.right);
|
|
|
|
|
catProductList= okHttpShoppingcart.getProductPack(userId);
|
|
|
|
|
cartList=okHttpShoppingcart.getShoppingCartPack(userId);
|
|
|
|
|
IndexActivity.cartList=cartList;
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
@ -194,9 +163,21 @@ public class ShoppingCartFragment extends Fragment implements View.OnClickListen
|
|
|
|
|
}).start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
|
|
public void onDestroyView() {
|
|
|
|
|
super.onDestroyView();
|
|
|
|
|
//Log.d("Destroy","--------Destroy shoppingcart fragment");
|
|
|
|
|
}
|
|
|
|
|
public void refreshData(){
|
|
|
|
|
ShoppingCartFragment shoppingCartFragment=new ShoppingCartFragment();
|
|
|
|
|
FragmentTransaction transaction = getFragmentManager().beginTransaction();
|
|
|
|
|
if (shoppingCartFragment == null) {
|
|
|
|
|
shoppingCartFragment = new ShoppingCartFragment();
|
|
|
|
|
}
|
|
|
|
|
Bundle bundle = getArguments();
|
|
|
|
|
shoppingCartFragment.setArguments(bundle);
|
|
|
|
|
bundle.putInt("id",userId);
|
|
|
|
|
transaction.replace(R.id.main_content0, shoppingCartFragment);
|
|
|
|
|
transaction.commit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|