Explorar o código

special zone ui update

hanjing %!s(int64=6) %!d(string=hai) anos
pai
achega
c8a2aa5bc3

+ 84 - 41
app/src/main/java/com/sheep/gamegroup/module/game/util/SpecialZoneHelper.java

@@ -1,26 +1,27 @@
 package com.sheep.gamegroup.module.game.util;
 
+import android.support.annotation.NonNull;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ImageView;
-import android.widget.LinearLayout;
 import android.widget.TextView;
-import android.widget.Toast;
 
 import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
+import com.bumptech.glide.request.RequestOptions;
 import com.sheep.gamegroup.model.entity.AppSpecial;
-import com.sheep.gamegroup.model.entity.Article;
 import com.sheep.gamegroup.model.entity.BaseMessage;
-import com.sheep.gamegroup.model.entity.GameListTag;
 import com.sheep.gamegroup.model.entity.GameListType;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
-import com.youth.banner.loader.ImageLoader;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import io.reactivex.android.schedulers.AndroidSchedulers;
@@ -28,13 +29,20 @@ import io.reactivex.schedulers.Schedulers;
 
 public class SpecialZoneHelper {
 
-    private LinearLayout container;
+    private View rootView;
+    private RecyclerView zoneListView;
+    private ZoneAdapter zoneAdapter;
 
-    public SpecialZoneHelper(View rootView) {
-        this.container = rootView.findViewById(R.id.special_container);
+    public SpecialZoneHelper(View rView) {
+        rootView = rView;
+        this.zoneListView = rootView.findViewById(R.id.special_zone_list_view);
+        rootView.setVisibility(View.GONE);
     }
 
     public SpecialZoneHelper config() {
+        zoneListView.setLayoutManager(new LinearLayoutManager(zoneListView.getContext(), LinearLayoutManager.HORIZONTAL, false));
+        zoneAdapter = new ZoneAdapter();
+        zoneListView.setAdapter(zoneAdapter);
         return this;
     }
 
@@ -46,52 +54,87 @@ public class SpecialZoneHelper {
 
                     @Override
                     public void onNext(BaseMessage baseMessage) {
-                        container.removeAllViews();
+
                         List<AppSpecial> list = baseMessage.getDataList(AppSpecial.class);
-                        for (AppSpecial zone : list) {
-                            View view = generateSpecialView(list.indexOf(zone), zone);
-                            container.addView(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+                        if (list != null && list.size() > 0) {
+                            rootView.setVisibility(View.VISIBLE);
+                            zoneAdapter.setData(list);
                         }
                     }
 
                     @Override
                     public void onError(BaseMessage baseMessage) {
-                        G.showToast(baseMessage);
-                        container.setVisibility(View.GONE);
                     }
                 });
     }
 
-    private View generateSpecialView(int index, AppSpecial zone) {
-        View view = null;
-        if (index % 2 == 0) {
-            view = LayoutInflater.from(container.getContext()).inflate(R.layout.app_special_left, container, false);
-        } else {
-            view = LayoutInflater.from(container.getContext()).inflate(R.layout.app_special_right, container, false);
+    public class ZoneAdapter extends RecyclerView.Adapter<ZoneHolder> {
+
+        private List<AppSpecial> zonelist = new ArrayList<>();
+
+        public void setData(List<AppSpecial> list) {
+            zonelist.clear();
+            zonelist.addAll(list);
+            notifyDataSetChanged();
+        }
+
+        @NonNull
+        @Override
+        public ZoneHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
+            View view = LayoutInflater.from(zoneListView.getContext()).inflate(R.layout.app_special_zone_tile, zoneListView, false);
+            return new ZoneHolder(view);
         }
-        ImageView themeView = view.findViewById(R.id.theme_view);
-        ImageView bgView = view.findViewById(R.id.bg_view);
-        TextView titleView = view.findViewById(R.id.title_view);
-        ImageView[] iconViews = new ImageView[]{
-                view.findViewById(R.id.icon_1),
-                view.findViewById(R.id.icon_2),
-                view.findViewById(R.id.icon_3)
-        };
-        Glide.with(container.getContext()).load(zone.getMain_publicize()).into(themeView);
-        Glide.with(container.getContext()).load(zone.getIcon()).into(bgView);
-        titleView.setText(zone.getName() + "\nGO>>");
-        if (zone.getApp_icons() != null && zone.getApp_icons().length > 0) {
-            for (int i = 0; i < zone.getApp_icons().length && i < 3; i++) {
-                Glide.with(container.getContext()).load(zone.getApp_icons()[i]).into(iconViews[i]);
+
+        @Override
+        public void onBindViewHolder(@NonNull ZoneHolder zoneHolder, int i) {
+            zoneHolder.bind(zonelist.get(i));
+            if (i == zonelist.size() - 1) {
+                RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) zoneHolder.itemView.getLayoutParams();
+                layoutParams.rightMargin = G.getRealPix(8);
+            }
+        }
+
+        @Override
+        public int getItemCount() {
+            return zonelist.size();
+        }
+    }
+
+    public class ZoneHolder extends RecyclerView.ViewHolder {
+
+        public AppSpecial zone;
+
+        ImageView themeView;
+        TextView titleView;
+        ImageView[] iconViews;
+
+        public ZoneHolder(@NonNull View itemView) {
+            super(itemView);
+            themeView = itemView.findViewById(R.id.theme_view);
+            titleView = itemView.findViewById(R.id.title_view);
+            iconViews = new ImageView[]{
+                    itemView.findViewById(R.id.icon_1),
+                    itemView.findViewById(R.id.icon_2),
+                    itemView.findViewById(R.id.icon_3)
+            };
+            itemView.setOnClickListener(v -> {
+                GameListType type = new GameListType();
+                type.setSpecial_id(zone.getId());
+                type.setTitle(zone.getName());
+                Jump2View.getInstance().goActPlayGameList(itemView.getContext(), type);
+            });
+        }
+
+        public void bind(AppSpecial z) {
+            zone = z;
+            Glide.with(itemView.getContext()).load(zone.getMain_publicize()).apply(new RequestOptions().centerCrop().transform(new RoundedCorners(G.getRealPix(6)))).into(themeView);
+            titleView.setText(zone.getName() + "\nGO>>");
+            if (zone.getApp_icons() != null && zone.getApp_icons().length > 0) {
+                for (int i = 0; i < zone.getApp_icons().length && i < 3; i++) {
+                    Glide.with(itemView.getContext()).load(zone.getApp_icons()[i]).into(iconViews[i]);
+                }
             }
         }
-        view.setOnClickListener(v -> {
-            GameListType type = new GameListType();
-            type.setSpecial_id(zone.getId());
-            type.setTitle(zone.getName());
-            Jump2View.getInstance().goActPlayGameList(container.getContext(), type);
-        });
-        return view;
     }
 
 }

+ 0 - 62
app/src/main/res/layout/app_special_left.xml

@@ -1,62 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="100dp"
-    android:orientation="horizontal">
-
-
-    <ImageView
-        android:id="@+id/theme_view"
-        android:layout_width="match_parent"
-        android:layout_height="100dp"
-        android:layout_weight="1"
-        android:scaleType="centerCrop" />
-
-    <RelativeLayout
-        android:layout_width="match_parent"
-        android:layout_height="100dp"
-        android:layout_weight="2"
-        android:orientation="horizontal">
-
-        <ImageView
-            android:id="@+id/bg_view"
-            android:layout_width="match_parent"
-            android:layout_height="100dp"
-            android:scaleType="centerCrop" />
-
-        <TextView
-            android:id="@+id/title_view"
-            android:layout_width="match_parent"
-            android:layout_height="60dp"
-            android:gravity="center"
-            android:text="腾讯专区\nGO>>"
-            android:textColor="@color/white"
-            android:textSize="13sp" />
-
-        <LinearLayout
-            android:layout_width="match_parent"
-            android:layout_height="50dp"
-            android:layout_alignParentBottom="true"
-            android:gravity="center"
-            android:orientation="horizontal">
-
-            <ImageView
-                android:id="@+id/icon_1"
-                android:layout_width="32dp"
-                android:layout_height="32dp" />
-
-            <ImageView
-                android:id="@+id/icon_2"
-                android:layout_width="32dp"
-                android:layout_height="32dp"
-                android:layout_marginLeft="6dp"
-                android:layout_marginRight="6dp" />
-
-            <ImageView
-                android:id="@+id/icon_3"
-                android:layout_width="32dp"
-                android:layout_height="32dp" />
-        </LinearLayout>
-    </RelativeLayout>
-
-</LinearLayout>

+ 13 - 19
app/src/main/res/layout/app_special_right.xml

@@ -1,21 +1,21 @@
 <?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="100dp"
-    android:orientation="horizontal">
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_marginLeft="8dp"
+    android:layout_width="277dp"
+    android:layout_height="100dp">
+
+    <ImageView
+        android:id="@+id/theme_view"
+        android:layout_width="277dp"
+        android:layout_height="100dp"
+        android:scaleType="centerCrop" />
 
     <RelativeLayout
-        android:layout_width="match_parent"
+        android:layout_alignParentRight="true"
+        android:layout_width="120dp"
         android:layout_height="100dp"
-        android:layout_weight="2"
         android:orientation="horizontal">
 
-        <ImageView
-            android:id="@+id/bg_view"
-            android:layout_width="match_parent"
-            android:layout_height="100dp"
-            android:scaleType="centerCrop" />
-
         <TextView
             android:id="@+id/title_view"
             android:layout_width="match_parent"
@@ -50,11 +50,5 @@
                 android:layout_height="32dp" />
         </LinearLayout>
     </RelativeLayout>
-    <ImageView
-        android:id="@+id/theme_view"
-        android:layout_width="match_parent"
-        android:layout_height="100dp"
-        android:layout_weight="1"
-        android:scaleType="centerCrop" />
 
-</LinearLayout>
+</RelativeLayout>

+ 3 - 6
app/src/main/res/layout/fgt_play_game.xml

@@ -30,12 +30,9 @@
                 android:id="@+id/play_game_news"
                 layout="@layout/item_game_news" />
 
-            <LinearLayout
-                android:id="@+id/special_container"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:background="@color/white"
-                android:orientation="vertical"></LinearLayout>
+            <include
+                android:id="@+id/play_game_special"
+                layout="@layout/play_game_special"></include>
 
             <android.support.v7.widget.RecyclerView
                 android:id="@+id/play_game_center_type_list"

+ 5 - 0
app/src/main/res/layout/inclue_hp_refresh_welfare_box.xml

@@ -6,6 +6,11 @@
     android:background="@color/white"
     android:orientation="vertical">
 
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="10dp"
+        android:background="@color/bg_home_color" />
+
     <include
         android:id="@+id/hp_game_welfare_entrance"
         android:layout_width="match_parent"

+ 24 - 0
app/src/main/res/layout/play_game_special.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:background="@color/white">
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="10dp"
+        android:background="@color/bg_home_color" />
+
+    <TextView
+        style="@style/style_wc_line_title"
+        android:text="热门专区" />
+
+    <android.support.v7.widget.RecyclerView
+        android:id="@+id/special_zone_list_view"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="8dp"
+        android:layout_marginBottom="8dp"/>
+
+</LinearLayout>