enable direction style edit

This commit is contained in:
ShirosakiMio 2024-02-20 18:03:12 +08:00
parent 18fde095ab
commit 1f54ffe84a
3 changed files with 36 additions and 4 deletions

View File

@ -42,19 +42,22 @@ public class AddDirectionStyleDialog extends FCLDialog implements View.OnClickLi
private FCLLinearLayout buttonStyleLayout;
private FCLLinearLayout rockerStyleLayout;
private ControlDirectionStyle style = new ControlDirectionStyle("");
private ControlDirectionStyle style;
private ControlButtonStyle buttonStyle;
private boolean isEdit;
public interface Callback {
void onStyleAdd(ControlDirectionStyle style);
}
public AddDirectionStyleDialog(@NonNull Context context, Callback callback) {
public AddDirectionStyleDialog(@NonNull Context context,ControlDirectionStyle beforeStyle, boolean isEdit, Callback callback) {
super(context);
setContentView(R.layout.dialog_add_direction_style);
setCancelable(false);
this.callback = callback;
this.style = beforeStyle == null ? new ControlDirectionStyle("") : beforeStyle;
this.isEdit = isEdit;
positive = findViewById(R.id.positive);
negative = findViewById(R.id.negative);
@ -79,6 +82,7 @@ public class AddDirectionStyleDialog extends FCLDialog implements View.OnClickLi
buttonStyleLayout = (FCLLinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.view_direction_style_button, null);
rockerStyleLayout = (FCLLinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.view_direction_style_rocker, null);
editName.setText(style.getName());
style.nameProperty().bind(editName.stringProperty());
{
@ -289,6 +293,10 @@ public class AddDirectionStyleDialog extends FCLDialog implements View.OnClickLi
container.addView(rockerStyleLayout);
}
});
if (style.getStyleType() == ControlDirectionStyle.Type.ROCKER) {
container.removeAllViewsInLayout();
container.addView(rockerStyleLayout);
}
}
private String getHex(int color) {
@ -298,7 +306,7 @@ public class AddDirectionStyleDialog extends FCLDialog implements View.OnClickLi
@Override
public void onClick(View v) {
if (v == positive) {
if (DirectionStyles.getStyles().stream().anyMatch(it -> it.getName().equals(style.getName()))) {
if (!isEdit && DirectionStyles.getStyles().stream().anyMatch(it -> it.getName().equals(style.getName()))) {
Toast.makeText(getContext(), getContext().getString(R.string.style_warning_exist), Toast.LENGTH_SHORT).show();
} else if (StringUtils.isBlank(style.getName())) {
Toast.makeText(getContext(), getContext().getString(R.string.style_warning_name), Toast.LENGTH_SHORT).show();

View File

@ -20,6 +20,7 @@ public class DirectionStyleDialog extends FCLDialog implements View.OnClickListe
private final Callback callback;
private FCLButton addStyle;
private FCLButton editStyle;
private FCLButton positive;
private HorizontalListView listView;
@ -37,12 +38,18 @@ public class DirectionStyleDialog extends FCLDialog implements View.OnClickListe
setCancelable(false);
addStyle = findViewById(R.id.add_style);
editStyle = findViewById(R.id.edit_style);
positive = findViewById(R.id.positive);
addStyle.setOnClickListener(this);
editStyle.setOnClickListener(this);
positive.setOnClickListener(this);
listView = findViewById(R.id.list);
refreshList();
if (!select) {
editStyle.setVisibility(View.GONE);
}
}
private DirectionStyleAdapter adapter;
@ -55,7 +62,15 @@ public class DirectionStyleDialog extends FCLDialog implements View.OnClickListe
@Override
public void onClick(View v) {
if (v == addStyle) {
AddDirectionStyleDialog dialog = new AddDirectionStyleDialog(getContext(), style -> {
AddDirectionStyleDialog dialog = new AddDirectionStyleDialog(getContext(), null, false, style -> {
DirectionStyles.addStyle(style);
refreshList();
});
dialog.show();
}
if (v == editStyle) {
AddDirectionStyleDialog dialog = new AddDirectionStyleDialog(getContext(), adapter.getSelectedStyle(), true, style -> {
DirectionStyles.removeStyles(adapter.getSelectedStyle());
DirectionStyles.addStyle(style);
refreshList();
});

View File

@ -35,6 +35,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<com.tungsten.fcllibrary.component.view.FCLButton
android:id="@+id/edit_style"
android:text="@string/menu_control_style_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
app:layout_constraintLeft_toRightOf="@id/add_style"
app:layout_constraintBottom_toBottomOf="parent"/>
<com.tungsten.fcllibrary.component.view.FCLButton
android:id="@+id/positive"
android:text="@string/dialog_positive"