This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'refs/remotes/origin/main' into release
- Loading branch information
Showing
18 changed files
with
569 additions
and
173 deletions.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
app/src/main/java/tkaxv7s/xposed/sesame/data/modelFieldExt/SelectAndCountModelField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
app/src/main/java/tkaxv7s/xposed/sesame/data/modelFieldExt/SelectAndCountOneModelField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.