月心愿单的设置与展示

This commit is contained in:
18401019693 2023-03-30 16:36:53 +08:00
parent 55290a71aa
commit 87ba382e81
3 changed files with 208 additions and 9 deletions

View File

@ -95,6 +95,20 @@ public class LiveNewWishAdapter extends RecyclerView.Adapter {
}); });
} else if (holder instanceof LunarWishItemViewHolder) { } else if (holder instanceof LunarWishItemViewHolder) {
LunarWishItemViewHolder lunarWishItemViewHolder = (LunarWishItemViewHolder) holder; LunarWishItemViewHolder lunarWishItemViewHolder = (LunarWishItemViewHolder) holder;
lunarWishItemViewHolder.steLunarWishData(wishList.get(position), position, new LunarWishItemViewHolder.LunarWishItemListener() {
@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 SeasonalWishItemViewHolder) { } else if (holder instanceof SeasonalWishItemViewHolder) {
SeasonalWishItemViewHolder seasonalWishItemViewHolder = (SeasonalWishItemViewHolder) holder; SeasonalWishItemViewHolder seasonalWishItemViewHolder = (SeasonalWishItemViewHolder) holder;
} }

View File

@ -1,12 +1,103 @@
package com.yunbao.common.views; package com.yunbao.common.views;
import android.view.View; 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.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; 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 LunarWishItemViewHolder extends RecyclerView.ViewHolder { public class LunarWishItemViewHolder extends RecyclerView.ViewHolder {
private TextView wishTab, wishlistName, wishlistProgress, wishlistNum, wishlistNum2, subtraction, addition;
private ImageView wishIcon;
private FrameLayout wishIconBg, tabBg, iconCancel;
private ProgressBar progressBar;
public LunarWishItemViewHolder(@NonNull View itemView) { public LunarWishItemViewHolder(@NonNull View itemView) {
super(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 steLunarWishData(WishModel model, int index, LunarWishItemListener 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_lunar_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 LunarWishItemListener {
void onDelete(int index);
void onUpdate(WishModel model, int index);
} }
} }

View File

@ -1,33 +1,44 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab_bg"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="125dp" android:layout_height="125dp"
android:layout_margin="4dp" android:layout_margin="4dp"
android:background="@mipmap/bg_lunar_wish"> android:background="@mipmap/bg_lunar_wish">
<FrameLayout
android:id="@+id/icon_cancel"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end"
android:layout_marginTop="4dp"
android:layout_marginEnd="19dp">
<ImageView <ImageView
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
android:layout_gravity="end" android:layout_gravity="end"
android:layout_marginTop="4dp"
android:layout_marginEnd="19dp"
android:background="@mipmap/icon_cancel" /> android:background="@mipmap/icon_cancel" />
</FrameLayout>
<TextView <TextView
android:id="@+id/wish_tab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="18dp" android:layout_marginStart="18dp"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:text="心願二"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="14sp" /> android:textSize="14sp" />
<FrameLayout <FrameLayout
android:id="@+id/wish_icon_bg"
android:layout_width="64dp" android:layout_width="64dp"
android:layout_height="64dp" android:layout_height="64dp"
android:layout_marginStart="11dp" android:layout_marginStart="11dp"
android:layout_marginTop="40dp" android:layout_marginTop="40dp">
android:background="@drawable/background_wish_item">
<ImageView <ImageView
android:id="@+id/wish_icon" android:id="@+id/wish_icon"
@ -35,4 +46,87 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="3dp" /> android:layout_margin="3dp" />
</FrameLayout> </FrameLayout>
<TextView
android:id="@+id/wishlist_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="85dp"
android:layout_marginTop="49dp"
android:textColor="@color/white"
android:textSize="16sp" />
<LinearLayout
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="85dp"
android:layout_marginTop="78dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="100dp"
android:layout_height="11dp"
android:max="100"
android:progress="30"
android:progressDrawable="@drawable/progress_wishlist2" />
<TextView
android:id="@+id/wishlist_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="9dp"
android:text="2"
android:textColor="#FFE062"
android:textSize="12sp" />
<TextView
android:id="@+id/wishlist_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/20"
android:textColor="@color/white"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/hind_layout"
android:layout_width="70dp"
android:layout_height="20dp"
android:layout_gravity="end"
android:layout_marginTop="77dp"
android:layout_marginEnd="19dp"
android:background="@drawable/bg_xyd_number"
android:orientation="horizontal">
<TextView
android:id="@+id/subtraction"
android:layout_width="20dp"
android:layout_height="match_parent"
android:gravity="center"
android:text="-"
android:textColor="@color/white"
android:textSize="16sp" />
<TextView
android:id="@+id/wishlist_num2"
android:layout_width="30dp"
android:layout_height="match_parent"
android:gravity="center"
android:text="x23"
android:textColor="@color/white"
android:textSize="12sp" />
<TextView
android:id="@+id/addition"
android:layout_width="20dp"
android:layout_height="match_parent"
android:gravity="center"
android:text="+"
android:textColor="@color/white"
android:textSize="14sp" />
</LinearLayout>
</FrameLayout> </FrameLayout>