Skip to content

Commit

Permalink
Reorder types in UI, and fix number logic in custom property
Browse files Browse the repository at this point in the history
Also hide the value label for the clear custom property type.
  • Loading branch information
guperrot committed Oct 9, 2018
1 parent b450de7 commit cfeae1a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class CustomPropertyFragment extends EditDateTimeFragment {

private CheckBox mEditBool;

private View mValueLabel;

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand All @@ -36,6 +38,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
mEditString = view.findViewById(R.id.string);
mEditNumber = view.findViewById(R.id.number);
mEditBool = view.findViewById(R.id.bool);
mValueLabel = view.findViewById(R.id.value_label);

/* Set change type callback. */
mEditType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
Expand All @@ -58,6 +61,7 @@ private void updateValueType() {
mEditNumber.setVisibility(type == CustomPropertyType.NUMBER ? View.VISIBLE : View.GONE);
mEditBool.setVisibility(type == CustomPropertyType.BOOLEAN ? View.VISIBLE : View.GONE);
mDateTime.setVisibility(type == CustomPropertyType.DATETIME ? View.VISIBLE : View.GONE);
mValueLabel.setVisibility(type != CustomPropertyType.CLEAR ? View.VISIBLE : View.GONE);
}

public CustomPropertyType getType() {
Expand All @@ -77,10 +81,14 @@ public void set(CustomProperties customProperties) {
case NUMBER:
String stringValue = mEditNumber.getText().toString();
Number value;
try {
value = Integer.parseInt(stringValue);
} catch (NumberFormatException ignored) {
value = Double.parseDouble(stringValue);
if (!stringValue.isEmpty()) {
try {
value = Integer.parseInt(stringValue);
} catch (NumberFormatException ignored) {
value = Double.parseDouble(stringValue);
}
} else {
value = Double.NaN;
}
customProperties.set(key, value);
break;
Expand All @@ -94,10 +102,10 @@ public void set(CustomProperties customProperties) {
}

public enum CustomPropertyType {
CLEAR,
STRING,
BOOLEAN,
NUMBER,
DATETIME,
STRING
CLEAR
}
}
1 change: 1 addition & 0 deletions apps/sasquatch/src/main/res/layout/custom_property.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
android:entries="@array/custom_property_types" />

<TextView
android:id="@+id/value_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/value" />
Expand Down
6 changes: 3 additions & 3 deletions apps/sasquatch/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
<string name="value" tools:ignore="MissingTranslation">Value</string>
<string name="type" tools:ignore="MissingTranslation">Type</string>
<string-array name="typed_property_types" tools:ignore="MissingTranslation">
<item>String</item>
<item>Boolean</item>
<item>Double</item>
<item>Long</item>
<item>Date/Time</item>
<item>String</item>
</string-array>
<string-array name="custom_property_types" tools:ignore="MissingTranslation">
<item>Clear</item>
<item>String</item>
<item>Boolean</item>
<item>Number</item>
<item>Date/Time</item>
<item>String</item>
<item>Clear</item>
</string-array>
<string name="version_x_available" tools:ignore="MissingTranslation">Version %1$s available!</string>
<string name="push_toast" tools:ignore="MissingTranslation">Push clicked with data=%1s</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ private void resetValue() {
}

public enum EventPropertyType {
STRING,
BOOLEAN,
NUMBER_DOUBLE,
NUMBER_LONG,
DATETIME,
STRING
DATETIME
}
}

0 comments on commit cfeae1a

Please sign in to comment.