Upgrade controller
This commit is contained in:
parent
ae2d325340
commit
d20cec2f13
|
@ -1,9 +1,11 @@
|
|||
{
|
||||
"id": "00000000",
|
||||
"name": "Default",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"versionCode": 1,
|
||||
"author": "Tungsten",
|
||||
"description": "Default controller of Fold Craft Launcher.",
|
||||
"controllerVersion": 10,
|
||||
"controllerVersion": 20,
|
||||
"buttonStyles": [
|
||||
{
|
||||
"name": "Default",
|
|
@ -543,7 +543,7 @@ public class GameMenu implements MenuCallback, View.OnClickListener {
|
|||
});
|
||||
|
||||
editModeProperty.set(isSimulated());
|
||||
controllerProperty.set(Controllers.findControllerByName(activity.getIntent().getExtras().getString("controller")));
|
||||
controllerProperty.set(Controllers.findControllerById(activity.getIntent().getExtras().getString("controller")));
|
||||
|
||||
baseLayout = findViewById(R.id.base_layout);
|
||||
touchPad = findViewById(R.id.touch_pad);
|
||||
|
|
|
@ -53,7 +53,7 @@ public class SelectControllerDialog extends FCLDialog implements View.OnClickLis
|
|||
this.selectedController.set(selectedController);
|
||||
}
|
||||
|
||||
public SelectControllerDialog(@NonNull Context context, String name, Callback callback) {
|
||||
public SelectControllerDialog(@NonNull Context context, String id, Callback callback) {
|
||||
super(context);
|
||||
this.callback = callback;
|
||||
setContentView(R.layout.dialog_select_controller);
|
||||
|
@ -64,7 +64,7 @@ public class SelectControllerDialog extends FCLDialog implements View.OnClickLis
|
|||
|
||||
boolean set = true;
|
||||
for (Controller controller : Controllers.getControllers()) {
|
||||
if (controller.getName().equals(name)) {
|
||||
if (controller.getId().equals(id)) {
|
||||
setSelectedController(controller);
|
||||
set = false;
|
||||
}
|
||||
|
|
|
@ -49,12 +49,27 @@ import java.lang.reflect.Type;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@JsonAdapter(Controller.Serializer.class)
|
||||
public class Controller implements Cloneable, Observable {
|
||||
|
||||
private final SimpleStringProperty id;
|
||||
|
||||
public StringProperty idProperty() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id.get();
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id.set(id);
|
||||
}
|
||||
|
||||
private final SimpleStringProperty name;
|
||||
|
||||
public StringProperty nameProperty() {
|
||||
|
@ -83,6 +98,20 @@ public class Controller implements Cloneable, Observable {
|
|||
this.version.set(version);
|
||||
}
|
||||
|
||||
private final SimpleIntegerProperty versionCode;
|
||||
|
||||
public IntegerProperty versionCodeProperty() {
|
||||
return versionCode;
|
||||
}
|
||||
|
||||
public int getVersionCode() {
|
||||
return versionCode.get();
|
||||
}
|
||||
|
||||
public void setVersionCode(int versionCode) {
|
||||
this.versionCode.set(versionCode);
|
||||
}
|
||||
|
||||
private final SimpleStringProperty author;
|
||||
|
||||
public StringProperty authorProperty() {
|
||||
|
@ -132,28 +161,38 @@ public class Controller implements Cloneable, Observable {
|
|||
}
|
||||
|
||||
public Controller(String name) {
|
||||
this(name, "");
|
||||
this(generateRandomId(), name);
|
||||
}
|
||||
|
||||
public Controller(String name, String version) {
|
||||
this(name, version, "");
|
||||
public Controller(String id, String name) {
|
||||
this(id, name, "");
|
||||
}
|
||||
|
||||
public Controller(String name, String version, String author) {
|
||||
this(name, version, author, "");
|
||||
public Controller(String id, String name, String version) {
|
||||
this(id, name, version, 1);
|
||||
}
|
||||
|
||||
public Controller(String name, String version, String author, String description) {
|
||||
this(name, version, author, description, Constants.CONTROLLER_VERSION);
|
||||
public Controller(String id, String name, String version, int versionCode) {
|
||||
this(id, name, version, versionCode, "");
|
||||
}
|
||||
|
||||
public Controller(String name, String version, String author, String description, int controllerVersion) {
|
||||
this(name, version, author, description, controllerVersion, FXCollections.observableArrayList(new ArrayList<>()));
|
||||
public Controller(String id, String name, String version, int versionCode, String author) {
|
||||
this(id, name, version, versionCode, author, "");
|
||||
}
|
||||
|
||||
public Controller(String name, String version, String author, String description, int controllerVersion, ObservableList<ControlViewGroup> viewGroups) {
|
||||
public Controller(String id, String name, String version, int versionCode, String author, String description) {
|
||||
this(id, name, version, versionCode, author, description, Constants.CONTROLLER_VERSION);
|
||||
}
|
||||
|
||||
public Controller(String id, String name, String version, int versionCode, String author, String description, int controllerVersion) {
|
||||
this(id, name, version, versionCode, author, description, controllerVersion, FXCollections.observableArrayList(new ArrayList<>()));
|
||||
}
|
||||
|
||||
public Controller(String id, String name, String version, int versionCode, String author, String description, int controllerVersion, ObservableList<ControlViewGroup> viewGroups) {
|
||||
this.id = new SimpleStringProperty(this, "id", id);
|
||||
this.name = new SimpleStringProperty(this, "name", name);
|
||||
this.version = new SimpleStringProperty(this, "version", version);
|
||||
this.versionCode = new SimpleIntegerProperty(this, "versionCode", versionCode);
|
||||
this.author = new SimpleStringProperty(this, "author", author);
|
||||
this.description = new SimpleStringProperty(this, "description", description);
|
||||
this.viewGroups = viewGroups;
|
||||
|
@ -163,6 +202,10 @@ public class Controller implements Cloneable, Observable {
|
|||
addPropertyChangedListener(onInvalidating(this::invalidate));
|
||||
}
|
||||
|
||||
public static String generateRandomId() {
|
||||
return UUID.randomUUID().toString().substring(0, 8);
|
||||
}
|
||||
|
||||
public void addViewGroup(ControlViewGroup viewGroup) {
|
||||
boolean exist = false;
|
||||
for (ControlViewGroup group : viewGroups()) {
|
||||
|
@ -200,8 +243,10 @@ public class Controller implements Cloneable, Observable {
|
|||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("id", getId())
|
||||
.append("name", getName())
|
||||
.append("version", getVersion())
|
||||
.append("versionCode", getVersionCode())
|
||||
.append("author", getAuthor())
|
||||
.append("description", getDescription())
|
||||
.append("controllerVersion", getControllerVersion())
|
||||
|
@ -209,8 +254,10 @@ public class Controller implements Cloneable, Observable {
|
|||
}
|
||||
|
||||
private void addPropertyChangedListener(InvalidationListener listener) {
|
||||
id.addListener(listener);
|
||||
name.addListener(listener);
|
||||
version.addListener(listener);
|
||||
versionCode.addListener(listener);
|
||||
author.addListener(listener);
|
||||
description.addListener(listener);
|
||||
viewGroups.addListener(listener);
|
||||
|
@ -242,13 +289,13 @@ public class Controller implements Cloneable, Observable {
|
|||
public Controller clone() {
|
||||
ObservableList<ControlViewGroup> viewGroups = FXCollections.observableArrayList(new ArrayList<>());
|
||||
viewGroups.addAll(viewGroups().stream().map(ControlViewGroup::clone).collect(Collectors.toList()));
|
||||
return new Controller(getName() + "_clone", getVersion(), getAuthor(), getDescription(), getControllerVersion(), viewGroups);
|
||||
return new Controller(generateRandomId(), getName() + "_clone", getVersion(), getVersionCode(), getAuthor(), getDescription(), getControllerVersion(), viewGroups);
|
||||
}
|
||||
|
||||
// function
|
||||
|
||||
public String getFileName() {
|
||||
return getName() + ".json";
|
||||
return getId() + ".json";
|
||||
}
|
||||
|
||||
public void saveToDisk() throws IOException {
|
||||
|
@ -259,23 +306,27 @@ public class Controller implements Cloneable, Observable {
|
|||
FileUtils.writeText(new File(FCLPath.CONTROLLER_DIR, getFileName()), str);
|
||||
}
|
||||
|
||||
public void rename(String newName) throws IOException {
|
||||
FileUtils.copyFile(new File(FCLPath.CONTROLLER_DIR, getFileName()), new File(FCLPath.CONTROLLER_DIR, newName + ".json"));
|
||||
new File(FCLPath.CONTROLLER_DIR, getFileName()).delete();
|
||||
setName(newName);
|
||||
public void changeId(String newId) throws IOException {
|
||||
renameFile(getFileName(), newId + ".json");
|
||||
setId(newId);
|
||||
}
|
||||
|
||||
public void renameFile(String oldFileName, String newFileName) throws IOException {
|
||||
FileUtils.copyFile(new File(FCLPath.CONTROLLER_DIR, oldFileName), new File(FCLPath.CONTROLLER_DIR, newFileName));
|
||||
new File(FCLPath.CONTROLLER_DIR, oldFileName).delete();
|
||||
}
|
||||
|
||||
public void upgrade() {
|
||||
this.controllerVersion.set(Constants.CONTROLLER_VERSION);
|
||||
}
|
||||
|
||||
public static void showUpgradeDialog(Context context, String name) {
|
||||
public static void showUpgradeDialog(Context context, String name, String id) {
|
||||
Schedulers.androidUIThread().execute(() -> {
|
||||
FCLAlertDialog.Builder builder = new FCLAlertDialog.Builder(context);
|
||||
builder.setCancelable(false);
|
||||
builder.setAlertLevel(FCLAlertDialog.AlertLevel.INFO);
|
||||
builder.setMessage(String.format(context.getString(R.string.control_upgrade), name));
|
||||
builder.setPositiveButton(() -> Controllers.findControllerByName(name).upgrade());
|
||||
builder.setPositiveButton(() -> Controllers.findControllerById(id).upgrade());
|
||||
builder.setNegativeButton(null);
|
||||
builder.create().show();
|
||||
});
|
||||
|
@ -301,8 +352,10 @@ public class Controller implements Cloneable, Observable {
|
|||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("id", src.getId());
|
||||
jsonObject.addProperty("name", src.getName());
|
||||
jsonObject.addProperty("version", src.getVersion());
|
||||
jsonObject.addProperty("versionCode", src.getVersionCode());
|
||||
jsonObject.addProperty("author", src.getAuthor());
|
||||
jsonObject.addProperty("description", src.getDescription());
|
||||
jsonObject.addProperty("controllerVersion", src.getControllerVersion());
|
||||
|
@ -321,8 +374,10 @@ public class Controller implements Cloneable, Observable {
|
|||
JsonObject obj = (JsonObject) json;
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
String id = Optional.ofNullable(obj.get("id")).map(JsonElement::getAsString).orElse(generateRandomId());
|
||||
String name = Optional.ofNullable(obj.get("name")).map(JsonElement::getAsString).orElse("Error");
|
||||
String version = Optional.ofNullable(obj.get("version")).map(JsonElement::getAsString).orElse("");
|
||||
int versionCode = Optional.ofNullable(obj.get("versionCode")).map(JsonElement::getAsInt).orElse(1);
|
||||
String author = Optional.ofNullable(obj.get("author")).map(JsonElement::getAsString).orElse("");
|
||||
String description = Optional.ofNullable(obj.get("description")).map(JsonElement::getAsString).orElse("");
|
||||
|
||||
|
@ -341,10 +396,10 @@ public class Controller implements Cloneable, Observable {
|
|||
ObservableList<ControlViewGroup> viewGroups = FXCollections.observableList(gson.fromJson(Optional.ofNullable(obj.get("viewGroups")).map(JsonElement::getAsJsonArray).orElse(new JsonArray()), new TypeToken<ArrayList<ControlViewGroup>>(){}.getType()));
|
||||
|
||||
if (controllerVersion < Constants.CONTROLLER_VERSION) {
|
||||
showUpgradeDialog(FCLPath.CONTEXT, name);
|
||||
showUpgradeDialog(FCLPath.CONTEXT, name, id);
|
||||
}
|
||||
|
||||
return new Controller(name, version, author, description, controllerVersion, viewGroups);
|
||||
return new Controller(id, name, version, versionCode, author, description, controllerVersion, viewGroups);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class Controllers {
|
|||
if (controllers.isEmpty()) {
|
||||
try {
|
||||
if (DEFAULT_CONTROLLER == null) {
|
||||
String str = IOUtils.readFullyAsString(Controllers.class.getResourceAsStream("/assets/controllers/Default.json"));
|
||||
String str = IOUtils.readFullyAsString(Controllers.class.getResourceAsStream("/assets/controllers/00000000.json"));
|
||||
DEFAULT_CONTROLLER = new GsonBuilder()
|
||||
.registerTypeAdapterFactory(new JavaFxPropertyTypeAdapterFactory(true, true))
|
||||
.setPrettyPrinting()
|
||||
|
@ -74,7 +74,7 @@ public class Controllers {
|
|||
if (files != null) {
|
||||
ArrayList<String> fileNames = (ArrayList<String>) controllers.stream().map(Controller::getFileName).collect(Collectors.toList());
|
||||
for (File file : files) {
|
||||
if (file.isDirectory() || !fileNames.contains(file.getName())) {
|
||||
if (((file.isDirectory() && !file.getName().equals("styles")) || !fileNames.contains(file.getName())) && !file.getName().endsWith(".bak")) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
@ -101,9 +101,7 @@ public class Controllers {
|
|||
checkControllers();
|
||||
|
||||
initialized = true;
|
||||
CALLBACKS.forEach(callback -> {
|
||||
Schedulers.androidUIThread().execute(callback);
|
||||
});
|
||||
CALLBACKS.forEach(callback -> Schedulers.androidUIThread().execute(callback));
|
||||
CALLBACKS.clear();
|
||||
}
|
||||
|
||||
|
@ -118,6 +116,9 @@ public class Controllers {
|
|||
.registerTypeAdapterFactory(new JavaFxPropertyTypeAdapterFactory(true, true))
|
||||
.setPrettyPrinting()
|
||||
.create().fromJson(str, Controller.class);
|
||||
if (!json.getName().equals(controller.getFileName())) {
|
||||
controller.renameFile(json.getName(), controller.getFileName());
|
||||
}
|
||||
list.add(controller);
|
||||
} catch (IOException e) {
|
||||
Logging.LOG.log(Level.WARNING, "Can't read file: " + json.getAbsolutePath(), e.getMessage());
|
||||
|
@ -152,9 +153,9 @@ public class Controllers {
|
|||
controllers.remove(controller);
|
||||
}
|
||||
|
||||
public static Controller findControllerByName(String name) {
|
||||
public static Controller findControllerById(String id) {
|
||||
checkControllers();
|
||||
return controllers.stream().filter(it -> it.getName().equals(name)).findFirst().orElse(controllers.get(0));
|
||||
return controllers.stream().filter(it -> it.getId().equals(id)).findFirst().orElse(controllers.get(0));
|
||||
}
|
||||
|
||||
public static void addCallback(Runnable callback) {
|
||||
|
|
|
@ -310,7 +310,7 @@ public final class VersionSetting implements Cloneable {
|
|||
VKDriverSystemProperty.set(vulkanDriverSystem);
|
||||
}
|
||||
|
||||
private final StringProperty controllerProperty = new SimpleStringProperty(this, "controller", "Default");
|
||||
private final StringProperty controllerProperty = new SimpleStringProperty(this, "controller", "00000000");
|
||||
|
||||
public StringProperty controllerProperty() {
|
||||
return controllerProperty;
|
||||
|
@ -362,11 +362,11 @@ public final class VersionSetting implements Cloneable {
|
|||
Controllers.addCallback(() -> {
|
||||
Controllers.checkControllers();
|
||||
Controller controller = Controllers.getControllers().stream()
|
||||
.filter(it -> it.getName().equals(getController()))
|
||||
.filter(it -> it.getId().equals(getController()))
|
||||
.findFirst()
|
||||
.orElse(Controllers.getControllers().get(0));
|
||||
|
||||
setController(controller.getName());
|
||||
setController(controller.getId());
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -465,7 +465,7 @@ public final class VersionSetting implements Cloneable {
|
|||
vs.setNotCheckJVM(Optional.ofNullable(obj.get("notCheckJVM")).map(JsonElement::getAsBoolean).orElse(false));
|
||||
vs.setBeGesture(Optional.ofNullable(obj.get("beGesture")).map(JsonElement::getAsBoolean).orElse(false));
|
||||
vs.setVKDriverSystem(Optional.ofNullable(obj.get("vulkanDriverSystem")).map(JsonElement::getAsBoolean).orElse(false));
|
||||
vs.setController(Optional.ofNullable(obj.get("controller")).map(JsonElement::getAsString).orElse("Default"));
|
||||
vs.setController(Optional.ofNullable(obj.get("controller")).map(JsonElement::getAsString).orElse("00000000"));
|
||||
vs.setRenderer(FCLConfig.Renderer.values()[Optional.ofNullable(obj.get("renderer")).map(JsonElement::getAsInt).orElse(FCLConfig.Renderer.RENDERER_GL4ES.ordinal())]);
|
||||
vs.setIsolateGameDir(Optional.ofNullable(obj.get("isolateGameDir")).map(JsonElement::getAsBoolean).orElse(false));
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.tungsten.fcl.ui.controller;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
@ -8,7 +9,7 @@ import androidx.annotation.NonNull;
|
|||
|
||||
import com.tungsten.fcl.R;
|
||||
import com.tungsten.fcl.setting.Controller;
|
||||
import com.tungsten.fcl.setting.Controllers;
|
||||
import com.tungsten.fclcore.util.StringUtils;
|
||||
import com.tungsten.fclcore.util.platform.OperatingSystem;
|
||||
import com.tungsten.fcllibrary.component.dialog.FCLDialog;
|
||||
import com.tungsten.fcllibrary.component.view.FCLButton;
|
||||
|
@ -17,9 +18,6 @@ import com.tungsten.fcllibrary.component.view.FCLEditText;
|
|||
import com.tungsten.fcllibrary.component.view.FCLLinearLayout;
|
||||
import com.tungsten.fcllibrary.component.view.FCLTextView;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ControllerInfoDialog extends FCLDialog implements View.OnClickListener {
|
||||
|
||||
private final boolean create;
|
||||
|
@ -29,12 +27,14 @@ public class ControllerInfoDialog extends FCLDialog implements View.OnClickListe
|
|||
private FCLEditText editName;
|
||||
|
||||
private FCLEditText editVersion;
|
||||
private FCLEditText editVersionCode;
|
||||
private FCLEditText editAuthor;
|
||||
private FCLEditText editDescription;
|
||||
|
||||
private FCLButton positive;
|
||||
private FCLButton negative;
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
public ControllerInfoDialog(@NonNull Context context, boolean create, Controller controller, Callback callback) {
|
||||
super(context);
|
||||
this.create = create;
|
||||
|
@ -50,11 +50,15 @@ public class ControllerInfoDialog extends FCLDialog implements View.OnClickListe
|
|||
|
||||
FCLLinearLayout moreInfoLayout = findViewById(R.id.more_info_layout);
|
||||
editVersion = findViewById(R.id.version);
|
||||
editVersionCode = findViewById(R.id.version_code);
|
||||
editAuthor = findViewById(R.id.author);
|
||||
editDescription = findViewById(R.id.description);
|
||||
|
||||
editVersionCode.setIntegerFilter(1);
|
||||
|
||||
editName.setText(controller.getName());
|
||||
editVersion.setText(controller.getVersion());
|
||||
editVersionCode.setText(controller.getVersionCode() + "");
|
||||
editAuthor.setText(controller.getAuthor());
|
||||
editDescription.setText(controller.getDescription());
|
||||
|
||||
|
@ -72,17 +76,17 @@ public class ControllerInfoDialog extends FCLDialog implements View.OnClickListe
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
if (view == positive) {
|
||||
List<String> nameList = Controllers.getControllers().stream().map(Controller::getName).collect(Collectors.toList());
|
||||
if (!create) {
|
||||
nameList.remove(controller.getName());
|
||||
}
|
||||
if (!OperatingSystem.isNameValid(editName.getText().toString()) || editName.getText().toString().equals("Error")) {
|
||||
Toast.makeText(getContext(), getContext().getString(R.string.control_info_name_invalid), Toast.LENGTH_SHORT).show();
|
||||
} else if (nameList.contains(editName.getText().toString())) {
|
||||
Toast.makeText(getContext(), getContext().getString(R.string.control_info_name_exist), Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Controller controller = new Controller(editName.getText().toString(),
|
||||
String id = this.controller.getId();
|
||||
if (!editAuthor.getText().toString().equals(this.controller.getAuthor())) {
|
||||
id = Controller.generateRandomId();
|
||||
}
|
||||
Controller controller = new Controller(id,
|
||||
editName.getText().toString(),
|
||||
editVersion.getText().toString(),
|
||||
Integer.parseInt(StringUtils.isBlank(editVersionCode.getText().toString()) ? "1" : editVersionCode.getText().toString()),
|
||||
editAuthor.getText().toString(),
|
||||
editDescription.getText().toString(),
|
||||
this.controller.getControllerVersion());
|
||||
|
|
|
@ -42,7 +42,6 @@ import com.tungsten.fcllibrary.component.view.FCLUILayout;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ControllerUI extends FCLCommonUI implements View.OnClickListener {
|
||||
|
@ -154,17 +153,20 @@ public class ControllerUI extends FCLCommonUI implements View.OnClickListener {
|
|||
}
|
||||
|
||||
public void changeControllerInfo(Controller old, Controller newValue) {
|
||||
old.setName(newValue.getName());
|
||||
old.setVersion(newValue.getVersion());
|
||||
old.setVersionCode(newValue.getVersionCode());
|
||||
old.setAuthor(newValue.getAuthor());
|
||||
old.setDescription(newValue.getDescription());
|
||||
|
||||
if (!old.getName().equals(newValue.getName())) {
|
||||
if (!old.getId().equals(newValue.getId())) {
|
||||
try {
|
||||
old.rename(newValue.getName());
|
||||
old.changeId(newValue.getId());
|
||||
} catch (IOException e) {
|
||||
Logging.LOG.log(Level.SEVERE, "Failed to rename controller!", e.getMessage());
|
||||
Logging.LOG.log(Level.SEVERE, "Failed to change controller id!", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
refreshProperty.set(!refreshProperty.get());
|
||||
}
|
||||
|
||||
|
@ -225,7 +227,7 @@ public class ControllerUI extends FCLCommonUI implements View.OnClickListener {
|
|||
if (view == editController) {
|
||||
Intent intent = new Intent(getContext(), ControllerActivity.class);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("controller", getSelectedController().getName());
|
||||
bundle.putString("controller", getSelectedController().getId());
|
||||
intent.putExtras(bundle);
|
||||
getActivity().startActivity(intent);
|
||||
}
|
||||
|
|
|
@ -394,9 +394,7 @@ public class VersionSettingPage extends FCLCommonPage implements ManageUI.Versio
|
|||
onDeleteIcon();
|
||||
}
|
||||
if (view == controllerButton) {
|
||||
SelectControllerDialog dialog = new SelectControllerDialog(getContext(), lastVersionSetting.getController(), controller -> {
|
||||
lastVersionSetting.setController(controller.getName());
|
||||
});
|
||||
SelectControllerDialog dialog = new SelectControllerDialog(getContext(), lastVersionSetting.getController(), controller -> lastVersionSetting.setController(controller.getId()));
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.tungsten.fcl.util;
|
|||
|
||||
public class Constants {
|
||||
|
||||
public static final int CONTROLLER_VERSION = 10;
|
||||
public static final int CONTROLLER_VERSION = 20;
|
||||
|
||||
public static final int MIN_CONTROLLER_VERSION = 0;
|
||||
|
||||
|
|
|
@ -88,6 +88,32 @@
|
|||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.tungsten.fcllibrary.component.view.FCLTextView
|
||||
android:layout_weight="1"
|
||||
android:singleLine="true"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/control_info_version_code"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
<com.tungsten.fcllibrary.component.view.FCLEditText
|
||||
android:singleLine="true"
|
||||
android:textSize="14sp"
|
||||
android:inputType="number"
|
||||
android:hint="@string/input_hint_not_empty"
|
||||
android:id="@+id/version_code"
|
||||
android:layout_width="250dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -158,6 +158,7 @@
|
|||
<string name="control_info_name_exist">کنترل کننده از قبل وجود دارد ، لطفاً نام را تغییر دهید!</string>
|
||||
<string name="control_info_name_invalid">نام نامعتبر</string>
|
||||
<string name="control_info_version">نسخه:</string>
|
||||
<string name="control_info_version_code">کد نسخه:</string>
|
||||
<string name="control_list">لیست کنترل کننده</string>
|
||||
<string name="control_select">کنترلر را انتخاب کنید</string>
|
||||
<string name="control_share">کنترل کننده</string>
|
||||
|
|
|
@ -158,6 +158,7 @@
|
|||
<string name="control_info_name_exist">O controle já existe, por favor mude o nome!</string>
|
||||
<string name="control_info_name_invalid">Nome Inválido</string>
|
||||
<string name="control_info_version">Versão: </string>
|
||||
<string name="control_info_version_code">Código da versão:</string>
|
||||
<string name="control_list">Lista de Controles</string>
|
||||
<string name="control_select">Selecionar Controle</string>
|
||||
<string name="control_share">Compartilhar</string>
|
||||
|
|
|
@ -158,6 +158,7 @@
|
|||
<string name="control_info_name_exist">Контроллер уже существует, измените имя!</string>
|
||||
<string name="control_info_name_invalid">Неверное имя</string>
|
||||
<string name="control_info_version">Версия: </string>
|
||||
<string name="control_info_version_code">Код версии:</string>
|
||||
<string name="control_list">Список контроллеров</string>
|
||||
<string name="control_select">Выберите контроллер</string>
|
||||
<string name="control_share">Поделиться контроллером</string>
|
||||
|
|
|
@ -139,6 +139,7 @@
|
|||
<string name="control_info_name_exist">该布局已存在,请换一个名字!</string>
|
||||
<string name="control_info_name_invalid">无效的名称</string>
|
||||
<string name="control_info_version">版本:</string>
|
||||
<string name="control_info_version_code">版本号:</string>
|
||||
<string name="control_list">布局列表</string>
|
||||
<string name="control_select">选择布局</string>
|
||||
<string name="control_share">分享布局</string>
|
||||
|
|
|
@ -160,6 +160,7 @@
|
|||
<string name="control_info_name_exist">The controller already exist, please change the name!</string>
|
||||
<string name="control_info_name_invalid">Invalid Name</string>
|
||||
<string name="control_info_version">Version: </string>
|
||||
<string name="control_info_version_code">Version Code: </string>
|
||||
<string name="control_list">Controller List</string>
|
||||
<string name="control_select">Select Controller</string>
|
||||
<string name="control_share">Share Controller</string>
|
||||
|
|
|
@ -6,6 +6,8 @@ import android.content.res.TypedArray;
|
|||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
|
@ -24,6 +26,8 @@ import com.tungsten.fclcore.task.Schedulers;
|
|||
import com.tungsten.fcllibrary.R;
|
||||
import com.tungsten.fcllibrary.component.theme.ThemeEngine;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class FCLEditText extends AppCompatEditText {
|
||||
|
||||
private boolean autoTint;
|
||||
|
@ -121,6 +125,30 @@ public class FCLEditText extends AppCompatEditText {
|
|||
});
|
||||
}
|
||||
|
||||
private static final class SignedIntegerFilter implements InputFilter {
|
||||
private final Pattern pattern;
|
||||
|
||||
SignedIntegerFilter(int min) {
|
||||
pattern = Pattern.compile("^" + (min < 0 ? "-?" : "") + "[0-9]*$");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
|
||||
StringBuilder builder = new StringBuilder(dest);
|
||||
builder.insert(dstart, source);
|
||||
if (!pattern.matcher(builder.toString()).matches()) {
|
||||
return "";
|
||||
}
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
public void setIntegerFilter(int min) {
|
||||
setFilters(new InputFilter[]{
|
||||
new SignedIntegerFilter(min)
|
||||
});
|
||||
}
|
||||
|
||||
public FCLEditText(@NonNull Context context) {
|
||||
super(context);
|
||||
autoTint = false;
|
||||
|
|
Loading…
Reference in New Issue