Skip to content

Commit

Permalink
Minor improvements (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
valterc committed Dec 18, 2022
1 parent 953062a commit 225b9be
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

public class ConnectionDataInfo implements Parcelable {

private DeviceId deviceId;
private ConnectionStatus status;
private Map<DataType, DataInfo> dataMap;
private final DeviceId deviceId;
private final ConnectionStatus status;
private final Map<DataType, DataInfo> dataMap;

public static final Parcelable.Creator<ConnectionDataInfo> CREATOR = new Parcelable.Creator<ConnectionDataInfo>() {
public ConnectionDataInfo createFromParcel(Parcel in) {
Expand All @@ -34,11 +34,16 @@ public ConnectionDataInfo(DeviceId deviceId, ConnectionStatus status, Map<DataTy
}

private ConnectionDataInfo(Parcel in) {
readFromParcel(in);
}
deviceId = in.readParcelable(DeviceId.class.getClassLoader());
status = ConnectionStatus.fromValue(in.readInt());

public ConnectionDataInfo(ConnectionStatus status) {
this.status = status;
int size = in.readInt();
dataMap = new HashMap<>(size);
for (int i = 0; i < size; i++) {
DataType dataType = DataType.fromFlag(in.readInt());
DataInfo value = in.readParcelable(DataInfo.class.getClassLoader());
dataMap.put(dataType, value);
}
}

@Override
Expand All @@ -53,19 +58,6 @@ public void writeToParcel(Parcel out, int flags) {
}
}

public void readFromParcel(Parcel in) {
deviceId = in.readParcelable(DeviceId.class.getClassLoader());
status = ConnectionStatus.fromValue(in.readInt());

int size = in.readInt();
dataMap = new HashMap<>(size);
for (int i = 0; i < size; i++) {
DataType dataType = DataType.fromFlag(in.readInt());
DataInfo value = in.readParcelable(DataInfo.class.getClassLoader());
dataMap.put(dataType, value);
}
}

@Override
public int describeContents() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class ConnectionInfo implements Parcelable {

private ConnectionStatus status;
private final ConnectionStatus status;

public static final Parcelable.Creator<ConnectionInfo> CREATOR = new Parcelable.Creator<ConnectionInfo>() {
public ConnectionInfo createFromParcel(Parcel in) {
Expand All @@ -18,7 +18,7 @@ public ConnectionInfo[] newArray(int size) {
};

private ConnectionInfo(Parcel in) {
readFromParcel(in);
status = ConnectionStatus.fromValue(in.readInt());
}

public ConnectionInfo(ConnectionStatus status) {
Expand All @@ -30,10 +30,6 @@ public void writeToParcel(Parcel out, int flags) {
out.writeInt(status.getValue());
}

public void readFromParcel(Parcel in) {
status = ConnectionStatus.fromValue(in.readInt());
}

@Override
public int describeContents() {
return 0;
Expand Down
12 changes: 4 additions & 8 deletions app/src/main/java/com/valterc/ki2/data/device/DeviceId.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

public class DeviceId implements Parcelable {

private String uid;
private DeviceType deviceType;
private final String uid;
private final DeviceType deviceType;

public static final Parcelable.Creator<DeviceId> CREATOR = new Parcelable.Creator<DeviceId>() {
public DeviceId createFromParcel(Parcel in) {
Expand All @@ -23,7 +23,8 @@ public DeviceId[] newArray(int size) {
};

private DeviceId(Parcel in) {
readFromParcel(in);
uid = in.readString();
deviceType = DeviceType.fromDeviceTypeValue(in.readInt());
}

public DeviceId(String uid, DeviceType deviceType) {
Expand All @@ -37,11 +38,6 @@ public void writeToParcel(Parcel out, int flags) {
out.writeInt(deviceType.getDeviceTypeValue());
}

public void readFromParcel(Parcel in) {
uid = in.readString();
deviceType = DeviceType.fromDeviceTypeValue(in.readInt());
}

@Override
public int describeContents() {
return 0;
Expand Down
19 changes: 13 additions & 6 deletions app/src/main/java/com/valterc/ki2/data/device/SignalInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

public class SignalInfo implements Parcelable {

private int value;
private final int value;

public static final Creator<SignalInfo> CREATOR = new Creator<SignalInfo>() {
public SignalInfo createFromParcel(Parcel in) {
Expand All @@ -18,7 +20,7 @@ public SignalInfo[] newArray(int size) {
};

private SignalInfo(Parcel in) {
readFromParcel(in);
value = in.readInt();
}

public SignalInfo(int value) {
Expand All @@ -30,10 +32,6 @@ public void writeToParcel(Parcel out, int flags) {
out.writeInt(value);
}

public void readFromParcel(Parcel in) {
value = in.readInt();
}

@Override
public int describeContents() {
return 0;
Expand Down Expand Up @@ -69,4 +67,13 @@ public boolean equals(Object o) {
public int hashCode() {
return value;
}

@NonNull
@Override
public String toString() {
return "SignalInfo{" +
"value=" + value +
", strength=" + getSignalStrength() +
'}';
}
}
38 changes: 21 additions & 17 deletions app/src/main/java/com/valterc/ki2/data/input/KarooKeyEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

public class KarooKeyEvent implements Parcelable {

private KarooKey key;
private KeyAction action;
private int repeat;
private int replicate;
private final KarooKey key;
private final KeyAction action;
private final int repeat;
private final int replicate;

public static final Parcelable.Creator<KarooKeyEvent> CREATOR = new Parcelable.Creator<KarooKeyEvent>() {
public KarooKeyEvent createFromParcel(Parcel in) {
Expand All @@ -21,12 +23,10 @@ public KarooKeyEvent[] newArray(int size) {
};

private KarooKeyEvent(Parcel in) {
readFromParcel(in);
}

public KarooKeyEvent(KarooKey key, KeyAction action)
{
this(key, action, 0);
key = KarooKey.fromKeyCode(in.readInt());
action = KeyAction.fromActionNumber(in.readInt());
repeat = in.readInt();
replicate = in.readInt();
}

public KarooKeyEvent(KarooKeyEvent keyEvent, int replicate)
Expand Down Expand Up @@ -55,13 +55,6 @@ public void writeToParcel(Parcel out, int flags) {
out.writeInt(replicate);
}

public void readFromParcel(Parcel in) {
key = KarooKey.fromKeyCode(in.readInt());
action = KeyAction.fromActionNumber(in.readInt());
repeat = in.readInt();
replicate = in.readInt();
}

@Override
public int describeContents() {
return 0;
Expand Down Expand Up @@ -104,4 +97,15 @@ public int hashCode() {
result = 31 * result + replicate;
return result;
}

@NonNull
@Override
public String toString() {
return "KarooKeyEvent{" +
"key=" + key +
", action=" + action +
", repeat=" + repeat +
", replicate=" + replicate +
'}';
}
}
24 changes: 10 additions & 14 deletions app/src/main/java/com/valterc/ki2/data/message/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

public class Message implements Parcelable {

private String key;
private Bundle bundle;
private MessageType messageType;
private boolean persistent;
private String classType;
private final String key;
private final Bundle bundle;
private final MessageType messageType;
private final boolean persistent;
private final String classType;

public static Message createEvent(String key, MessageType messageType) {
return new Message(key, null, messageType, false);
Expand Down Expand Up @@ -55,7 +55,11 @@ protected Message(String key, Bundle bundle, MessageType messageType, boolean pe
}

private Message(Parcel in) {
readFromParcel(in);
key = in.readString();
bundle = in.readBundle(getClass().getClassLoader());
messageType = MessageType.fromValue(in.readInt());
persistent = in.readByte() == 1;
classType = in.readString();
}

public String getKey() {
Expand Down Expand Up @@ -91,14 +95,6 @@ public void writeToParcel(Parcel out, int flags) {
out.writeString(classType);
}

public void readFromParcel(Parcel in) {
key = in.readString();
bundle = in.readBundle(getClass().getClassLoader());
messageType = MessageType.fromValue(in.readInt());
persistent = in.readByte() == 1;
classType = in.readString();
}

@Override
public int describeContents() {
return 0;
Expand Down
30 changes: 13 additions & 17 deletions app/src/main/java/com/valterc/ki2/data/shifting/ShiftingInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

public final class ShiftingInfo implements Parcelable {

private boolean buzzerOn;
private int frontGear;
private int frontGearMax;
private int rearGear;
private int rearGearMax;
private ShiftingMode shiftingMode;
private final boolean buzzerOn;
private final int frontGear;
private final int frontGearMax;
private final int rearGear;
private final int rearGearMax;
private final ShiftingMode shiftingMode;

public static final Parcelable.Creator<ShiftingInfo> CREATOR = new Parcelable.Creator<ShiftingInfo>() {
public ShiftingInfo createFromParcel(Parcel in) {
Expand All @@ -25,7 +25,12 @@ public ShiftingInfo[] newArray(int size) {
};

private ShiftingInfo(Parcel in) {
readFromParcel(in);
buzzerOn = in.readByte() == 1;
frontGear = in.readInt();
frontGearMax = in.readInt();
rearGear = in.readInt();
rearGearMax = in.readInt();
shiftingMode = ShiftingMode.fromValue(in.readInt());
}

public ShiftingInfo(boolean buzzerOn, int frontGear, int frontGearMax, int rearGear, int rearGearMax, ShiftingMode shiftingMode)
Expand All @@ -40,23 +45,14 @@ public ShiftingInfo(boolean buzzerOn, int frontGear, int frontGearMax, int rearG

@Override
public void writeToParcel(Parcel out, int flags) {
out.writeByte(buzzerOn == true ? (byte) 1 : (byte) 0);
out.writeByte(buzzerOn ? (byte) 1 : (byte) 0);
out.writeInt(frontGear);
out.writeInt(frontGearMax);
out.writeInt(rearGear);
out.writeInt(rearGearMax);
out.writeInt(shiftingMode.getValue());
}

public void readFromParcel(Parcel in) {
buzzerOn = in.readByte() == 1;
frontGear = in.readInt();
frontGearMax = in.readInt();
rearGear = in.readInt();
rearGearMax = in.readInt();
shiftingMode = ShiftingMode.fromValue(in.readInt());
}

@Override
public int describeContents() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public enum SwitchCommand {
NO_SWITCH(240);

public static SwitchCommand fromCommandNumber(int commandNumber) {
for (SwitchCommand s : SwitchCommand.values()) {
if (s.commandNumber == commandNumber) {
return s;
for (SwitchCommand switchCommand : SwitchCommand.values()) {
if (switchCommand.commandNumber == commandNumber) {
return switchCommand;
}
}

Expand Down
16 changes: 6 additions & 10 deletions app/src/main/java/com/valterc/ki2/data/switches/SwitchEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

public class SwitchEvent implements Parcelable {

private SwitchType type;
private SwitchCommand command;
private int repeat;
private final SwitchType type;
private final SwitchCommand command;
private final int repeat;

public static final Parcelable.Creator<SwitchEvent> CREATOR = new Parcelable.Creator<SwitchEvent>() {
public SwitchEvent createFromParcel(Parcel in) {
Expand All @@ -20,7 +20,9 @@ public SwitchEvent[] newArray(int size) {
};

private SwitchEvent(Parcel in) {
readFromParcel(in);
type = SwitchType.fromValue(in.readInt());
command = SwitchCommand.fromCommandNumber(in.readInt());
repeat = in.readInt();
}

public SwitchEvent(SwitchType type, SwitchCommand command, int repeat) {
Expand All @@ -36,12 +38,6 @@ public void writeToParcel(Parcel out, int flags) {
out.writeInt(repeat);
}

public void readFromParcel(Parcel in) {
type = SwitchType.fromValue(in.readInt());
command = SwitchCommand.fromCommandNumber(in.readInt());
repeat = in.readInt();
}

@Override
public int describeContents() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static boolean switchToMapPage() {
try {
Object pageType = FIELD_PAGER_PAGE_TYPE.getValue().get(page);
if (pageType == ENUM_PAGE_TYPE_MAP.getValue()) {
viewPager.setCurrentItem(index);
viewPager.setCurrentItem(index, false);
return true;
}
} catch (Exception e) {
Expand Down

0 comments on commit 225b9be

Please sign in to comment.