using System; using System.Collections.Generic; using Unity.UIWidgets.foundation; using Unity.UIWidgets.ui; namespace Unity.UIWidgets.animation { public abstract class AnimationLazyListenerMixinAnimation : Animation { int _listenerCounter = 0; protected void didRegisterListener() { D.assert(this._listenerCounter >= 0); if (this._listenerCounter == 0) { this.didStartListening(); } this._listenerCounter += 1; } protected void didUnregisterListener() { D.assert(this._listenerCounter >= 1); this._listenerCounter -= 1; if (this._listenerCounter == 0) { this.didStopListening(); } } protected abstract void didStartListening(); protected abstract void didStopListening(); public bool isListening { get { return this._listenerCounter > 0; } } } public abstract class AnimationEagerListenerMixinAnimation : Animation { protected void didRegisterListener() { } protected void didUnregisterListener() { } public virtual void dispose() { } } public abstract class AnimationLocalListenersMixinAnimationLazyListenerMixinAnimation : AnimationLazyListenerMixinAnimation { readonly ObserverList _listeners = new ObserverList(); public override void addListener(VoidCallback listener) { this.didRegisterListener(); this._listeners.Add(listener); } public override void removeListener(VoidCallback listener) { this._listeners.Remove(listener); this.didUnregisterListener(); } public void notifyListeners() { var localListeners = new List(this._listeners); foreach (VoidCallback listener in localListeners) { try { if (this._listeners.Contains(listener)) { listener(); } } catch (Exception exception) { UIWidgetsError.reportError(new UIWidgetsErrorDetails( exception: exception, library: "animation library", context: "while notifying listeners for " + this.GetType(), informationCollector: information => { information.AppendLine("The " + this.GetType() + " notifying listeners was:"); information.Append(" " + this); } )); } } } } public abstract class AnimationLocalListenersMixinAnimationEagerListenerMixinAnimation : AnimationEagerListenerMixinAnimation { readonly ObserverList _listeners = new ObserverList(); public override void addListener(VoidCallback listener) { this.didRegisterListener(); this._listeners.Add(listener); } public override void removeListener(VoidCallback listener) { this._listeners.Remove(listener); this.didUnregisterListener(); } public void notifyListeners() { var localListeners = new List(this._listeners); foreach (VoidCallback listener in localListeners) { try { if (this._listeners.Contains(listener)) { listener(); } } catch (Exception exception) { UIWidgetsError.reportError(new UIWidgetsErrorDetails( exception: exception, library: "animation library", context: "while notifying listeners for " + this.GetType(), informationCollector: information => { information.AppendLine("The " + this.GetType() + " notifying listeners was:"); information.Append(" " + this); } )); } } } } public abstract class AnimationLocalStatusListenersMixinAnimationLocalListenersMixinAnimationLazyListenerMixinAnimation : AnimationLocalListenersMixinAnimationLazyListenerMixinAnimation { readonly ObserverList _statusListeners = new ObserverList(); public override void addStatusListener(AnimationStatusListener listener) { this.didRegisterListener(); this._statusListeners.Add(listener); } public override void removeStatusListener(AnimationStatusListener listener) { this._statusListeners.Remove(listener); this.didUnregisterListener(); } public void notifyStatusListeners(AnimationStatus status) { var localListeners = new List(this._statusListeners); foreach (AnimationStatusListener listener in localListeners) { try { if (this._statusListeners.Contains(listener)) { listener(status); } } catch (Exception exception) { UIWidgetsError.reportError(new UIWidgetsErrorDetails( exception: exception, library: "animation library", context: "while notifying status listeners for " + this.GetType(), informationCollector: information => { information.AppendLine("The " + this.GetType() + " notifying status listeners was:"); information.Append(" " + this); } )); } } } } public abstract class AnimationLocalStatusListenersMixinAnimationLazyListenerMixinAnimation : AnimationLazyListenerMixinAnimation { readonly ObserverList _statusListeners = new ObserverList(); public override void addStatusListener(AnimationStatusListener listener) { this.didRegisterListener(); this._statusListeners.Add(listener); } public override void removeStatusListener(AnimationStatusListener listener) { this._statusListeners.Remove(listener); this.didUnregisterListener(); } public void notifyStatusListeners(AnimationStatus status) { var localListeners = new List(this._statusListeners); foreach (AnimationStatusListener listener in localListeners) { try { if (this._statusListeners.Contains(listener)) { listener(status); } } catch (Exception exception) { UIWidgetsError.reportError(new UIWidgetsErrorDetails( exception: exception, library: "animation library", context: "while notifying status listeners for " + this.GetType(), informationCollector: information => { information.AppendLine("The " + this.GetType() + " notifying status listeners was:"); information.Append(" " + this); } )); } } } } public abstract class AnimationLocalStatusListenersMixinAnimationLocalListenersMixinAnimationEagerListenerMixinAnimation : AnimationLocalListenersMixinAnimationEagerListenerMixinAnimation { readonly ObserverList _statusListeners = new ObserverList(); public override void addStatusListener(AnimationStatusListener listener) { this.didRegisterListener(); this._statusListeners.Add(listener); } public override void removeStatusListener(AnimationStatusListener listener) { this._statusListeners.Remove(listener); this.didUnregisterListener(); } public void notifyStatusListeners(AnimationStatus status) { var localListeners = new List(this._statusListeners); foreach (AnimationStatusListener listener in localListeners) { try { if (this._statusListeners.Contains(listener)) { listener(status); } } catch (Exception exception) { UIWidgetsError.reportError(new UIWidgetsErrorDetails( exception: exception, library: "animation library", context: "while notifying status listeners for " + this.GetType(), informationCollector: information => { information.AppendLine("The " + this.GetType() + " notifying status listeners was:"); information.Append(" " + this); } )); } } } } }