|
|
@@ -1,17 +1,24 @@
|
|
|
package com.modular.booking.activity.services;
|
|
|
|
|
|
+import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
+import android.graphics.drawable.BitmapDrawable;
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
import android.os.Parcelable;
|
|
|
-import android.support.v7.app.ActionBar;
|
|
|
+import android.view.Gravity;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.view.WindowManager;
|
|
|
import android.widget.AbsListView;
|
|
|
import android.widget.AdapterView;
|
|
|
import android.widget.Button;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
+import android.widget.ListView;
|
|
|
+import android.widget.PopupWindow;
|
|
|
import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
@@ -19,7 +26,10 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.common.LogUtil;
|
|
|
import com.common.data.ListUtils;
|
|
|
+import com.common.system.DisplayUtil;
|
|
|
import com.core.base.OABaseActivity;
|
|
|
+import com.core.utils.CommonUtil;
|
|
|
+import com.core.utils.helper.AvatarHelper;
|
|
|
import com.core.widget.CustomerListView;
|
|
|
import com.core.widget.DrawableCenterTextView;
|
|
|
import com.core.widget.PinnedSectionListView;
|
|
|
@@ -33,10 +43,13 @@ import com.modular.booking.activity.utils.ShoppingCart;
|
|
|
import com.modular.booking.activity.utils.ShoppingCartPanel;
|
|
|
import com.modular.booking.adapter.ItemDishCategoryListAdapter;
|
|
|
import com.modular.booking.adapter.ItemDishPinnedListAdapter;
|
|
|
+import com.modular.booking.adapter.LayoutShoppingCartItemAdapter;
|
|
|
import com.modular.booking.model.Product;
|
|
|
import com.modular.booking.model.ProductCategory;
|
|
|
+import com.modular.booking.model.ShoppingEntity;
|
|
|
import com.modular.booking.utils.EventMessage;
|
|
|
import com.modular.booking.utils.RxBus;
|
|
|
+import com.modular.booking.widget.ShoppingCountView;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
@@ -55,6 +68,7 @@ public class DishSelectActivity extends OABaseActivity {
|
|
|
private CircleImageView iv_header;
|
|
|
private TextView tv_title;
|
|
|
private TextView tv_sub;
|
|
|
+ private TextView num_tv;
|
|
|
private BottomSheetLayout mBottmSheetLayout;
|
|
|
private LinearLayout ll_bottom;
|
|
|
private CustomerListView lv_product_category;
|
|
|
@@ -90,16 +104,16 @@ public class DishSelectActivity extends OABaseActivity {
|
|
|
}
|
|
|
|
|
|
private void initView(){
|
|
|
- View view = LayoutInflater.from(ct).inflate(R.layout.action_book_service, null);
|
|
|
- mBackImageView = (ImageView) view.findViewById(R.id.book_service_back);
|
|
|
- mSearchTv = (DrawableCenterTextView) view.findViewById(R.id.book_service_et);
|
|
|
- mRelativeTop = (RelativeLayout) view.findViewById(R.id.book_service_action);
|
|
|
- ActionBar bar = this.getSupportActionBar();
|
|
|
- bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
|
- drawBg = getResources().getDrawable(R.color.antionbarcolor);
|
|
|
- bar.setBackgroundDrawable(drawBg);
|
|
|
- bar.setCustomView(view);
|
|
|
-
|
|
|
+// View view = LayoutInflater.from(ct).inflate(R.layout.action_book_service, null);
|
|
|
+// mBackImageView = (ImageView) view.findViewById(R.id.book_service_back);
|
|
|
+// mSearchTv = (DrawableCenterTextView) view.findViewById(R.id.book_service_et);
|
|
|
+// mRelativeTop = (RelativeLayout) view.findViewById(R.id.book_service_action);
|
|
|
+// ActionBar bar = this.getSupportActionBar();
|
|
|
+// bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
|
+// drawBg = getResources().getDrawable(R.color.antionbarcolor);
|
|
|
+// bar.setBackgroundDrawable(drawBg);
|
|
|
+// bar.setCustomView(view);
|
|
|
+
|
|
|
mShoppingCartPanel = new ShoppingCartPanel(this);
|
|
|
lv_product_category= findViewById(R.id.lv_product_category);
|
|
|
mBottmSheetLayout=findViewById(R.id.bottom_sheet_layout);
|
|
|
@@ -113,6 +127,7 @@ public class DishSelectActivity extends OABaseActivity {
|
|
|
ivShopCar=findViewById(R.id.ivShopCar);
|
|
|
tvShopSure=findViewById(R.id.tvShopSure);
|
|
|
tvTotalPrice=findViewById(R.id.tvTotalPrice);
|
|
|
+ num_tv=findViewById(R.id.num_tv);
|
|
|
|
|
|
itemDishCategoryListAdapter=new ItemDishCategoryListAdapter(DishSelectActivity.this,productCategories);
|
|
|
lv_product_category.setAdapter( itemDishCategoryListAdapter);
|
|
|
@@ -123,11 +138,27 @@ public class DishSelectActivity extends OABaseActivity {
|
|
|
itemDishPinnedListAdapter.setAnimTargetView(ivShopCar);
|
|
|
lv_product.setAdapter(itemDishPinnedListAdapter);
|
|
|
|
|
|
-
|
|
|
+ Intent data=getIntent();
|
|
|
+ if (data!=null) {
|
|
|
+ String sb_imageurl= data.getStringExtra("headImgUrl");
|
|
|
+ String tvsub= data.getStringExtra("tvSub");
|
|
|
+ String tvtitle= data.getStringExtra("tvTitle");
|
|
|
+ getSupportActionBar().setTitle(tvtitle);
|
|
|
+ tv_title.setText(tvtitle);
|
|
|
+ tv_sub.setText(tvsub);
|
|
|
+ AvatarHelper.getInstance().display(sb_imageurl, iv_header, true);
|
|
|
+ AvatarHelper.getInstance().display(sb_imageurl, max_img, true);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
private boolean isClickTrigger=true;
|
|
|
private void initEvent(){
|
|
|
+ mBottmSheetLayout.addOnSheetStateChangeListener(new BottomSheetLayout.OnSheetStateChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void onSheetStateChanged(BottomSheetLayout.State state) {
|
|
|
+ LogUtil.d(TAG,"BottomSheetLayout.State:"+state);
|
|
|
+ }
|
|
|
+ });
|
|
|
tvShopSure.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
@@ -145,6 +176,7 @@ public class DishSelectActivity extends OABaseActivity {
|
|
|
@Override
|
|
|
public void onClick(View view) {
|
|
|
showShoppingCartPanel();
|
|
|
+ //showShopWindow(view);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -194,12 +226,41 @@ public class DishSelectActivity extends OABaseActivity {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-// lv_product.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
-// @Override
|
|
|
-// public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
-//
|
|
|
-// }
|
|
|
-// });
|
|
|
+ lv_product.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
|
+ if (view.getTag() instanceof ItemDishPinnedListAdapter.ItemViewHolder){
|
|
|
+ ItemDishPinnedListAdapter.ItemViewHolder itemViewHolder= (ItemDishPinnedListAdapter.ItemViewHolder) view.getTag();
|
|
|
+ final Product product=itemViewHolder.product;
|
|
|
+ itemViewHolder.img_product_photo.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ showPopupWindow(view,product);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ itemViewHolder.txt_product_name.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ showPopupWindow(view,product);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ itemViewHolder.txt_product_month_sales.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ showPopupWindow(view,product);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ itemViewHolder.txt_product_price.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ showPopupWindow(view,product);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
|
|
|
mSubscription= RxBus.getInstance().toObservable()
|
|
|
@@ -211,6 +272,7 @@ public class DishSelectActivity extends OABaseActivity {
|
|
|
}
|
|
|
|
|
|
private void initData(){
|
|
|
+
|
|
|
HttpClient httpClient=new HttpClient.Builder("http://192.168.253.200:8080/Chapter/").build();
|
|
|
httpClient.Api().send(new HttpClient.Builder()
|
|
|
.url("data/dish")
|
|
|
@@ -268,6 +330,8 @@ public class DishSelectActivity extends OABaseActivity {
|
|
|
// }
|
|
|
}
|
|
|
}));
|
|
|
+
|
|
|
+ refreshBottomUi();
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -300,9 +364,12 @@ public class DishSelectActivity extends OABaseActivity {
|
|
|
double totalPrice = shoppingCart.getTotalPrice();
|
|
|
if (totalCount>0) {
|
|
|
tvTotalPrice.setText("共¥" + totalPrice);
|
|
|
+ num_tv.setVisibility(View.VISIBLE);
|
|
|
+ num_tv.setText(String.valueOf(totalCount));
|
|
|
ivShopCar.setBackgroundResource(R.drawable.icon_shop_car);
|
|
|
ivShopCar.setImageDrawable(getResources().getDrawable(R.drawable.icon_shop_car));
|
|
|
}else{
|
|
|
+ num_tv.setVisibility(View.GONE);
|
|
|
tvTotalPrice.setText(getString(R.string.tv_shop_empty) );
|
|
|
ivShopCar.setBackgroundResource(R.drawable.icon_shop_empty);
|
|
|
ivShopCar.setImageDrawable(getResources().getDrawable(R.drawable.icon_shop_empty));
|
|
|
@@ -317,4 +384,137 @@ public class DishSelectActivity extends OABaseActivity {
|
|
|
mSubscription.unsubscribe();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private PopupWindow popupWindow = null;
|
|
|
+ ImageView ivIconProduct = null;
|
|
|
+ TextView tvDishDesc = null;
|
|
|
+ TextView tvDishName = null;
|
|
|
+ TextView txtProductMonthSales = null;
|
|
|
+ TextView txtProductPrice = null;
|
|
|
+ TextView ptvShopSure = null;
|
|
|
+ ShoppingCountView shopping_count_view=null;
|
|
|
+ public void showPopupWindow(View parent,Product product) {
|
|
|
+ View view = null;
|
|
|
+ WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
|
|
+ if (popupWindow == null) {
|
|
|
+ LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
+ view = layoutInflater.inflate(R.layout.dialog_dish_product, null);
|
|
|
+ ivIconProduct = (ImageView) view.findViewById( R.id.iv_icon_product );
|
|
|
+ tvDishDesc = (TextView)view.findViewById( R.id.tv_dish_desc );
|
|
|
+ tvDishName = (TextView)view.findViewById( R.id.tv_dish_name );
|
|
|
+ txtProductMonthSales = (TextView)view.findViewById( R.id.txt_product_month_sales );
|
|
|
+ txtProductPrice = (TextView)view.findViewById( R.id.txt_product_price );
|
|
|
+ ptvShopSure = (TextView)view.findViewById( R.id.tvShopSure );
|
|
|
+ shopping_count_view=view.findViewById(R.id.shopping_count_view);
|
|
|
+ popupWindow = new PopupWindow(view,
|
|
|
+ windowManager.getDefaultDisplay().getWidth() - CommonUtil.dip2px(mContext,70),
|
|
|
+ LinearLayout.LayoutParams.MATCH_PARENT);
|
|
|
+ }
|
|
|
+ int num= ShoppingCart.getInstance().getQuantityForProduct(product);
|
|
|
+ if (num>0){
|
|
|
+ ptvShopSure.setVisibility(View.GONE);
|
|
|
+ shopping_count_view.setShoppingCount(num);
|
|
|
+ shopping_count_view.setVisibility(View.VISIBLE);
|
|
|
+ }else{
|
|
|
+ ptvShopSure.setVisibility(View.VISIBLE);
|
|
|
+ shopping_count_view.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ AvatarHelper.getInstance().display("http://p0.meituan.net/deal/__16971854__3919079.jpg@380w_214h_1e_1c",ivIconProduct,false);
|
|
|
+ tvDishName.setText(product.getName());
|
|
|
+ txtProductMonthSales.setText("月售0");
|
|
|
+ txtProductPrice.setText("¥"+product.getUnitItems().get(0).getPrice());
|
|
|
+
|
|
|
+ ptvShopSure.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ ptvShopSure.setVisibility(View.GONE);
|
|
|
+ ptvShopSure.setEnabled(false);
|
|
|
+ if (!ShoppingCart.getInstance().add(product)) {
|
|
|
+ }
|
|
|
+ shopping_count_view.setShoppingCount(1);
|
|
|
+ shopping_count_view.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ shopping_count_view.setOnShoppingClickListener(new ShoppingCountView.ShoppingClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onAddClick(int num) {
|
|
|
+ if (!ShoppingCart.getInstance().add(product)) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onMinusClick(int num) {
|
|
|
+ if (!ShoppingCart.getInstance().delete(product)) {
|
|
|
+ }
|
|
|
+ if (num==0){
|
|
|
+ new Handler().postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ ptvShopSure.setVisibility(View.VISIBLE);
|
|
|
+ ptvShopSure.setEnabled(true);
|
|
|
+ shopping_count_view.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ },10);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ tvDishDesc.setText(product.getName());
|
|
|
+ popupWindow.setFocusable(true);
|
|
|
+ popupWindow.setOutsideTouchable(true);
|
|
|
+ popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ DisplayUtil.backgroundAlpha(activity, 1f);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ DisplayUtil.backgroundAlpha(this, 0.5f);
|
|
|
+ popupWindow.setBackgroundDrawable(new BitmapDrawable());
|
|
|
+ popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
+ // 显示的位置为:屏幕的宽度的一半-PopupWindow的高度的一半
|
|
|
+ // popupWindow.showAsDropDown(parent, windowManager.getDefaultDisplay().getWidth(), 0);
|
|
|
+ popupWindow .showAtLocation(activity.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private PopupWindow pListWindow = null;
|
|
|
+ TextView mClearTxt;
|
|
|
+ ListView lv_data;
|
|
|
+ LayoutShoppingCartItemAdapter layoutShoppingCartItemAdapter;
|
|
|
+ public void showShopWindow(View parent){
|
|
|
+ View view = null;
|
|
|
+ WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
|
|
+ if (pListWindow == null) {
|
|
|
+ LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
+ view = layoutInflater.inflate(R.layout.layout_shopping_cart_panel, null);
|
|
|
+ mClearTxt=view.findViewById(R.id.txt_clear);
|
|
|
+ lv_data=view.findViewById(R.id.lv_data);
|
|
|
+ layoutShoppingCartItemAdapter=new LayoutShoppingCartItemAdapter(mContext);
|
|
|
+ lv_data.setAdapter(layoutShoppingCartItemAdapter);
|
|
|
+ pListWindow= new PopupWindow(view,
|
|
|
+ windowManager.getDefaultDisplay().getWidth(),
|
|
|
+ windowManager.getDefaultDisplay().getHeight()/2);
|
|
|
+
|
|
|
+ }
|
|
|
+ ShoppingCart shoppingCart = ShoppingCart.getInstance();
|
|
|
+ List<ShoppingEntity> entities = shoppingCart.getShoppingList();
|
|
|
+ LogUtil.d("ShopCar", "面板data:"+JSON.toJSONString(entities));
|
|
|
+ layoutShoppingCartItemAdapter.setItems(entities);
|
|
|
+ pListWindow.setFocusable(true);
|
|
|
+ pListWindow.setOutsideTouchable(true);
|
|
|
+ pListWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
+ @Override
|
|
|
+ public void onDismiss() {
|
|
|
+ DisplayUtil.backgroundAlpha(activity, 1f);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ DisplayUtil.backgroundAlpha(this, 0.5f);
|
|
|
+ pListWindow.setBackgroundDrawable(new BitmapDrawable());
|
|
|
+ pListWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
+ // 显示的位置为:屏幕的宽度的一半-PopupWindow的高度的一半
|
|
|
+ pListWindow.showAsDropDown(parent, windowManager.getDefaultDisplay().getWidth(), 0);
|
|
|
+ }
|
|
|
+
|
|
|
}
|