コード例 #1
0
        private void ShowChallengePage(Challenge challenge, bool noMoreChallenges, bool startChallenge, bool showMessageIfSkipChallenge, bool showActionButtons = true)
        {
            int points = int.Parse(_configuration.ReadProperty("Points") ?? "0");

            SaveEventData(new DistractionEventData()
            {
                EventType = startChallenge ? DistractionEventType.StartChallenge : DistractionEventType.ChangeChallenge,
                Time      = DateTime.UtcNow,
                UserId    = _configuration.UserId,
                Data      = $"Challenge type: { challenge.Type }, Challenge Id: { challenge.Id }",
            });

            ChallengePage challengePage = new ChallengePage(_configuration, challenge, noMoreChallenges, points, showMessageIfSkipChallenge, showActionButtons);

            //selectChallengeTypePage.BackButtonPressed += () => { ShowSelectFirstEmotionalStatusPage(); };
            challengePage.EnableBackButton = false;
            //selectChallengeTypePage.NextButtonPressed += () => { ShowChallengePage(); };
            challengePage.EnableNextButton = false;

            challengePage.ShowNavigationBarOnEntry    = false;
            challengePage.AnimateNavigationBarOnEntry = false;
            challengePage.AnimateNavigationBarOnBack  = false;
            challengePage.AnimateNavigationBarOnNext  = false;

            challengePage.ChallengeNoMore += () => {
                var completedDB = PositiveThingsDatabase.GetChallengesCompleted();
                foreach (Challenge ch in _challenges)
                {
                    if (ch.Completed)
                    {
                        if (_configuration.ReadBoolProperty("personal") && ch.TypeCheck.Contains("1"))
                        {
                            PositiveThingsDatabase.RemoveChallengeCompletedId(ch.Id);
                            ch.Completed = false;
                            continue;
                        }

                        if (_configuration.ReadBoolProperty("acertijos") && ch.TypeCheck.Contains("2"))
                        {
                            PositiveThingsDatabase.RemoveChallengeCompletedId(ch.Id);
                            ch.Completed = false;
                            continue;
                        }

                        if (_configuration.ReadBoolProperty("enigmas") && ch.TypeCheck.Contains("3"))
                        {
                            PositiveThingsDatabase.RemoveChallengeCompletedId(ch.Id);
                            ch.Completed = false;
                            continue;
                        }

                        if (_configuration.ReadBoolProperty("diferencias") && ch.TypeCheck.Contains("4"))
                        {
                            PositiveThingsDatabase.RemoveChallengeCompletedId(ch.Id);
                            ch.Completed = false;
                            continue;
                        }

                        if (_configuration.ReadBoolProperty("sopas") && ch.TypeCheck.Contains("5"))
                        {
                            PositiveThingsDatabase.RemoveChallengeCompletedId(ch.Id);
                            ch.Completed = false;
                            continue;
                        }

                        if (_configuration.ReadBoolProperty("relacionarme") && ch.TypeCheck.Contains("6"))
                        {
                            PositiveThingsDatabase.RemoveChallengeCompletedId(ch.Id);
                            ch.Completed = false;
                            continue;
                        }

                        if (_configuration.ReadBoolProperty("moverme") && ch.TypeCheck.Contains("7"))
                        {
                            PositiveThingsDatabase.RemoveChallengeCompletedId(ch.Id);
                            ch.Completed = false;
                            continue;
                        }

                        if (_configuration.ReadBoolProperty("musica") && ch.TypeCheck.Contains("8"))
                        {
                            PositiveThingsDatabase.RemoveChallengeCompletedId(ch.Id);
                            ch.Completed = false;
                            continue;
                        }

                        if (_configuration.ReadBoolProperty("relax") && ch.TypeCheck.Contains("9"))
                        {
                            PositiveThingsDatabase.RemoveChallengeCompletedId(ch.Id);
                            ch.Completed = false;
                            continue;
                        }
                    }
                }
                var completedDB2 = PositiveThingsDatabase.GetChallengesCompleted();
                //Task.Run(() => ShowChallengePage());
                //Device.BeginInvokeOnMainThread(() => ShowChallengePage());
                _currentChallenges = null;
                ShowChallengePage();
            };

            challengePage.ChallengeSkipped += () => { Task.Run(() => /*ShowChallengePage(challenge.Type)*/ ShowChallengePage()); };

            challengePage.ChallengeEnd += (challengeResult) =>
            {
                _currentChallenges     = null;
                _currentChallengeIndex = 0;

                var cc = new ChallengeCompleted()
                {
                    ChallengeId = challengeResult.ChallengeId
                };

                PositiveThingsDatabase.SaveChallengeCompleted(cc);

                var ch = _challenges.First(x => x.Id == cc.ChallengeId);

                ch.Completed = true;

                int totaPoints = Math.Max(0, int.Parse(_configuration.ReadProperty("Points") ?? "0") + challengeResult.ChallengePoints);

                _configuration.SaveProperty("Points", totaPoints.ToString());

                SaveEventDataSync(new DistractionEventData()
                {
                    EventType = DistractionEventType.EndChallenge,
                    Time      = DateTime.UtcNow,
                    UserId    = _configuration.UserId,
                    Data      = challengeResult.ToString(),
                });

                return(_configuration.ReadProperty("ranking"));
            };

            challengePage.ChallengeExit += (continuePlaying) =>
            {
                if (continuePlaying)
                {
                    //ShowSelectChallengeTypePage();
                    ShowChallengePage();

                    /*TabbedPage1 tabbed = new TabbedPage1(_configuration);
                     *
                     * Device.BeginInvokeOnMainThread(() => { Xamarin.Forms.Application.Current.MainPage = tabbed; });*/
                }
                else
                {
                    ShowSelectEndEmotionalStatusPage();
                }
            };

            challengePage.Initialize();

            //await currentPage.Navigation.PushModalAsync(selectNegativeTagFirstLevelSummaryPage, false);

            Device.BeginInvokeOnMainThread(() => { Xamarin.Forms.Application.Current.MainPage = challengePage; });

            //await Task.Delay(1000);

            //Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { Task.Delay(1000); });

            //await Task.Delay(1000);

            currentPage = challengePage;
        }
コード例 #2
0
 public static void CallChallengeCompleted()
 {
     ChallengeCompleted?.Invoke();
 }