private async Task SetUserContent()
        {
            MainPage.CurrentUser = await WakaTimeRepo.GetCurrentUser();

            if (MainPage.CurrentUser != null)
            {
                masterPage.gridUser.IsVisible      = true;
                masterPage.gridUser.BindingContext = MainPage.CurrentUser;
            }

            Leaders leaders = await WakaTimeRepo.GetLeaders();

            MainPage.CurrentLeader = leaders.CurrentUser;
        }
Esempio n. 2
0
        public async Task Cache(uint maxPage)
        {
            for (uint i = 1; i <= maxPage; i++)
            {
                if (this.leaders.ContainsKey(i))
                {
                    continue;
                }

                Leaders leaders = await WakaTimeRepo.GetLeaders(i);

                // Create thread to set the cache, prevent stuttering
                this.AddPageToCache(i, leaders);
            }
        }
Esempio n. 3
0
        internal async Task <Leaders> GetPage(uint currentPage)
        {
            if (this.leaders.ContainsKey(currentPage))
            {
                this.leaders.TryGetValue(currentPage, out Leaders value);

                return(value);
            }

            Leaders leaders = await WakaTimeRepo.GetLeaders(currentPage);

            // Create thread to set the cache, prevent stuttering
            this.AddPageToCache(currentPage, leaders);

            return(leaders);
        }
Esempio n. 4
0
        protected override void OnAppLinkRequestReceived(Uri uri)
        {
            string token = uri.Segments[2];

            if (!WakaTimeRepo.IsTokenValid(token))
            {
                Current.MainPage.DisplayAlert("Invalid Token", "An invalid token was supplied, you have not been signed in.", "Ok");

                return;
            }

            App.cache.RemoveAll();

            Preferences.Set("token", token);

            MainPage = new MainPage();

            Current.MainPage.DisplayAlert("Successful Login", "You can always log out at the bottom of the navigation menu.", "Ok");
        }
        private async void LoadContent()
        {
            AllTimeStats stats = await WakaTimeRepo.GetCurrentUserAllTimeStats();

            this.layoutStatsCalculating.IsVisible = !stats.UpToDate;
            this.layoutStats.IsVisible            = stats.UpToDate;

            this.grid.BindingContext = stats;

            List <AllTimeComparison> comparisons = new List <AllTimeComparison>();

            comparisons.Add(
                new AllTimeComparison("Watching the LOTR extended movies ", Math.Round(stats.TotalSeconds / 41040d, 1).ToString(), " times")
                );

            comparisons.Add(
                new AllTimeComparison("Traveling ", Math.Round(stats.TotalSeconds / 4924800d, 3).ToString(), " times around the world by train.")
                );

            lvwComparisons.ItemsSource = comparisons;
        }
        private async void LoadUserStats()
        {
            Stats stats = await WakaTimeRepo.GetUserStats(this.user.Id);

            lvwProjects.ItemsSource = stats.Projects;
        }
        private async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            NavigationItem item = e.SelectedItem as NavigationItem;

            if (item == null)
            {
                return;
            }

            if (item.TargetType != null)
            {
                Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType));
            }
            else
            {
                switch (item.Title)
                {
                case "Profile":
                    Detail = new NavigationPage(new UserPage(MainPage.CurrentLeader));

                    break;

                case "Login":
                    if (await DisplayAlert("Login", "You are about to be redirected.", "Continue", "Cancel"))
                    {
                        try
                        {
                            await Browser.OpenAsync(WakaTimeRepo.RedirectUrl, BrowserLaunchMode.External);
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("Failed to start browser, the device might not have a browser installed.");

                            break;
                        }

                        string result = await DisplayPromptAsync("Token", "Go To https://wakatime.damon.sh if you didn't get redirected.\n\nPut the login token in the field below after authenticating.", "Confirm", "Cancel");

                        if (WakaTimeRepo.IsTokenValid(result))
                        {
                            App.cache.RemoveAll();

                            Preferences.Set("token", result);

                            (Application.Current).MainPage = new MainPage();
                        }
                        else
                        {
                            DisplayAlert("Invalid Token", "An invalid WakaTime token has been inserted", "Ok");
                        }
                    }

                    break;

                case "Logout":
                    if (await DisplayAlert("Logout?", "Are you sure you want to logout?", "Yes, please", "No, please take me back"))
                    {
                        App.cache.RemoveAll();

                        Preferences.Remove("token");

                        (Application.Current).MainPage = new MainPage();
                    }

                    break;

                default:
                    break;
                }
            }

            IsPresented = false;
            masterPage.lvwNavigation.SelectedItem       = null;
            masterPage.lvwBottomNavigation.SelectedItem = null;
        }
Esempio n. 8
0
        private async void ShowsStats()
        {
            var stats = await WakaTimeRepo.GetUserStats(this.leader.User.Id);

            List <ChartEntry> entries = new List <ChartEntry>();

            for (int i = 0; i < stats.Categories.Count; i++)
            {
                var category = stats.Categories[i];
                var color    = SKColor.Parse(Colors[i]);

                entries.Add(new ChartEntry(category.Percent)
                {
                    Label           = category.Name,
                    ValueLabel      = category.Text,
                    Color           = color,
                    ValueLabelColor = color
                });
            }

            chrtVwCategories.Chart = new DonutChart
            {
                Entries = entries
            };

            entries = new List <ChartEntry>();
            for (int i = 0; i < stats.Editors.Count; i++)
            {
                var editor = stats.Editors[i];
                var color  = SKColor.Parse(Colors[i]);

                entries.Add(new ChartEntry(editor.Percent)
                {
                    Label           = editor.Name,
                    ValueLabel      = editor.Text,
                    Color           = color,
                    ValueLabelColor = color
                });
            }

            chrtVwEditors.Chart = new DonutChart
            {
                Entries = entries
            };

            entries = new List <ChartEntry>();
            for (int i = 0; i < stats.Languages.Count; i++)
            {
                if (i == Colors.Length)
                {
                    break;
                }

                var language = stats.Languages[i];
                var color    = SKColor.Parse(Colors[i]);

                entries.Add(new ChartEntry(language.Percent)
                {
                    Label           = language.Name,
                    ValueLabel      = language.Text,
                    Color           = color,
                    ValueLabelColor = color
                });
            }

            chrtVwLanguages.HeightRequest = 300 + (stats.Languages.Count - 3) * 35;
            chrtVwLanguages.Chart         = new DonutChart
            {
                Entries   = entries,
                LabelMode = LabelMode.RightOnly
            };

            if (Device.RuntimePlatform == Device.Android)
            {
                chrtVwCategories.Chart.LabelTextSize = 32;
                chrtVwEditors.Chart.LabelTextSize    = 32;
                chrtVwLanguages.Chart.LabelTextSize  = 32;
            }

            this.stats = stats;
        }