-
Notifications
You must be signed in to change notification settings - Fork 131
Fix soft button object invalid states #1776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
2445b37
72e24b5
c9da956
0aebb4e
b00cea5
8413d94
f95aec3
648bdc3
9a82059
053ac1b
9d47512
386027f
75d1e1e
d15498f
34c0622
528769f
e183f35
666f99a
14b7569
39efd8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -38,7 +38,6 @@ | |||||
| import com.smartdevicelink.proxy.rpc.OnButtonPress; | ||||||
| import com.smartdevicelink.proxy.rpc.SoftButton; | ||||||
| import com.smartdevicelink.util.DebugTool; | ||||||
|
|
||||||
| import java.util.Collections; | ||||||
| import java.util.List; | ||||||
|
|
||||||
|
|
@@ -73,12 +72,24 @@ public class SoftButtonObject implements Cloneable{ | |||||
| */ | ||||||
| public SoftButtonObject(@NonNull String name, @NonNull List<SoftButtonState> states, @NonNull String initialStateName, OnEventListener onEventListener) { | ||||||
|
|
||||||
| // Make sure there aren't two states with the same name | ||||||
| if (hasTwoStatesOfSameName(states)) { | ||||||
| DebugTool.logError(TAG, "Two states have the same name in states list for soft button object"); | ||||||
| return; | ||||||
| boolean repeatedStateNames = hasTwoStatesOfSameName(states); | ||||||
|
|
||||||
| boolean hasStateWithInitialName = false; | ||||||
| for (SoftButtonState state : states) { | ||||||
| if(state.getName().equals(initialStateName)) { | ||||||
| hasStateWithInitialName = true; | ||||||
| break; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if (repeatedStateNames) { | ||||||
| DebugTool.logError(TAG, "A SoftButtonObject must have states with different names."); | ||||||
| return; | ||||||
| } | ||||||
| if (!hasStateWithInitialName) { | ||||||
| DebugTool.logError(TAG, "A SoftButtonObject must have a state with initialStateName."); | ||||||
| return; | ||||||
| } | ||||||
| this.name = name; | ||||||
| this.states = states; | ||||||
RHenigan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| this.currentStateName = initialStateName; | ||||||
|
|
@@ -264,6 +275,26 @@ public List<SoftButtonState> getStates() { | |||||
| * @param states a list of the object's soft button states. <strong>states should be unique for every SoftButtonObject. A SoftButtonState instance cannot be reused for multiple SoftButtonObjects.</strong> | ||||||
| */ | ||||||
| public void setStates(@NonNull List<SoftButtonState> states) { | ||||||
|
|
||||||
| boolean repeatedStateNames = hasTwoStatesOfSameName(states); | ||||||
|
|
||||||
| if (repeatedStateNames) { | ||||||
| DebugTool.logError(TAG, "A SoftButtonObject must have states with different names."); | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| boolean hasStateWithCurrentName = false; | ||||||
| for (SoftButtonState state : states) { | ||||||
| if(state.getName().equals(currentStateName)) { | ||||||
| hasStateWithCurrentNameName = true; | ||||||
|
||||||
| hasStateWithCurrentNameName = true; | |
| hasStateWithCurrentName = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, and that'll be easy to fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also to avoid confusion for the developer we will still want to set the states in the case the currentState is not present in the list, but we will still want to log the error.
We should test and confirm that the SoftButtonManager can handle this error case (trying to upload a SoftButton where the currentState is not in the list)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just cleaning up white space.