From: Lukasz Stanislawski Date: Fri, 27 Nov 2020 10:52:26 +0000 (+0100) Subject: API enhancement + docs added X-Git-Tag: accepted/tizen/unified/20210915.100113~123 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7fd94929bd9e1498d59b65f165b35385aa6f3df1;p=profile%2Fiot%2Fapps%2Fdotnet%2Ffitness.git API enhancement + docs added --- diff --git a/Fitness/Controls/BaseTransition.cs b/Fitness/Controls/BaseTransition.cs index bcf65c7..bdebeb8 100644 --- a/Fitness/Controls/BaseTransition.cs +++ b/Fitness/Controls/BaseTransition.cs @@ -9,32 +9,31 @@ namespace Fitness.Controls public abstract class BaseTransition : ITransition { /// - /// + /// Event triggered when animation has started. /// public event EventHandler TransitionStarted; /// - /// + /// Event triggered when animation has finished. /// public event EventHandler TransitionFinished; /// - /// - /// - public event EventHandler TransitionCancelled; - - /// /// Transition duration (in milliseconds) /// public int Duration { get; set; } /// - /// + /// Start transition on target view. /// public virtual void Transit(View target) { } + public virtual void Dispose() + { + } + /// /// Raises TransitionStarted event /// @@ -50,18 +49,5 @@ namespace Fitness.Controls { TransitionFinished?.Invoke(this, null); } - - /// - /// Raises TransitionCancelled event - /// - protected void RaiseTransitionCancelled() - { - TransitionCancelled?.Invoke(this, null); - } - - public virtual void Dispose() - { - } } } - diff --git a/Fitness/Controls/BindableRecyclerView.cs b/Fitness/Controls/BindableRecyclerView.cs index 48b51c1..54a8e9f 100644 --- a/Fitness/Controls/BindableRecyclerView.cs +++ b/Fitness/Controls/BindableRecyclerView.cs @@ -43,26 +43,18 @@ namespace Fitness.Controls public static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue) { - Logger.Debug(""); var recycler = bindable as BindableRecyclerView; if (recycler != null && recycler.Adapter != null) { - Logger.Debug(""); var enumerable = newValue as IEnumerable; var enumerator = enumerable?.GetEnumerator(); var list = new List(); while ((enumerator != null) && enumerator.MoveNext()) { - Logger.Debug($"Item: {enumerator.Current.GetHashCode()}"); - if (enumerator.Current is WorkoutViewModel) - { - Logger.Debug($"enumerator.Current is WorkoutViewModel)"); - } list.Add(enumerator.Current); } - Logger.Debug($"list.Count: {list.Count}"); recycler.Adapter.Data = list; // Set selected item by default on first item diff --git a/Fitness/Controls/Connected.cs b/Fitness/Controls/Connected.cs index 655b925..c350806 100644 --- a/Fitness/Controls/Connected.cs +++ b/Fitness/Controls/Connected.cs @@ -1,7 +1,5 @@ -using Tizen.NUI.Binding; using Tizen.NUI.BaseComponents; - -using Fitness.Services; +using Tizen.NUI.Binding; namespace Fitness.Controls { @@ -11,7 +9,7 @@ namespace Fitness.Controls /// Connected animation id, bindable property. /// public static readonly BindableProperty IdProperty = - BindableProperty.CreateAttached("Id", typeof(string), typeof(View), null); + BindableProperty.CreateAttached("Id", typeof(string), typeof(View), null); /// /// Set connected animation id. diff --git a/Fitness/Controls/ConnectedAnimation.cs b/Fitness/Controls/ConnectedAnimation.cs index 8abf687..594b92f 100644 --- a/Fitness/Controls/ConnectedAnimation.cs +++ b/Fitness/Controls/ConnectedAnimation.cs @@ -2,69 +2,69 @@ using System; using Tizen.NUI; using Tizen.NUI.BaseComponents; -using Fitness.Services; - namespace Fitness.Controls { public class ConnectedAnimation : Animation { - private View Source { get; set; } - public ConnectedAnimation(View source) : base() { Source = source; } - public void AnimateFromSourceTo(View view, string propertyName, object to, Interpolation interpolation = Interpolation.Linear, AlphaFunction alphaFunction = null) - { - PropertyValue sourceValue, toValue; + private View Source { get; set; } - int idx = Source.GetPropertyIndex(propertyName); + public void AnimateFromSourceTo(View view, string propertyName, object to, Interpolation interpolation = Interpolation.Linear, AlphaFunction alphaFunction = null) + { + PropertyValue sourceValue, toValue; - switch (propertyName) - { - case "Position": - sourceValue = PropertyValue.CreateFromObject(GetWorldPosition(Source) - GetWorldPosition(view)); - break; - case "PositionX": - sourceValue = PropertyValue.CreateFromObject((GetWorldPosition(Source) - GetWorldPosition(view)).X); - break; - case "PositionY": - sourceValue = PropertyValue.CreateFromObject((GetWorldPosition(Source) - GetWorldPosition(view)).Y); - break; - case "PositionZ": - sourceValue = PropertyValue.CreateFromObject((GetWorldPosition(Source) - GetWorldPosition(view)).Z); - break; - default: - sourceValue = Source.GetProperty(idx); - break; - } - toValue = PropertyValue.CreateFromObject(to); + int idx = Source.GetPropertyIndex(propertyName); - AnimatePropertyBetween(view, propertyName, sourceValue, toValue, interpolation, alphaFunction); - } + switch (propertyName) + { + case "Position": + sourceValue = PropertyValue.CreateFromObject(GetWorldPosition(Source) - GetWorldPosition(view)); + break; + case "PositionX": + sourceValue = PropertyValue.CreateFromObject((GetWorldPosition(Source) - GetWorldPosition(view)).X); + break; + case "PositionY": + sourceValue = PropertyValue.CreateFromObject((GetWorldPosition(Source) - GetWorldPosition(view)).Y); + break; + case "PositionZ": + sourceValue = PropertyValue.CreateFromObject((GetWorldPosition(Source) - GetWorldPosition(view)).Z); + break; + default: + sourceValue = Source.GetProperty(idx); + break; + } - private static Position GetWorldPosition(View view) - { - Position position = new Position(); + toValue = PropertyValue.CreateFromObject(to); - while (view != null) - { - position += view.Position; - view = view.GetParent() as View; - } - return position; - } + AnimatePropertyBetween(view, propertyName, sourceValue, toValue, interpolation, alphaFunction); + } - private void AnimatePropertyBetween(View view, string propertyName, PropertyValue from, PropertyValue to, Interpolation interpolation, AlphaFunction alphaFunction) - { - var frames = new KeyFrames(); + private static Position GetWorldPosition(View view) + { + Position position = new Position(); - frames.Add(0.0f, from); - frames.Add(1.0f, to); + while (view != null) + { + position += view.Position; + view = view.GetParent() as View; + } - AnimateBetween(view, propertyName, frames, interpolation, alphaFunction); - } + return position; + } + + private void AnimatePropertyBetween(View view, string propertyName, PropertyValue from, PropertyValue to, Interpolation interpolation, AlphaFunction alphaFunction) + { + var frames = new KeyFrames(); + + frames.Add(0.0f, from); + frames.Add(1.0f, to); + + AnimateBetween(view, propertyName, frames, interpolation, alphaFunction); + } } } diff --git a/Fitness/Controls/ConnectedAnimationsContext.cs b/Fitness/Controls/ConnectedAnimationsContext.cs index 6d00480..fb4038d 100644 --- a/Fitness/Controls/ConnectedAnimationsContext.cs +++ b/Fitness/Controls/ConnectedAnimationsContext.cs @@ -6,19 +6,34 @@ using Tizen.NUI.BaseComponents; namespace Fitness.Controls { /// - /// + /// ConnectedAnimationsContext is a class that allows + /// creating animations between two unrelated parts of the + /// Application's UI. + /// + /// The class allows to create smooth animations across multiple Pages, + /// keeping Page implementations loosly-coupled to other Pages. + /// + /// ConnectedAnimationsContext performs two operations: + /// * Registering - at first View must register themself + /// as a source of ConnectedAnimation using predefined "AnimationId" string. + /// * ConnectedAnimation creating - after registering the View, + /// other part of the App can create ConnectedAnimation using + /// the same predefined "AnimationId" /// public sealed class ConnectedAnimationsContext { - private Dictionary ViewMap; - + /// + /// Creates new ConnectedAnimationsContext + /// public ConnectedAnimationsContext() { ViewMap = new Dictionary(); } + private Dictionary ViewMap { get; set; } + /// - /// + /// Registers object as a source of ConnectedAnimation /// public void RegisterConnectedView(string animationId, View view) { @@ -26,19 +41,24 @@ namespace Fitness.Controls { throw new InvalidOperationException($"ConnectedAnimationContext already contains View for animation id: {animationId}"); } + ViewMap[animationId] = view; } /// - /// + /// Creates new ConnectedAnimation that is associated to View previously + /// registerd with RegisterConnectedView. + /// + /// If no View has been registered on specific key the function returns + /// null. /// public ConnectedAnimation GetConnectedAnimation(string animationId) { if (!ViewMap.ContainsKey(animationId)) { - throw new InvalidOperationException($"ConnectedAnimationContext does not contain View for animation id: {animationId}"); + return null; } - + return new ConnectedAnimation(ViewMap[animationId]); } } diff --git a/Fitness/Controls/ConnectedTransition.cs b/Fitness/Controls/ConnectedTransition.cs index 77ddbc6..17a4554 100644 --- a/Fitness/Controls/ConnectedTransition.cs +++ b/Fitness/Controls/ConnectedTransition.cs @@ -2,40 +2,55 @@ using System; using Tizen.NUI; using Tizen.NUI.BaseComponents; -using Fitness.Services; - namespace Fitness.Controls { + /// + /// ConnectedTransition is a utility class that allows easy + /// creation and management of ConnectedAnimations. + /// public class ConnectedTransition : BaseTransition { private ConnectedAnimation animation; + /// + /// AnimationId that will be used to create Transition + /// public string AnimationId { get; set; } - public View Target { get; set; } - - public ConnectedTransition() - { - } + /// + /// Overrides default Transit target + /// + public View TargetOverride { get; set; } public override void Transit(View target) { animation?.Stop(); animation?.Dispose(); - // in case when Target is explicite set use Target property - // instead of function argument + // FIXME + // Transit should generally use target argument only, + // however as Transitions can currently only be attached + // to Page object, but not any View, I need to add the "TargetOverride" + // property so the Transtion can be applied on specific object that we want + // to animate. + target = TargetOverride != null ? TargetOverride : target; - var container = FindContainerForView(Target); + var container = FindContainerForView(target); if (container == null) { throw new InvalidOperationException("Cannot run ConnectedTransition on Target which is not a descendant of IConnectedAnimationsContainer"); } - animation = container.GetContext().GetConnectedAnimation(AnimationId); - animation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOut); + animation = container.GetContext()?.GetConnectedAnimation(AnimationId); + + if (animation == null) + { + Services.Logger.Warn($"Unable to find AnimationId: {AnimationId}, ConnectedTransition aborted"); + return; + } + animation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOut); animation.Duration = Duration; if (animation == null) @@ -43,9 +58,9 @@ namespace Fitness.Controls return; } - animation.AnimateFromSourceTo(Target, "Position", Target.Position); - animation.AnimateFromSourceTo(Target, "Size", Target.Size); - animation.AnimateFromSourceTo(Target, "Opacity", Target.Opacity); + animation.AnimateFromSourceTo(target, "Position", target.Position); + animation.AnimateFromSourceTo(target, "Size", target.Size); + animation.AnimateFromSourceTo(target, "Opacity", target.Opacity); animation.Finished += AnimationFinished; animation.Play(); @@ -63,6 +78,7 @@ namespace Fitness.Controls { view = view.GetParent() as View; } + return view as IConnectedAnimationsContainer; } diff --git a/Fitness/Controls/FadeInTransition.cs b/Fitness/Controls/FadeTransition.cs similarity index 50% rename from Fitness/Controls/FadeInTransition.cs rename to Fitness/Controls/FadeTransition.cs index e0e7057..f2d2844 100644 --- a/Fitness/Controls/FadeInTransition.cs +++ b/Fitness/Controls/FadeTransition.cs @@ -4,10 +4,30 @@ using Tizen.NUI.BaseComponents; namespace Fitness.Controls { - public class FadeInTransition : BaseTransition + /// + /// FaceTransition - animates opacity from StartOpacity to EndOpacity. + /// + public class FadeTransition : BaseTransition { private Animation animation; + public FadeTransition() + : base() + { + StartOpacity = 0.0f; + EndOpacity = 1.0f; + } + + /// + /// Initial Opacity that will be set on object when Transit begins + /// + public float StartOpacity { get; set; } + + /// + /// Initial Opacity that will be set on object when Transit ends + /// + public float EndOpacity { get; set; } + public override void Transit(View target) { animation?.Dispose(); @@ -15,11 +35,10 @@ namespace Fitness.Controls animation = new Animation(Duration); animation.DefaultAlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseOut); - target.Opacity = 0.0f; - animation.AnimateBy(target, "Opacity", 1.0f); + target.Opacity = StartOpacity; + animation.AnimateBy(target, "Opacity", EndOpacity); animation.Finished += AnimationFinished; animation.Play(); - Services.Logger.Debug($"TranstionStarted"); RaiseTransitionStarted(); } @@ -30,7 +49,6 @@ namespace Fitness.Controls private void AnimationFinished(object o, EventArgs args) { - Services.Logger.Debug($"AnimationFinished"); RaiseTransitionFinished(); } } diff --git a/Fitness/Controls/ITransition.cs b/Fitness/Controls/ITransition.cs index b91ac5b..1e95cdb 100644 --- a/Fitness/Controls/ITransition.cs +++ b/Fitness/Controls/ITransition.cs @@ -5,12 +5,13 @@ namespace Fitness.Controls { public interface ITransition : IDisposable { - void Transit(View target); - event EventHandler TransitionStarted; event EventHandler TransitionFinished; - event EventHandler TransitionCancelled; + /// + /// Run transtion (animation) on target View + /// + void Transit(View target); } } diff --git a/Fitness/Controls/Page.cs b/Fitness/Controls/Page.cs index fc37cb9..154932d 100644 --- a/Fitness/Controls/Page.cs +++ b/Fitness/Controls/Page.cs @@ -4,8 +4,6 @@ using Tizen.NUI; using Tizen.NUI.BaseComponents; using Tizen.NUI.Components; -using Fitness.Services; - namespace Fitness.Controls { /// @@ -13,7 +11,7 @@ namespace Fitness.Controls /// public class Page : Control, IConnectedAnimationsContainer { - private View _content = null; + private View content = null; public Page() : base() @@ -22,37 +20,49 @@ namespace Fitness.Controls HeightResizePolicy = ResizePolicyType.FillToParent; } + public PageTransitionCollection PageTransitions { get; set; } + public View Content { get { - return _content; + return content; } + set { - if (_content != value) + if (content != value) { - if (_content) + if (content) { - Remove(_content); + Remove(content); } - _content = value; - if (_content != null) + + content = value; + if (content != null) { - _content.WidthResizePolicy = ResizePolicyType.FillToParent; - _content.HeightResizePolicy = ResizePolicyType.FillToParent; - Add(_content); + content.WidthResizePolicy = ResizePolicyType.FillToParent; + content.HeightResizePolicy = ResizePolicyType.FillToParent; + Add(content); } } } } + internal Page ConnectedPage { get; set; } + public ConnectedAnimationsContext GetContext() { return ConnectedPage?.BuildConnectedAnimationContext(); } - internal Page ConnectedPage; + public virtual void OnTransitionStarted() + { + } + + public virtual void OnTransitionEnded() + { + } internal ConnectedAnimationsContext BuildConnectedAnimationContext() { @@ -72,16 +82,16 @@ namespace Fitness.Controls children.AddRange(child.Children); children.Remove(child); } + return context; } - public PageTransitionCollection PageTransitions { get; set; } - internal void RunTransitions() { if (PageTransitions != null) { PageTransitions.TransitionFinished += TransitionsFinished; + PageTransitions.TransitionStarted += TransitionsStarted; PageTransitions.Transit(this); } } @@ -92,12 +102,10 @@ namespace Fitness.Controls OnTransitionEnded(); } - public virtual void OnTransitionStarted() - { - } - - public virtual void OnTransitionEnded() + private void TransitionsStarted(object o, EventArgs args) { + PageTransitions.TransitionStarted -= TransitionsStarted; + OnTransitionStarted(); } } } diff --git a/Fitness/Controls/PageTransitionCollection.cs b/Fitness/Controls/PageTransitionCollection.cs index d75cdf5..9931736 100644 --- a/Fitness/Controls/PageTransitionCollection.cs +++ b/Fitness/Controls/PageTransitionCollection.cs @@ -8,32 +8,54 @@ namespace Fitness.Controls { private int runningTransitionsCounter; + /// + /// Triggered when first TransitionStarted event is raised. + /// public event EventHandler TransitionStarted; + /// + /// Triggered when last TransitionFinished event is raised. + /// public event EventHandler TransitionFinished; - public event EventHandler TransitionCancelled; - + /// + /// Start all Transitions in the collection. + /// public void Transit(View target) { runningTransitionsCounter = Count; foreach (var transition in this) { - transition.TransitionCancelled += CheckFinishCondition; transition.TransitionFinished += CheckFinishCondition; + transition.TransitionStarted += CheckStartedCondition; transition.Transit(target); } + } + + public void Dispose() + { + foreach (var transition in this) + { + transition.Dispose(); + } + } + + private void CheckStartedCondition(object o, EventArgs args) + { + foreach (var transition in this) + { + transition.TransitionStarted -= CheckStartedCondition; + } TransitionStarted?.Invoke(this, null); } - public void CheckFinishCondition(object o, EventArgs args) + private void CheckFinishCondition(object o, EventArgs args) { if (o is ITransition t) { t.TransitionFinished -= CheckFinishCondition; - t.TransitionCancelled -= CheckFinishCondition; runningTransitionsCounter--; @@ -43,13 +65,5 @@ namespace Fitness.Controls } } } - - public void Dispose() - { - foreach (var transition in this) - { - transition.Dispose(); - } - } } } diff --git a/Fitness/Views/ExercisePreviewView.cs b/Fitness/Views/ExercisePreviewView.cs index f422bea..81acc74 100644 --- a/Fitness/Views/ExercisePreviewView.cs +++ b/Fitness/Views/ExercisePreviewView.cs @@ -9,8 +9,6 @@ namespace Fitness.Views { public partial class ExercisePreviewView : Fitness.Controls.Page { - static private bool done = false; - public ExercisePreviewView() { InitializeComponent(); @@ -19,7 +17,6 @@ namespace Fitness.Views public override void OnTransitionEnded() { - Services.Logger.Debug("OnTransitionEnded"); CreateVideoUrlBinding(); this.player.Show(); @@ -34,23 +31,19 @@ namespace Fitness.Views this.nextButton.Clicked += ReplyVideo; this.previousButton.Clicked += ReplyVideo; this.player.Hide(); - this.temp.Relayout += (obj, args) => - { - if (done) - return; - - done = true; + this.temp.Relayout += RunPageTransitions; + } - // this should'nt be here however currently not better place to - // put it. - this.RunTransitions(); - }; + private void RunPageTransitions(object o, EventArgs args) + { + this.temp.Relayout -= RunPageTransitions; + RunTransitions(); } private void CreateVideoUrlBinding() { - Logger.Debug("Create BindingContext for VideoView"); var binding = new Binding("CurrentWorkout"); + binding.Source = this.context; this.player.SetBinding(BindableObject.BindingContextProperty, binding); diff --git a/Fitness/Views/FitnessItemViewRecycleAdapter.cs b/Fitness/Views/FitnessItemViewRecycleAdapter.cs index 9bf8488..aad7def 100644 --- a/Fitness/Views/FitnessItemViewRecycleAdapter.cs +++ b/Fitness/Views/FitnessItemViewRecycleAdapter.cs @@ -12,7 +12,6 @@ namespace Fitness.Views public override RecycleItem CreateRecycleItem() { - Fitness.Services.Logger.Debug("CreateRecycleItem"); var it = new FitnessItemView(); it.BackgroundColor = Color.Red; return it; @@ -20,11 +19,9 @@ namespace Fitness.Views public override void BindData(RecycleItem item) { - Fitness.Services.Logger.Debug("BindData"); item.BindingContext = Data[item.DataIndex]; if (item is FitnessItemView fitnessItem) { - Fitness.Services.Logger.Debug("item is FitnessItemView fitnessItem"); fitnessItem.image.BindingContext = item.BindingContext; fitnessItem.label.BindingContext = item.BindingContext; fitnessItem.favourite.BindingContext = item.BindingContext; diff --git a/Fitness/Views/MainView.xaml.cs b/Fitness/Views/MainView.xaml.cs index a2581e2..b10ed98 100644 --- a/Fitness/Views/MainView.xaml.cs +++ b/Fitness/Views/MainView.xaml.cs @@ -3,8 +3,6 @@ using Tizen.NUI; using Tizen.NUI.BaseComponents; using Tizen.NUI.Components; -using Fitness.Services; - namespace Fitness.Views { public partial class MainView : Fitness.Controls.Page @@ -16,8 +14,6 @@ namespace Fitness.Views this.button1.ApplyStyle(Styles.Buttons.Inverse); this.button2.ApplyStyle(Styles.Buttons.Regular); this.scroller.ScrollingDirection = ScrollableBase.Direction.Horizontal; - - Logger.Debug("MainView constructor end"); } } } diff --git a/Fitness/res/layout/ExercisePreviewView.xaml b/Fitness/res/layout/ExercisePreviewView.xaml index e262267..4788244 100644 --- a/Fitness/res/layout/ExercisePreviewView.xaml +++ b/Fitness/res/layout/ExercisePreviewView.xaml @@ -14,8 +14,8 @@ - - + +