@@ -30,31 +30,24 @@ typedef BaseWidgetMenuItemOptions as {
3030
3131class BaseWidgetMenuItem extends BaseSitemapMenuItem {
3232
33+ // Store whether the subclass indicated that an action icon should be shown
34+ // This information is passed into the constructor as option, but needed
35+ // also during updates
36+ private var _isActionable as Boolean ;
37+
3338 // The submenu representing the nested elements, if there are any
3439 private var _page as PageMenu ?;
35-
40+
41+ // The current sitemap widget associated with this menu item
42+ private var _sitemapWidget as SitemapWidget ;
43+
3644 // Reference to the parent menu is required so that submenus
3745 // can navigate back. Submenus may be created not only in the
3846 // constructor, but also dynamically in updateWidget(), so we
3947 // store the parent menu as a member variable and use a weak
4048 // reference to avoid memory leaks due to circular references.
4149 private var _weakParent as WeakReference ;
4250
43- // Store whether the subclass indicated that an action icon should be shown
44- // This information is passed into the constructor as option, but needed
45- // also during updates
46- private var _isActionable as Boolean ;
47-
48- // The last time an internal update was applied. Internal updates are applied
49- // by some menu items directly after a command is sent to immediately reflect
50- // the new state. Storing this timestamp is required to apply the post-command
51- // hold time configured in the app settings.
52- private var lastLocalStateUpdate as Moment ?;
53-
54- // The sitemap widget is stored, so in updateWidget() we can check if the
55- // state has changed, and if yes call onStateUpdated()
56- private var _sitemapWidget as SitemapWidget ;
57-
5851 // Constructor
5952 protected function initialize (
6053 options as BaseWidgetMenuItemOptions
@@ -81,50 +74,35 @@ class BaseWidgetMenuItem extends BaseSitemapMenuItem {
8174 );
8275 }
8376
77+
8478 // Returns the current sitemap widget
8579 protected function getSitemapWidget () as SitemapWidget {
8680 return _sitemapWidget ;
8781 }
8882
83+
8984 // Returns true if the widget is linked to a page (sub menu)
9085 public function hasPage () as Boolean {
9186 return _page != null ;
9287 }
9388
94- // Returns true if the item is still within the configured post-command hold time
95- // since the last internal state update.
96- public function isInHoldTime () as Boolean {
97- var postCommandHoldTime = AppSettings .getPostCommandHoldTime ();
98- if ( lastLocalStateUpdate != null && postCommandHoldTime .value () > 0 ) {
99- return Time .now ().lessThan ( lastLocalStateUpdate .add ( postCommandHoldTime ) );
100- } else {
101- return false ;
102- }
103- }
10489
10590 // Subclasses must override this method to determine whether the given
10691 // `SitemapWidget` instance is compatible with this menu item type.
10792 public static function isMyType ( sitemapWidget as SitemapWidget ) as Boolean {
10893 throw new AbstractMethodException ( " BaseSitemapMenuItem.getItemType" );
10994 }
11095
111- // Must be called by subclasses when they perform an internal state update.
112- // Some menu items use internal updates to immediately reflect the new state
113- // after a command is sent. This notification stores the time of the update,
114- // which is required to apply the configured post-command hold time.
115- protected function notifyStateUpdatedLocally () as Void {
116- lastLocalStateUpdate = Time .now ();
117- }
11896
11997 /*
120- * Subclasses need to override this method to process state updates.
121- * Note: updateWidget() can be overriden if other widget properties have an
122- * effect on the
98+ * Subclasses can to override this method to process state changes.
99+ * Note: this is triggered only when the state has changed. If updates
100+ * to other widget data elements should be processed independent of a
101+ * state change, then updateWidget() should be overriden to process those.
123102 */
124- public function onStateUpdated () as Void {
125- // throw new AbstractMethodException( "BaseWidgetMenuItem.onStateUpdated" );
126- }
127-
103+ public function onStateChanged () as Void {}
104+
105+
128106 // Handles selection of the menu item.
129107 //
130108 // If a submenu is present, it is opened on selection. This typically takes precedence
@@ -195,10 +173,10 @@ class BaseWidgetMenuItem extends BaseSitemapMenuItem {
195173 * parts of the update, but they must also call the base class’s
196174 * updateWidget() to ensure core functionality is preserved.
197175 *
198- * To process state updates subclasses SHOULD NOT use this function, but
199- * instead override onStateUpdated (). This method is only called
176+ * To process state changes subclasses SHOULD NOT use this function, but
177+ * instead override onStateChanged (). This method is only called
200178 * if the state has changed, subclasses may use that implementation also
201- * to process local updates .
179+ * to process local changes .
202180 */
203181 public function updateWidget ( sitemapWidget as SitemapWidget ) as Void {
204182 // Store the new widget instance
@@ -209,17 +187,19 @@ class BaseWidgetMenuItem extends BaseSitemapMenuItem {
209187 // during an update, we always use the async task queue
210188 processWidget ( sitemapWidget , BasePageMenu .PROCESSING_ASYNC );
211189
212- // Determine if the state as changed and if
213- // yes, call onStateUpdated ()
190+ // Determine if the display state or state as changed and if
191+ // yes, call onStateChanged ()
214192 var previousItem = previousSitemapWidget .getItem ();
215193 var newItem = sitemapWidget .getItem ();
216194 var hasStateChanged =
217- ( previousItem == null ) != ( newItem == null )
195+ ! previousSitemapWidget .getDisplayState ().equals ( sitemapWidget .getDisplayState () )
196+ || ( previousItem == null ) != ( newItem == null )
218197 || ( previousItem != null
219198 && newItem != null
220199 && ! previousItem .getState ().equals ( newItem .getState () ) );
200+
221201 if ( hasStateChanged ) {
222- onStateUpdated ();
202+ onStateChanged ();
223203 }
224204
225205 WatchUi .requestUpdate ();
0 commit comments