The DataType class, from which all attribute data types are derived, defines two methods for returning a string representation of the attribute. As I understand it, the representation is the following
toString() returns a string representation which can be passed to a constructor of the class to recreate an identical copy of the instance. The string returned must contain all necessary information for this. For complex types, such as OmniArea, this string is an XML representation of all fields. Consequently, it may not always be suitable for user output.
getValue() returns a string representation suitable for user display, which is used to prepopulate rule descriptions and, for some data types, to populate the entry field UI. It may not always be suitable for parsing.
It takes an instance of a DataType descendant and appends it to a StringBuilder. Internally, StringBuilder calls the toString() method—which means that the string representation passed to the object is the one which is guaranteed to be parseable, but not necessarily user friendly.
As a result, notifications will display XML for complex data types. It has become more of an issue with a few extensions I’m currently developing, such as speech output and new data types, which are complex internally but can be simplified to a short string for display purposes. For example, instead of simply reading out battery percentage (one figure), I now get an entire XML document (one root element with two children) read out. Try it—it’s fun! Alas, it’s not very practical…
On the other hand, other actions might actually require a parseable representation of the data (think of a new action that stores the current location as a POI in a navigation app), so simply passing getValue() to actions may possibly break other use cases.
The
DataType
class, from which all attribute data types are derived, defines two methods for returning a string representation of the attribute. As I understand it, the representation is the followingtoString()
returns a string representation which can be passed to a constructor of the class to recreate an identical copy of the instance. The string returned must contain all necessary information for this. For complex types, such asOmniArea
, this string is an XML representation of all fields. Consequently, it may not always be suitable for user output.getValue()
returns a string representation suitable for user display, which is used to prepopulate rule descriptions and, for some data types, to populate the entry field UI. It may not always be suitable for parsing.When attributes are passed to actions, the
CoreActionsDbHelper#fillParamWithEventAttrib()
method takes care of that. Code: https://github.com/biotinker/LibreTasks/blob/master/LibreTasks/src/app/model/CoreActionsDbHelper.java#L236It takes an instance of a
DataType
descendant and appends it to aStringBuilder
. Internally,StringBuilder
calls thetoString()
method—which means that the string representation passed to the object is the one which is guaranteed to be parseable, but not necessarily user friendly.As a result, notifications will display XML for complex data types. It has become more of an issue with a few extensions I’m currently developing, such as speech output and new data types, which are complex internally but can be simplified to a short string for display purposes. For example, instead of simply reading out battery percentage (one figure), I now get an entire XML document (one root element with two children) read out. Try it—it’s fun! Alas, it’s not very practical…
On the other hand, other actions might actually require a parseable representation of the data (think of a new action that stores the current location as a POI in a navigation app), so simply passing
getValue()
to actions may possibly break other use cases.Any ideas on how that can be addressed?