Second Version of Silicon Valley Mall 2 -- homepage module, second version of Silicon Valley Mall 2 --

Source: Internet
Author: User

Second Version of Silicon Valley Mall 2 -- homepage module, second version of Silicon Valley Mall 2 --


1. fragment_home.xml

<RelativeLayout 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"
    tools: context = ". home.fragment.HomeFragment">

    <include
        android: id = "@ + id / titlebar"
        layout = "@ layout / titlebar" />

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

    <ImageButton
        android: id = "@ + id / ib_top"
        android: layout_width = "40dp"
        android: layout_height = "40dp"
        android: layout_alignParentBottom = "true"
        android: layout_alignParentRight = "true"
        android: layout_marginBottom = "20dp"
        android: layout_marginRight = "20dp"
        android: background = "@ drawable / top_btn"
        android: visibility = "gone" />
</ RelativeLayout>
2. Six item types in RecyclerView:

Banner Advertising Channel Activity Spike Recommended Hot

3. Banner Advertising

Banner realizes carousel

4. Spike

HomeRecyclerViewAdapter

public RecyclerView.ViewHolder onCreateViewHolder (ViewGroup parent, int viewType) {
    .....
    } else if (viewType == SECKILL) {
        return new SeckillViewHolder (mLayoutInflater.inflate (R.layout.seckill_item, null), mContext);
    }
}
seckill_item.xml

<? xml version = "1.0" encoding = "utf-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
    android: layout_width = "380dp"
    android: layout_height = "180dp"
    android: background = "# fff"
    android: orientation = "vertical"
    android: padding = "10dp">

    <LinearLayout
        android: layout_width = "match_parent"
        android: layout_height = "wrap_content">

        <ImageView
            android: layout_width = "wrap_content"
            android: layout_height = "wrap_content"
            android: src = "@ drawable / home_arrow_left_flash" />

        <TextView
            android: layout_width = "wrap_content"
            android: layout_height = "wrap_content"
            android: layout_marginLeft = "10dp"
            android: text = "Today's flash sale distance from the end"
            android: textColor = "# 000" />

        <TextView
            android: id = "@ + id / tv_time_seckill"
            android: layout_width = "wrap_content"
            android: layout_height = "wrap_content"
            android: layout_marginLeft = "10dp"
            android: background = "@ drawable / time_shape"
            android: padding = "2dp"
            android: text = "00:00:00"
            android: textColor = "# fff" />

        <TextView
            android: id = "@ + id / tv_more_seckill"
            android: layout_width = "wrap_content"
            android: layout_height = "wrap_content"
            android: layout_weight = "1"
            android: drawablePadding = "5dp"
            android: drawableRight = "@ drawable / home_arrow_right"
            android: gravity = "end"
            android: text = "View more" />
    </ LinearLayout>

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


SeckillViewHolder

class SeckillViewHolder extends RecyclerView.ViewHolder {
    private TextView tvMore;
    private RecyclerView recyclerView;
    public Context mContext;

    public SeckillViewHolder (View itemView, Context mContext) {
        super (itemView);
        tvTime = (TextView) itemView.findViewById (R.id.tv_time_seckill);
        tvMore = (TextView) itemView.findViewById (R.id.tv_more_seckill);
        recyclerView = (RecyclerView) itemView.findViewById (R.id.rv_seckill);
        this.mContext = mContext;
    }


    public void setData (final ResultBean.SeckillInfoBean data) {
        // Set the time
        if (isFirst) {
// dt = (int) (Integer.parseInt (data.getEnd_time ())-System.currentTimeMillis ());
            dt = (int) (Integer.parseInt (data.getEnd_time ())-(Integer.parseInt (data.getStart_time ())));
            isFirst = false;
        }

        // Set RecyclerView
        recyclerView.setLayoutManager (new LinearLayoutManager (mContext, LinearLayoutManager.HORIZONTAL, false));
        SeckillRecyclerViewAdapter adapter = new SeckillRecyclerViewAdapter (mContext, data);
        recyclerView.setAdapter (adapter);

        // Countdown
        handler.sendEmptyMessageDelayed (0, 1000);

        // click event
        adapter.setOnSeckillRecyclerView (new SeckillRecyclerViewAdapter.OnSeckillRecyclerView () {
            @Override
            public void onClick (int position) {
                ResultBean.SeckillInfoBean.ListBean listBean = data.getList (). Get (position);
                String name = listBean.getName ();
                String cover_price = listBean.getCover_price ();
                String figure = listBean.getFigure ();
                String product_id = listBean.getProduct_id ();
                GoodsBean goodsBean = new GoodsBean (name, cover_price, figure, product_id);
//
                Intent intent = new Intent (mContext, GoodsInfoActivity.class);
                intent.putExtra (GOODS_BEAN, goodsBean);
                 mContext.startActivity (intent);

                 // Toast.makeText (mContext, "position:" + position, Toast.LENGTH_SHORT) .show ();
             }
         });

     }
}


private boolean isFirst = true;
     private TextView tvTime;
     private int dt;
     private Handler handler = new Handler () {
         @Override
         public void handleMessage (Message msg) {
             if (msg.what == 0) {
                 dt = dt-1000;
                 SimpleDateFormat sd = new SimpleDateFormat ("HH: mm: ss");
                 tvTime.setText (sd.format (new Date (dt)));

                 handler.removeMessages (0);
                 handler.sendEmptyMessageDelayed (0, 1000);
                 if (dt == 0) {
                     handler.removeMessages (0);
                 }
             }

         }
     };
Use CountdownView to achieve the effect of countdown to spike

 

 

github: https: //github.com/ganchuanpu/Shopping

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.