心愿单添加部分功能实现
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package com.yunbao.common.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.bean.WishModel;
|
||||
import com.yunbao.common.views.DayWishItemViewHolder;
|
||||
import com.yunbao.common.views.LunarWishItemViewHolder;
|
||||
import com.yunbao.common.views.SeasonalWishItemViewHolder;
|
||||
import com.yunbao.common.views.WeekWishItemViewHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LiveNewWishAdapter extends RecyclerView.Adapter {
|
||||
private int type = 0;
|
||||
private List<WishModel> wishList = new ArrayList<>();
|
||||
|
||||
public void addData(List<WishModel> wishModelList, int type) {
|
||||
this.type = type;
|
||||
wishList.clear();
|
||||
wishList.addAll(wishModelList);
|
||||
wishList.add(null);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void addGiftListModel(WishModel model) {
|
||||
wishList.add(0, model);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
if (type == 1) {
|
||||
View dayWish = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_day_wish, parent, false);
|
||||
return new DayWishItemViewHolder(dayWish);
|
||||
} else if (type == 2) {
|
||||
View weekWish = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_week_wish, parent, false);
|
||||
return new WeekWishItemViewHolder(weekWish);
|
||||
} else if (type == 3) {
|
||||
View lunarWish = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_lunar_wish, parent, false);
|
||||
return new LunarWishItemViewHolder(lunarWish);
|
||||
} else {
|
||||
View seasonalWish = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_seasonal_wish, parent, false);
|
||||
return new SeasonalWishItemViewHolder(seasonalWish);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
if (position == wishList.size()) return;
|
||||
if (holder instanceof DayWishItemViewHolder) {
|
||||
DayWishItemViewHolder dayWishItemViewHolder = (DayWishItemViewHolder) holder;
|
||||
dayWishItemViewHolder.steDayWishData(wishList.get(position), position, new DayWishItemViewHolder.DayWishItemListener() {
|
||||
@Override
|
||||
public void onDelete(int index) {
|
||||
wishList.remove(index);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(WishModel model, int index) {
|
||||
wishList.remove(index);
|
||||
wishList.add(index, model);
|
||||
notifyItemChanged(index);
|
||||
}
|
||||
});
|
||||
} else if (holder instanceof WeekWishItemViewHolder) {
|
||||
WeekWishItemViewHolder weekWishItemViewHolder = (WeekWishItemViewHolder) holder;
|
||||
} else if (holder instanceof LunarWishItemViewHolder) {
|
||||
LunarWishItemViewHolder lunarWishItemViewHolder = (LunarWishItemViewHolder) holder;
|
||||
} else if (holder instanceof SeasonalWishItemViewHolder) {
|
||||
SeasonalWishItemViewHolder seasonalWishItemViewHolder = (SeasonalWishItemViewHolder) holder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return wishList.size();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.yunbao.common.adapter;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.bean.GiftListModel;
|
||||
import com.yunbao.common.event.LiveNewWishGiftEvent;
|
||||
import com.yunbao.common.utils.Bus;
|
||||
import com.yunbao.common.views.LiveNewWishGiftViewHolder;
|
||||
import com.yunbao.common.views.weight.ViewClicksAntiShake;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LiveNewWishGiftAdapter extends RecyclerView.Adapter {
|
||||
private List<GiftListModel> giftListModels = new ArrayList<>();
|
||||
|
||||
public LiveNewWishGiftAdapter(List<GiftListModel> giftListModels) {
|
||||
this.giftListModels = giftListModels;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View dayWish = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_gitf_wish, parent, false);
|
||||
return new LiveNewWishGiftViewHolder(dayWish);
|
||||
}
|
||||
|
||||
private int index = -1;
|
||||
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
|
||||
LiveNewWishGiftViewHolder wishGiftViewHolder = (LiveNewWishGiftViewHolder) holder;
|
||||
wishGiftViewHolder.setData(giftListModels.get(position), new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
index = position;
|
||||
notifyDataSetChanged();
|
||||
Bus.get().post(new LiveNewWishGiftEvent().setModel(giftListModels.get(position)));
|
||||
}
|
||||
});
|
||||
wishGiftViewHolder.onSelect(index == position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return giftListModels.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.yunbao.common.adapter;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LiveNewWishListAdapter extends FragmentStateAdapter {
|
||||
private List<Fragment> list = new ArrayList<>();
|
||||
|
||||
public LiveNewWishListAdapter(@NonNull FragmentActivity fragmentActivity, List<Fragment> list) {
|
||||
super(fragmentActivity);
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
return list.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return list.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.yunbao.common.bean;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class GiftListModel extends BaseModel {
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
@SerializedName("price")
|
||||
private String price;
|
||||
@SerializedName("img")
|
||||
private String img;
|
||||
@SerializedName("id")
|
||||
private String id;
|
||||
@SerializedName("gift_type")
|
||||
private String giftType;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public GiftListModel setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public GiftListModel setPrice(String price) {
|
||||
this.price = price;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
|
||||
public GiftListModel setImg(String img) {
|
||||
this.img = img;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public GiftListModel setId(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getGiftType() {
|
||||
return giftType;
|
||||
}
|
||||
|
||||
public GiftListModel setGiftType(String giftType) {
|
||||
this.giftType = giftType;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GiftListModel{" +
|
||||
"name='" + name + '\'' +
|
||||
", price='" + price + '\'' +
|
||||
", img='" + img + '\'' +
|
||||
", id='" + id + '\'' +
|
||||
", giftType='" + giftType + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.yunbao.common.bean;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 心愿单礼物配置
|
||||
*/
|
||||
public class WishListGiftConfModel extends BaseModel {
|
||||
|
||||
@SerializedName("giftList")
|
||||
private List<GiftListModel> giftList = new ArrayList<>();
|
||||
@SerializedName("guardList")
|
||||
private List<GiftListModel> guardList = new ArrayList<>();
|
||||
@SerializedName("nobleList")
|
||||
private List<GiftListModel> nobleList = new ArrayList<>();
|
||||
|
||||
public List<GiftListModel> getGiftList() {
|
||||
return giftList;
|
||||
}
|
||||
|
||||
public WishListGiftConfModel setGiftList(List<GiftListModel> giftList) {
|
||||
this.giftList = giftList;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<GiftListModel> getGuardList() {
|
||||
return guardList;
|
||||
}
|
||||
|
||||
public WishListGiftConfModel setGuardList(List<GiftListModel> guardList) {
|
||||
this.guardList = guardList;
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<GiftListModel> getNobleList() {
|
||||
return nobleList;
|
||||
}
|
||||
|
||||
public WishListGiftConfModel setNobleList(List<GiftListModel> nobleList) {
|
||||
this.nobleList = nobleList;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,12 @@ package com.yunbao.common.bean;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WishListModel extends BaseModel {
|
||||
@SerializedName("wishList")
|
||||
private List<WishModel> wishList;
|
||||
private List<WishModel> wishList = new ArrayList<>();
|
||||
@SerializedName("img")
|
||||
private String img;
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.yunbao.common.bean;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WishListModel2 extends BaseModel {
|
||||
|
||||
@SerializedName("wishlist")
|
||||
private List<List<WishModel>> wishlist;
|
||||
@SerializedName("img")
|
||||
private String img;
|
||||
|
||||
public List<List<WishModel>> getWishlist() {
|
||||
return wishlist;
|
||||
}
|
||||
|
||||
public WishListModel2 setWishlist(List<List<WishModel>> wishlist) {
|
||||
this.wishlist = wishlist;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
|
||||
public WishListModel2 setImg(String img) {
|
||||
this.img = img;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,12 @@ public class WishModel extends BaseModel {
|
||||
private String wishlistName;
|
||||
@SerializedName("create_time")
|
||||
private String createTime;
|
||||
@SerializedName("type")
|
||||
private int type;
|
||||
@SerializedName("gift_type")
|
||||
private int giftType;
|
||||
@SerializedName("price")
|
||||
private int price;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
@@ -103,4 +109,50 @@ public class WishModel extends BaseModel {
|
||||
this.createTime = createTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public WishModel setType(int type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getGiftType() {
|
||||
return giftType;
|
||||
}
|
||||
|
||||
public WishModel setGiftType(int giftType) {
|
||||
this.giftType = giftType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public WishModel setPrice(int price) {
|
||||
this.price = price;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int wishProgress() {
|
||||
int progress = 0;
|
||||
try {
|
||||
progress = Integer.parseInt(wishlistNum);
|
||||
} catch (NumberFormatException e) {
|
||||
progress = 0;
|
||||
}
|
||||
return progress;
|
||||
}
|
||||
public int wishCurrent(){
|
||||
int current = 0;
|
||||
try {
|
||||
current = Integer.parseInt(wishlistProgress);
|
||||
} catch (NumberFormatException e) {
|
||||
current = 0;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.yunbao.common.event;
|
||||
|
||||
import com.yunbao.common.bean.BaseModel;
|
||||
import com.yunbao.common.bean.GiftListModel;
|
||||
|
||||
public class LiveNewWishGiftEvent extends BaseModel {
|
||||
private GiftListModel model;
|
||||
|
||||
public GiftListModel getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public LiveNewWishGiftEvent setModel(GiftListModel model) {
|
||||
this.model = model;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yunbao.common.event;
|
||||
|
||||
import com.yunbao.common.bean.BaseModel;
|
||||
import com.yunbao.common.bean.GiftListModel;
|
||||
|
||||
public class LiveNewWishListEvent extends BaseModel {
|
||||
private GiftListModel model;
|
||||
private int type = 0;
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public LiveNewWishListEvent setType(int type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GiftListModel getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public LiveNewWishListEvent setModel(GiftListModel model) {
|
||||
this.model = model;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package com.yunbao.common.fragment;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.shencoder.pagergridlayoutmanager.PagerGridLayoutManager;
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.adapter.LiveNewWishGiftAdapter;
|
||||
import com.yunbao.common.bean.GiftListModel;
|
||||
import com.yunbao.common.utils.DpUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class LiveNewWishGiftFragment extends BaseFragment {
|
||||
private List<GiftListModel> giftListModels;
|
||||
private RecyclerView giftList;
|
||||
private LiveNewWishGiftAdapter liveNewWishGiftAdapter;
|
||||
private TabLayout wishTab;
|
||||
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
return inflater.inflate(R.layout.view_live_new_wish_gitf, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initVariables(Bundle bundle) {
|
||||
giftListModels = (List<GiftListModel>) bundle.getSerializable("GiftList");
|
||||
for (GiftListModel model : giftListModels) {
|
||||
Log.e("LiveNewWishGiftFragment", model.getName());
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews(Bundle savedInstanceState, View contentView) {
|
||||
wishTab = contentView.findViewById(R.id.wish_tab);
|
||||
wishTab.setSelectedTabIndicatorColor(Color.TRANSPARENT);
|
||||
wishTab.setFocusableInTouchMode(false);
|
||||
|
||||
//计算总页数
|
||||
int pagerCount = giftListModels.size() / 8;
|
||||
if (giftListModels.size() % 8 != 0) {
|
||||
++pagerCount;
|
||||
}
|
||||
|
||||
if (pagerCount > 1) {
|
||||
for (int i = 0; i < pagerCount; i++) {
|
||||
TextView wishItem = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.view_tablaout_wish_item, null, false);
|
||||
TabLayout.Tab tab = wishTab.newTab().setCustomView(wishItem).setId(i);
|
||||
|
||||
wishTab.addTab(tab, i == 0);
|
||||
}
|
||||
ViewGroup tabs = (ViewGroup) wishTab.getChildAt(0);
|
||||
//设置边距,tab宽
|
||||
for (int i = 0; i < tabs.getChildCount(); i++) {
|
||||
View tab = tabs.getChildAt(i);
|
||||
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) tab.getLayoutParams();
|
||||
layoutParams.rightMargin = DpUtil.dp2px(5);
|
||||
layoutParams.leftMargin = DpUtil.dp2px(5);
|
||||
layoutParams.width = DpUtil.dp2px(6);
|
||||
layoutParams.height = DpUtil.dp2px(6);
|
||||
tab.setLayoutParams(layoutParams);
|
||||
wishTab.requestLayout();
|
||||
}
|
||||
wishTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
View customView = tab.getCustomView();
|
||||
customView.setSelected(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
View customView = tab.getCustomView();
|
||||
customView.setSelected(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
|
||||
}
|
||||
});
|
||||
} else {
|
||||
wishTab.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
giftList = contentView.findViewById(R.id.gift_list);
|
||||
liveNewWishGiftAdapter = new LiveNewWishGiftAdapter(giftListModels);
|
||||
PagerGridLayoutManager layoutManager = new PagerGridLayoutManager( /*rows*/2,
|
||||
/*columns*/ 4,
|
||||
/*PagerGridLayoutManager.VERTICAL*/PagerGridLayoutManager.HORIZONTAL,
|
||||
/*reverseLayout*/ false);
|
||||
layoutManager.setHandlingSlidingConflictsEnabled(true);
|
||||
giftList.setLayoutManager(layoutManager);
|
||||
giftList.setAdapter(liveNewWishGiftAdapter);
|
||||
layoutManager.setPagerChangedListener(new PagerGridLayoutManager.PagerChangedListener() {
|
||||
@Override
|
||||
public void onPagerCountChanged(int pagerCount) {
|
||||
Log.e("LiveNewWishGiftFragment", "onPagerCountChanged-pagerCount:" + pagerCount);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPagerIndexSelected(int prePagerIndex, int currentPagerIndex) {
|
||||
Log.e("LiveNewWishGiftFragment", "onPagerIndexSelected-prePagerIndex " + prePagerIndex + ",currentPagerIndex:" + currentPagerIndex);
|
||||
if (wishTab.getVisibility() == View.VISIBLE)
|
||||
wishTab.getTabAt(currentPagerIndex).select();
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadData() {
|
||||
|
||||
}
|
||||
|
||||
public static LiveNewWishGiftFragment newInstance(List<GiftListModel> giftListModels) {
|
||||
LiveNewWishGiftFragment searchRecommendFragment = new LiveNewWishGiftFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable("GiftList", (Serializable) giftListModels);
|
||||
searchRecommendFragment.setArguments(bundle);
|
||||
return searchRecommendFragment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.yunbao.common.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.lxj.xpopup.XPopup;
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.adapter.LiveNewWishAdapter;
|
||||
import com.yunbao.common.bean.WishListModel;
|
||||
import com.yunbao.common.bean.WishModel;
|
||||
import com.yunbao.common.http.base.HttpCallback;
|
||||
import com.yunbao.common.http.live.LiveNetManager;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.common.views.LiveNewWishGiftPopup;
|
||||
|
||||
public class LiveNewWishListFragment extends BaseFragment {
|
||||
private int type = 0;
|
||||
private RecyclerView wishList;
|
||||
private LiveNewWishAdapter liveNewWishAdapter;
|
||||
private ImageView imageView2;
|
||||
|
||||
@Override
|
||||
public View createView(LayoutInflater layoutInflater, ViewGroup viewGroup) {
|
||||
return layoutInflater.inflate(R.layout.view_live_new_wish, viewGroup, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initVariables(Bundle bundle) {
|
||||
type = bundle.getInt("type", 0);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews(Bundle savedInstanceState, View contentView) {
|
||||
wishList = contentView.findViewById(R.id.wish_list);
|
||||
imageView2 = contentView.findViewById(R.id.imageView2);
|
||||
liveNewWishAdapter = new LiveNewWishAdapter();
|
||||
wishList.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
|
||||
wishList.setAdapter(liveNewWishAdapter);
|
||||
imageView2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new XPopup.Builder(getContext())
|
||||
.enableDrag(false)
|
||||
.asCustom(new LiveNewWishGiftPopup(getActivity(), type))
|
||||
.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadData() {
|
||||
LiveNetManager.get(getContext()).getWishlistV2(new HttpCallback<WishListModel>() {
|
||||
@Override
|
||||
public void onSuccess(WishListModel data) {
|
||||
liveNewWishAdapter.addData(data.getWishList(), type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
ToastUtil.show(R.string.net_error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static LiveNewWishListFragment newInstance(int type) {
|
||||
LiveNewWishListFragment searchRecommendFragment = new LiveNewWishListFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("type", type);
|
||||
|
||||
searchRecommendFragment.setArguments(bundle);
|
||||
return searchRecommendFragment;
|
||||
}
|
||||
|
||||
public void addGiftListModel(WishModel model) {
|
||||
liveNewWishAdapter.addGiftListModel(model);
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,9 @@ import com.yunbao.common.bean.SetAttentsModel;
|
||||
import com.yunbao.common.bean.SlideInBannerModel;
|
||||
import com.yunbao.common.bean.StarChallengeStatusModel;
|
||||
import com.yunbao.common.bean.VipModel;
|
||||
import com.yunbao.common.bean.WishListGiftConfModel;
|
||||
import com.yunbao.common.bean.WishListModel;
|
||||
import com.yunbao.common.bean.WishListModel2;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -636,4 +639,37 @@ public interface PDLiveApi {
|
||||
Observable<ResponseModel<String>> delContactMsg(
|
||||
@Query("msgId") int msgId
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取心愿单配置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET("/api/public/?service=Guide.getWishlistV2")
|
||||
Observable<ResponseModel<List<WishListModel>>> getWishlistV2();
|
||||
|
||||
/**
|
||||
* 获取礼物配置
|
||||
*
|
||||
* @param type 1日心愿单,2周,3月,4季度
|
||||
* @return
|
||||
*/
|
||||
@GET("/api/public/?service=Guide.getWishListGiftConf")
|
||||
Observable<ResponseModel<WishListGiftConfModel>> getWishListGiftConf(
|
||||
@Query("type") int type
|
||||
);
|
||||
|
||||
/**
|
||||
* 设置心愿单
|
||||
*
|
||||
* @param type 1日心愿单,2周,3月,4季度
|
||||
* @param list 列表json数据
|
||||
* @return
|
||||
*/
|
||||
@GET("/api/public/?service=Guide.setWishlistV2")
|
||||
Observable<ResponseModel<String>> setWishlistV2(
|
||||
@Query("type") int type,
|
||||
@Query("list") String list
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ import com.yunbao.common.bean.RankPkInfoBean;
|
||||
import com.yunbao.common.bean.SetAttentsModel;
|
||||
import com.yunbao.common.bean.StarChallengeStatusModel;
|
||||
import com.yunbao.common.bean.VipModel;
|
||||
import com.yunbao.common.bean.WishListGiftConfModel;
|
||||
import com.yunbao.common.bean.WishListModel;
|
||||
import com.yunbao.common.bean.WishListModel2;
|
||||
import com.yunbao.common.http.API;
|
||||
import com.yunbao.common.http.ResponseModel;
|
||||
import com.yunbao.common.http.base.CheckLiveCallBack;
|
||||
@@ -1287,6 +1290,55 @@ public class LiveNetManager {
|
||||
}).isDisposed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取心愿单配置
|
||||
*
|
||||
* @param callback
|
||||
*/
|
||||
public void getWishlistV2(HttpCallback<WishListModel> callback) {
|
||||
API.get().pdLiveApi(mContext)
|
||||
.getWishlistV2()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Consumer<ResponseModel<List<WishListModel>>>() {
|
||||
@Override
|
||||
public void accept(ResponseModel<List<WishListModel>> listResponseModel) throws Exception {
|
||||
if (callback != null) {
|
||||
callback.onSuccess(listResponseModel.getData().getInfo().get(0));
|
||||
}
|
||||
}
|
||||
}, new Consumer<Throwable>() {
|
||||
@Override
|
||||
public void accept(Throwable throwable) throws Exception {
|
||||
if (callback != null) {
|
||||
callback.onError(throwable.getMessage());
|
||||
}
|
||||
}
|
||||
}).isDisposed();
|
||||
}
|
||||
|
||||
public void getWishListGiftConf(int type, HttpCallback<WishListGiftConfModel> callback) {
|
||||
API.get().pdLiveApi(mContext)
|
||||
.getWishListGiftConf(type)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Consumer<ResponseModel<WishListGiftConfModel>>() {
|
||||
@Override
|
||||
public void accept(ResponseModel<WishListGiftConfModel> wishListGiftConfModelResponseModel) throws Exception {
|
||||
if (callback != null) {
|
||||
callback.onSuccess(wishListGiftConfModelResponseModel.getData().getInfo());
|
||||
}
|
||||
}
|
||||
}, new Consumer<Throwable>() {
|
||||
@Override
|
||||
public void accept(Throwable throwable) throws Exception {
|
||||
if (callback != null) {
|
||||
callback.onError(throwable.getMessage());
|
||||
}
|
||||
}
|
||||
}).isDisposed();
|
||||
}
|
||||
|
||||
/**
|
||||
* 直播间取消网络请求
|
||||
*/
|
||||
|
||||
@@ -33,4 +33,30 @@ public class WordsTypeUtil {
|
||||
}
|
||||
return changeText;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} num
|
||||
* @returns ---汉字
|
||||
*/
|
||||
// 转换数字为大写
|
||||
public static String numberConvertToUppercase(int number) {
|
||||
String[] upperCaseNumber = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"};
|
||||
int length = String.valueOf(number).length();
|
||||
if (length == 1) {
|
||||
return upperCaseNumber[number];
|
||||
} else if (length == 2) {
|
||||
if (number == 10) {
|
||||
return upperCaseNumber[number];
|
||||
} else if (number > 10 && number < 20) {
|
||||
return upperCaseNumber[10] + upperCaseNumber[number - 10];
|
||||
} else {
|
||||
int num1 = number / 10;
|
||||
int num2 = number - (num1 * 10);
|
||||
return upperCaseNumber[num1] + upperCaseNumber[10] + upperCaseNumber[num2];
|
||||
}
|
||||
} else {
|
||||
return String.valueOf(number);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.yunbao.common.views;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.bean.WishModel;
|
||||
import com.yunbao.common.glide.ImgLoader;
|
||||
import com.yunbao.common.utils.WordsTypeUtil;
|
||||
import com.yunbao.common.views.weight.ViewClicksAntiShake;
|
||||
|
||||
/**
|
||||
* 日心愿单
|
||||
*/
|
||||
public class DayWishItemViewHolder extends RecyclerView.ViewHolder {
|
||||
private TextView wishTab, wishlistName, wishlistProgress, wishlistNum, wishlistNum2, subtraction, addition;
|
||||
private ImageView wishIcon;
|
||||
private FrameLayout wishIconBg, tabBg,iconCancel;
|
||||
private ProgressBar progressBar;
|
||||
|
||||
public DayWishItemViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
wishTab = itemView.findViewById(R.id.wish_tab);
|
||||
wishIcon = itemView.findViewById(R.id.wish_icon);
|
||||
tabBg = itemView.findViewById(R.id.tab_bg);
|
||||
wishIconBg = itemView.findViewById(R.id.wish_icon_bg);
|
||||
iconCancel = itemView.findViewById(R.id.icon_cancel);
|
||||
wishlistName = itemView.findViewById(R.id.wishlist_name);
|
||||
progressBar = itemView.findViewById(R.id.progressBar);
|
||||
wishlistProgress = itemView.findViewById(R.id.wishlist_progress);
|
||||
wishlistNum = itemView.findViewById(R.id.wishlist_num);
|
||||
wishlistNum2 = itemView.findViewById(R.id.wishlist_num2);
|
||||
subtraction = itemView.findViewById(R.id.subtraction);
|
||||
addition = itemView.findViewById(R.id.addition);
|
||||
}
|
||||
|
||||
public void steDayWishData(WishModel model, int index, DayWishItemListener listener) {
|
||||
if (model != null) {
|
||||
itemView.findViewById(R.id.hind_layout).setVisibility(View.VISIBLE);
|
||||
itemView.findViewById(R.id.wish_icon_bg).setVisibility(View.VISIBLE);
|
||||
itemView.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
|
||||
iconCancel.setVisibility(View.VISIBLE);
|
||||
wishTab.setVisibility(View.VISIBLE);
|
||||
wishlistName.setVisibility(View.VISIBLE);
|
||||
wishTab.setText(String.format(itemView.getContext().getString(R.string.wish_number), WordsTypeUtil.numberConvertToUppercase(index + 1)));
|
||||
ImgLoader.display(itemView.getContext(), model.getWishlistIcon(), wishIcon);
|
||||
tabBg.setBackgroundResource(R.mipmap.bg_day_wish);
|
||||
wishIconBg.setBackgroundResource(R.mipmap.background_wish_item);
|
||||
wishlistName.setText(model.getWishlistName());
|
||||
progressBar.setMax(model.wishProgress());
|
||||
progressBar.setProgress(model.wishCurrent());//当前进度
|
||||
wishlistProgress.setText(model.getWishlistProgress());
|
||||
wishlistNum.setText(String.format("/%s", model.getWishlistNum()));
|
||||
wishlistNum2.setText(String.format("x%s", model.getWishlistNum()));
|
||||
ViewClicksAntiShake.clicksAntiShake(iconCancel, new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
if (listener != null) {
|
||||
listener.onDelete(index);
|
||||
}
|
||||
}
|
||||
});
|
||||
ViewClicksAntiShake.clicksAntiShake(addition, new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
int number = model.wishProgress();
|
||||
model.setWishlistNum(String.valueOf(number + 1));
|
||||
if (listener != null) {
|
||||
listener.onUpdate(model, index);
|
||||
}
|
||||
}
|
||||
});
|
||||
ViewClicksAntiShake.clicksAntiShake(subtraction, new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
int number = model.wishProgress();
|
||||
model.setWishlistNum(String.valueOf(number - 1));
|
||||
if (listener != null) {
|
||||
listener.onUpdate(model, index);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
itemView.findViewById(R.id.hind_layout).setVisibility(View.GONE);
|
||||
itemView.findViewById(R.id.progress_bar).setVisibility(View.GONE);
|
||||
tabBg.setBackground(null);
|
||||
wishTab.setVisibility(View.GONE);
|
||||
wishlistName.setVisibility(View.GONE);
|
||||
iconCancel.setVisibility(View.GONE);
|
||||
itemView.findViewById(R.id.wish_icon_bg).setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public interface DayWishItemListener {
|
||||
void onDelete(int index);
|
||||
|
||||
void onUpdate(WishModel model, int index);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package com.yunbao.common.views;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.lxj.xpopup.core.BottomPopupView;
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.adapter.LiveNewWishListAdapter;
|
||||
import com.yunbao.common.bean.GiftListModel;
|
||||
import com.yunbao.common.bean.WishListGiftConfModel;
|
||||
import com.yunbao.common.event.LiveNewWishGiftEvent;
|
||||
import com.yunbao.common.event.LiveNewWishListEvent;
|
||||
import com.yunbao.common.fragment.LiveNewWishGiftFragment;
|
||||
import com.yunbao.common.http.base.HttpCallback;
|
||||
import com.yunbao.common.http.live.LiveNetManager;
|
||||
import com.yunbao.common.utils.Bus;
|
||||
import com.yunbao.common.utils.DpUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.common.views.weight.ViewClicksAntiShake;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LiveNewWishGiftPopup extends BottomPopupView {
|
||||
private TabLayout wishTab;
|
||||
private int type = 0;
|
||||
private ViewPager2 fragmentViewpager;
|
||||
private FragmentActivity mContext;
|
||||
private ArrayList<Fragment> ViewList = new ArrayList<>(); //页卡视图集合
|
||||
private GiftListModel model = null;
|
||||
private Button wishGitfButton;
|
||||
|
||||
public LiveNewWishGiftPopup(@NonNull FragmentActivity context, int type) {
|
||||
super(context);
|
||||
this.type = type;
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
// 返回自定义弹窗的布局
|
||||
@Override
|
||||
protected int getImplLayoutId() {
|
||||
return R.layout.dialog_live_new_wish_gitf;
|
||||
}
|
||||
|
||||
// 执行初始化操作,比如:findView,设置点击,或者任何你弹窗内的业务逻辑
|
||||
@Override
|
||||
protected void onCreate() {
|
||||
super.onCreate();
|
||||
Bus.getOn(this);
|
||||
initView();
|
||||
initDate();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDismiss() {
|
||||
super.onDismiss();
|
||||
Bus.getOff(this);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onLiveNewWishGiftEvent(LiveNewWishGiftEvent event) {
|
||||
model = event.getModel();
|
||||
Log.e("LiveNewWishGiftPopup", model.toString());
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
fragmentViewpager = findViewById(R.id.context_layout);
|
||||
wishGitfButton = findViewById(R.id.wish_gitf_button);
|
||||
wishTab = findViewById(R.id.wish_tab);
|
||||
wishTab.setSelectedTabIndicatorColor(Color.TRANSPARENT);
|
||||
wishTab.setFocusableInTouchMode(false);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
TextView wishItem = (TextView) LayoutInflater.from(getContext())
|
||||
.inflate(R.layout.view_tablaout_wish_item, null, false);
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
wishItem.setText(R.string.live_gift);
|
||||
wishItem.setTextColor(Color.parseColor("#FFBE41"));
|
||||
break;
|
||||
case 1:
|
||||
wishItem.setText(R.string.aristocrat);
|
||||
wishItem.setTextColor(Color.parseColor("#B6B6B6"));
|
||||
break;
|
||||
case 2:
|
||||
wishItem.setText(R.string.live_guard);
|
||||
wishItem.setTextColor(Color.parseColor("#B6B6B6"));
|
||||
break;
|
||||
}
|
||||
TabLayout.Tab tab = wishTab.newTab().setCustomView(wishItem).setId(i);
|
||||
wishTab.addTab(tab, i == 0);
|
||||
}
|
||||
ViewGroup tabs = (ViewGroup) wishTab.getChildAt(0);
|
||||
//设置边距,tab宽
|
||||
for (int i = 0; i < tabs.getChildCount() - 1; i++) {
|
||||
View tab = tabs.getChildAt(i);
|
||||
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) tab.getLayoutParams();
|
||||
layoutParams.setMarginEnd(DpUtil.dp2px(4));
|
||||
layoutParams.width = DpUtil.dp2px(58);
|
||||
tab.setLayoutParams(layoutParams);
|
||||
wishTab.requestLayout();
|
||||
}
|
||||
wishTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
TextView customView = (TextView) tab.getCustomView();
|
||||
customView.setTextColor(Color.parseColor("#FFBE41"));
|
||||
fragmentViewpager.setCurrentItem(tab.getId(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
TextView customView = (TextView) tab.getCustomView();
|
||||
customView.setTextColor(Color.parseColor("#B6B6B6"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
|
||||
}
|
||||
});
|
||||
ViewClicksAntiShake.clicksAntiShake(wishGitfButton, new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
if (model != null) {
|
||||
Bus.get().post(new LiveNewWishListEvent()
|
||||
.setModel(model)
|
||||
.setType(type));
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initDate() {
|
||||
LiveNetManager.get(getContext()).getWishListGiftConf(type, new HttpCallback<WishListGiftConfModel>() {
|
||||
@Override
|
||||
public void onSuccess(WishListGiftConfModel data) {
|
||||
List<GiftListModel> giftListModels = new ArrayList<>();
|
||||
giftListModels.addAll(data.getGiftList());
|
||||
giftListModels.addAll(data.getGiftList());
|
||||
giftListModels.addAll(data.getGiftList());
|
||||
giftListModels.addAll(data.getGiftList());
|
||||
giftListModels.addAll(data.getGiftList());
|
||||
giftListModels.addAll(data.getGiftList());
|
||||
giftListModels.addAll(data.getGiftList());
|
||||
giftListModels.addAll(data.getGiftList());
|
||||
giftListModels.addAll(data.getGiftList());
|
||||
ViewList.add(LiveNewWishGiftFragment.newInstance(giftListModels));
|
||||
ViewList.add(LiveNewWishGiftFragment.newInstance(data.getNobleList()));
|
||||
ViewList.add(LiveNewWishGiftFragment.newInstance(data.getGuardList()));
|
||||
LiveNewWishListAdapter liveNewWishListAdapter = new LiveNewWishListAdapter(mContext, ViewList);
|
||||
fragmentViewpager.setAdapter(liveNewWishListAdapter);
|
||||
fragmentViewpager.setOffscreenPageLimit(1); //预加载页面数
|
||||
//禁止左右滑动,false为禁止
|
||||
fragmentViewpager.setUserInputEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
ToastUtil.show(R.string.net_error);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.yunbao.common.views;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.bean.GiftListModel;
|
||||
import com.yunbao.common.glide.ImgLoader;
|
||||
import com.yunbao.common.views.weight.ViewClicksAntiShake;
|
||||
|
||||
/**
|
||||
* 心愿礼物配置页面
|
||||
*/
|
||||
public class LiveNewWishGiftViewHolder extends RecyclerView.ViewHolder {
|
||||
private ImageView giftImg;
|
||||
private TextView giftName;
|
||||
|
||||
public LiveNewWishGiftViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
giftImg = itemView.findViewById(R.id.gift_img);
|
||||
giftName = itemView.findViewById(R.id.gift_name);
|
||||
}
|
||||
|
||||
public void setData(GiftListModel model, ViewClicksAntiShake.ViewClicksCallBack callBack) {
|
||||
ImgLoader.display(itemView.getContext(), model.getImg(), giftImg);
|
||||
giftName.setText(model.getName());
|
||||
ViewClicksAntiShake.clicksAntiShake(itemView.findViewById(R.id.wish_gift), callBack);
|
||||
}
|
||||
|
||||
public void onSelect(boolean select) {
|
||||
itemView.findViewById(R.id.wish_gift).setSelected(select);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
package com.yunbao.common.views;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.lxj.xpopup.core.BottomPopupView;
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.adapter.LiveNewWishListAdapter;
|
||||
import com.yunbao.common.bean.WishModel;
|
||||
import com.yunbao.common.event.LiveNewWishListEvent;
|
||||
import com.yunbao.common.fragment.LiveNewWishListFragment;
|
||||
import com.yunbao.common.utils.Bus;
|
||||
import com.yunbao.common.utils.DpUtil;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* 新版心愿单
|
||||
*/
|
||||
public class LiveNewWishListPopup extends BottomPopupView {
|
||||
private TabLayout wishTab;
|
||||
private FragmentActivity mContext;
|
||||
private ViewPager2 fragmentViewpager;
|
||||
private ArrayList<Fragment> ViewList = new ArrayList<>(); //页卡视图集合
|
||||
|
||||
private LiveNewWishListFragment dayWishFragment, zhouXinFragment, lunarWishFragment, seasonalWishFragment;
|
||||
|
||||
public LiveNewWishListPopup(@NonNull FragmentActivity context) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
// 返回自定义弹窗的布局
|
||||
@Override
|
||||
protected int getImplLayoutId() {
|
||||
return R.layout.dialog_live_new_wish_list;
|
||||
}
|
||||
|
||||
// 执行初始化操作,比如:findView,设置点击,或者任何你弹窗内的业务逻辑
|
||||
@Override
|
||||
protected void onCreate() {
|
||||
super.onCreate();
|
||||
Bus.getOn(this);
|
||||
initView();
|
||||
initDate();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDismiss() {
|
||||
Bus.getOff(this);
|
||||
super.onDismiss();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onLiveNewWishListEvent(LiveNewWishListEvent event) {
|
||||
WishModel model = new WishModel();
|
||||
model.setId(event.getModel().getId())
|
||||
.setWishlistName(event.getModel().getName())
|
||||
.setWishlistIcon(event.getModel().getImg())
|
||||
.setWishlistNum("1")
|
||||
.setWishlistProgress("0")
|
||||
.setPrice(Integer.parseInt(event.getModel().getPrice()))
|
||||
.setGiftType(Integer.parseInt(event.getModel().getGiftType()))
|
||||
.setType(event.getType());
|
||||
switch (event.getType()) {
|
||||
case 1:
|
||||
dayWishFragment.addGiftListModel(model);
|
||||
break;
|
||||
case 2:
|
||||
zhouXinFragment.addGiftListModel(model);
|
||||
break;
|
||||
case 3:
|
||||
lunarWishFragment.addGiftListModel(model);
|
||||
break;
|
||||
case 4:
|
||||
lunarWishFragment.addGiftListModel(model);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
fragmentViewpager = findViewById(R.id.context_layout);
|
||||
wishTab = findViewById(R.id.wish_tab);
|
||||
wishTab.setSelectedTabIndicatorColor(Color.TRANSPARENT);
|
||||
wishTab.setFocusableInTouchMode(false);
|
||||
dayWishFragment = LiveNewWishListFragment.newInstance(1);
|
||||
zhouXinFragment = LiveNewWishListFragment.newInstance(2);
|
||||
lunarWishFragment = LiveNewWishListFragment.newInstance(3);
|
||||
seasonalWishFragment = LiveNewWishListFragment.newInstance(4);
|
||||
ViewList.add(dayWishFragment);
|
||||
ViewList.add(zhouXinFragment);
|
||||
ViewList.add(lunarWishFragment);
|
||||
ViewList.add(seasonalWishFragment);
|
||||
|
||||
LiveNewWishListAdapter liveNewWishListAdapter = new LiveNewWishListAdapter(mContext, ViewList);
|
||||
fragmentViewpager.setAdapter(liveNewWishListAdapter);
|
||||
|
||||
fragmentViewpager.setOffscreenPageLimit(1); //预加载页面数
|
||||
|
||||
//禁止左右滑动,false为禁止
|
||||
fragmentViewpager.setUserInputEnabled(false);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
TextView wishItem = (TextView) LayoutInflater.from(getContext())
|
||||
.inflate(R.layout.view_tablaout_wish_item, null, false);
|
||||
switch (i) {
|
||||
case 0:
|
||||
wishItem.setText(R.string.day_wish);
|
||||
break;
|
||||
case 1:
|
||||
wishItem.setText(R.string.zhou_xin);
|
||||
break;
|
||||
case 2:
|
||||
wishItem.setText(R.string.lunar_wish);
|
||||
break;
|
||||
case 3:
|
||||
wishItem.setText(R.string.seasonal_wish);
|
||||
break;
|
||||
}
|
||||
TabLayout.Tab tab = wishTab.newTab().setCustomView(wishItem).setId(i);
|
||||
wishTab.addTab(tab, i == 0);
|
||||
}
|
||||
ViewGroup tabs = (ViewGroup) wishTab.getChildAt(0);
|
||||
//设置边距,tab宽
|
||||
for (int i = 0; i < tabs.getChildCount() - 1; i++) {
|
||||
View tab = tabs.getChildAt(i);
|
||||
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) tab.getLayoutParams();
|
||||
layoutParams.setMarginEnd(DpUtil.dp2px(6));
|
||||
layoutParams.width = DpUtil.dp2px(83);
|
||||
tab.setLayoutParams(layoutParams);
|
||||
wishTab.requestLayout();
|
||||
}
|
||||
wishTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
View customView = tab.getCustomView();
|
||||
customView.setSelected(true);
|
||||
fragmentViewpager.setCurrentItem(tab.getId(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
View customView = tab.getCustomView();
|
||||
customView.setSelected(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initDate() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yunbao.common.views;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class LunarWishItemViewHolder extends RecyclerView.ViewHolder {
|
||||
public LunarWishItemViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yunbao.common.views;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class SeasonalWishItemViewHolder extends RecyclerView.ViewHolder {
|
||||
public SeasonalWishItemViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yunbao.common.views;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class WeekWishItemViewHolder extends RecyclerView.ViewHolder {
|
||||
public WeekWishItemViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user