/** 修改适配器模式 */ private void changeAdapterMode(View v) { if (null != mPullToZoomListView) {} if (null != mDishAdapter) { boolean isSingle = mDishAdapter.getMode().equals(DishDetailAdapter.DISH_MODE_SINGLE); mDishAdapter.setMode( isSingle ? DishDetailAdapter.DISH_MODE_DOUBLE : DishDetailAdapter.DISH_MODE_SINGLE); mTitleBarCategoryLayout .getmOrderByChooseView() .setSwitchImg( isSingle ? R.drawable.app_ic_layout_mode_big : R.drawable.app_ic_layout_mode_small); mCategoryLayout .getmOrderByChooseView() .setSwitchImg( isSingle ? R.drawable.app_ic_layout_mode_big : R.drawable.app_ic_layout_mode_small); mDishAdapter.notifyDataSetChanged(); mAdapter.notifyDataSetChanged(); if (null != mPullToZoomListView && mPullToZoomListView.getAdapter() != null) { if (mDishAdapter.getMode().equals(DishDetailAdapter.DISH_MODE_SINGLE)) { int scrollToPosition = Math.max( 0, (mPullToZoomListView.getFirstVisiblePosition() + mPullToZoomListView.getFirstVisiblePosition() % 2) * 2 - 2); mPullToZoomListView.smoothScrollToPosition( Math.min(scrollToPosition, mPullToZoomListView.getCount() - 1)); } else { int scrollToPosition = Math.max( 0, (mPullToZoomListView.getFirstVisiblePosition() + mPullToZoomListView.getFirstVisiblePosition() % 2) / 2); mPullToZoomListView.smoothScrollToPosition( Math.min(scrollToPosition, mPullToZoomListView.getCount() - 1)); } } } }
@Override public View onCreateView( LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { if (view != null) { return view; } view = inflater.inflate(R.layout.fragment_restaurant_detail, null); mPullToZoomListView = (PullToZoomListView) view.findViewById(R.id.app_restaurant_detail_list); mPullToZoomListView.setHeaderViewSize( ScreenUtils.getScreenWidthInt(), (int) (210f * ScreenUtils.getScreenWidthInt() / 375f)); mPullToZoomListView.setOnListViewZoomListener( new PullToZoomListView.OnListViewZoomListener() { @Override public void onHeaderZoom(float f) { Rect categorySize = ScreenUtils.getViewSize(mCategoryLayout); Rect categoryTitlebarSize = ScreenUtils.getViewSize(mTitleBarCategoryLayout); if (categoryTitlebarSize.top > 0 && categorySize.top > 0) { if (mAnimators.isEmpty()) { mAnimatorDuration = categorySize.top - categoryTitlebarSize.top; defaultAnimationTime = (int) mAnimatorDuration; createAnimation(mAnimatorDuration); } int offset = categorySize.top - categoryTitlebarSize.top; if (offset <= 0) { // 显示 mTitleBarCategoryLayout.setVisibility(View.VISIBLE); mCategoryLayout.relationWith(null); mTitleBarCategoryLayout.relationWith(mCategoryLayout); getTitleBar().enableBottomDiv(true); } else { mTitleBarCategoryLayout.setVisibility(View.GONE); mTitleBarCategoryLayout.relationWith(null); mCategoryLayout.relationWith(mTitleBarCategoryLayout); getTitleBar().enableBottomDiv(false); } updateZoomAnimator(mAnimatorDuration - offset); } } }); mHeadView = mPullToZoomListView.getHeaderView(); mHeadImageView = (ImageView) mHeadView.findViewById(R.id.app_list_head_image); mHeadImageView.setImageResource(R.drawable.app_bg_restaurant); mNoticeView = (FrameLayout) mHeadView.findViewById(R.id.app_list_head_notice); mRestaurantImageView = (ImageView) mHeadView.findViewById(R.id.app_restaurant_detail_image); mScoreCountView = (TextView) mHeadView.findViewById(R.id.app_restaurant_detail_score_title); mScoreDescView = (TextView) mHeadView.findViewById(R.id.app_restaurant_detail_score_desc); mHeadView .findViewById(R.id.app_restaurant_detail_score) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // 用户评论 LogGather.onEventDishRestaurantDetailGoEvaluate(); Bundle bundle = new Bundle(); bundle.putString(DishRestaurantCommentFragment.EXTRA_RESTAURANT_ID, mRestaurantId); next(DishRestaurantCommentFragment.class, bundle); } }); mSaleCountView = (TextView) mHeadView.findViewById(R.id.app_restaurant_detail_sale_title); mHeadView .findViewById(R.id.app_restaurant_detail_sale) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // 热门销量 LogGather.onEventDishRestaurantDetailGoSale(); Bundle bundle = new Bundle(); bundle.putString(DishHotSaleListFragment.EXTRA_RESTAURANT_ID, mRestaurantId); next(DishHotSaleListFragment.class, bundle); } }); mRestaurantNoticeView = view.findViewById(R.id.app_restaurant_detail_notice); mRestaurantNoticeContentView = (TextView) view.findViewById(R.id.app_restaurant_detail_notice_content); mTitleBarCategoryLayout = (DishCategoryView) view.findViewById(R.id.app_restaurant_detail_anchor); mCategoryLayout = (DishCategoryView) inflater.inflate(R.layout.view_category_order, null); mCategoryLayout.relationWith(mTitleBarCategoryLayout); mCategoryLayout.setHandler( new DishCategoryView.OnCategoryOrderHandler() { @Override public void onOrderItemClick(int position) { requestDishList(); } @Override public void onCategoryItemClick(Tags tag) { requestDishList(); } }); int default_menu_icon = default_dish_mode.equals(DishDetailAdapter.DISH_MODE_SINGLE) ? R.drawable.app_ic_layout_mode_small : R.drawable.app_ic_layout_mode_big; mTitleBarCategoryLayout.getmOrderByChooseView().setSwitchImg(default_menu_icon); mCategoryLayout.getmOrderByChooseView().setSwitchImg(default_menu_icon); mTitleBarCategoryLayout .getmOrderByChooseView() .setOnMenuItemClick( new DishOrderByView.OnMenuItemClick() { @Override public void OnClick(View v) { changeAdapterMode(v); } }); mCategoryLayout .getmOrderByChooseView() .setOnMenuItemClick( new DishOrderByView.OnMenuItemClick() { @Override public void OnClick(View v) { changeAdapterMode(v); } }); return view; }