diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpActivity.java index 42e9bb7b..ea639a7e 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CpActivity.java @@ -1,13 +1,29 @@ package com.bonait.bnframework.modules.home.fragment.from; +import static com.bonait.bnframework.MainApplication.getContext; + import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v7.widget.GridLayoutManager; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.view.View; +import android.view.ViewGroup; +import android.view.animation.AnimationUtils; import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseActivity; +import com.bonait.bnframework.common.utils.ToastUtils; +import com.bonait.bnframework.modules.home.fragment.mode.QDListSectionAdapter; +import com.bonait.bnframework.modules.home.fragment.mode.SectionHeader; +import com.bonait.bnframework.modules.home.fragment.mode.SectionItem; import com.orhanobut.logger.Logger; import com.qmuiteam.qmui.widget.QMUITopBar; +import com.qmuiteam.qmui.widget.section.QMUISection; +import com.qmuiteam.qmui.widget.section.QMUIStickySectionAdapter; +import com.qmuiteam.qmui.widget.section.QMUIStickySectionLayout; + +import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; @@ -17,6 +33,11 @@ public class CpActivity extends BaseActivity { @BindView(R.id.topbar) QMUITopBar mTopBar; + @BindView(R.id.qmuisection_layout) + QMUIStickySectionLayout mSectionLayout; + private RecyclerView.LayoutManager mLayoutManager; + protected static QMUIStickySectionAdapter mAdapter; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -24,11 +45,106 @@ public class CpActivity extends BaseActivity { //属性绑定 ButterKnife.bind(this); initTopBar(); + initAdapter(); + initAdapterLogicalOperation(); + } + + private void initAdapter() { + mLayoutManager = createLayoutManager(); + mSectionLayout.setLayoutManager(mLayoutManager); + mAdapter = createAdapter(); + //mSectionLayout.setAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.aword_fade_enter)); + } + + private void initAdapterLogicalOperation() { + mAdapter.setCallback(new QMUIStickySectionAdapter.Callback() { + @Override + public void loadMore(final QMUISection section, final boolean loadMoreBefore) { + } + + //点击事件 + @Override + public void onItemClick(QMUIStickySectionAdapter.ViewHolder holder, int position) { + if (holder.getItemViewType() != 1) { + int pos = holder.isForStickyHeader ? position : holder.getAdapterPosition(); + mAdapter.toggleFold(pos, false); + } + ToastUtils.info(mAdapter.getItemIndex(position)+""); + } + + //长按事件 + @Override + public boolean onItemLongClick(QMUIStickySectionAdapter.ViewHolder holder, int position) { + int FirstPos = mAdapter.getSectionIndex(position); + int SecondPos = mAdapter.getItemIndex(position); + //ItemPopupWindow.show(getContext(), holder.itemView, holder.getItemViewType(), FirstPos, SecondPos); + ToastUtils.info("一级条目" +FirstPos+ "二级"+ SecondPos); + return true; + } + }); + mSectionLayout.setAdapter(mAdapter, true); + mAdapter.setData(getList()); + } + + protected QMUIStickySectionAdapter createAdapter() { + return new QDListSectionAdapter(); + } + + protected RecyclerView.LayoutManager createLayoutManager() { +// return new LinearLayoutManager(getContext()) { +// @Override +// public RecyclerView.LayoutParams generateDefaultLayoutParams() { +// return new RecyclerView.LayoutParams( +// ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); +// } +// }; + final GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 3); + layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { + @Override + public int getSpanSize(int i) { + return mAdapter.getItemIndex(i) < 0 ? layoutManager.getSpanCount() : 1; + } + }); + return layoutManager; + } + + private static ArrayList> getList() { + ArrayList> list = new ArrayList<>(); + + int n = 0; + SectionHeader header = new SectionHeader("本地菜谱","",""); + ArrayList contents = new ArrayList<>(); + for (int j = 0; j < 20/* 二级条目辅助数据*/; j++) { + contents.add(new SectionItem("回锅肉"+j, "185" + n, "",j%4==0)); + n++; + } + QMUISection section = new QMUISection<>(header, contents, false); + list.add(section); + + + header = new SectionHeader("收藏菜谱","",""); + contents = new ArrayList<>(); + for (int j = 0; j < 20/* 二级条目辅助数据*/; j++) { + contents.add(new SectionItem("回锅肉"+j, "185" + n, "",j%4==0)); + n++; + } + section = new QMUISection<>(header, contents, true); + list.add(section); + + header = new SectionHeader("云端菜谱","",""); + contents = new ArrayList<>(); + for (int j = 0; j < 20/* 二级条目辅助数据*/; j++) { + contents.add(new SectionItem("回锅肉"+j, "185" + n, "",j%4==0)); + n++; + } + section = new QMUISection<>(header, contents, true); + list.add(section); + return list; } private void initTopBar() { mTopBar.setTitle("菜谱管理"); - mTopBar.addLeftImageButton(R.mipmap.fanhui,R.id.topbar).setOnClickListener(new View.OnClickListener() { + mTopBar.addLeftImageButton(R.mipmap.fanhui, R.id.topbar).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { finish(); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/QDListSectionAdapter.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/QDListSectionAdapter.java new file mode 100644 index 00000000..0b63df9e --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/QDListSectionAdapter.java @@ -0,0 +1,108 @@ +package com.bonait.bnframework.modules.home.fragment.mode; + + +import android.content.Context; +import android.support.annotation.NonNull; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.common.utils.ToastUtils; +import com.qmuiteam.qmui.widget.section.QMUIDefaultStickySectionAdapter; +import com.qmuiteam.qmui.widget.section.QMUISection; + +public class QDListSectionAdapter extends QMUIDefaultStickySectionAdapter { + private TextView tvTag ,tvNote,tvAccount,Sc_text,delete_text; + + private RelativeLayout ImageUrl;//图片 + + private ImageView sc_image;//是否收藏 + + public boolean IsSC=false; + + @NonNull + @Override + protected ViewHolder onCreateSectionHeaderViewHolder(@NonNull ViewGroup viewGroup) { + return new ViewHolder(new QDSectionHeaderView(viewGroup.getContext())); + } + public QDListSectionAdapter() { + } + + @Override + protected void onBindSectionHeader(final ViewHolder holder, final int position, QMUISection section) { + + QDSectionHeaderView itemView = (QDSectionHeaderView) holder.itemView; + itemView.render((SectionHeader) section.getHeader(), section.isFold()); + //点击事件 + itemView.getArrowView().setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + int pos = holder.isForStickyHeader ? position : holder.getAdapterPosition(); + toggleFold(pos, false); + } + }); + } + + @Override + protected void onBindSectionItem(ViewHolder holder, int position, QMUISection section, int itemIndex) { + //获取id + tvTag = holder.itemView.findViewById(R.id.Tag_text); + tvNote = holder.itemView.findViewById(R.id.Note_text); + Sc_text = holder.itemView.findViewById(R.id.Sc_text); + delete_text = holder.itemView.findViewById(R.id.delete_text); + sc_image=holder.itemView.findViewById(R.id.sc_image);//收藏 + ImageUrl=holder.itemView.findViewById(R.id.ImageUrl);//图片 + //设置文本 + + String name=((SectionItem)section.getItemAt(itemIndex)).getTag(); + IsSC=((SectionItem)section.getItemAt(itemIndex)).getIsSC(); + tvTag.setText(name); + tvNote.setText("时间:"+ ((SectionItem)section.getItemAt(itemIndex)).getNote()+"秒"); + //设置图片 + ImageUrl.setBackground(holder.itemView.getContext().getResources().getDrawable(R.mipmap.hgr)); + Sc_text.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + ToastUtils.info("点击上传按钮,菜品:"+name); + } + }); + delete_text.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + ToastUtils.info("点击删除按钮,菜品:"+name); + } + }); + SetImage(sc_image,IsSC); + sc_image.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + IsSC=!IsSC; + SetImage(sc_image,IsSC); + } + }); + } + + public void SetImage(ImageView image,boolean isxz) + { + if(isxz) + { + image.setImageResource(R.mipmap.sc3); + }else + { + image.setImageResource(R.mipmap.wsc3); + } + } + + @NonNull + @Override + protected ViewHolder onCreateSectionItemViewHolder(@NonNull ViewGroup viewGroup) { + Context context = viewGroup.getContext(); + //这里是通过xml绑定布局,当然你也可以用代码new出来,方法请看头部视图 + View itemView = LayoutInflater.from(context).inflate(R.layout.note_rv_tree_second, viewGroup, false); + return new ViewHolder(itemView); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/QDSectionHeaderView.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/QDSectionHeaderView.java new file mode 100644 index 00000000..c37b865d --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/QDSectionHeaderView.java @@ -0,0 +1,62 @@ +package com.bonait.bnframework.modules.home.fragment.mode; + +import android.content.Context; +import android.graphics.Color; +import android.support.annotation.Nullable; +import android.support.v7.widget.AppCompatImageView; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.bonait.bnframework.R; +import com.qmuiteam.qmui.util.QMUIDisplayHelper; +import com.qmuiteam.qmui.util.QMUIResHelper; + +public class QDSectionHeaderView extends LinearLayout { + private TextView mTitleTv; + private ImageView mArrowView; + + private int headerHeight = QMUIDisplayHelper.dp2px(getContext(), 56); + + public QDSectionHeaderView(Context context) { + this(context, null); + } + + public QDSectionHeaderView(Context context, @Nullable AttributeSet attrs) { + super(context, attrs); + setOrientation(LinearLayout.HORIZONTAL); + setGravity(Gravity.CENTER_VERTICAL); + setBackgroundColor(Color.WHITE); + int paddingHor = QMUIDisplayHelper.dp2px(context, 24); + mTitleTv = new TextView(getContext()); + mTitleTv.setTextSize(16); + mTitleTv.setTextColor(Color.BLACK); + mTitleTv.setPadding(paddingHor, 0, paddingHor, 0); + addView(mTitleTv, new LinearLayout.LayoutParams( + 0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); + mArrowView = new AppCompatImageView(context); + mArrowView.setImageDrawable(QMUIResHelper.getAttrDrawable(getContext(), + R.attr.qmui_common_list_item_chevron)); + mArrowView.setScaleType(ImageView.ScaleType.CENTER); + addView(mArrowView, new LinearLayout.LayoutParams(headerHeight, headerHeight)); + } + + public ImageView getArrowView() { + return mArrowView; + } + + public void render(SectionHeader header, boolean isFold) { + mTitleTv.setText(header.getText()); + mArrowView.setRotation(isFold ? 0f : 90f); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, + MeasureSpec.makeMeasureSpec(headerHeight, MeasureSpec.EXACTLY)); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SectionHeader.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SectionHeader.java new file mode 100644 index 00000000..aaa600e7 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SectionHeader.java @@ -0,0 +1,64 @@ +/* + * Tencent is pleased to support the open source community by making QMUI_Android available. + * + * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the MIT License (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package com.bonait.bnframework.modules.home.fragment.mode; + +import com.qmuiteam.qmui.widget.section.QMUISection; + +/** + * 选中头 + */ +public class SectionHeader implements QMUISection.Model { + + private String tvText; + private String tvDate; + private String tvTotalAmount; + public SectionHeader(String name1, String name2, String name3) { + this.tvText = name1; + this.tvDate = name2; + this.tvTotalAmount = name3; + } + + public String getText() { + return tvText; + } + + public String getDate() { + return tvDate; + } + + public String getTotalAmount() { + return tvTotalAmount; + } + + @Override + + public SectionHeader cloneForDiff() { + return new SectionHeader(getText(), getDate(), getTotalAmount()); + } + + @Override + public boolean isSameItem(SectionHeader other) { + return tvText == other.tvText || (tvText != null && tvText.equals(other.tvText)) + && tvDate == other.tvDate || (tvDate != null && tvDate.equals(other.tvDate)) + && tvTotalAmount == other.tvTotalAmount || (tvTotalAmount != null && tvTotalAmount.equals(other.tvTotalAmount)); + } + @Override + public boolean isSameContent(SectionHeader other) { + return true; + } +} diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SectionItem.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SectionItem.java new file mode 100644 index 00000000..d791ee82 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SectionItem.java @@ -0,0 +1,82 @@ +/* + * Tencent is pleased to support the open source community by making QMUI_Android available. + * + * Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the MIT License (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package com.bonait.bnframework.modules.home.fragment.mode; + +import com.qmuiteam.qmui.widget.section.QMUISection; + +/** + * 选中Item + */ +public class SectionItem implements QMUISection.Model { + /** + * 标签 + */ + private String tvTag; + /** + * 备注 + */ + private String tvNote; + /** + * 金额 + */ + private String tvAccount; + /** + * 是否收藏 + */ + private Boolean IsSC; + public SectionItem(String name1, String name2, String name3,boolean isSC) { + this.tvTag = name1; + this.tvNote = name2; + this.tvAccount = name3; + this.IsSC=isSC; + } + + public String getTag() { + return tvTag; + } + + public String getNote() { + return tvNote; + } + + public String getAccount() { + return tvAccount; + } + public Boolean getIsSC() { + return IsSC; + } + + @Override + public SectionItem cloneForDiff() { + return new SectionItem(getTag(), getNote(), getAccount(),getIsSC()); + } + + @Override + public boolean isSameItem(SectionItem other) { + return tvTag == other.tvTag || (tvTag != null && tvTag.equals(other.tvTag)) + && tvNote == other.tvNote || (tvNote != null && tvNote.equals(other.tvNote)) + && IsSC == other.IsSC || (IsSC != null && IsSC.equals(other.IsSC)) + && tvAccount == other.tvAccount || (tvAccount != null && tvAccount.equals(other.tvAccount)); + } + @Override + + public boolean isSameContent(SectionItem other) { + return true; + } + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/button.xml b/app/src/main/res/drawable/button.xml new file mode 100644 index 00000000..9be22b9f --- /dev/null +++ b/app/src/main/res/drawable/button.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button1.xml b/app/src/main/res/drawable/button1.xml new file mode 100644 index 00000000..e544b565 --- /dev/null +++ b/app/src/main/res/drawable/button1.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/input_bj.xml b/app/src/main/res/drawable/input_bj.xml new file mode 100644 index 00000000..7ec495e2 --- /dev/null +++ b/app/src/main/res/drawable/input_bj.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_cp.xml b/app/src/main/res/layout/activity_cp.xml index 73efd97f..50492502 100644 --- a/app/src/main/res/layout/activity_cp.xml +++ b/app/src/main/res/layout/activity_cp.xml @@ -15,14 +15,14 @@ - - - + android:background="@color/activity_background"> + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_diy.xml b/app/src/main/res/layout/activity_diy.xml index e34e3989..36db85cd 100644 --- a/app/src/main/res/layout/activity_diy.xml +++ b/app/src/main/res/layout/activity_diy.xml @@ -16,13 +16,239 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/qmui_config_color_white"> - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +