Browse Source

首页布局

詹子聪 5 years ago
parent
commit
7b79e87d76

+ 2 - 1
app/src/main/java/com/itant/shibei/tool/DataTool.java

@@ -73,7 +73,8 @@ public class DataTool {
         goodsBean.coverImageUrl = "https://img14.360buyimg.com/n12/jfs/t1/97822/29/10664/255856/5e1ebf26Eea1a28ec/ac2c298127bae9a4.jpg";
         goodsBean.title = "华硕(ASUS) PN60 商用办公家用教育 台式机电脑主机 (i3-8130U 128G SSD 4G 正版Win10 三年上门)迷你主机";
         goodsBean.description = "远程教育,在家办公,顺畅不卡顿!";
-
+        goodsBean.dingNum = 108;
+        goodsBean.caiNum = 23;
         goodsBean.enable = true;
         goodsList.add(goodsBean);
         return goodsList;

+ 18 - 0
app/src/main/java/com/itant/shibei/tool/StringTool.java

@@ -23,6 +23,24 @@ public class StringTool {
         return FORMAT_TWO.format(number);
     }
 
+    /**
+     * 计算百分比
+     * @param targetNum
+     * @param totalNum
+     * @return
+     */
+    public static String getPercent(int targetNum, int totalNum) {
+        if (totalNum == 0) {
+            return "100%";
+        }
+
+        BigDecimal target = BigDecimal.valueOf(targetNum);
+        BigDecimal total = BigDecimal.valueOf(totalNum);
+        // 四舍五入
+        BigDecimal result = target.divide(total, 2, RoundingMode.HALF_UP);
+        return result.multiply(BigDecimal.valueOf(100)).intValue() + "%";
+    }
+
     public static String getEncodeString(String rawString) {
         String base64String = Base64.encodeToString(rawString.getBytes(StandardCharsets.UTF_8), Base64.NO_WRAP);
         StringBuilder stringBuffer = new StringBuilder(base64String);

+ 18 - 3
app/src/main/java/com/itant/shibei/ui/home/goods/GoodsAdapter.java

@@ -20,6 +20,7 @@ import com.chad.library.adapter.base.BaseViewHolder;
 import com.itant.shibei.R;
 import com.itant.shibei.base.ItemLongClickListener;
 import com.itant.shibei.manager.UserInfoManager;
+import com.itant.shibei.tool.StringTool;
 import com.itant.shibei.ui.TabActivity;
 import com.itant.shibei.ui.home.goods.play.VideoPlayActivity;
 import com.makeramen.roundedimageview.RoundedImageView;
@@ -47,6 +48,10 @@ public class GoodsAdapter extends BaseQuickAdapter<GoodsBean, BaseViewHolder> {
     @Override
     protected void convert(@NonNull BaseViewHolder holder, GoodsBean goodsBean) {
         holder.setText(R.id.tv_title, goodsBean.title);
+        holder.setText(R.id.tv_good_comment, StringTool.getPercent(goodsBean.dingNum, goodsBean.dingNum+goodsBean.caiNum));
+        holder.setText(R.id.tv_ding, StringTool.getNumberString(goodsBean.dingNum));
+        holder.setText(R.id.tv_cai, StringTool.getNumberString(goodsBean.caiNum));
+        holder.setText(R.id.tv_see_num, StringTool.getNumberString(goodsBean.seeNum));
 
         holder.setOnClickListener(R.id.cv_goods, v -> {
             if (!UserInfoManager.getInstance().getBeiUser().isVip) {
@@ -63,7 +68,6 @@ public class GoodsAdapter extends BaseQuickAdapter<GoodsBean, BaseViewHolder> {
             }
 
             // todo 跳到详情界面
-
         });
 
         // 解决图片错乱
@@ -107,12 +111,24 @@ public class GoodsAdapter extends BaseQuickAdapter<GoodsBean, BaseViewHolder> {
             fl_video_play.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {
+                    if (!UserInfoManager.getInstance().getBeiUser().isVip) {
+                        ToastTool.showShort("请先激活会员");
+                        if (mContext instanceof TabActivity) {
+                            ((TabActivity) mContext).setCurrentPage(2);
+                        }
+                        return;
+                    }
+
+                    if (!goodsBean.enable) {
+                        ToastTool.showShort("敬请期待");
+                        return;
+                    }
+
                     // 全屏播放视频
                     Intent playIntent = new Intent(mContext, VideoPlayActivity.class);
                     playIntent.putExtra(VideoPlayActivity.KEY_URL, goodsBean.videoUrl);
                     playIntent.putExtra(VideoPlayActivity.KEY_TITLE, goodsBean.title);
                     mContext.startActivity(playIntent);
-                    //JzvdStd.startFullscreen(this, JZVideoPlayerStandard.class, "http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4", "嫂子辛苦了");
                 }
             });
         } else {
@@ -139,5 +155,4 @@ public class GoodsAdapter extends BaseQuickAdapter<GoodsBean, BaseViewHolder> {
     public void setGoodsLongClickListener(ItemLongClickListener goodsLongClickListener) {
         this.goodsLongClickListener = goodsLongClickListener;
     }
-
 }

+ 5 - 0
app/src/main/java/com/itant/shibei/ui/home/goods/GoodsBean.java

@@ -97,5 +97,10 @@ public class GoodsBean implements Serializable {
      */
     public long updateTimeMillis;
 
+    /**
+     * 浏览次数
+     */
+    public long seeNum;
+
     public boolean enable;
 }

+ 69 - 195
app/src/main/res/layout/item_goods.xml

@@ -20,18 +20,18 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:gravity="center_vertical"
-            android:orientation="horizontal"
+            android:orientation="vertical"
             android:padding="@dimen/margin_s">
 
             <FrameLayout
                 android:id="@+id/fl_video_play"
-                android:layout_width="wrap_content"
+                android:layout_width="match_parent"
                 android:layout_height="wrap_content">
                 <com.makeramen.roundedimageview.RoundedImageView
                     android:id="@+id/aciv_goods"
-                    android:layout_width="@dimen/size_image_list"
-                    android:layout_height="@dimen/size_image_list"
-                    android:scaleType="center"
+                    android:layout_width="match_parent"
+                    android:layout_height="@dimen/height_cover"
+                    android:scaleType="centerInside"
                     app:riv_corner_radius="4dp"
                     android:src="@mipmap/logo_gray"/>
 
@@ -43,15 +43,11 @@
                     android:src="@mipmap/video_play"/>
             </FrameLayout>
 
-
-
-
             <LinearLayout
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:layout_marginStart="@dimen/margin_s"
-                android:minHeight="@dimen/size_image_list"
-                android:orientation="vertical">
+                android:orientation="vertical"
+                android:layout_marginTop="@dimen/margin_ss">
                 <!--标题-->
                 <TextView
                     android:id="@+id/tv_title"
@@ -59,220 +55,98 @@
                     android:layout_height="wrap_content"
                     android:layout_marginBottom="@dimen/margin_ss"
                     android:ellipsize="end"
-                    android:maxLines="2"
+                    android:maxLines="3"
                     android:textColor="@color/black"
-                    android:textSize="@dimen/text_normal" />
-
-                <Space
-                    android:layout_width="wrap_content"
-                    android:layout_height="0dp"
-                    android:layout_weight="1" />
-
+                    android:textSize="@dimen/text_normal_p" />
 
-                <!--一句话推荐-->
-                <TextView
-                    android:id="@+id/tv_reason"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:layout_marginBottom="@dimen/margin_ss"
-                    android:background="@drawable/shape_gray_tag"
-                    android:ellipsize="end"
-                    android:paddingStart="@dimen/margin_s"
-                    android:paddingTop="@dimen/padding_tag"
-                    android:paddingEnd="@dimen/margin_s"
-                    android:paddingBottom="@dimen/padding_tag"
-                    android:singleLine="true"
-                    android:textColor="@color/jd_gray_bg_text"
-                    android:textSize="@dimen/text_ss" />
-
-                <Space
-                    android:layout_width="wrap_content"
-                    android:layout_height="0dp"
-                    android:layout_weight="1" />
-
-                <!--价格-->
+                <!--好评-->
                 <LinearLayout
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:gravity="center_vertical"
                     android:orientation="horizontal">
-
                     <TextView
-                        android:id="@+id/tv_old_price"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
-                        android:textColor="@color/jd_gray_text"
-                        android:textSize="@dimen/text_normal"
-                        android:textStyle="bold"
-                        android:visibility="gone"/>
+                        android:background="@drawable/shape_purple_tag_gradient"
+                        android:paddingStart="@dimen/margin_tag"
+                        android:paddingTop="@dimen/padding_tag"
+                        android:paddingEnd="@dimen/margin_tag"
+                        android:paddingBottom="@dimen/padding_tag"
+                        android:text=" 好评 "
+                        android:textColor="@color/white_slight"
+                        android:textSize="@dimen/text_sss" />
 
                     <TextView
+                        android:id="@+id/tv_good_comment"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
-                        android:textColor="@color/black_theme"
-                        android:textSize="@dimen/text_normal"
+                        android:background="@drawable/shape_purple_stroke_right"
+                        android:ellipsize="end"
+                        android:paddingStart="@dimen/margin_tag"
+                        android:paddingTop="@dimen/padding_tag"
+                        android:paddingEnd="@dimen/margin_tag"
+                        android:paddingBottom="@dimen/padding_tag"
+                        android:singleLine="true"
+                        android:textColor="@color/black_text"
+                        android:textSize="@dimen/text_sss"
                         android:textStyle="bold"
-                        android:text=" - "
-                        android:visibility="gone"/>
+                        android:text="100%"/>
 
+
+                    <ImageView
+                        android:layout_width="20dp"
+                        android:layout_height="20dp"
+                        android:src="@mipmap/zan"
+                        android:tint="@color/red_droid"
+                        android:rotation="180"
+                        android:layout_marginStart="@dimen/margin_s"/>
                     <TextView
-                        android:id="@+id/tv_now_price"
+                        android:id="@+id/tv_ding"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
-                        android:textColor="@color/jd_red_price"
-                        android:textSize="@dimen/text_normal"
-                        android:textStyle="bold" />
-
+                        android:ellipsize="end"
+                        android:singleLine="true"
+                        android:textColor="@color/gray_text_s"
+                        android:textSize="@dimen/text_shop_name"/>
+
+                    <ImageView
+                        android:layout_width="20dp"
+                        android:layout_height="20dp"
+                        android:src="@mipmap/zan"
+                        android:tint="@color/green_logo"
+                        android:layout_marginStart="@dimen/margin_s"/>
                     <TextView
+                        android:id="@+id/tv_cai"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
-                        android:textColor="@color/jd_gray_text"
-                        android:textSize="@dimen/text_normal"
-                        android:textStyle="bold"
-                        android:text=" = "
-                        android:visibility="gone"/>
+                        android:ellipsize="end"
+                        android:singleLine="true"
+                        android:textColor="@color/gray_text_s"
+                        android:textSize="@dimen/text_shop_name"/>
 
-                    <TextView
-                        android:id="@+id/tv_rebate"
+                    <Space
                         android:layout_width="0dp"
                         android:layout_weight="1"
-                        android:layout_height="wrap_content"
-                        android:textColor="@color/black_theme"
-                        android:textSize="@dimen/text_normal"
-                        android:singleLine="true"
-                        android:ellipsize="marquee"
-                        android:marqueeRepeatLimit="marquee_forever"
-                        android:scrollHorizontally="true"
-                        android:textStyle="bold"
-                        android:visibility="gone"/>
-                </LinearLayout>
-
-                <Space
-                    android:layout_width="wrap_content"
-                    android:layout_height="0dp"
-                    android:layout_weight="1" />
-
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:orientation="vertical">
-                    <!--自营-->
-                    <LinearLayout
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:layout_marginBottom="@dimen/margin_ss"
-                        android:gravity="center_vertical"
-                        android:orientation="horizontal">
-
-                        <TextView
-                            android:id="@+id/tv_self"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:background="@drawable/shape_red_tag_gradient"
-                            android:paddingStart="@dimen/margin_tag"
-                            android:paddingTop="@dimen/padding_tag"
-                            android:paddingEnd="@dimen/margin_tag"
-                            android:paddingBottom="@dimen/padding_tag"
-                            android:layout_marginEnd="@dimen/margin_ss"
-                            android:text="自营"
-                            android:textColor="@color/white_slight"
-                            android:textSize="@dimen/text_sss" />
-
-                        <TextView
-                            android:id="@+id/tv_shop_name"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_gravity="center_vertical"
-                            android:ellipsize="end"
-                            android:singleLine="true"
-                            android:textColor="@color/gray_text_s"
-                            android:textSize="@dimen/text_shop_name" />
-                    </LinearLayout>
-
-
-                    <!--好评-->
-                    <LinearLayout
-                        android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:gravity="center_vertical"
-                        android:orientation="horizontal">
-
-                        <TextView
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:background="@drawable/shape_purple_tag_gradient"
-                            android:paddingStart="@dimen/margin_tag"
-                            android:paddingTop="@dimen/padding_tag"
-                            android:paddingEnd="@dimen/margin_tag"
-                            android:paddingBottom="@dimen/padding_tag"
-                            android:text="好评"
-                            android:textColor="@color/white_slight"
-                            android:textSize="@dimen/text_sss" />
-
-                        <TextView
-                            android:id="@+id/tv_good_comment"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:background="@drawable/shape_purple_stroke_right"
-                            android:ellipsize="end"
-                            android:paddingStart="@dimen/margin_tag"
-                            android:paddingTop="@dimen/padding_tag"
-                            android:paddingEnd="@dimen/margin_tag"
-                            android:paddingBottom="@dimen/padding_tag"
-                            android:singleLine="true"
-                            android:textColor="@color/black_text"
-                            android:textSize="@dimen/text_sss"
-                            android:textStyle="bold" />
-
-
-                        <TextView
-                            android:id="@+id/tv_comment_num"
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"
-                            android:gravity="end"
-                            android:layout_marginStart="@dimen/margin_ss"
-                            android:paddingStart="@dimen/margin_sss"
-                            android:paddingEnd="@dimen/margin_sss"
-                            android:ellipsize="end"
-                            android:singleLine="true"
-                            android:textColor="@color/gray_text_s"
-                            android:textSize="@dimen/text_shop_name" />
-
-
-                    </LinearLayout>
-                </LinearLayout>
-
-
-                <!--<LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:orientation="horizontal"
-                    android:gravity="bottom">
-                    <LinearLayout
+                        android:layout_height="wrap_content"/>
+                    <ImageView
+                        android:layout_width="14dp"
+                        android:layout_height="14dp"
+                        android:src="@mipmap/see"
+                        android:tint="@color/black_text_comfortable"
+                        android:layout_marginStart="@dimen/margin_s"/>
+                    <TextView
+                        android:id="@+id/tv_see_num"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
-                        android:background="@drawable/shape_black_radius_transparent"
-                        android:gravity="center"
-                        android:orientation="vertical"
-                        android:padding="@dimen/margin_ss"
                         android:layout_marginStart="@dimen/margin_ss"
-                        android:visibility="gone">
-
-                        <TextView
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:text="购买返现"
-                            android:textColor="@color/white_slight"
-                            android:textSize="@dimen/text_rebate_tips" />
+                        android:ellipsize="end"
+                        android:singleLine="true"
+                        android:textColor="@color/gray_text_s"
+                        android:textSize="@dimen/text_shop_name"/>
 
-                        <TextView
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:textColor="@color/jd_yellow_bg_tag_select_from"
-                            android:textSize="@dimen/text_s" />
+                </LinearLayout>
 
-                    </LinearLayout>
-                </LinearLayout>-->
 
             </LinearLayout>
         </LinearLayout>

BIN
app/src/main/res/mipmap-xxhdpi/see.png


BIN
app/src/main/res/mipmap-xxhdpi/zan.png


+ 2 - 2
app/src/main/res/values/dimens.xml

@@ -24,9 +24,9 @@
     <dimen name="padding_full_width">12.8dp</dimen>
     <dimen name="margin_s">8dp</dimen>
     <dimen name="margin_ss">4dp</dimen>
-    <dimen name="margin_tag">3.2dp</dimen>
+    <dimen name="margin_tag">4dp</dimen>
     <dimen name="margin_sss">2dp</dimen>
-    <dimen name="padding_tag">1dp</dimen>
+    <dimen name="padding_tag">2.5dp</dimen>
     <dimen name="padding_slim">0.5dp</dimen>
     <dimen name="size_image_bar">120dp</dimen>
     <dimen name="size_image_huge">96dp</dimen>