Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add AssertionErrors as per iOS alignment
Make constructor check for valid initialStateName in state list
Adjust tests to reflect new behavior
  • Loading branch information
noah-livio committed Jan 7, 2022
commit 9d475122ab407dbd32775030d6dd20fa202c0d21
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public void testAssignNonEmptyStateListToSoftButtonObject() {
SoftButtonState softButtonState2 = new SoftButtonState("general_kenobi", "General Kenobi", null);
stateList2.add(softButtonState2);

SoftButtonObject softButtonObject = new SoftButtonObject("general_kenobi", stateList1, "general_kenobi", null);
SoftButtonObject softButtonObject = new SoftButtonObject("general_kenobi", stateList1, "hello_there", null);

softButtonObject.setStates(stateList2);

Expand All @@ -477,7 +477,7 @@ public void testAssignSameNameStateListToSoftButtonObject() {
SoftButtonState softButtonState3 = new SoftButtonState("general_kenobi", "General Kenobi Again", null);
stateListDuplicateNames.add(softButtonState3);

SoftButtonObject softButtonObject = new SoftButtonObject("general_kenobi", stateListUnique, "general_kenobi", null);
SoftButtonObject softButtonObject = new SoftButtonObject("general_kenobi", stateListUnique, "hello_there", null);

softButtonObject.setStates(stateListDuplicateNames);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
package com.smartdevicelink.managers.screen;

import androidx.annotation.NonNull;

import com.livio.BuildConfig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unused import

import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
import com.smartdevicelink.proxy.rpc.OnButtonEvent;
import com.smartdevicelink.proxy.rpc.OnButtonPress;
Expand Down Expand Up @@ -71,7 +73,7 @@ public class SoftButtonObject implements Cloneable{
*/
public SoftButtonObject(@NonNull String name, @NonNull List<SoftButtonState> states, @NonNull String initialStateName, OnEventListener onEventListener) {

// If the list of states is empty, throw an error with DebugTool and return
/*// If the list of states is empty, throw an error with DebugTool and return
if (states.isEmpty()) {
DebugTool.logError(TAG,"The state list is empty");
return;
Expand All @@ -80,8 +82,30 @@ public SoftButtonObject(@NonNull String name, @NonNull List<SoftButtonState> sta
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.");
if (BuildConfig.DEBUG && repeatedStateNames)
throw new AssertionError("A SoftButtonObject must have states with different names.");
return;
}
if (!hasStateWithInitialName) {
DebugTool.logError(TAG, "A SoftButtonObject must have a state with initialStateName.");
if (BuildConfig.DEBUG && !hasStateWithInitialName)
throw new AssertionError("A SoftButtonObject must have a state with initialStateName.");
return;
}
this.name = name;
this.states = states;
this.currentStateName = initialStateName;
Expand Down Expand Up @@ -267,7 +291,7 @@ 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) {
// If the list of states is empty, throw an error with DebugTool and return
/*// If the list of states is empty, throw an error with DebugTool and return
if (states.isEmpty()) {
DebugTool.logError(TAG,"The state list is empty");
return;
Expand All @@ -276,6 +300,21 @@ public void setStates(@NonNull List<SoftButtonState> states) {
if (hasTwoStatesOfSameName(states)) {
DebugTool.logError(TAG, "Two states have the same name in states list for soft button object");
return;
}*/

boolean repeatedStateNames = hasTwoStatesOfSameName(states);

if (repeatedStateNames) {
DebugTool.logError(TAG, "A SoftButtonObject must have states with different names.");
if (BuildConfig.DEBUG && repeatedStateNames)
throw new AssertionError("A SoftButtonObject must have states with different names.");
return;
}
if (states.isEmpty()) {
DebugTool.logError(TAG, "A SoftButtonState list must contain at least one state");
if (BuildConfig.DEBUG && states.isEmpty())
throw new AssertionError("A SoftButtonState list must contain at least one state");
return;
}

this.states = states;
Expand Down