Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
TKaxv-7S committed Jul 10, 2024
2 parents b051451 + 625a75f commit 2352bb3
Show file tree
Hide file tree
Showing 18 changed files with 569 additions and 173 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package tkaxv7s.xposed.sesame.data.modelFieldExt;


import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import com.fasterxml.jackson.core.type.TypeReference;
import tkaxv7s.xposed.sesame.R;
import tkaxv7s.xposed.sesame.data.ModelField;
import tkaxv7s.xposed.sesame.data.modelFieldExt.common.SelectModelFieldFunc;
import tkaxv7s.xposed.sesame.entity.IdAndName;
import tkaxv7s.xposed.sesame.ui.ListDialog;
import tkaxv7s.xposed.sesame.util.JsonUtil;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
* 数据结构说明
* Map<String, Integer> 表示已选择的数据与已经设置的数量映射关系
* List<? extends IdAndName> 需要选择的数据
*/
public class SelectAndCountModelField extends ModelField implements SelectModelFieldFunc {

private static final TypeReference<LinkedHashMap<String, Integer>> typeReference = new TypeReference<LinkedHashMap<String, Integer>>() {
};

private SelectListFunc selectListFunc;

private List<? extends IdAndName> expandValue;

public SelectAndCountModelField(String code, String name, Map<String, Integer> value, List<? extends IdAndName> expandValue) {
super(code, name, value);
this.expandValue = expandValue;
}

public SelectAndCountModelField(String code, String name, Map<String, Integer> value, SelectListFunc selectListFunc) {
super(code, name, value);
this.selectListFunc = selectListFunc;
}

@Override
public String getType() {
return "SELECT_AND_COUNT";
}

public List<? extends IdAndName> getExpandValue() {
return selectListFunc == null ? expandValue : selectListFunc.getList();
}

@Override
public void setValue(Object value) {
if (value == null) {
value = defaultValue;
}
this.value = JsonUtil.parseObject(value, typeReference);
}

@Override
public Map<String, Integer> getValue() {
return (Map<String, Integer>) value;
}

public String getConfigValue() {
return JsonUtil.toNoFormatJsonString(value);
}

@Override
public View getView(Context context) {
Button btn = new Button(context);
btn.setText(getName());
btn.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
btn.setTextColor(Color.parseColor("#008175"));
btn.setBackground(context.getResources().getDrawable(R.drawable.button));
btn.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
btn.setMinHeight(150);
btn.setMaxHeight(180);
btn.setPaddingRelative(40, 0, 40, 0);
btn.setAllCaps(false);
btn.setOnClickListener(v -> ListDialog.show(v.getContext(), ((Button) v).getText(), this));
return btn;
}

@Override
public void clear() {
getValue().clear();
}

@Override
public Integer get(String id) {
return getValue().get(id);
}

@Override
public void add(String id, Integer count) {
getValue().put(id, count);
}

@Override
public void remove(String id) {
getValue().remove(id);
}

@Override
public Boolean contains(String id) {
return getValue().containsKey(id);
}

public interface SelectListFunc {
List<? extends IdAndName> getList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package tkaxv7s.xposed.sesame.data.modelFieldExt;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import com.fasterxml.jackson.core.type.TypeReference;
import tkaxv7s.xposed.sesame.R;
import tkaxv7s.xposed.sesame.data.ModelField;
import tkaxv7s.xposed.sesame.data.modelFieldExt.common.SelectModelFieldFunc;
import tkaxv7s.xposed.sesame.entity.IdAndName;
import tkaxv7s.xposed.sesame.entity.KVNode;
import tkaxv7s.xposed.sesame.ui.ListDialog;
import tkaxv7s.xposed.sesame.util.JsonUtil;

import java.util.List;
import java.util.Objects;

public class SelectAndCountOneModelField extends ModelField implements SelectModelFieldFunc {

private static final TypeReference<KVNode<String, Integer>> typeReference = new TypeReference<KVNode<String, Integer>>() {
};

private SelectListFunc selectListFunc;

private List<? extends IdAndName> expandValue;

public SelectAndCountOneModelField(String code, String name, KVNode<String, Integer> value, List<? extends IdAndName> expandValue) {
super(code, name, value);
this.expandValue = expandValue;
}

public SelectAndCountOneModelField(String code, String name, KVNode<String, Integer> value, SelectListFunc selectListFunc) {
super(code, name, value);
this.selectListFunc = selectListFunc;
}

@Override
public String getType() {
return "SELECT_AND_COUNT_ONE";
}

public List<? extends IdAndName> getExpandValue() {
return selectListFunc == null ? expandValue : selectListFunc.getList();
}

@Override
public void setValue(Object value) {
if (value == null) {
value = defaultValue;
}
this.value = JsonUtil.parseObject(value, typeReference);
}

@Override
public KVNode<String, Integer> getValue() {
return (KVNode<String, Integer>) value;
}

public String getConfigValue() {
return JsonUtil.toNoFormatJsonString(value);
}

@Override
public View getView(Context context) {
Button btn = new Button(context);
btn.setText(getName());
btn.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
btn.setTextColor(Color.parseColor("#008175"));
btn.setBackground(context.getResources().getDrawable(R.drawable.button));
btn.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
btn.setMinHeight(150);
btn.setPaddingRelative(40, 0, 40, 0);
btn.setAllCaps(false);
btn.setOnClickListener(v -> ListDialog.show(v.getContext(), ((Button) v).getText(), this, ListDialog.ListType.RADIO));
return btn;
}

@Override
public void clear() {
value = defaultValue;
}

@Override
public Integer get(String id) {
KVNode<String, Integer> kvNode = getValue();
if (kvNode != null && Objects.equals(kvNode.getKey(), id)) {
return kvNode.getValue();
}
return 0;
}

@Override
public void add(String id, Integer count) {
value = new KVNode<>(id, count);
}

@Override
public void remove(String id) {
KVNode<String, Integer> kvNode = getValue();
if (kvNode != null && Objects.equals(kvNode.getKey(), id)) {
value = defaultValue;
}
}

@Override
public Boolean contains(String id) {
KVNode<String, Integer> kvNode = getValue();
return kvNode != null && Objects.equals(kvNode.getKey(), id);
}

public interface SelectListFunc {
List<? extends IdAndName> getList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,35 @@
import com.fasterxml.jackson.core.type.TypeReference;
import tkaxv7s.xposed.sesame.R;
import tkaxv7s.xposed.sesame.data.ModelField;
import tkaxv7s.xposed.sesame.data.modelFieldExt.common.SelectModelFieldFunc;
import tkaxv7s.xposed.sesame.entity.IdAndName;
import tkaxv7s.xposed.sesame.entity.KVNode;
import tkaxv7s.xposed.sesame.ui.ListDialog;
import tkaxv7s.xposed.sesame.util.JsonUtil;

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* 数据结构说明
* KVNode<Map<String, Integer>, Boolean>
* Map<String, Integer> 表示已选择的数据与已经设置的数量映射关系,如果未设置数量,则默认为0
* Boolean 表示是否需要设置数量
* Set<String> 表示已选择的数据
* List<? extends IdAndName> 需要选择的数据
*/
public class SelectModelField extends ModelField {
public class SelectModelField extends ModelField implements SelectModelFieldFunc {

private static final TypeReference<KVNode<LinkedHashMap<String, Integer>, Boolean>> typeReference = new TypeReference<KVNode<LinkedHashMap<String, Integer>, Boolean>>() {
private static final TypeReference<LinkedHashSet<String>> typeReference = new TypeReference<LinkedHashSet<String>>() {
};

private SelectListFunc selectListFunc;

private List<? extends IdAndName> expandValue;

public SelectModelField(String code, String name, KVNode<Map<String, Integer>, Boolean> value, List<? extends IdAndName> expandValue) {
public SelectModelField(String code, String name, Set<String> value, List<? extends IdAndName> expandValue) {
super(code, name, value);
this.expandValue = expandValue;
}

public SelectModelField(String code, String name, KVNode<Map<String, Integer>, Boolean> value, SelectListFunc selectListFunc) {
public SelectModelField(String code, String name, Set<String> value, SelectListFunc selectListFunc) {
super(code, name, value);
this.selectListFunc = selectListFunc;
}
Expand All @@ -64,8 +62,8 @@ public void setValue(Object value) {
}

@Override
public KVNode<Map<String, Integer>, Boolean> getValue() {
return (KVNode<Map<String, Integer>, Boolean>) value;
public Set<String> getValue() {
return (Set<String>) value;
}

public String getConfigValue() {
Expand All @@ -88,35 +86,29 @@ public View getView(Context context) {
return btn;
}

public static class SelectOneModelField extends SelectModelField {
@Override
public void clear() {
getValue().clear();
}

public SelectOneModelField(String code, String name, KVNode<Map<String, Integer>, Boolean> value, List<? extends IdAndName> idAndNameList) {
super(code, name, value, idAndNameList);
}
@Override
public Integer get(String id) {
return 0;
}

public SelectOneModelField(String code, String name, KVNode<Map<String, Integer>, Boolean> value, SelectListFunc selectListFunc) {
super(code, name, value, selectListFunc);
}
@Override
public void add(String id, Integer count) {
getValue().add(id);
}

@Override
public String getType() {
return "SELECT_ONE";
}
@Override
public void remove(String id) {
getValue().remove(id);
}

@Override
public View getView(Context context) {
Button btn = new Button(context);
btn.setText(getName());
btn.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
btn.setTextColor(Color.parseColor("#008175"));
btn.setBackground(context.getResources().getDrawable(R.drawable.button));
btn.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
btn.setMinHeight(150);
btn.setPaddingRelative(40, 0, 40, 0);
btn.setAllCaps(false);
btn.setOnClickListener(v -> ListDialog.show(v.getContext(), ((Button) v).getText(), this, ListDialog.ListType.RADIO));
return btn;
}
@Override
public Boolean contains(String id) {
return getValue().contains(id);
}

public interface SelectListFunc {
Expand Down
Loading

0 comments on commit 2352bb3

Please sign in to comment.