淘宝分类详情

1.分类页面布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <android.support.v7.widget.RecyclerView
        android:layout_width="130dp"
        android:layout_height="match_parent"
        android:id="@+id/rece_liebiao"
        />

    <ExpandableListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/expan_view"
        />

</LinearLayout>

2.分类主页面

public class LiebiaoFragment extends BaseFragment<LiebiaoPresenter> implements LiebiaoContract.View {

    @BindView(R.id.rece_liebiao)
    RecyclerView receLiebiao;
    @BindView(R.id.expan_view)
    ExpandableListView expanView;
    Unbinder unbinder;

    public static LiebiaoFragment newInstance() {
        LiebiaoFragment fragment = new LiebiaoFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(@NonNull AppComponent appComponent) {
        DaggerLiebiaoComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .liebiaoModule(new LiebiaoModule(this))
                .build()
                .inject(this);
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_liebiao, container, false);
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

    }


    @Override
    public void setData(@Nullable Object data) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }

    @Override
    public void showDataZuo(NewsZuo5 newsZuo5) {

        List<NewsZuo5.DataBean> data = newsZuo5.getData();

        //线性布局
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        receLiebiao.setLayoutManager(linearLayoutManager);
        //创建左侧适配器
        MyLieZuoAdapter myLieZuoAdapter = new MyLieZuoAdapter(getActivity(), data);
        receLiebiao.setAdapter(myLieZuoAdapter);
        myLieZuoAdapter.setOnItemClickListener(new MyLieZuoAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                int cid = newsZuo5.getData().get(position).getCid();
                mPresenter.lieyou(cid);
            }
        });
    }

    @Override
    public void showDataYou(NewsYou5 newsYou5) {

        List<NewsYou5.DataBean> data = newsYou5.getData();
        MyLieYouAdapter myLieYouAdapter = new MyLieYouAdapter(getActivity(), newsYou5);
        expanView.setAdapter(myLieYouAdapter);

        int count = expanView.getCount();
        for (int i = 0; i < count; i++) {
            expanView.expandGroup(i);
        }
    }

    @Override
    public void error(String s) {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        mPresenter.liezuo();
        mPresenter.lieyou(1);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
3.分类及接口

//分类左侧
    @GET("product/getCatagory")
    Observable<NewsZuo5> getLiezuo();

    //分类右侧
    @GET("product/getProductCatagory")
    Observable<NewsYou5> getLieyou(@Query("cid")int id);
4.分类请求

public interface LiebiaoContract {
    //对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
    interface View extends IView {

        //左侧请求
        void showDataZuo(NewsZuo5 newsZuo5);

        //右侧请求
        void showDataYou(NewsYou5 newsYou5);

        void error(String s);
    }

    //Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存
    interface Model extends IModel {

        //左侧
        Observable<NewsZuo5> responLieZuo();
        //右侧
        Observable<NewsYou5> responLieYou(int id);
    }
}
5.分类左边适配器

public class MyLieZuoAdapter extends RecyclerView.Adapter<MyLieZuoAdapter.LieZuoViewHolder> {
    private Context context;
    private List<NewsZuo5.DataBean> listzuo;
    private OnItemClickListener   mOnItemClickListener;

    public MyLieZuoAdapter(Context context, List<NewsZuo5.DataBean> listzuo) {
        this.context = context;
        this.listzuo = listzuo;
    }

    public interface OnItemClickListener{
        void onItemClick(View view, int position);
    }
    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }

        @NonNull
    @Override
    public LieZuoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.liezuo_layout, null);
        LieZuoViewHolder lieZuoViewHolder = new LieZuoViewHolder(inflate);
        return lieZuoViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull LieZuoViewHolder holder, int position) {

        holder.text_zuolie.setText(listzuo.get(position).getName());
        if(mOnItemClickListener !=null)
        {
            holder.text_zuolie.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int layoutPosition = holder.getLayoutPosition();
                    mOnItemClickListener.onItemClick(holder.itemView,position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return listzuo.size();
    }

    class LieZuoViewHolder extends RecyclerView.ViewHolder
    {

        private final TextView text_zuolie;

        public LieZuoViewHolder(View itemView) {
            super(itemView);
            text_zuolie = (TextView)itemView.findViewById(R.id.text_zuolie);
        }
    }
}
6.左边适配器布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center"
        android:text="名字"
        android:layout_gravity="center"
        android:id="@+id/text_zuolie"
        />

</LinearLayout>
7.分类右边适配器

public class MyLieYouAdapter extends BaseExpandableListAdapter {
    private Context context;
    private NewsYou5 newsYou5;

    public MyLieYouAdapter(Context context, NewsYou5 newsYou5) {
        this.context = context;
        this.newsYou5 = newsYou5;
    }

    @Override
    public int getGroupCount() {
        return newsYou5.getData().size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return 1;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return newsYou5.getData().get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return newsYou5.getData().get(groupPosition).getList().get(groupPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        View v = View.inflate(context, R.layout.you_item, null);
        TextView expand_tv = v.findViewById(R.id.text_liebiaoti);
        expand_tv.setText(newsYou5.getData().get(groupPosition).getName());
        return v;
    }

    @Override
    public View getChildView(int i, int i1, boolean isLastChild, View convertView, ViewGroup parent) {
        View v = View.inflate(context, R.layout.youhai_item, null);
        RecyclerView expand_recycler = v.findViewById(R.id.rece_fenlie);
        //网格格式
        GridLayoutManager gridLayoutManager = new GridLayoutManager(context, 3);
        expand_recycler.setLayoutManager(gridLayoutManager);
        //RecyclerView的适配器
        MyReViewAdapter myReViewAdapter = new MyReViewAdapter(context, newsYou5, i, i1);
        expand_recycler.setAdapter(myReViewAdapter);
        return v;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }
}
7.右边适配器条目布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="XXX"
        android:id="@+id/text_liebiaoti"
        />

</LinearLayout>
8.右边内部条目布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/rece_fenlie"
        />

</LinearLayout>

9.右边内部网格布局

public class MyReViewAdapter extends RecyclerView.Adapter<MyReViewAdapter.FenLieViewHolder> {

    private Context context;
   private NewsYou5 newsYou5;
    private int i,i1;
    private OnItemClickListener mOnItemClickListener;

    public MyReViewAdapter(Context context, NewsYou5 newsYou5, int i, int i1) {
        this.context = context;
        this.newsYou5 = newsYou5;
        this.i = i;
        this.i1 = i1;
    }

    //点击事件
    public interface OnItemClickListener{
        void onItemClick(View view, int position);
    }
    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener){
        this.mOnItemClickListener = mOnItemClickListener;
    }


    @NonNull
    @Override
    public FenLieViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = View.inflate(context, R.layout.zhanshi_item, null);
        FenLieViewHolder fenLieViewHolder = new FenLieViewHolder(v);
        return fenLieViewHolder;

    }

    @Override
    public void onBindViewHolder(@NonNull FenLieViewHolder holder, int position) {

        holder.text_zhanshi.setText(newsYou5.getData().get(i).getName());
        Uri parse = Uri.parse(newsYou5.getData().get(i).getList().get(0).getIcon());
        holder.simp_zhanshi.setImageURI(parse);

        if(mOnItemClickListener!=null)
        {
            holder.simp_zhanshi.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int layoutPosition = holder.getLayoutPosition();

                    mOnItemClickListener.onItemClick(holder.itemView,position);
                }
            });
        }

    }

    @Override
    public int getItemCount() {
        return newsYou5.getData().get(i).getList().size();
    }

    class FenLieViewHolder extends RecyclerView.ViewHolder
    {

        private final SimpleDraweeView simp_zhanshi;
        private final TextView text_zhanshi;

        public FenLieViewHolder(View itemView) {
            super(itemView);
            simp_zhanshi = (SimpleDraweeView)itemView.findViewById(R.id.simp_zhanshi);
            text_zhanshi = (TextView)itemView.findViewById(R.id.text_zhanshi);
        }
    }
}
10.网格布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <com.facebook.drawee.view.SimpleDraweeView
        android:layout_width="60dp"
        android:layout_height="60dp"
        app:placeholderImage="@mipmap/ic_launcher"
        android:id="@+id/simp_zhanshi"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="xxx"
        android:id="@+id/text_zhanshi"
        android:layout_marginLeft="15dp"
        />

</LinearLayout>
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值