|
|
@@ -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;
|
|
|
}
|
|
|
|
|
|
}
|