From e3017dae8a486fe89bd9376e085f36e106c31d7b Mon Sep 17 00:00:00 2001 From: James Power Date: Tue, 10 Mar 2026 17:55:10 -0400 Subject: [PATCH 1/2] Convert data classes to Kotlin and add Room entities. --- .../com/offsetnull/bt/alias/AliasData.java | 62 ---- .../offsetnull/bt/button/SlickButtonData.java | 319 ------------------ .../offsetnull/bt/launcher/MudConnection.java | 74 ---- .../bt/settings/ColorSetSettings.java | 180 ---------- .../bt/settings/HyperSAXParser.java | 2 +- .../offsetnull/bt/settings/HyperSettings.java | 4 +- .../bt/speedwalk/DirectionData.java | 57 ---- .../com/offsetnull/bt/timer/TimerData.java | 145 -------- .../bt/timer/TimerEditorDialog.java | 2 +- .../com/offsetnull/bt/timer/TimerParser.java | 2 +- .../offsetnull/bt/trigger/TriggerData.java | 217 ------------ .../com/offsetnull/bt/alias/AliasData.kt | 15 + .../offsetnull/bt/button/SlickButtonData.kt | 112 ++++++ .../com/offsetnull/bt/data/AppDatabase.kt | 32 ++ .../com/offsetnull/bt/data/dao/AliasDao.kt | 21 ++ .../com/offsetnull/bt/data/dao/ButtonDao.kt | 24 ++ .../bt/data/dao/MudConnectionDao.kt | 22 ++ .../com/offsetnull/bt/data/dao/TimerDao.kt | 21 ++ .../com/offsetnull/bt/data/dao/TriggerDao.kt | 21 ++ .../offsetnull/bt/launcher/MudConnection.kt | 21 ++ .../bt/settings/ColorSetSettings.kt | 46 +++ .../offsetnull/bt/speedwalk/DirectionData.kt | 9 + .../com/offsetnull/bt/timer/TimerData.kt | 61 ++++ .../com/offsetnull/bt/trigger/TriggerData.kt | 80 +++++ 24 files changed, 490 insertions(+), 1059 deletions(-) delete mode 100644 BTLib/src/main/java/com/offsetnull/bt/alias/AliasData.java delete mode 100644 BTLib/src/main/java/com/offsetnull/bt/button/SlickButtonData.java delete mode 100644 BTLib/src/main/java/com/offsetnull/bt/launcher/MudConnection.java delete mode 100644 BTLib/src/main/java/com/offsetnull/bt/settings/ColorSetSettings.java delete mode 100644 BTLib/src/main/java/com/offsetnull/bt/speedwalk/DirectionData.java delete mode 100644 BTLib/src/main/java/com/offsetnull/bt/timer/TimerData.java delete mode 100644 BTLib/src/main/java/com/offsetnull/bt/trigger/TriggerData.java create mode 100644 BTLib/src/main/kotlin/com/offsetnull/bt/alias/AliasData.kt create mode 100644 BTLib/src/main/kotlin/com/offsetnull/bt/button/SlickButtonData.kt create mode 100644 BTLib/src/main/kotlin/com/offsetnull/bt/data/AppDatabase.kt create mode 100644 BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/AliasDao.kt create mode 100644 BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/ButtonDao.kt create mode 100644 BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/MudConnectionDao.kt create mode 100644 BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/TimerDao.kt create mode 100644 BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/TriggerDao.kt create mode 100644 BTLib/src/main/kotlin/com/offsetnull/bt/launcher/MudConnection.kt create mode 100644 BTLib/src/main/kotlin/com/offsetnull/bt/settings/ColorSetSettings.kt create mode 100644 BTLib/src/main/kotlin/com/offsetnull/bt/speedwalk/DirectionData.kt create mode 100644 BTLib/src/main/kotlin/com/offsetnull/bt/timer/TimerData.kt create mode 100644 BTLib/src/main/kotlin/com/offsetnull/bt/trigger/TriggerData.kt diff --git a/BTLib/src/main/java/com/offsetnull/bt/alias/AliasData.java b/BTLib/src/main/java/com/offsetnull/bt/alias/AliasData.java deleted file mode 100644 index a91688ed..00000000 --- a/BTLib/src/main/java/com/offsetnull/bt/alias/AliasData.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.offsetnull.bt.alias; - -public class AliasData { - - private String pre; - private String post; - private boolean enabled; - - public AliasData() { - pre = ""; - post = ""; - enabled = true; - } - - public AliasData(String pPre, String pPost, boolean enabled) { - pre = pPre; - post = pPost; - this.enabled = enabled; - } - - public AliasData copy() { - AliasData tmp = new AliasData(); - tmp.pre = this.pre; - tmp.post = this.post; - tmp.enabled = this.enabled; - return tmp; - } - - public boolean equals(Object o) { - if (o == this) return true; - if (!(o instanceof AliasData)) return false; - AliasData t = (AliasData) o; - if (!t.pre.equals(this.pre)) return false; - if (!t.post.equals(this.post)) return false; - if (t.enabled != this.enabled) return false; - return true; - } - - public String getPre() { - return pre; - } - - public void setPre(String pre) { - this.pre = pre; - } - - public String getPost() { - return post; - } - - public void setPost(String post) { - this.post = post; - } - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } -} diff --git a/BTLib/src/main/java/com/offsetnull/bt/button/SlickButtonData.java b/BTLib/src/main/java/com/offsetnull/bt/button/SlickButtonData.java deleted file mode 100644 index 2d67b58e..00000000 --- a/BTLib/src/main/java/com/offsetnull/bt/button/SlickButtonData.java +++ /dev/null @@ -1,319 +0,0 @@ -package com.offsetnull.bt.button; - -import com.offsetnull.bt.settings.ColorSetSettings; - -public class SlickButtonData { - - private int x; - private int y; - private int width; - private int height; - private String text; - private String label; - private String flipCommand; - private String targetSet; - - private int primaryColor; - private int selectedColor; - private int flipColor; - private int labelColor; - - private int labelSize; - - private String flipLabel; - private int flipLabelColor; - - // private String foo; - - public static final int MOVE_FREE = 0; - public static final int MOVE_NUDGE = 1; - public static final int MOVE_FREEZE = 2; - - public static final int DEFAULT_COLOR = 0x880000FF; - public static final int DEFAULT_SELECTED_COLOR = 0x8800FF00; - public static final int DEFAULT_FLIP_COLOR = 0x88FF0000; - public static final int DEFAULT_LABEL_COLOR = 0xAAAAAAAA; - public static final int DEFAULT_FLIPLABEL_COLOR = 0x990000FF; - - public static final int DEFAULT_BUTTON_WDITH = 48; - public static final int DEFAULT_BUTTON_HEIGHT = 48; - public static final int DEFAULT_LABEL_SIZE = 16; - - public int MOVE_STATE = MOVE_FREE; - - public SlickButtonData() { - x = 0; - y = 0; - text = ""; - label = ""; - flipCommand = ""; - targetSet = ""; - height = 80; - width = 80; - primaryColor = DEFAULT_COLOR; - selectedColor = DEFAULT_SELECTED_COLOR; - flipColor = DEFAULT_FLIP_COLOR; - labelColor = DEFAULT_LABEL_COLOR; - labelSize = DEFAULT_LABEL_SIZE; - flipLabel = ""; - flipLabelColor = DEFAULT_FLIPLABEL_COLOR; - } - - public SlickButtonData(int ix, int iy, String itext, String ilbl) { - x = ix; - y = iy; - text = itext; - label = ilbl; - flipCommand = ""; - targetSet = ""; - height = 80; - width = 80; - primaryColor = DEFAULT_COLOR; - selectedColor = DEFAULT_SELECTED_COLOR; - flipColor = DEFAULT_FLIP_COLOR; - labelColor = DEFAULT_LABEL_COLOR; - labelSize = DEFAULT_LABEL_SIZE; - flipLabel = ""; - flipLabelColor = DEFAULT_FLIPLABEL_COLOR; - } - - public void setFromSetSettings(ColorSetSettings in, ColorSetSettings old) { - if (primaryColor == old.getPrimaryColor()) primaryColor = in.getPrimaryColor(); - if (selectedColor == old.getSelectedColor()) selectedColor = in.getSelectedColor(); - if (flipColor == old.getFlipColor()) flipColor = in.getFlipColor(); - if (labelColor == old.getLabelColor()) labelColor = in.getLabelColor(); - if (flipLabelColor == old.getFlipLabelColor()) flipLabelColor = in.getFlipLabelColor(); - if (labelSize == old.getLabelSize()) labelSize = in.getLabelSize(); - if (width == old.getButtonWidth()) width = in.getButtonWidth(); - if (height == old.getButtonHeight()) height = in.getButtonHeight(); - } - - public boolean equals(Object aTest) { - // check for self equality - if (this == aTest) { - return true; - } - - // return false if this is not a slickbuttondata holder - if (!(aTest instanceof SlickButtonData)) return false; - - SlickButtonData test = (SlickButtonData) aTest; - - boolean retval = true; - if (this.x != test.x) return false; - if (this.y != test.y) return false; - if (this.height != test.height) return false; - if (this.width != test.width) return false; - if (!this.label.equals(test.label)) return false; - if (!this.text.equals(test.text)) return false; - if (!this.flipCommand.equals(test.flipCommand)) return false; - if (this.MOVE_STATE != test.MOVE_STATE) return false; - // if(this.id != test.id) retval = false; - if (!this.targetSet.equals(test.targetSet)) return false; - - if (this.primaryColor != test.primaryColor) return false; - if (this.selectedColor != test.selectedColor) return false; - if (this.flipColor != test.flipColor) return false; - if (this.labelColor != test.labelColor) return false; - if (this.labelSize != test.labelSize) return false; - if (!this.flipLabel.equals(test.flipLabel)) return false; - if (this.flipLabelColor != test.flipLabelColor) return false; - // Log.e("SLICKBUTTONDATA","Comparing " + this.toString() + " against " + test.toString() + - // " returning " + retval); - - return retval; - } - - public String toString() { - /*if(the_text == null) { - the_text = ""; - } - if(the_label == null) { - the_label = ""; - } - if(flip_command == null) { - flip_command = ""; - }*/ - return x - + "||" - + y - + "||" - + (text.equals("") ? "[NONE]" : text) - + "||" - + (label.equals("") ? "[NONE]" : label) - + "||" - + (flipCommand.equals("") ? "[NONE]" : flipCommand) - + "||" - + MOVE_STATE - + "||" - + targetSet - + "||" - + width - + "||" - + height; - } - - /*public void setDataFromString(String input) { - //String[] elements = input.split("\\|\\|"); - - //if(elements.length != 6) { - //SBD","String not properly formatted"); - } - - x = new Integer(elements[0]).intValue(); - y = new Integer(elements[1]).intValue(); - the_text = elements[2].equals("[NONE]") ? "" : elements[2]; - the_label = elements[3].equals("[NONE]") ? "" : elements[3]; - flip_command = elements[4].equals("[NONE]") ? "" : elements[4]; - MOVE_STATE = new Integer(elements[5]).intValue(); - - }*/ - - public SlickButtonData copy() { - SlickButtonData tmp = new SlickButtonData(); - tmp.x = this.x; - tmp.y = this.y; - tmp.flipCommand = this.flipCommand; - tmp.label = this.label; - tmp.text = this.text; - tmp.MOVE_STATE = this.MOVE_STATE; - tmp.targetSet = this.targetSet; - tmp.height = this.height; - tmp.width = this.width; - tmp.primaryColor = this.primaryColor; - tmp.selectedColor = this.selectedColor; - tmp.flipColor = this.flipColor; - tmp.labelColor = this.labelColor; - tmp.labelSize = this.labelSize; - tmp.flipLabel = this.flipLabel; - tmp.flipLabelColor = this.flipLabelColor; - return tmp; - } - - public void setX(int x) { - this.x = x; - } - - public int getX() { - return x; - } - - public void setY(int y) { - this.y = y; - } - - public int getY() { - return y; - } - - public void setText(String text) { - if (text == null) text = ""; - this.text = text; - } - - public String getText() { - return text; - } - - public void setLabel(String label) { - if (flipCommand == null) flipCommand = ""; - this.label = label; - } - - public String getLabel() { - return label; - } - - public void setFlipCommand(String flipCommand) { - if (flipCommand == null) flipCommand = ""; - this.flipCommand = flipCommand; - } - - public String getFlipCommand() { - return flipCommand; - } - - public void setTargetSet(String targetSet) { - if (targetSet == null) targetSet = ""; - this.targetSet = targetSet; - } - - public String getTargetSet() { - return targetSet; - } - - public void setWidth(int width) { - this.width = width; - } - - public int getWidth() { - return width; - } - - public void setHeight(int height) { - this.height = height; - } - - public int getHeight() { - return height; - } - - public void setPrimaryColor(int primaryColor) { - this.primaryColor = primaryColor; - } - - public int getPrimaryColor() { - return primaryColor; - } - - public void setSelectedColor(int selectedColor) { - this.selectedColor = selectedColor; - } - - public int getSelectedColor() { - return selectedColor; - } - - public void setFlipColor(int flipColor) { - this.flipColor = flipColor; - } - - public int getFlipColor() { - return flipColor; - } - - public void setLabelColor(int labelColor) { - this.labelColor = labelColor; - } - - public int getLabelColor() { - return labelColor; - } - - public void setLabelSize(int labelSize) { - this.labelSize = labelSize; - } - - public int getLabelSize() { - return labelSize; - } - - public void setFlipLabel(String flipLabel) { - if (flipLabel == null) { - flipLabel = ""; - } - this.flipLabel = flipLabel; - } - - public String getFlipLabel() { - return flipLabel; - } - - public void setFlipLabelColor(int flipLabelColor) { - this.flipLabelColor = flipLabelColor; - } - - public int getFlipLabelColor() { - return flipLabelColor; - } -} diff --git a/BTLib/src/main/java/com/offsetnull/bt/launcher/MudConnection.java b/BTLib/src/main/java/com/offsetnull/bt/launcher/MudConnection.java deleted file mode 100644 index fc6c5eca..00000000 --- a/BTLib/src/main/java/com/offsetnull/bt/launcher/MudConnection.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.offsetnull.bt.launcher; - -public class MudConnection { - - private String displayname; - private String hostname; - private String port; - private String lastPlayed = "never"; - private boolean connected = false; - - public MudConnection copy() { - MudConnection tmp = new MudConnection(); - - tmp.displayname = this.displayname; - tmp.hostname = this.hostname; - tmp.port = this.port; - tmp.lastPlayed = this.lastPlayed; - - return tmp; - } - - public String getDisplayName() { - return displayname; - } - - public String getHostName() { - return hostname; - } - - public String getPortString() { - return port; - } - - public void setDisplayName(String in) { - displayname = in; - } - - public void setHostName(String in) { - hostname = in; - } - - public void setPortString(String in) { - port = in; - } - - public boolean equals(Object o) { - if (o == this) return true; - if (!(o instanceof MudConnection)) return false; - - MudConnection test = (MudConnection) o; - - if (!test.getDisplayName().equals(this.getDisplayName())) return false; - if (!test.getHostName().equals(this.getHostName())) return false; - if (!test.getPortString().equals(this.getPortString())) return false; - if (!test.getLastPlayed().equals(this.getLastPlayed())) return false; - return true; - } - - public void setLastPlayed(String lastPlayed) { - this.lastPlayed = lastPlayed; - } - - public String getLastPlayed() { - return lastPlayed; - } - - public void setConnected(boolean connected) { - this.connected = connected; - } - - public boolean isConnected() { - return connected; - } -} diff --git a/BTLib/src/main/java/com/offsetnull/bt/settings/ColorSetSettings.java b/BTLib/src/main/java/com/offsetnull/bt/settings/ColorSetSettings.java deleted file mode 100644 index 93443904..00000000 --- a/BTLib/src/main/java/com/offsetnull/bt/settings/ColorSetSettings.java +++ /dev/null @@ -1,180 +0,0 @@ -package com.offsetnull.bt.settings; - -import com.offsetnull.bt.button.SlickButtonData; - -public class ColorSetSettings { - - private int selectedColor; - private int primaryColor; - private int flipColor; - private int labelColor; - private int buttonHeight; - private int buttonWidth; - private int labelSize; - private int flipLabelColor; - private boolean locked; - private boolean lockNewButtons; - private boolean lockMoveButtons; - private boolean lockEditButtons; - - public static final boolean DEFAULT_LOCKED = false; - public static final boolean DEFAULT_LOCKNEWBUTTONS = true; - public static final boolean DEFAULT_LOCKMOVEBUTTONS = false; - public static final boolean DEFAULT_LOCKEDITBUTTONS = false; - - public ColorSetSettings() { - toDefautls(); - } - - public ColorSetSettings copy() { - ColorSetSettings tmp = new ColorSetSettings(); - tmp.selectedColor = this.selectedColor; - tmp.primaryColor = this.primaryColor; - tmp.flipColor = this.flipColor; - tmp.labelColor = this.labelColor; - tmp.buttonHeight = this.buttonHeight; - tmp.buttonWidth = this.buttonWidth; - tmp.labelSize = this.labelSize; - tmp.flipLabelColor = this.flipLabelColor; - tmp.locked = this.locked; - tmp.lockNewButtons = this.lockNewButtons; - tmp.lockMoveButtons = this.lockMoveButtons; - tmp.lockEditButtons = this.lockEditButtons; - return tmp; - } - - public void toDefautls() { - selectedColor = SlickButtonData.DEFAULT_SELECTED_COLOR; - primaryColor = SlickButtonData.DEFAULT_COLOR; - flipColor = SlickButtonData.DEFAULT_FLIP_COLOR; - labelColor = SlickButtonData.DEFAULT_LABEL_COLOR; - buttonWidth = SlickButtonData.DEFAULT_BUTTON_WDITH; - buttonHeight = SlickButtonData.DEFAULT_BUTTON_HEIGHT; - labelSize = SlickButtonData.DEFAULT_LABEL_SIZE; - flipLabelColor = SlickButtonData.DEFAULT_FLIPLABEL_COLOR; - locked = ColorSetSettings.DEFAULT_LOCKED; - lockNewButtons = ColorSetSettings.DEFAULT_LOCKNEWBUTTONS; - lockMoveButtons = ColorSetSettings.DEFAULT_LOCKMOVEBUTTONS; - lockEditButtons = ColorSetSettings.DEFAULT_LOCKEDITBUTTONS; - } - - public boolean equals(Object o) { - if (o == this) return true; - - if (!(o instanceof ColorSetSettings)) { - return false; - } - - ColorSetSettings test = (ColorSetSettings) o; - - if (this.selectedColor != test.selectedColor) return false; - if (this.flipColor != test.flipColor) return false; - if (this.primaryColor != test.primaryColor) return false; - if (this.labelColor != test.labelColor) return false; - if (this.flipLabelColor != test.flipLabelColor) return false; - if (this.labelSize != test.labelSize) return false; - if (this.buttonHeight != test.buttonHeight) return false; - if (this.buttonWidth != test.buttonWidth) return false; - if (this.locked != test.locked) return false; - if (this.lockNewButtons != test.lockNewButtons) return false; - if (this.lockMoveButtons != test.lockMoveButtons) return false; - if (this.lockEditButtons != test.lockEditButtons) return false; - return true; - } - - public void setSelectedColor(int selectedColor) { - this.selectedColor = selectedColor; - } - - public int getSelectedColor() { - return selectedColor; - } - - public void setPrimaryColor(int primaryColor) { - this.primaryColor = primaryColor; - } - - public int getPrimaryColor() { - return primaryColor; - } - - public void setFlipColor(int flipColor) { - this.flipColor = flipColor; - } - - public int getFlipColor() { - return flipColor; - } - - public void setLabelColor(int labelColor) { - this.labelColor = labelColor; - } - - public int getLabelColor() { - return labelColor; - } - - public void setButtonHeight(int buttonHeight) { - this.buttonHeight = buttonHeight; - } - - public int getButtonHeight() { - return buttonHeight; - } - - public void setButtonWidth(int buttonWidth) { - this.buttonWidth = buttonWidth; - } - - public int getButtonWidth() { - return buttonWidth; - } - - public void setLabelSize(int labelSize) { - this.labelSize = labelSize; - } - - public int getLabelSize() { - return labelSize; - } - - public void setFlipLabelColor(int flipLabelColor) { - this.flipLabelColor = flipLabelColor; - } - - public int getFlipLabelColor() { - return flipLabelColor; - } - - public void setLocked(boolean locked) { - this.locked = locked; - } - - public boolean isLocked() { - return locked; - } - - public void setLockNewButtons(boolean lockNewButtons) { - this.lockNewButtons = lockNewButtons; - } - - public boolean isLockNewButtons() { - return lockNewButtons; - } - - public void setLockMoveButtons(boolean lockMoveButtons) { - this.lockMoveButtons = lockMoveButtons; - } - - public boolean isLockMoveButtons() { - return lockMoveButtons; - } - - public void setLockEditButtons(boolean lockEditButtons) { - this.lockEditButtons = lockEditButtons; - } - - public boolean isLockEditButtons() { - return lockEditButtons; - } -} diff --git a/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSAXParser.java b/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSAXParser.java index f9019926..b97ac696 100644 --- a/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSAXParser.java +++ b/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSAXParser.java @@ -708,7 +708,7 @@ public void start(Attributes a) { public void end() { tmp.getTimers() - .put(current_timer.getOrdinal().toString(), current_timer.copy()); + .put(String.valueOf(current_timer.getOrdinal()), current_timer.copy()); } }); timerNotificationResponder.setStartElementListener( diff --git a/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSettings.java b/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSettings.java index 2aa18b54..786366e3 100644 --- a/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSettings.java +++ b/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSettings.java @@ -519,8 +519,8 @@ public static String writeXml2(HyperSettings data) { for (TimerData timer : data.getTimers().values()) { out.startTag("", BaseParser.TAG_TIMER); out.attribute("", BaseParser.ATTR_TIMERNAME, timer.getName()); - out.attribute("", BaseParser.ATTR_ORDINAL, timer.getOrdinal().toString()); - out.attribute("", BaseParser.ATTR_SECONDS, timer.getSeconds().toString()); + out.attribute("", BaseParser.ATTR_ORDINAL, String.valueOf(timer.getOrdinal())); + out.attribute("", BaseParser.ATTR_SECONDS, String.valueOf(timer.getSeconds())); out.attribute("", BaseParser.ATTR_REPEAT, (timer.isRepeat()) ? "true" : "false"); out.attribute("", BaseParser.ATTR_PLAYING, (timer.isPlaying()) ? "true" : "false"); OutputResponders(out, timer.getResponders()); diff --git a/BTLib/src/main/java/com/offsetnull/bt/speedwalk/DirectionData.java b/BTLib/src/main/java/com/offsetnull/bt/speedwalk/DirectionData.java deleted file mode 100644 index 398f75d1..00000000 --- a/BTLib/src/main/java/com/offsetnull/bt/speedwalk/DirectionData.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.offsetnull.bt.speedwalk; - -public class DirectionData { - private String direction = ""; - private String command = ""; - private String reverse = ""; - - public DirectionData() {} - - public DirectionData(String direction, String command) { - this.direction = direction; - this.command = command; - } - - public boolean equals(Object o) { - if (o == this) return true; - if (!(o instanceof DirectionData)) return false; - DirectionData tmp = (DirectionData) o; - if (!tmp.direction.equals(this.direction)) return false; - if (!tmp.command.equals(this.command)) return false; - if (!tmp.reverse.equals(this.reverse)) return false; - - return true; - } - - public DirectionData copy() { - DirectionData tmp = new DirectionData(); - tmp.direction = this.direction; - tmp.command = this.command; - tmp.reverse = this.reverse; - return tmp; - } - - public void setDirection(String direction) { - this.direction = direction; - } - - public String getDirection() { - return direction; - } - - public void setCommand(String command) { - this.command = command; - } - - public String getCommand() { - return command; - } - - public void setReverse(String reverse) { - this.reverse = reverse; - } - - public String getReverse() { - return reverse; - } -} diff --git a/BTLib/src/main/java/com/offsetnull/bt/timer/TimerData.java b/BTLib/src/main/java/com/offsetnull/bt/timer/TimerData.java deleted file mode 100644 index 7cb8f8bf..00000000 --- a/BTLib/src/main/java/com/offsetnull/bt/timer/TimerData.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.offsetnull.bt.timer; - -import com.offsetnull.bt.responder.TriggerResponder; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -// import android.util.Log; - -public class TimerData { - - private String name; - private Integer ordinal; - private Integer seconds; - private boolean repeat; - private boolean playing; - private long startTime; - private int remainingTime; - - // data that is not serialized, but should still be parcelable. - // private long ttf; - // private Long pauseLocation; - - private List responders; - - public TimerData() { - name = ""; - ordinal = 0; - seconds = 30; - repeat = true; - playing = false; - // ttf = seconds*1000; - responders = new ArrayList(); - // pauseLocation = 0l; - - } - - public void reset() { - // ttf = seconds*1000; - // pauseLocation = 0l; - } - - public TimerData copy() { - - TimerData tmp = new TimerData(); - tmp.name = this.name; - tmp.ordinal = this.ordinal; - tmp.seconds = this.seconds; - tmp.repeat = this.repeat; - tmp.playing = this.playing; - tmp.remainingTime = this.remainingTime; - for (TriggerResponder responder : this.responders) { - tmp.responders.add(responder.copy()); - } - - return tmp; - } - - public boolean equals(Object o) { - if (o == this) return true; - if (!(o instanceof TimerData)) return false; - TimerData test = (TimerData) o; - if (!test.name.equals(this.name)) return false; - if (test.ordinal != this.ordinal) return false; - if (test.seconds != this.seconds) return false; - if (test.repeat != this.repeat) return false; - if (test.playing != this.playing) return false; - // ttf shouldn't be considered for equality. it seems wrong. - Iterator test_responders = test.responders.iterator(); - Iterator my_responders = this.responders.iterator(); - while (test_responders.hasNext()) { - TriggerResponder test_responder = test_responders.next(); - TriggerResponder my_responder = my_responders.next(); - if (!test_responder.equals(my_responder)) return false; - } - - return true; - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setOrdinal(Integer ordinal) { - this.ordinal = ordinal; - } - - public Integer getOrdinal() { - return ordinal; - } - - public void setSeconds(Integer seconds) { - this.seconds = seconds; - // ttf = seconds*1000; - } - - public Integer getSeconds() { - return seconds; - } - - public void setRepeat(boolean repeat) { - this.repeat = repeat; - } - - public boolean isRepeat() { - return repeat; - } - - public void setResponders(List responders) { - this.responders = responders; - } - - public List getResponders() { - return responders; - } - - public void setPlaying(boolean playing) { - this.playing = playing; - } - - public boolean isPlaying() { - return playing; - } - - public long getStartTime() { - return startTime; - } - - public void setStartTime(long startTime) { - this.startTime = startTime; - } - - public int getRemainingTime() { - return remainingTime; - } - - public void setRemainingTime(int remainingTime) { - this.remainingTime = remainingTime; - } -} diff --git a/BTLib/src/main/java/com/offsetnull/bt/timer/TimerEditorDialog.java b/BTLib/src/main/java/com/offsetnull/bt/timer/TimerEditorDialog.java index 308f6752..6da7a3c6 100644 --- a/BTLib/src/main/java/com/offsetnull/bt/timer/TimerEditorDialog.java +++ b/BTLib/src/main/java/com/offsetnull/bt/timer/TimerEditorDialog.java @@ -122,7 +122,7 @@ public void onClick(View v) { if (isEditor) { name.setText(orig_timer.getName()); - seconds.setText(orig_timer.getSeconds().toString()); + seconds.setText(String.valueOf(orig_timer.getSeconds())); repeat.setChecked(orig_timer.isRepeat()); donebutton.setText(R.string.btn_done); } diff --git a/BTLib/src/main/java/com/offsetnull/bt/timer/TimerParser.java b/BTLib/src/main/java/com/offsetnull/bt/timer/TimerParser.java index 12f1e50d..a502bc11 100644 --- a/BTLib/src/main/java/com/offsetnull/bt/timer/TimerParser.java +++ b/BTLib/src/main/java/com/offsetnull/bt/timer/TimerParser.java @@ -39,7 +39,7 @@ public static void saveTimerToXML(XmlSerializer out, TimerData timer) // out.startTag("", BasePluginParser.TAG_TIMER); out.attribute("", BasePluginParser.ATTR_TIMERNAME, timer.getName()); // out.attribute("", BasePluginParser.ATTR_ORDINAL, timer.getOrdinal().toString()); - out.attribute("", BasePluginParser.ATTR_SECONDS, timer.getSeconds().toString()); + out.attribute("", BasePluginParser.ATTR_SECONDS, String.valueOf(timer.getSeconds())); out.attribute("", BasePluginParser.ATTR_REPEAT, (timer.isRepeat()) ? "true" : "false"); out.attribute("", BasePluginParser.ATTR_PLAYING, (timer.isPlaying()) ? "true" : "false"); for (TriggerResponder r : timer.getResponders()) { diff --git a/BTLib/src/main/java/com/offsetnull/bt/trigger/TriggerData.java b/BTLib/src/main/java/com/offsetnull/bt/trigger/TriggerData.java deleted file mode 100644 index 656a90d3..00000000 --- a/BTLib/src/main/java/com/offsetnull/bt/trigger/TriggerData.java +++ /dev/null @@ -1,217 +0,0 @@ -package com.offsetnull.bt.trigger; - -import com.offsetnull.bt.responder.TriggerResponder; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class TriggerData { - - private String name; - private String pattern; - private boolean interpretAsRegex; - private boolean fireOnce; - - private boolean fired = false; - - private boolean hidden = false; - - private boolean enabled = true; - - private boolean save = true; - private int sequence = DEFAULT_SEQUENCE; - private boolean keepEvaluating = DEFAULT_KEEPEVAL; - private String group = DEFAULT_GROUP; - private List responders; - - private Pattern p = null; - private Matcher m = null; - - // private Matcher m = null; - - public TriggerData() { - name = ""; - pattern = ""; - interpretAsRegex = false; - responders = new ArrayList(); - fireOnce = false; - hidden = false; - enabled = true; - sequence = DEFAULT_SEQUENCE; - group = DEFAULT_GROUP; - keepEvaluating = DEFAULT_KEEPEVAL; - buildData(); - } - - public TriggerData copy() { - TriggerData tmp = new TriggerData(); - tmp.name = this.name; - tmp.pattern = this.pattern; - tmp.interpretAsRegex = this.interpretAsRegex; - tmp.fireOnce = this.fireOnce; - tmp.hidden = this.hidden; - tmp.enabled = this.enabled; - tmp.sequence = this.sequence; - tmp.group = this.group; - tmp.keepEvaluating = this.keepEvaluating; - for (TriggerResponder responder : this.responders) { - tmp.responders.add(responder.copy()); - } - tmp.buildData(); - return tmp; - } - - private void buildData() { - // if(p == null || p.equals("")) return; - if (this.interpretAsRegex) { - this.p = Pattern.compile(pattern); - } else { - this.p = Pattern.compile("\\Q" + pattern + "\\E"); - } - this.m = p.matcher(""); - } - - public Matcher getMatcher() { - return m; - } - - public boolean equals(Object o) { - if (o == this) return true; - if (!(o instanceof TriggerData)) return false; - TriggerData test = (TriggerData) o; - if (!test.name.equals(this.name)) return false; - if (!test.pattern.equals(this.pattern)) return false; - if (test.interpretAsRegex != this.interpretAsRegex) return false; - if (test.fireOnce != this.fireOnce) return false; - if (test.hidden != this.hidden) return false; - if (test.enabled != this.enabled) return false; - if (test.sequence != this.sequence) return false; - if (test.group != this.group) return false; - if (test.keepEvaluating != this.keepEvaluating) return false; - Iterator test_responders = test.responders.iterator(); - Iterator my_responders = this.responders.iterator(); - while (test_responders.hasNext()) { - TriggerResponder test_responder = test_responders.next(); - TriggerResponder my_responder = my_responders.next(); - - if (!test_responder.equals(my_responder)) return false; - } - - return true; - } - - public static final int DEFAULT_SEQUENCE = 10; - public static final String DEFAULT_GROUP = ""; - public static final boolean DEFAULT_KEEPEVAL = true; - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setPattern(String pattern) { - this.pattern = pattern; - buildData(); - } - - public String getPattern() { - return pattern; - } - - public void setInterpretAsRegex(boolean interpretAsRegex) { - this.interpretAsRegex = interpretAsRegex; - // buildData(); - } - - public boolean isInterpretAsRegex() { - return interpretAsRegex; - } - - public void setResponders(List responders) { - this.responders = responders; - } - - public List getResponders() { - return responders; - } - - public void setFireOnce(boolean fireOnce) { - this.fireOnce = fireOnce; - } - - public boolean isFireOnce() { - return fireOnce; - } - - public void setFired(boolean fired) { - this.fired = fired; - } - - public boolean isFired() { - return fired; - } - - public void setHidden(boolean hidden) { - this.hidden = hidden; - } - - public boolean isHidden() { - return hidden; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public boolean isEnabled() { - return enabled; - } - - public Pattern getCompiledPattern() { - return p; - } - - // public boolean matches(CharSequence text) { - // m.reset(text); - - public void setSave(boolean save) { - this.save = save; - } - - public boolean isSave() { - return save; - } - - public int getSequence() { - return sequence; - } - - public void setSequence(int sequence) { - this.sequence = sequence; - } - - public boolean isKeepEvaluating() { - return keepEvaluating; - } - - public void setKeepEvaluating(boolean keepEvaluating) { - this.keepEvaluating = keepEvaluating; - } - - public String getGroup() { - return group; - } - - public void setGroup(String group) { - this.group = group; - } - - // } - -} diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/alias/AliasData.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/alias/AliasData.kt new file mode 100644 index 00000000..508c118f --- /dev/null +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/alias/AliasData.kt @@ -0,0 +1,15 @@ +package com.offsetnull.bt.alias + +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "aliases") +data class AliasData( + @PrimaryKey(autoGenerate = true) var id: Long = 0, + var connectionId: Long = 0, + var pre: String = "", + var post: String = "", + @get:JvmName("isEnabled") var enabled: Boolean = true, +) { + fun copy(): AliasData = AliasData(id, connectionId, pre, post, enabled) +} diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/button/SlickButtonData.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/button/SlickButtonData.kt new file mode 100644 index 00000000..b95b25c5 --- /dev/null +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/button/SlickButtonData.kt @@ -0,0 +1,112 @@ +package com.offsetnull.bt.button + +import androidx.room.Entity +import androidx.room.Ignore +import androidx.room.PrimaryKey +import com.offsetnull.bt.settings.ColorSetSettings + +@Entity(tableName = "buttons") +class SlickButtonData( + @PrimaryKey(autoGenerate = true) var id: Long = 0, + var connectionId: Long = 0, + var buttonSetName: String = "", + var x: Int = 0, + var y: Int = 0, + var width: Int = 80, + var height: Int = 80, + text: String = "", + label: String = "", + flipCommand: String = "", + targetSet: String = "", + var primaryColor: Int = DEFAULT_COLOR, + var selectedColor: Int = DEFAULT_SELECTED_COLOR, + var flipColor: Int = DEFAULT_FLIP_COLOR, + var labelColor: Int = DEFAULT_LABEL_COLOR, + var labelSize: Int = DEFAULT_LABEL_SIZE, + flipLabel: String = "", + var flipLabelColor: Int = DEFAULT_FLIPLABEL_COLOR, +) { + var text: String = text + set(value) { field = value ?: "" } + var label: String = label + set(value) { field = value ?: "" } + var flipCommand: String = flipCommand + set(value) { field = value ?: "" } + var targetSet: String = targetSet + set(value) { field = value ?: "" } + var flipLabel: String = flipLabel + set(value) { field = value ?: "" } + + @Ignore + @JvmField + var MOVE_STATE: Int = MOVE_FREE + + companion object { + const val MOVE_FREE = 0 + const val MOVE_NUDGE = 1 + const val MOVE_FREEZE = 2 + const val DEFAULT_COLOR = 0x880000FF.toInt() + const val DEFAULT_SELECTED_COLOR = 0x8800FF00.toInt() + const val DEFAULT_FLIP_COLOR = 0x88FF0000.toInt() + const val DEFAULT_LABEL_COLOR = 0xAAAAAAAA.toInt() + const val DEFAULT_FLIPLABEL_COLOR = 0x990000FF.toInt() + const val DEFAULT_BUTTON_WDITH = 48 + const val DEFAULT_BUTTON_HEIGHT = 48 + const val DEFAULT_LABEL_SIZE = 16 + } + + constructor(ix: Int, iy: Int, itext: String, ilbl: String) : this( + x = ix, y = iy, text = itext, label = ilbl + ) + + fun setFromSetSettings(new: ColorSetSettings, old: ColorSetSettings) { + if (primaryColor == old.primaryColor) primaryColor = new.primaryColor + if (selectedColor == old.selectedColor) selectedColor = new.selectedColor + if (flipColor == old.flipColor) flipColor = new.flipColor + if (labelColor == old.labelColor) labelColor = new.labelColor + if (flipLabelColor == old.flipLabelColor) flipLabelColor = new.flipLabelColor + if (labelSize == old.labelSize) labelSize = new.labelSize + if (width == old.buttonWidth) width = new.buttonWidth + if (height == old.buttonHeight) height = new.buttonHeight + } + + fun copy(): SlickButtonData { + val tmp = SlickButtonData() + tmp.id = id; tmp.connectionId = connectionId; tmp.buttonSetName = buttonSetName + tmp.x = x; tmp.y = y; tmp.width = width; tmp.height = height + tmp.text = text; tmp.label = label; tmp.flipCommand = flipCommand + tmp.targetSet = targetSet; tmp.primaryColor = primaryColor + tmp.selectedColor = selectedColor; tmp.flipColor = flipColor + tmp.labelColor = labelColor; tmp.labelSize = labelSize + tmp.flipLabel = flipLabel; tmp.flipLabelColor = flipLabelColor + tmp.MOVE_STATE = MOVE_STATE + return tmp + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is SlickButtonData) return false + return x == other.x && y == other.y && height == other.height && width == other.width + && label == other.label && text == other.text && flipCommand == other.flipCommand + && MOVE_STATE == other.MOVE_STATE && targetSet == other.targetSet + && primaryColor == other.primaryColor && selectedColor == other.selectedColor + && flipColor == other.flipColor && labelColor == other.labelColor + && labelSize == other.labelSize && flipLabel == other.flipLabel + && flipLabelColor == other.flipLabelColor + } + + override fun hashCode(): Int { + var result = x + result = 31 * result + y + result = 31 * result + width + result = 31 * result + height + result = 31 * result + text.hashCode() + result = 31 * result + label.hashCode() + return result + } + + override fun toString(): String { + return "$x||$y||${text.ifEmpty { "[NONE]" }}||${label.ifEmpty { "[NONE]" }}" + + "||${flipCommand.ifEmpty { "[NONE]" }}||$MOVE_STATE||$targetSet||$width||$height" + } +} diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/data/AppDatabase.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/data/AppDatabase.kt new file mode 100644 index 00000000..36fee706 --- /dev/null +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/data/AppDatabase.kt @@ -0,0 +1,32 @@ +package com.offsetnull.bt.data + +import androidx.room.Database +import androidx.room.RoomDatabase +import com.offsetnull.bt.alias.AliasData +import com.offsetnull.bt.button.SlickButtonData +import com.offsetnull.bt.data.dao.AliasDao +import com.offsetnull.bt.data.dao.ButtonDao +import com.offsetnull.bt.data.dao.MudConnectionDao +import com.offsetnull.bt.data.dao.TimerDao +import com.offsetnull.bt.data.dao.TriggerDao +import com.offsetnull.bt.launcher.MudConnection +import com.offsetnull.bt.timer.TimerData +import com.offsetnull.bt.trigger.TriggerData + +@Database( + entities = [ + AliasData::class, + TriggerData::class, + TimerData::class, + SlickButtonData::class, + MudConnection::class, + ], + version = 1, +) +abstract class AppDatabase : RoomDatabase() { + abstract fun aliasDao(): AliasDao + abstract fun triggerDao(): TriggerDao + abstract fun timerDao(): TimerDao + abstract fun buttonDao(): ButtonDao + abstract fun connectionDao(): MudConnectionDao +} diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/AliasDao.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/AliasDao.kt new file mode 100644 index 00000000..dc5ca416 --- /dev/null +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/AliasDao.kt @@ -0,0 +1,21 @@ +package com.offsetnull.bt.data.dao + +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.Query +import androidx.room.Update +import com.offsetnull.bt.alias.AliasData +import kotlinx.coroutines.flow.Flow + +@Dao +interface AliasDao { + @Query("SELECT * FROM aliases WHERE connectionId = :connectionId") + fun getByConnection(connectionId: Long): Flow> + + @Insert fun insert(alias: AliasData): Long + @Update fun update(alias: AliasData) + @Delete fun delete(alias: AliasData) + @Query("DELETE FROM aliases WHERE connectionId = :connectionId") + fun deleteByConnection(connectionId: Long) +} diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/ButtonDao.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/ButtonDao.kt new file mode 100644 index 00000000..1b8d3ea9 --- /dev/null +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/ButtonDao.kt @@ -0,0 +1,24 @@ +package com.offsetnull.bt.data.dao + +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.Query +import androidx.room.Update +import com.offsetnull.bt.button.SlickButtonData +import kotlinx.coroutines.flow.Flow + +@Dao +interface ButtonDao { + @Query("SELECT * FROM buttons WHERE connectionId = :connectionId") + fun getByConnection(connectionId: Long): Flow> + + @Query("SELECT * FROM buttons WHERE connectionId = :connectionId AND buttonSetName = :setName") + fun getByConnectionAndSet(connectionId: Long, setName: String): Flow> + + @Insert fun insert(button: SlickButtonData): Long + @Update fun update(button: SlickButtonData) + @Delete fun delete(button: SlickButtonData) + @Query("DELETE FROM buttons WHERE connectionId = :connectionId") + fun deleteByConnection(connectionId: Long) +} diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/MudConnectionDao.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/MudConnectionDao.kt new file mode 100644 index 00000000..aeff260c --- /dev/null +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/MudConnectionDao.kt @@ -0,0 +1,22 @@ +package com.offsetnull.bt.data.dao + +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.Query +import androidx.room.Update +import com.offsetnull.bt.launcher.MudConnection +import kotlinx.coroutines.flow.Flow + +@Dao +interface MudConnectionDao { + @Query("SELECT * FROM connections") + fun getAll(): Flow> + + @Query("SELECT * FROM connections WHERE id = :id") + fun getById(id: Long): MudConnection? + + @Insert fun insert(connection: MudConnection): Long + @Update fun update(connection: MudConnection) + @Delete fun delete(connection: MudConnection) +} diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/TimerDao.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/TimerDao.kt new file mode 100644 index 00000000..bfe0e9ae --- /dev/null +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/TimerDao.kt @@ -0,0 +1,21 @@ +package com.offsetnull.bt.data.dao + +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.Query +import androidx.room.Update +import com.offsetnull.bt.timer.TimerData +import kotlinx.coroutines.flow.Flow + +@Dao +interface TimerDao { + @Query("SELECT * FROM timers WHERE connectionId = :connectionId") + fun getByConnection(connectionId: Long): Flow> + + @Insert fun insert(timer: TimerData): Long + @Update fun update(timer: TimerData) + @Delete fun delete(timer: TimerData) + @Query("DELETE FROM timers WHERE connectionId = :connectionId") + fun deleteByConnection(connectionId: Long) +} diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/TriggerDao.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/TriggerDao.kt new file mode 100644 index 00000000..9733ea3a --- /dev/null +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/data/dao/TriggerDao.kt @@ -0,0 +1,21 @@ +package com.offsetnull.bt.data.dao + +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.Query +import androidx.room.Update +import com.offsetnull.bt.trigger.TriggerData +import kotlinx.coroutines.flow.Flow + +@Dao +interface TriggerDao { + @Query("SELECT * FROM triggers WHERE connectionId = :connectionId") + fun getByConnection(connectionId: Long): Flow> + + @Insert fun insert(trigger: TriggerData): Long + @Update fun update(trigger: TriggerData) + @Delete fun delete(trigger: TriggerData) + @Query("DELETE FROM triggers WHERE connectionId = :connectionId") + fun deleteByConnection(connectionId: Long) +} diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/launcher/MudConnection.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/launcher/MudConnection.kt new file mode 100644 index 00000000..9c261d95 --- /dev/null +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/launcher/MudConnection.kt @@ -0,0 +1,21 @@ +package com.offsetnull.bt.launcher + +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "connections") +data class MudConnection( + @PrimaryKey(autoGenerate = true) var id: Long = 0, + @get:JvmName("getDisplayName") @set:JvmName("setDisplayName") + var displayName: String = "", + @get:JvmName("getHostName") @set:JvmName("setHostName") + var hostName: String = "", + @get:JvmName("getPortString") @set:JvmName("setPortString") + var portString: String = "", + var lastPlayed: String = "never", + @get:JvmName("isConnected") var connected: Boolean = false, +) { + fun copy(): MudConnection = MudConnection( + id, displayName, hostName, portString, lastPlayed, connected, + ) +} diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/settings/ColorSetSettings.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/settings/ColorSetSettings.kt new file mode 100644 index 00000000..42955807 --- /dev/null +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/settings/ColorSetSettings.kt @@ -0,0 +1,46 @@ +package com.offsetnull.bt.settings + +import com.offsetnull.bt.button.SlickButtonData + +data class ColorSetSettings( + var selectedColor: Int = SlickButtonData.DEFAULT_SELECTED_COLOR, + var primaryColor: Int = SlickButtonData.DEFAULT_COLOR, + var flipColor: Int = SlickButtonData.DEFAULT_FLIP_COLOR, + var labelColor: Int = SlickButtonData.DEFAULT_LABEL_COLOR, + var buttonHeight: Int = SlickButtonData.DEFAULT_BUTTON_HEIGHT, + var buttonWidth: Int = SlickButtonData.DEFAULT_BUTTON_WDITH, + var labelSize: Int = SlickButtonData.DEFAULT_LABEL_SIZE, + var flipLabelColor: Int = SlickButtonData.DEFAULT_FLIPLABEL_COLOR, + @get:JvmName("isLocked") var locked: Boolean = DEFAULT_LOCKED, + @get:JvmName("isLockNewButtons") var lockNewButtons: Boolean = DEFAULT_LOCKNEWBUTTONS, + @get:JvmName("isLockMoveButtons") var lockMoveButtons: Boolean = DEFAULT_LOCKMOVEBUTTONS, + @get:JvmName("isLockEditButtons") var lockEditButtons: Boolean = DEFAULT_LOCKEDITBUTTONS, +) { + companion object { + const val DEFAULT_LOCKED = false + const val DEFAULT_LOCKNEWBUTTONS = true + const val DEFAULT_LOCKMOVEBUTTONS = false + const val DEFAULT_LOCKEDITBUTTONS = false + } + + fun copy(): ColorSetSettings = ColorSetSettings( + selectedColor, primaryColor, flipColor, labelColor, + buttonHeight, buttonWidth, labelSize, flipLabelColor, + locked, lockNewButtons, lockMoveButtons, lockEditButtons, + ) + + fun toDefautls() { + selectedColor = SlickButtonData.DEFAULT_SELECTED_COLOR + primaryColor = SlickButtonData.DEFAULT_COLOR + flipColor = SlickButtonData.DEFAULT_FLIP_COLOR + labelColor = SlickButtonData.DEFAULT_LABEL_COLOR + buttonWidth = SlickButtonData.DEFAULT_BUTTON_WDITH + buttonHeight = SlickButtonData.DEFAULT_BUTTON_HEIGHT + labelSize = SlickButtonData.DEFAULT_LABEL_SIZE + flipLabelColor = SlickButtonData.DEFAULT_FLIPLABEL_COLOR + locked = DEFAULT_LOCKED + lockNewButtons = DEFAULT_LOCKNEWBUTTONS + lockMoveButtons = DEFAULT_LOCKMOVEBUTTONS + lockEditButtons = DEFAULT_LOCKEDITBUTTONS + } +} diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/speedwalk/DirectionData.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/speedwalk/DirectionData.kt new file mode 100644 index 00000000..ea7df264 --- /dev/null +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/speedwalk/DirectionData.kt @@ -0,0 +1,9 @@ +package com.offsetnull.bt.speedwalk + +data class DirectionData @JvmOverloads constructor( + var direction: String = "", + var command: String = "", + var reverse: String = "", +) { + fun copy(): DirectionData = DirectionData(direction, command, reverse) +} diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/timer/TimerData.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/timer/TimerData.kt new file mode 100644 index 00000000..2acfd10e --- /dev/null +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/timer/TimerData.kt @@ -0,0 +1,61 @@ +package com.offsetnull.bt.timer + +import androidx.room.Entity +import androidx.room.Ignore +import androidx.room.PrimaryKey +import com.offsetnull.bt.responder.TriggerResponder + +@Entity(tableName = "timers") +data class TimerData( + @PrimaryKey(autoGenerate = true) var id: Long = 0, + var connectionId: Long = 0, + var name: String = "", + var ordinal: Int = 0, + var seconds: Int = 30, + @get:JvmName("isRepeat") var repeat: Boolean = true, +) { + @Ignore + @get:JvmName("isPlaying") + var playing: Boolean = false + + @Ignore var startTime: Long = 0L + @Ignore var remainingTime: Int = 0 + + @Ignore var responders: MutableList = mutableListOf() + + fun reset() { /* no-op, preserved for API compat */ } + + fun copy(): TimerData { + val tmp = TimerData( + id = id, connectionId = connectionId, name = name, + ordinal = ordinal, seconds = seconds, repeat = repeat + ) + tmp.playing = playing + tmp.remainingTime = remainingTime + for (r in responders) { tmp.responders.add(r.copy()) } + return tmp + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is TimerData) return false + if (name != other.name) return false + if (ordinal != other.ordinal) return false + if (seconds != other.seconds) return false + if (repeat != other.repeat) return false + if (playing != other.playing) return false + if (responders.size != other.responders.size) return false + for (i in responders.indices) { + if (responders[i] != other.responders[i]) return false + } + return true + } + + override fun hashCode(): Int { + var result = name.hashCode() + result = 31 * result + ordinal + result = 31 * result + seconds + result = 31 * result + repeat.hashCode() + return result + } +} diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/trigger/TriggerData.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/trigger/TriggerData.kt new file mode 100644 index 00000000..c6bddbc8 --- /dev/null +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/trigger/TriggerData.kt @@ -0,0 +1,80 @@ +package com.offsetnull.bt.trigger + +import androidx.room.Entity +import androidx.room.Ignore +import androidx.room.PrimaryKey +import com.offsetnull.bt.responder.TriggerResponder +import java.util.regex.Matcher +import java.util.regex.Pattern + +@Entity(tableName = "triggers") +class TriggerData( + @PrimaryKey(autoGenerate = true) var id: Long = 0, + var connectionId: Long = 0, + var name: String = "", + pattern: String = "", + @get:JvmName("isInterpretAsRegex") var interpretAsRegex: Boolean = false, + @get:JvmName("isFireOnce") var fireOnce: Boolean = false, + @get:JvmName("isHidden") var hidden: Boolean = false, + @get:JvmName("isEnabled") var enabled: Boolean = true, + @get:JvmName("isSave") var save: Boolean = true, + var sequence: Int = DEFAULT_SEQUENCE, + @get:JvmName("isKeepEvaluating") var keepEvaluating: Boolean = DEFAULT_KEEPEVAL, + var group: String = DEFAULT_GROUP, +) { + var pattern: String = pattern + set(value) { field = value; buildData() } + + @Ignore + @get:JvmName("isFired") + var fired: Boolean = false + + @Ignore var responders: MutableList = mutableListOf() + + @Ignore private var p: Pattern? = null + @Ignore private var m: Matcher? = null + + init { buildData() } + + private fun buildData() { + p = if (interpretAsRegex) Pattern.compile(pattern) else Pattern.compile("\\Q$pattern\\E") + m = p!!.matcher("") + } + + val matcher: Matcher? get() = m + val compiledPattern: Pattern? get() = p + + fun copy(): TriggerData { + val tmp = TriggerData( + name = name, pattern = pattern, interpretAsRegex = interpretAsRegex, + fireOnce = fireOnce, hidden = hidden, enabled = enabled, save = save, + sequence = sequence, keepEvaluating = keepEvaluating, group = group + ) + for (r in responders) { tmp.responders.add(r.copy()) } + return tmp + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is TriggerData) return false + return name == other.name && pattern == other.pattern + && interpretAsRegex == other.interpretAsRegex && fireOnce == other.fireOnce + && hidden == other.hidden && enabled == other.enabled + && sequence == other.sequence && group == other.group + && keepEvaluating == other.keepEvaluating + && responders == other.responders + } + + override fun hashCode(): Int { + var result = name.hashCode() + result = 31 * result + pattern.hashCode() + result = 31 * result + sequence + return result + } + + companion object { + const val DEFAULT_SEQUENCE = 10 + const val DEFAULT_GROUP = "" + const val DEFAULT_KEEPEVAL = true + } +} From ee5ef93e90cd20d98f122c1d362030540c7568bd Mon Sep 17 00:00:00 2001 From: James Power Date: Tue, 10 Mar 2026 18:02:01 -0400 Subject: [PATCH 2/2] fixup! Convert data classes to Kotlin and add Room entities. --- .../com/offsetnull/bt/button/SlickButton.java | 8 +++--- .../bt/settings/HyperSAXParser.java | 2 +- .../offsetnull/bt/settings/HyperSettings.java | 2 +- .../offsetnull/bt/button/SlickButtonData.kt | 27 ++++++++++++------- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/BTLib/src/main/java/com/offsetnull/bt/button/SlickButton.java b/BTLib/src/main/java/com/offsetnull/bt/button/SlickButton.java index bb4fb9cd..284a9e7a 100644 --- a/BTLib/src/main/java/com/offsetnull/bt/button/SlickButton.java +++ b/BTLib/src/main/java/com/offsetnull/bt/button/SlickButton.java @@ -179,11 +179,11 @@ public void setFlipCommand(String t) { public void setMoveMethod(int i) { // Log.e("SB","MOVE STATE CHANGED TO:"+i); - data.MOVE_STATE = i; + data.moveState = i; } public int getMoveMethod() { - return data.MOVE_STATE; + return data.moveState; } public void setLabel(String t) { @@ -322,7 +322,7 @@ public boolean onTouchEvent(MotionEvent e) { } if (e.getAction() == MotionEvent.ACTION_MOVE) { if (moving) { - if (data.MOVE_STATE == SlickButtonData.MOVE_FREE) { + if (data.moveState == SlickButtonData.MOVE_FREE) { if (!lockMove) { data.setX(touchx); data.setY(touchy); @@ -330,7 +330,7 @@ public boolean onTouchEvent(MotionEvent e) { updateRect(); // this.invalidate(); newstate = DISPLAY_STATE.MOVING; - } else if (data.MOVE_STATE == SlickButtonData.MOVE_NUDGE) { + } else if (data.moveState == SlickButtonData.MOVE_NUDGE) { // compute nudge int tmpx = touchx - start_x; int tmpy = touchy - start_y; diff --git a/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSAXParser.java b/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSAXParser.java index b97ac696..6c38063f 100644 --- a/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSAXParser.java +++ b/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSAXParser.java @@ -533,7 +533,7 @@ public void start(Attributes attributes) { ? "" : attributes.getValue( "", ATTR_LABEL))); // no primary label crash - tmp.MOVE_STATE = Integer.valueOf(attributes.getValue("", ATTR_MOVEMETHOD)); + tmp.moveState = Integer.valueOf(attributes.getValue("", ATTR_MOVEMETHOD)); tmp.setTargetSet(attributes.getValue("", ATTR_TARGETSET)); tmp.setWidth( (attributes.getValue("", ATTR_WIDTH) == null) diff --git a/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSettings.java b/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSettings.java index 786366e3..7312ab23 100644 --- a/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSettings.java +++ b/BTLib/src/main/java/com/offsetnull/bt/settings/HyperSettings.java @@ -426,7 +426,7 @@ public static String writeXml2(HyperSettings data) { out.attribute( "", BaseParser.ATTR_MOVEMETHOD, - Integer.valueOf(button.MOVE_STATE).toString()); + Integer.valueOf(button.moveState).toString()); if (!button.getTargetSet().equals("")) out.attribute("", BaseParser.ATTR_TARGETSET, button.getTargetSet()); if (button.getWidth() != setdefaults.getButtonWidth()) diff --git a/BTLib/src/main/kotlin/com/offsetnull/bt/button/SlickButtonData.kt b/BTLib/src/main/kotlin/com/offsetnull/bt/button/SlickButtonData.kt index b95b25c5..6e2a5627 100644 --- a/BTLib/src/main/kotlin/com/offsetnull/bt/button/SlickButtonData.kt +++ b/BTLib/src/main/kotlin/com/offsetnull/bt/button/SlickButtonData.kt @@ -39,7 +39,7 @@ class SlickButtonData( @Ignore @JvmField - var MOVE_STATE: Int = MOVE_FREE + var moveState: Int = MOVE_FREE companion object { const val MOVE_FREE = 0 @@ -79,22 +79,29 @@ class SlickButtonData( tmp.selectedColor = selectedColor; tmp.flipColor = flipColor tmp.labelColor = labelColor; tmp.labelSize = labelSize tmp.flipLabel = flipLabel; tmp.flipLabelColor = flipLabelColor - tmp.MOVE_STATE = MOVE_STATE + tmp.moveState = moveState return tmp } override fun equals(other: Any?): Boolean { if (this === other) return true if (other !is SlickButtonData) return false - return x == other.x && y == other.y && height == other.height && width == other.width - && label == other.label && text == other.text && flipCommand == other.flipCommand - && MOVE_STATE == other.MOVE_STATE && targetSet == other.targetSet - && primaryColor == other.primaryColor && selectedColor == other.selectedColor - && flipColor == other.flipColor && labelColor == other.labelColor - && labelSize == other.labelSize && flipLabel == other.flipLabel - && flipLabelColor == other.flipLabelColor + return layoutEquals(other) && contentEquals(other) && styleEquals(other) } + private fun layoutEquals(other: SlickButtonData): Boolean = + x == other.x && y == other.y && height == other.height && width == other.width + && moveState == other.moveState + + private fun contentEquals(other: SlickButtonData): Boolean = + text == other.text && label == other.label && flipCommand == other.flipCommand + && targetSet == other.targetSet && flipLabel == other.flipLabel + + private fun styleEquals(other: SlickButtonData): Boolean = + primaryColor == other.primaryColor && selectedColor == other.selectedColor + && flipColor == other.flipColor && labelColor == other.labelColor + && labelSize == other.labelSize && flipLabelColor == other.flipLabelColor + override fun hashCode(): Int { var result = x result = 31 * result + y @@ -107,6 +114,6 @@ class SlickButtonData( override fun toString(): String { return "$x||$y||${text.ifEmpty { "[NONE]" }}||${label.ifEmpty { "[NONE]" }}" + - "||${flipCommand.ifEmpty { "[NONE]" }}||$MOVE_STATE||$targetSet||$width||$height" + "||${flipCommand.ifEmpty { "[NONE]" }}||$moveState||$targetSet||$width||$height" } }