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);
if (seekY == 0) {
seekY = seekBar.getY();
}
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() {
@ -103,6 +110,7 @@ public class ContainerRecyclerAdapter extends RecyclerView.Adapter<BaseViewHolde
public void setList(ArrayList<? extends BaseBean> list) {
this.list = list;
this.selectPosition = -1;
hideSeekBar();
}
public int getSelectPosition() {
@ -218,4 +226,12 @@ public class ContainerRecyclerAdapter extends RecyclerView.Adapter<BaseViewHolde
public String getString(String 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,14 +9,17 @@ import com.yunbao.faceunity.R;
import com.yunbao.faceunity.entity.AnimationFilterBean;
import com.yunbao.faceunity.entity.BaseBean;
import java.util.List;
/**
* 动画滤镜 *暂无权限
*/
public class AnimViewHolder extends BaseViewHolder{
public class AnimViewHolder extends BaseViewHolder {
ImageView icon;
public AnimViewHolder(@NonNull View itemView) {
super(itemView);
icon =itemView.findViewById(R.id.iv_control);
icon = itemView.findViewById(R.id.iv_control);
icon.setBackgroundResource(R.drawable.bg_control_square_selector);
itemView.setOnClickListener(v -> {
adapter.getAnimojiDataFactory().onFilterSelected((AnimationFilterBean) itemView.getTag());
@ -29,7 +32,7 @@ public class AnimViewHolder extends BaseViewHolder{
public void setData(BaseBean data) {
itemView.setTag(data);
icon.setImageResource(data.getImageRes());
icon.setSelected(getAdapterPosition()==getSelectPosition());
icon.setSelected(getAdapterPosition() == getSelectPosition());
}
@Override
@ -41,4 +44,9 @@ public class AnimViewHolder extends BaseViewHolder{
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.BaseBean;
import java.util.List;
/**
* Animoji
*/
@ -32,7 +34,7 @@ public class AnimojiViewHolder extends BaseViewHolder {
icon.setImageResource(data.getImageRes());
int adapterPosition = getAdapterPosition();
int selectPosition = getSelectPosition();
if(loadData()){
if (loadData()) {
return;
}
icon.setSelected(adapterPosition == selectPosition);
@ -41,7 +43,7 @@ public class AnimojiViewHolder extends BaseViewHolder {
@Override
public boolean loadData() {
String data = adapter.getString(getClass().getSimpleName());
String data = adapter.getString(getName(this));
if (data != null) {
icon.setSelected(getAdapterPosition() == Integer.parseInt(data));
return true;
@ -51,6 +53,14 @@ public class AnimojiViewHolder extends BaseViewHolder {
@Override
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 void saveData();
public abstract void reset(List<? extends BaseBean> list);
}

View File

@ -13,10 +13,12 @@ import com.yunbao.faceunity.entity.ModelAttributeData;
import com.yunbao.faceunity.seekbar.DiscreteSeekBar;
import com.yunbao.faceunity.utils.SeekBarUtils;
import java.util.List;
/**
* 美体
*/
public class BeautyBodyViewHolder extends BaseViewHolder{
public class BeautyBodyViewHolder extends BaseViewHolder {
private ImageView icon;
private TextView title;
private TextView value;
@ -28,14 +30,14 @@ public class BeautyBodyViewHolder extends BaseViewHolder{
title = itemView.findViewById(R.id.item_title);
value = itemView.findViewById(R.id.item_value);
seekBar = itemView.findViewById(R.id.item_seekBar);
seekBar.setOnProgressChangeListener(new DiscreteSeekBar.OnSimpleProgressChangeListener(){
seekBar.setOnProgressChangeListener(new DiscreteSeekBar.OnSimpleProgressChangeListener() {
@Override
public void onProgressChanged(DiscreteSeekBar seekBar, int value, boolean fromUser) {
super.onProgressChanged(seekBar, value, fromUser);
BodyBeautyBean bean = (BodyBeautyBean) itemView.getTag();
double toValue = SeekBarUtils.Companion.seekToValue(bean.getModelAttributeData().getMaxRange(), value, seekBar.getMin());
BeautyBodyViewHolder.this.value.setText(String.format("%.1f",toValue));
adapter.getBodyBeautyDataFactory().updateParamIntensity(bean.getKey(),toValue);
BeautyBodyViewHolder.this.value.setText(String.format("%.1f", toValue));
adapter.getBodyBeautyDataFactory().updateParamIntensity(bean.getKey(), toValue);
saveData();
}
});
@ -46,7 +48,7 @@ public class BeautyBodyViewHolder extends BaseViewHolder{
itemView.setTag(data);
icon.setImageResource(data.getImageRes());
title.setText(data.getDesRes());
if(loadData()){
if (loadData()) {
return;
}
ModelAttributeData attributeData = data.getModelAttributeData();
@ -60,8 +62,8 @@ public class BeautyBodyViewHolder extends BaseViewHolder{
@Override
public boolean loadData() {
BodyBeautyBean bean = (BodyBeautyBean) itemView.getTag();
String val = adapter.getString(getName(this) + bean);
if(val==null){
String val = adapter.getString(getName(this) + bean.getKey());
if (val == null) {
return false;
}
ModelAttributeData attributeData = bean.getModelAttributeData();
@ -76,7 +78,16 @@ public class BeautyBodyViewHolder extends BaseViewHolder{
@Override
public void saveData() {
BodyBeautyBean bean = (BodyBeautyBean) itemView.getTag();
String key=getName(this)+bean.getKey();
String key = getName(this) + bean.getKey();
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.utils.SeekBarUtils;
import java.util.List;
/**
* 美型
*/
@ -80,4 +82,13 @@ public class BeautyShapeViewHolder extends BaseViewHolder {
FaceBeautyBean bean = (FaceBeautyBean) itemView.getTag();
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.utils.SeekBarUtils;
import java.util.List;
/**
* 美肤
*/
@ -81,4 +83,11 @@ public class BeautySkinViewHolder extends BaseViewHolder{
String val= (String) value.getText();
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.PropBean;
import java.util.List;
/**
* 大头
*/
@ -35,6 +37,7 @@ public class BigHeadViewHolder extends BaseViewHolder {
if(loadData()){
return;
}
if (getAdapterPosition() == 0) {
icon.setBackgroundResource(R.drawable.bg_control_oval2_selector);
}
@ -62,4 +65,11 @@ public class BigHeadViewHolder extends BaseViewHolder {
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

@ -10,6 +10,8 @@ import com.yunbao.faceunity.R;
import com.yunbao.faceunity.entity.BaseBean;
import com.yunbao.faceunity.entity.FaceBeautyFilterBean;
import java.util.List;
/**
* 滤镜
*/
@ -22,8 +24,8 @@ public class FilterViewHolder extends BaseViewHolder {
icon = itemView.findViewById(R.id.iv_control);
title = itemView.findViewById(R.id.tv_control);
itemView.setOnClickListener(view -> {
FaceBeautyFilterBean bean= (FaceBeautyFilterBean) itemView.getTag();
adapter.getFaceBeautyDataFactory().onFilterSelected(bean.getKey(),bean.getIntensity(),bean.getDesRes());
FaceBeautyFilterBean bean = (FaceBeautyFilterBean) itemView.getTag();
adapter.getFaceBeautyDataFactory().onFilterSelected(bean.getKey(), bean.getIntensity(), bean.getDesRes());
setSelectPosition(getAdapterPosition());
saveData();
});
@ -34,33 +36,40 @@ public class FilterViewHolder extends BaseViewHolder {
itemView.setTag(data);
icon.setImageResource(data.getImageRes());
title.setText(data.getDesRes());
if(loadData()){
if (loadData()) {
return;
}
icon.setSelected(getSelectPosition()==getAdapterPosition());
title.setSelected(getSelectPosition()==getAdapterPosition());
icon.setSelected(getSelectPosition() == getAdapterPosition());
title.setSelected(getSelectPosition() == getAdapterPosition());
}
@Override
public boolean loadData() {
FaceBeautyFilterBean bean= (FaceBeautyFilterBean) itemView.getTag();
FaceBeautyFilterBean bean = (FaceBeautyFilterBean) itemView.getTag();
String val = adapter.getString(getName(this));
if(val==null){
if (val == null) {
return false;
}
if(!val.equals(bean.getKey())){
if (!val.equals(bean.getKey())) {
return false;
}
icon.setSelected(true);
title.setSelected(true);
adapter.getFaceBeautyDataFactory().onFilterSelected(bean.getKey(),bean.getIntensity(),bean.getDesRes());
adapter.getFaceBeautyDataFactory().onFilterSelected(bean.getKey(), bean.getIntensity(), bean.getDesRes());
return true;
}
@Override
public void saveData() {
FaceBeautyFilterBean bean= (FaceBeautyFilterBean) itemView.getTag();
adapter.save(getName(this),bean.getKey());
FaceBeautyFilterBean bean = (FaceBeautyFilterBean) 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

@ -13,6 +13,8 @@ import com.yunbao.faceunity.entity.BaseBean;
import com.yunbao.faceunity.entity.net.FineStickerEntity;
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());
}
@Override
public void reset(List<? extends BaseBean> list) {
adapter.del(getName(this));
itemView.callOnClick();
adapter.setSelectPosition(0);
}
@Override
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.seekbar.DiscreteSeekBar;
import java.util.List;
public class MakeupCustomItemViewHolder extends BaseViewHolder {
private ImageView icon;
private TextView title;
@ -73,7 +75,7 @@ public class MakeupCustomItemViewHolder extends BaseViewHolder {
@Override
public boolean loadData() {
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");
if (model == null || val == null) {
return false;
@ -104,10 +106,20 @@ public class MakeupCustomItemViewHolder extends BaseViewHolder {
if(key==null){
return;
}
adapter.save(getName(this) + "_model", key);
adapter.save(getName(this), key);
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) {
String key = null;
switch (beanType) {

View File

@ -10,6 +10,8 @@ import com.yunbao.faceunity.R;
import com.yunbao.faceunity.entity.BaseBean;
import com.yunbao.faceunity.entity.MakeupCombinationBean;
import java.util.List;
/**
* 美妆
*/
@ -47,6 +49,17 @@ public class MakeupViewHolder extends BaseViewHolder {
@Override
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;
}
@ -56,4 +69,9 @@ public class MakeupViewHolder extends BaseViewHolder {
MakeupCombinationBean bean = (MakeupCombinationBean) itemView.getTag();
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.PropBean;
import java.util.List;
/**
* 普通贴纸
*/
@ -23,6 +25,7 @@ public class StickerViewHolder extends BaseViewHolder{
adapter.getPropDataFactory().setPropType(FunctionEnum.STICKER);
adapter.getPropDataFactory().onItemSelected(bean);
setSelectPosition(getAdapterPosition());
saveData();
});
}
@ -30,6 +33,9 @@ public class StickerViewHolder extends BaseViewHolder{
public void setData(BaseBean data) {
itemView.setTag(data);
icon.setImageResource(data.getImageRes());
if(loadData()){
return;
}
if(getAdapterPosition()==0){
icon.setBackgroundResource(R.drawable.bg_control_oval2_selector);
}
@ -38,12 +44,31 @@ public class StickerViewHolder extends BaseViewHolder{
@Override
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;
}
@Override
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.entity.BaseBean;
import java.util.List;
/**
* 风格推荐
*/
@ -23,6 +25,7 @@ public class StyleViewHolder extends BaseViewHolder{
BaseBean bean= (BaseBean) itemView.getTag();
adapter.getFaceBeautyDataFactory().onStyleSelected(bean.getKey());
setSelectPosition(getAdapterPosition());
saveData();
});
}
@ -31,18 +34,40 @@ public class StyleViewHolder extends BaseViewHolder{
itemView.setTag(data);
icon.setImageResource(data.getImageRes());
title.setText(data.getDesRes());
if(loadData()){
return;
}
icon.setSelected(getSelectPosition()==getAdapterPosition());
title.setSelected(getSelectPosition()==getAdapterPosition());
}
@Override
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;
}
@Override
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();
setTab(createTabs(list));
});
menu2Reset.setOnClickListener(view -> {
containerAdapter.reset();
});
}
private void goBackMainMenu() {

View File

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