This commit is contained in:
Yutousama 2022-09-22 00:02:45 +08:00
parent e29ecd2845
commit 80c5609bb7
16 changed files with 209 additions and 29 deletions

View File

@ -72,9 +72,16 @@ public class ContainerRecyclerAdapter extends RecyclerView.Adapter<BaseViewHolde
seekBar.setVisibility(View.VISIBLE); seekBar.setVisibility(View.VISIBLE);
if (seekY == 0) { if (seekY == 0) {
seekY = seekBar.getY(); seekY = seekBar.getY();
}
seekBar.setY(seekY - DpUtil.dp2px(20)); seekBar.setY(seekY - DpUtil.dp2px(20));
} }
}
public void hideSeekBar(){
if(seekBar.getVisibility()==View.INVISIBLE){
return;
}
seekBar.setOnProgressChangeListener(null);
seekBar.setVisibility(View.INVISIBLE);
}
private void initDataFactory() { private void initDataFactory() {
@ -103,6 +110,7 @@ public class ContainerRecyclerAdapter extends RecyclerView.Adapter<BaseViewHolde
public void setList(ArrayList<? extends BaseBean> list) { public void setList(ArrayList<? extends BaseBean> list) {
this.list = list; this.list = list;
this.selectPosition = -1; this.selectPosition = -1;
hideSeekBar();
} }
public int getSelectPosition() { public int getSelectPosition() {
@ -218,4 +226,12 @@ public class ContainerRecyclerAdapter extends RecyclerView.Adapter<BaseViewHolde
public String getString(String key){ public String getString(String key){
return FaceSPUtils.getInstance().getString(key); return FaceSPUtils.getInstance().getString(key);
} }
public void del(String key){
FaceSPUtils.getInstance().del(key);
}
public void reset(){
if(vh!=null){
vh.reset(list);
}
}
} }

View File

@ -9,11 +9,14 @@ import com.yunbao.faceunity.R;
import com.yunbao.faceunity.entity.AnimationFilterBean; import com.yunbao.faceunity.entity.AnimationFilterBean;
import com.yunbao.faceunity.entity.BaseBean; import com.yunbao.faceunity.entity.BaseBean;
import java.util.List;
/** /**
* 动画滤镜 *暂无权限 * 动画滤镜 *暂无权限
*/ */
public class AnimViewHolder extends BaseViewHolder { public class AnimViewHolder extends BaseViewHolder {
ImageView icon; ImageView icon;
public AnimViewHolder(@NonNull View itemView) { public AnimViewHolder(@NonNull View itemView) {
super(itemView); super(itemView);
icon = itemView.findViewById(R.id.iv_control); icon = itemView.findViewById(R.id.iv_control);
@ -41,4 +44,9 @@ public class AnimViewHolder extends BaseViewHolder{
public void saveData() { public void saveData() {
} }
@Override
public void reset(List<? extends BaseBean> list) {
adapter.setSelectPosition(0);
}
} }

View File

@ -10,6 +10,8 @@ import com.yunbao.faceunity.R;
import com.yunbao.faceunity.entity.AnimojiBean; import com.yunbao.faceunity.entity.AnimojiBean;
import com.yunbao.faceunity.entity.BaseBean; import com.yunbao.faceunity.entity.BaseBean;
import java.util.List;
/** /**
* Animoji * Animoji
*/ */
@ -41,7 +43,7 @@ public class AnimojiViewHolder extends BaseViewHolder {
@Override @Override
public boolean loadData() { public boolean loadData() {
String data = adapter.getString(getClass().getSimpleName()); String data = adapter.getString(getName(this));
if (data != null) { if (data != null) {
icon.setSelected(getAdapterPosition() == Integer.parseInt(data)); icon.setSelected(getAdapterPosition() == Integer.parseInt(data));
return true; return true;
@ -51,6 +53,14 @@ public class AnimojiViewHolder extends BaseViewHolder {
@Override @Override
public void saveData() { public void saveData() {
adapter.save(getClass().getSimpleName(), String.valueOf(getAdapterPosition())); adapter.save(getName(this), String.valueOf(getAdapterPosition()));
} }
@Override
public void reset(List<? extends BaseBean> list) {
adapter.del(getName(this));
adapter.setSelectPosition(0);
}
} }

View File

@ -35,6 +35,7 @@ public abstract class BaseViewHolder extends RecyclerView.ViewHolder {
public abstract boolean loadData(); public abstract boolean loadData();
public abstract void saveData(); public abstract void saveData();
public abstract void reset(List<? extends BaseBean> list);
} }

View File

@ -13,6 +13,8 @@ import com.yunbao.faceunity.entity.ModelAttributeData;
import com.yunbao.faceunity.seekbar.DiscreteSeekBar; import com.yunbao.faceunity.seekbar.DiscreteSeekBar;
import com.yunbao.faceunity.utils.SeekBarUtils; import com.yunbao.faceunity.utils.SeekBarUtils;
import java.util.List;
/** /**
* 美体 * 美体
*/ */
@ -60,7 +62,7 @@ public class BeautyBodyViewHolder extends BaseViewHolder{
@Override @Override
public boolean loadData() { public boolean loadData() {
BodyBeautyBean bean = (BodyBeautyBean) itemView.getTag(); BodyBeautyBean bean = (BodyBeautyBean) itemView.getTag();
String val = adapter.getString(getName(this) + bean); String val = adapter.getString(getName(this) + bean.getKey());
if (val == null) { if (val == null) {
return false; return false;
} }
@ -79,4 +81,13 @@ public class BeautyBodyViewHolder extends BaseViewHolder{
String key = getName(this) + bean.getKey(); String key = getName(this) + bean.getKey();
adapter.save(key, (String) value.getText()); adapter.save(key, (String) value.getText());
} }
@Override
public void reset(List<? extends BaseBean> list) {
String name = getName(this);
for (BaseBean bean : list) {
adapter.del(name + bean.getKey());
}
adapter.notifyDataSetChanged();
}
} }

View File

@ -13,6 +13,8 @@ import com.yunbao.faceunity.entity.ModelAttributeData;
import com.yunbao.faceunity.seekbar.DiscreteSeekBar; import com.yunbao.faceunity.seekbar.DiscreteSeekBar;
import com.yunbao.faceunity.utils.SeekBarUtils; import com.yunbao.faceunity.utils.SeekBarUtils;
import java.util.List;
/** /**
* 美型 * 美型
*/ */
@ -80,4 +82,13 @@ public class BeautyShapeViewHolder extends BaseViewHolder {
FaceBeautyBean bean = (FaceBeautyBean) itemView.getTag(); FaceBeautyBean bean = (FaceBeautyBean) itemView.getTag();
adapter.save(getName(this)+bean.getKey(), (String) value.getText()); adapter.save(getName(this)+bean.getKey(), (String) value.getText());
} }
@Override
public void reset(List<? extends BaseBean> list) {
String name = getName(this);
for (BaseBean bean : list) {
adapter.del(name+bean.getKey());
}
adapter.notifyDataSetChanged();
}
} }

View File

@ -13,6 +13,8 @@ import com.yunbao.faceunity.entity.ModelAttributeData;
import com.yunbao.faceunity.seekbar.DiscreteSeekBar; import com.yunbao.faceunity.seekbar.DiscreteSeekBar;
import com.yunbao.faceunity.utils.SeekBarUtils; import com.yunbao.faceunity.utils.SeekBarUtils;
import java.util.List;
/** /**
* 美肤 * 美肤
*/ */
@ -81,4 +83,11 @@ public class BeautySkinViewHolder extends BaseViewHolder{
String val= (String) value.getText(); String val= (String) value.getText();
adapter.save(getName(this)+key,val); adapter.save(getName(this)+key,val);
} }
@Override
public void reset(List<? extends BaseBean> list) {
for (BaseBean bean : list) {
adapter.del(getName(this)+bean.getKey());
}
}
} }

View File

@ -10,6 +10,8 @@ import com.yunbao.faceunity.entity.BaseBean;
import com.yunbao.faceunity.entity.FunctionEnum; import com.yunbao.faceunity.entity.FunctionEnum;
import com.yunbao.faceunity.entity.PropBean; import com.yunbao.faceunity.entity.PropBean;
import java.util.List;
/** /**
* 大头 * 大头
*/ */
@ -35,6 +37,7 @@ public class BigHeadViewHolder extends BaseViewHolder {
if(loadData()){ if(loadData()){
return; return;
} }
if (getAdapterPosition() == 0) { if (getAdapterPosition() == 0) {
icon.setBackgroundResource(R.drawable.bg_control_oval2_selector); icon.setBackgroundResource(R.drawable.bg_control_oval2_selector);
} }
@ -62,4 +65,11 @@ public class BigHeadViewHolder extends BaseViewHolder {
PropBean bean = (PropBean) itemView.getTag(); PropBean bean = (PropBean) itemView.getTag();
adapter.save(getName(this),bean.getKey()); adapter.save(getName(this),bean.getKey());
} }
@Override
public void reset(List<? extends BaseBean> list) {
adapter.del(getName(this));
itemView.callOnClick();
adapter.setSelectPosition(0);
}
} }

View File

@ -10,6 +10,8 @@ import com.yunbao.faceunity.R;
import com.yunbao.faceunity.entity.BaseBean; import com.yunbao.faceunity.entity.BaseBean;
import com.yunbao.faceunity.entity.FaceBeautyFilterBean; import com.yunbao.faceunity.entity.FaceBeautyFilterBean;
import java.util.List;
/** /**
* 滤镜 * 滤镜
*/ */
@ -63,4 +65,11 @@ public class FilterViewHolder extends BaseViewHolder {
FaceBeautyFilterBean bean = (FaceBeautyFilterBean) itemView.getTag(); FaceBeautyFilterBean bean = (FaceBeautyFilterBean) itemView.getTag();
adapter.save(getName(this), bean.getKey()); adapter.save(getName(this), bean.getKey());
} }
@Override
public void reset(List<? extends BaseBean> list) {
adapter.del(getName(this));
itemView.callOnClick();
adapter.setSelectPosition(0);
}
} }

View File

@ -13,6 +13,8 @@ import com.yunbao.faceunity.entity.BaseBean;
import com.yunbao.faceunity.entity.net.FineStickerEntity; import com.yunbao.faceunity.entity.net.FineStickerEntity;
import com.yunbao.faceunity.utils.net.StickerDownloadHelper; import com.yunbao.faceunity.utils.net.StickerDownloadHelper;
import java.util.List;
/** /**
* 精品贴纸 * 精品贴纸
*/ */
@ -65,6 +67,13 @@ public class FineStickerViewHolder extends BaseViewHolder implements StickerDown
adapter.save(getName(this), bean.getKey()); adapter.save(getName(this), bean.getKey());
} }
@Override
public void reset(List<? extends BaseBean> list) {
adapter.del(getName(this));
itemView.callOnClick();
adapter.setSelectPosition(0);
}
@Override @Override
public void onGetTags(String[] tags) { public void onGetTags(String[] tags) {

View File

@ -13,6 +13,8 @@ import com.yunbao.faceunity.entity.MakeupCustomBean;
import com.yunbao.faceunity.repo.MakeupSource; import com.yunbao.faceunity.repo.MakeupSource;
import com.yunbao.faceunity.seekbar.DiscreteSeekBar; import com.yunbao.faceunity.seekbar.DiscreteSeekBar;
import java.util.List;
public class MakeupCustomItemViewHolder extends BaseViewHolder { public class MakeupCustomItemViewHolder extends BaseViewHolder {
private ImageView icon; private ImageView icon;
private TextView title; private TextView title;
@ -73,7 +75,7 @@ public class MakeupCustomItemViewHolder extends BaseViewHolder {
@Override @Override
public boolean loadData() { public boolean loadData() {
MakeupCustomBean bean = (MakeupCustomBean) itemView.getTag(); MakeupCustomBean bean = (MakeupCustomBean) itemView.getTag();
String model = adapter.getString(getName(this) + "_model"); String model = adapter.getString(getName(this));
String val = adapter.getString(getName(this) + bean.getKey() + "_val"); String val = adapter.getString(getName(this) + bean.getKey() + "_val");
if (model == null || val == null) { if (model == null || val == null) {
return false; return false;
@ -104,10 +106,20 @@ public class MakeupCustomItemViewHolder extends BaseViewHolder {
if(key==null){ if(key==null){
return; return;
} }
adapter.save(getName(this) + "_model", key); adapter.save(getName(this), key);
adapter.save(getName(this) + bean.getKey() + "_val", adapter.getSeekBar().getProgress() + ""); adapter.save(getName(this) + bean.getKey() + "_val", adapter.getSeekBar().getProgress() + "");
} }
@Override
public void reset(List<? extends BaseBean> list) {
adapter.del(getName(this));
for (BaseBean bean : list) {
adapter.del(getName(this) + bean.getKey() + "_val");
}
itemView.callOnClick();
adapter.setSelectPosition(0);
}
public String getMakeupKey(int beanType) { public String getMakeupKey(int beanType) {
String key = null; String key = null;
switch (beanType) { switch (beanType) {

View File

@ -10,6 +10,8 @@ import com.yunbao.faceunity.R;
import com.yunbao.faceunity.entity.BaseBean; import com.yunbao.faceunity.entity.BaseBean;
import com.yunbao.faceunity.entity.MakeupCombinationBean; import com.yunbao.faceunity.entity.MakeupCombinationBean;
import java.util.List;
/** /**
* 美妆 * 美妆
*/ */
@ -47,6 +49,17 @@ public class MakeupViewHolder extends BaseViewHolder {
@Override @Override
public boolean loadData() { public boolean loadData() {
MakeupCombinationBean bean = (MakeupCombinationBean) itemView.getTag();
String val = adapter.getString(getName(this));
if(val==null){
return false;
}
if(!val.equals(bean.getKey())){
return false;
}
icon.setSelected(true);
title.setSelected(true);
adapter.getMakeupDataFactory().onMakeupCombinationSelected(bean);
return true; return true;
} }
@ -56,4 +69,9 @@ public class MakeupViewHolder extends BaseViewHolder {
MakeupCombinationBean bean = (MakeupCombinationBean) itemView.getTag(); MakeupCombinationBean bean = (MakeupCombinationBean) itemView.getTag();
adapter.save(getName(this),bean.getKey()); adapter.save(getName(this),bean.getKey());
} }
@Override
public void reset(List<? extends BaseBean>list) {
}
} }

View File

@ -10,6 +10,8 @@ import com.yunbao.faceunity.entity.BaseBean;
import com.yunbao.faceunity.entity.FunctionEnum; import com.yunbao.faceunity.entity.FunctionEnum;
import com.yunbao.faceunity.entity.PropBean; import com.yunbao.faceunity.entity.PropBean;
import java.util.List;
/** /**
* 普通贴纸 * 普通贴纸
*/ */
@ -23,6 +25,7 @@ public class StickerViewHolder extends BaseViewHolder{
adapter.getPropDataFactory().setPropType(FunctionEnum.STICKER); adapter.getPropDataFactory().setPropType(FunctionEnum.STICKER);
adapter.getPropDataFactory().onItemSelected(bean); adapter.getPropDataFactory().onItemSelected(bean);
setSelectPosition(getAdapterPosition()); setSelectPosition(getAdapterPosition());
saveData();
}); });
} }
@ -30,6 +33,9 @@ public class StickerViewHolder extends BaseViewHolder{
public void setData(BaseBean data) { public void setData(BaseBean data) {
itemView.setTag(data); itemView.setTag(data);
icon.setImageResource(data.getImageRes()); icon.setImageResource(data.getImageRes());
if(loadData()){
return;
}
if(getAdapterPosition()==0){ if(getAdapterPosition()==0){
icon.setBackgroundResource(R.drawable.bg_control_oval2_selector); icon.setBackgroundResource(R.drawable.bg_control_oval2_selector);
} }
@ -38,12 +44,31 @@ public class StickerViewHolder extends BaseViewHolder{
@Override @Override
public boolean loadData() { public boolean loadData() {
PropBean bean= (PropBean) itemView.getTag();
String val = adapter.getString(getName(this));
if(val==null){
return false;
}
if(!val.equals(bean.getKey())){
return false;
}
icon.setSelected(true);
adapter.getPropDataFactory().setPropType(FunctionEnum.STICKER);
adapter.getPropDataFactory().onItemSelected(bean);
return true; return true;
} }
@Override @Override
public void saveData() { public void saveData() {
PropBean bean= (PropBean) itemView.getTag();
adapter.save(getName(this),bean.getKey());
}
@Override
public void reset(List<? extends BaseBean> list) {
adapter.del(getName(this));
itemView.callOnClick();
adapter.setSelectPosition(0);
} }
} }

View File

@ -9,6 +9,8 @@ import androidx.annotation.NonNull;
import com.yunbao.faceunity.R; import com.yunbao.faceunity.R;
import com.yunbao.faceunity.entity.BaseBean; import com.yunbao.faceunity.entity.BaseBean;
import java.util.List;
/** /**
* 风格推荐 * 风格推荐
*/ */
@ -23,6 +25,7 @@ public class StyleViewHolder extends BaseViewHolder{
BaseBean bean= (BaseBean) itemView.getTag(); BaseBean bean= (BaseBean) itemView.getTag();
adapter.getFaceBeautyDataFactory().onStyleSelected(bean.getKey()); adapter.getFaceBeautyDataFactory().onStyleSelected(bean.getKey());
setSelectPosition(getAdapterPosition()); setSelectPosition(getAdapterPosition());
saveData();
}); });
} }
@ -31,18 +34,40 @@ public class StyleViewHolder extends BaseViewHolder{
itemView.setTag(data); itemView.setTag(data);
icon.setImageResource(data.getImageRes()); icon.setImageResource(data.getImageRes());
title.setText(data.getDesRes()); title.setText(data.getDesRes());
if(loadData()){
return;
}
icon.setSelected(getSelectPosition()==getAdapterPosition()); icon.setSelected(getSelectPosition()==getAdapterPosition());
title.setSelected(getSelectPosition()==getAdapterPosition()); title.setSelected(getSelectPosition()==getAdapterPosition());
} }
@Override @Override
public boolean loadData() { public boolean loadData() {
BaseBean bean= (BaseBean) itemView.getTag();
String val = adapter.getString(getName(this));
if(val==null){
return false;
}
if(!val.equals(bean.getKey())){
return false;
}
icon.setSelected(true);
title.setSelected(true);
adapter.getFaceBeautyDataFactory().onStyleSelected(bean.getKey());
return true; return true;
} }
@Override @Override
public void saveData() { public void saveData() {
BaseBean bean= (BaseBean) itemView.getTag();
adapter.save(getName(this),bean.getKey());
}
@Override
public void reset(List<? extends BaseBean> list) {
adapter.del(getName(this));
itemView.callOnClick();
adapter.setSelectPosition(0);
} }
} }

View File

@ -117,7 +117,9 @@ public class FaceUnityView extends LinearLayout implements StickerDownloadHelper
ArrayList<MakeupCustomClassBean> list = MakeupSource.buildCustomClasses(); ArrayList<MakeupCustomClassBean> list = MakeupSource.buildCustomClasses();
setTab(createTabs(list)); setTab(createTabs(list));
}); });
menu2Reset.setOnClickListener(view -> {
containerAdapter.reset();
});
} }
private void goBackMainMenu() { private void goBackMainMenu() {

View File

@ -26,4 +26,8 @@ public class FaceSPUtils {
public boolean saveBool(String key,boolean value){ public boolean saveBool(String key,boolean value){
return mSharedPreferences.getBoolean(key,false); return mSharedPreferences.getBoolean(key,false);
} }
public void del(String key) {
mSharedPreferences.edit().remove(key).apply();
}
} }