/// <summary>
        /// Initiates the view with the current lession.
        /// </summary>
        private void InitLesson()
        {
            CheckHintButton();

            // ----------------------------------------------------------------------
            // Module specifics
            // ----------------------------------------------------------------------

            // Set playground background color
            fragmentContainer.SetBackgroundColor(Color.ParseColor(DataHolder.Current.CurrentModule.Color));

            // ----------------------------------------------------------------------
            // Lesson specifics
            // ----------------------------------------------------------------------

            // Set the name of the current Lesson as page title
            Title = DataHolder.Current.CurrentLesson.Title;

            // ----------------------------------------------------------------------
            // Load Lesson fragment
            // ----------------------------------------------------------------------

            // Create an instance of the fragment according to the current type of level
            var transaction = FragmentManager.BeginTransaction();
            currentFragment = CreateFragmentForLesson();
            if (currentFragment != null)
            {
                // Handle LessonFragment events
                currentFragment.ProgressListRefreshRequested += LessonFragment_ProgressListRefreshRequested;
                currentFragment.LessonFinished += LessonFragment_LessonFinished;
                currentFragment.IterationFinished += Fragment_IterationFinished;
                currentFragment.IterationChanged += Fragment_IterationChanged;
                currentFragment.UserInteracted += CurrentFragment_UserInteracted;

                // Add the fragment to the container
                transaction.Replace(Resource.Id.fragmentContainer, currentFragment, lessonFragmentTag);
                transaction.Commit();
            }
            else
            {
                // Fragment for this type of Lesson could not be loaded. Remove old fragment
                var oldFragment = FragmentManager.FindFragmentByTag(lessonFragmentTag);
                if (oldFragment != null)
                {
                    transaction.Remove(oldFragment);
                    transaction.Commit();
                }
            }

            // Play instruction
            SoundPlayer.Stop();
            bool waitForCompletion = false;
            if (DataHolder.Current.CurrentLesson.IsRecurringTask)
            {
                var recurringTaskSoundFile = Common.RecurringTaskSoundFiles.PickRandomItems(1).FirstOrDefault();
                if (recurringTaskSoundFile != null)
                {
                    SoundPlayer.PlaySound(this, recurringTaskSoundFile);
                    waitForCompletion = true;
                }
            }
            SoundPlayer.PlaySound(this, waitForCompletion, DataHolder.Current.CurrentLesson.SoundPath);
        }
Beispiel #2
0
        /// <summary>
        /// Initiates the view with the current lession.
        /// </summary>
        private void InitLesson()
        {
            SoundPlayer.Stop();

            CheckHintButton();

            // ----------------------------------------------------------------------
            // Module specifics
            // ----------------------------------------------------------------------

            // Set playground background color
            fragmentContainer.SetBackgroundColor(Color.ParseColor(DataHolder.Current.CurrentModule.Color));

            // ----------------------------------------------------------------------
            // Lesson specifics
            // ----------------------------------------------------------------------

            // Set the name of the current Lesson as page title
            Title = DataHolder.Current.CurrentLesson.Title;

            // ----------------------------------------------------------------------
            // Load Lesson fragment
            // ----------------------------------------------------------------------

            // Create an instance of the fragment according to the current type of level
            var transaction = FragmentManager.BeginTransaction();

            currentFragment = CreateFragmentForLesson();
            if (currentFragment != null)
            {
                // Handle LessonFragment events
                currentFragment.ProgressListRefreshRequested += LessonFragment_ProgressListRefreshRequested;
                currentFragment.LessonFinished         += LessonFragment_LessonFinished;
                currentFragment.IterationFinished      += Fragment_IterationFinished;
                currentFragment.IterationChanged       += Fragment_IterationChanged;
                currentFragment.UserInteracted         += CurrentFragment_UserInteracted;
                currentFragment.CheckSolutionRequested += BtnNext_Click_CheckSolution;

                // Add the fragment to the container
                transaction.Replace(Resource.Id.fragmentContainer, currentFragment, lessonFragmentTag);
                transaction.Commit();
            }
            else
            {
                // Fragment for this type of Lesson could not be loaded. Remove old fragment
                var oldFragment = FragmentManager.FindFragmentByTag(lessonFragmentTag);
                if (oldFragment != null)
                {
                    transaction.Remove(oldFragment);
                    transaction.Commit();
                }
            }

            // Play instruction
            if (DataHolder.Current.CurrentLesson.IsRecurringTask)
            {
                var recurringTaskSoundFile = Common.RecurringTaskSoundFiles.PickRandomItems(1).FirstOrDefault();
                if (recurringTaskSoundFile != null)
                {
                    SoundPlayer.PlaySound(this, recurringTaskSoundFile);
                    SoundPlayer.Completion += (sender, e) => { SoundPlayer.PlaySound(this, DataHolder.Current.CurrentLesson.SoundPath); };
                }
                else
                {
                    SoundPlayer.PlaySound(this, DataHolder.Current.CurrentLesson.SoundPath);
                }
            }
            else
            {
                SoundPlayer.PlaySound(this, DataHolder.Current.CurrentLesson.SoundPath);
            }
        }