private async void stuffToDoWhenNavigatedTo()
        {
            
            //activity_d = new ObservableCollection<ActivityData>();
            bool res = await library.checkIfFileExists("activityDB");
            rtrackact = new RootObjectTrackAct();
            if (res)
            {
                //activityComboBox actiboxtemp = new activityComboBox();
                string restring = await library.readFile("activityDB");
                if (String.IsNullOrEmpty(restring))
                {
                    NavigationButtons.Visibility = Visibility.Collapsed;
                    NavigationButtons_secondary.Visibility = Visibility.Visible;
                    firstLaunch();
                }
                else
                {
                    activityName.Text = (string)ApplicationData.Current.RoamingSettings.Values["CurrentAct"];
                    rtrackact = TrackAct.trackactDataDeserializer(restring);
                    Debug.WriteLine("Not the first Launch");
                    
                    for (int i = 0; i < rtrackact.activity.Count; i++)
                    {
                        if (rtrackact.activity[i].name == activityName.Text)
                        {
                            activity_pos = i;
                        }

                    }
                    if (activity_pos == -1)
                    {
                        StatisticsGrid.Opacity = 0;
                        personalBestGrid.Opacity = 0;
                        NavigationButtons.Visibility = Visibility.Collapsed;
                        NavigationButtons_secondary.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        MedianTextBlock.Text = library.convertSecondsToString(rtrackact.activity[activity_pos].median_in_sec);
                        NinetyPercentileTextBlock.Text = library.convertSecondsToString(rtrackact.activity[activity_pos].ninetypercentile_second);
                        personalBest.Text = rtrackact.activity[activity_pos].personal_best;
                        NavigationButtons.Visibility = Visibility.Visible;
                        TimerData td = new TimerData();
                        td = rtrackact.activity[activity_pos].timer_data.Last();
                        //previousAttemptblock.Text = "Last time you spent";
                        previousAttempt.Text = "Last time we spent " + library.convertSecondsToString((long)td.time_in_seconds); //String.Format("{0:00}:{1:00}:{2:00}", (long)td.time_in_seconds / 3600, ((long)td.time_in_seconds / 60) % 60, (long)td.time_in_seconds % 60);
                        NavigationButtons_secondary.Visibility = Visibility.Collapsed;
                    }
                }
            }
            else
            {
                firstLaunch();
            }
        }
 public MainPage()
 {
     this.InitializeComponent();
     library = new Library();
     activity = new ObservableCollection<ActivityData>();
     tmdata = new ObservableCollection<TimerData>();
     tmdata.CollectionChanged += Tmdata_CollectionChanged;
     rtrackact = new RootObjectTrackAct();
     activityPos = new Hashtable();
     
     Loaded += MainPage_Loaded;
     ApplicationData.Current.RoamingSettings.Values["NewActivity"] = false;
     DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;
 }
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            tmdata.Clear();
            activity.Clear();
            activityPos.Clear();

            resume.Text = ApplicationData.Current.LocalSettings.Values["Resuming"] == null ? "Not initialized" : (string)ApplicationData.Current.LocalSettings.Values["Resuming"];
            ApplicationData.Current.LocalSettings.Values["Resuming"] = "temp_empty";
            //dataListView.ManipulationDelta += DataListView_ManipulationDelta;
            if (!await library.checkIfFileExists("activityDB"))
            {
                ApplicationData.Current.RoamingSettings.Values["FirstLaunch"] = true;
                Frame rootFrame = Window.Current.Content as Frame;
                ApplicationData.Current.LocalSettings.Values["TimerRunning"] = false;
                rootFrame.Navigate(typeof(TimerPage));
            }
            else
            {
                if (await library.checkIfFileExists("activityDB"))
                {
                    ApplicationData.Current.RoamingSettings.Values["FirstLaunch"] = false;
                    if (ApplicationData.Current.LocalSettings.Values["TimerRunning"] != null)
                    {
                        if ((bool)ApplicationData.Current.LocalSettings.Values["TimerRunning"] == true)
                        {
                            ApplicationData.Current.RoamingSettings.Values["FirstLaunch"] = false;
                            Frame rootFrame = Window.Current.Content as Frame;
                            rootFrame.Navigate(typeof(TimerPage));
                        }
                    }
                    string fileres = await library.readFile("activityDB");
                    rtrackact = TrackAct.trackactDataDeserializer(fileres);
                    updateUI(rtrackact);
                }
                else
                {
                    ApplicationData.Current.RoamingSettings.Values["FirstLaunch"] = false;
                    Frame rootFrame = Window.Current.Content as Frame;
                    rootFrame.Navigate(typeof(TimerPage));
                }              
                               
            }
        }
 private  void updateUI(RootObjectTrackAct rtact)
 {
     var tc = new TelemetryClient();
     var activityD = rtact.activity;
     int i = 0;
     foreach (var actv in activityD)
     {
         if (actv.isDelete == false)
         {
             activity.Add(actv);
             activityPos.Add(actv.name, i);
             i++;
         }
     }
     //var timedata = rtrackact.activity[0].timer_data;
     //foreach (var tdata in timedata)
     //{
     //    tmdata.Add(tdata);
     //}
     tc.TrackMetric("Number of Activities", rtact.activity.Count);
 }
Exemple #5
0
 public static string trackactSerializer(RootObjectTrackAct rtrackact)
 {
     string response = JsonConvert.SerializeObject(rtrackact);
     return response;
 }
 private async void introGo_Click(object sender, RoutedEventArgs e)
 {
     if ((introBox.Text != ""))
     {
         bool found = false;
         if (await library.checkIfFileExists("activityDB"))
         {
             found = false;
             RootObjectTrackAct ract = new RootObjectTrackAct();
             ract = TrackAct.trackactDataDeserializer(await library.readFile("activityDB"));
             for(int i = 0; i < ract.activity.Count; i++)
             {
                 if((ract.activity[i].name).ToLower() == (introBox.Text).ToLower())
                 {
                     found = true;
                     break;
                 }
             }
             if (found == true)
             {
                 introBox.Text = "";
                 introBox.PlaceholderText = "This act already exists";
             }
             else
             {
                 ApplicationData.Current.RoamingSettings.Values["CurrentAct"] = introBox.Text;
                 ApplicationData.Current.RoamingSettings.Values["Description"] = description.Text;
                 introGrid.Visibility = Visibility.Collapsed;
                 mainPageGrid.Visibility = Visibility.Visible;
                 stuffToDoWhenNavigatedTo();
             }
         }
         else
         {
             ApplicationData.Current.RoamingSettings.Values["CurrentAct"] = introBox.Text;
             ApplicationData.Current.RoamingSettings.Values["Description"] = description.Text;
             introGrid.Visibility = Visibility.Collapsed;
             mainPageGrid.Visibility = Visibility.Visible;
             stuffToDoWhenNavigatedTo();
         }
     }
     else
     {
         introBox.PlaceholderText = "This box cannot be left empty.";
     }
 }