<commit_before>﻿using CryptoTracker.Helpers;
using CryptoTracker.Views;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Graphics.Display;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media.Animation;

namespace CryptoTracker {
    public sealed partial class MainPage : Page {

        private readonly ObservableCollection<string> suggestions = new ObservableCollection<string>();
        private int CurrentTabIndex = 0;
        readonly UISettings uiSettings = new UISettings();

        // ###############################################################################################
        public MainPage() {
            this.InitializeComponent();

            // Clear the current tile
            //TileUpdateManager.CreateTileUpdaterForApplication().Clear();            

            if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Desktop") {
                CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
            }

            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) {
                var statusBar = StatusBar.GetForCurrentView();

                if (App.localSettings.Values["Theme"].Equals("Dark")) {
                    statusBar.BackgroundColor = Color.FromArgb(255, 23, 23, 23); //31 31 31
                    statusBar.BackgroundOpacity = 1;
                    statusBar.ForegroundColor = Color.FromArgb(255, 255, 255, 255);
                } else {
                    statusBar.BackgroundColor = Color.FromArgb(255, 242, 242, 242); // 230
                    statusBar.BackgroundOpacity = 1;
                    statusBar.ForegroundColor = Color.FromArgb(255, 0, 0, 0);
                }

                DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;
            }

            // Subscribe to light/dark theme change event
            uiSettings.ColorValuesChanged += ColorValuesChanged;

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            FirstRunDialogHelper.ShowIfAppropriateAsync();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            // Extend acrylic
            ExtendAcrylicIntoTitleBar();
        }

        private void ColorValuesChanged(UISettings sender, object args) {
            if (App.localSettings.Values["Theme"].Equals("Windows")){
                var color = uiSettings.GetColorValue(UIColorType.Background);
                switch (color.ToString()) {
                    case "#FF000000":
                        ChangeTheme("Dark");
                        break;
                    case "#FFFFFFFF":
                        ChangeTheme("Light");
                        break;
                }
            }
        }

        private async void ChangeTheme(string theme) {
            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                ((Frame)Window.Current.Content).RequestedTheme = theme.Equals("Dark") ? ElementTheme.Dark : ElementTheme.Light;
            });
        }

        /// Extend acrylic into the title bar. 
        private void ExtendAcrylicIntoTitleBar() {
            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
            ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
            titleBar.BackgroundColor = Colors.Transparent;
            titleBar.InactiveBackgroundColor = Colors.Transparent;
            titleBar.ButtonBackgroundColor = Colors.Transparent;
            titleBar.ButtonForegroundColor = Color.FromArgb(255, 150, 150, 150);
            titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
            titleBar.ButtonInactiveForegroundColor = Color.FromArgb(127, 150, 150, 150);

            //Window.Current.SetTitleBar(AppTitle);
        }

        // #########################################################################################
        internal async void UpdateButton_Click(object sender, RoutedEventArgs e) {
            SyncIcon.Visibility = Visibility.Collapsed;
            switch (ContentFrame.SourcePageType.Name) {
                case "CoinDetails":
                    var p0 = (CoinDetails)ContentFrame.Content;
                    p0.UpdatePage();
                    break;
                case "Home":
                    var p2 = (Home)ContentFrame.Content;
                    await p2.UpdateAllCards();
                    break;
                case "Portfolio":
                    var p1 = (Portfolio)ContentFrame.Content;
                    p1.UpdatePortfolio();
                    break;
            }

            SyncIcon.Visibility = Visibility.Visible;
            //LiveTile l = new LiveTile();
            //l.UpdateLiveTile();
        }

        // #########################################################################################
        //  Navigation View
        private void NavView_Loaded(object sender, RoutedEventArgs e) {
            // set the initial SelectedItem 
            NavView.SelectedItem = NavView.MenuItems[0];
        }

        private void NavView_Sync_Tapped(object sender, TappedRoutedEventArgs e) {
            UpdateButton_Click(sender, e);
        }

        private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args) {
            string source = "null";
            string selected = "null";

            if (((Frame)sender.Content).SourcePageType != null)
                source = (((Frame)sender.Content).SourcePageType).Name;
            <commit_msg>MainPage: added to News to Update()<commit_after>﻿using CryptoTracker.Helpers;
using CryptoTracker.Views;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Graphics.Display;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media.Animation;

namespace CryptoTracker {
    public sealed partial class MainPage : Page {

        private readonly ObservableCollection<string> suggestions = new ObservableCollection<string>();
        private int CurrentTabIndex = 0;
        readonly UISettings uiSettings = new UISettings();

        // ###############################################################################################
        public MainPage() {
            this.InitializeComponent();

            // Clear the current tile
            //TileUpdateManager.CreateTileUpdaterForApplication().Clear();            

            if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Desktop") {
                CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
            }

            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) {
                var statusBar = StatusBar.GetForCurrentView();

                if (App.localSettings.Values["Theme"].Equals("Dark")) {
                    statusBar.BackgroundColor = Color.FromArgb(255, 23, 23, 23); //31 31 31
                    statusBar.BackgroundOpacity = 1;
                    statusBar.ForegroundColor = Color.FromArgb(255, 255, 255, 255);
                } else {
                    statusBar.BackgroundColor = Color.FromArgb(255, 242, 242, 242); // 230
                    statusBar.BackgroundOpacity = 1;
                    statusBar.ForegroundColor = Color.FromArgb(255, 0, 0, 0);
                }

                DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;
            }

            // Subscribe to light/dark theme change event
            uiSettings.ColorValuesChanged += ColorValuesChanged;

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            FirstRunDialogHelper.ShowIfAppropriateAsync();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

            // Extend acrylic
            ExtendAcrylicIntoTitleBar();
        }

        private void ColorValuesChanged(UISettings sender, object args) {
            if (App.localSettings.Values["Theme"].Equals("Windows")){
                var color = uiSettings.GetColorValue(UIColorType.Background);
                switch (color.ToString()) {
                    case "#FF000000":
                        ChangeTheme("Dark");
                        break;
                    case "#FFFFFFFF":
                        ChangeTheme("Light");
                        break;
                }
            }
        }

        private async void ChangeTheme(string theme) {
            await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                ((Frame)Window.Current.Content).RequestedTheme = theme.Equals("Dark") ? ElementTheme.Dark : ElementTheme.Light;
            });
        }

        /// Extend acrylic into the title bar. 
        private void ExtendAcrylicIntoTitleBar() {
            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
            ApplicationViewTitleBar titleBar = ApplicationView.GetForCurrentView().TitleBar;
            titleBar.BackgroundColor = Colors.Transparent;
            titleBar.InactiveBackgroundColor = Colors.Transparent;
            titleBar.ButtonBackgroundColor = Colors.Transparent;
            titleBar.ButtonForegroundColor = Color.FromArgb(255, 150, 150, 150);
            titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
            titleBar.ButtonInactiveForegroundColor = Color.FromArgb(127, 150, 150, 150);

            //Window.Current.SetTitleBar(AppTitle);
        }

        // #########################################################################################
        internal async void UpdateButton_Click(object sender, RoutedEventArgs e) {
            SyncIcon.Visibility = Visibility.Collapsed;
            switch (ContentFrame.SourcePageType.Name) {
                case "CoinDetails":
                    var p0 = (CoinDetails)ContentFrame.Content;
                    p0.UpdatePage();
                    break;
                case "Home":
                    var p2 = (Home)ContentFrame.Content;
                    await p2.UpdateAllCards();
                    break;
                case "Portfolio":
                    var p1 = (Portfolio)ContentFrame.Content;
                    p1.UpdatePortfolio();
                    break;
                case "News":
                    var p3 = (News)ContentFrame.Content;
                    p3.GetNews();
                    break;
            }

            SyncIcon.Visibility = Visibility.Visible;
            //LiveTile l = new LiveTile();
            //l.UpdateLiveTile();
        }

        // #########################################################################################
        //  Navigation View
        private void NavView_Loaded(object sender, RoutedEventArgs e) {
            // set the initial SelectedItem 
            NavView.SelectedItem = NavView.MenuItems[0];
        }

        private void NavView_Sync_Tapped(object sender, TappedRoutedEventArgs e) {
            UpdateButton_Click(sender, e);
        }

        private void NavView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args) {
            string source = "null";
            string selected = "null";

            if (((Frame)sender.Content).SourcePageType != null)
                source = (((Frame)sender.Content).SourcePageType).Name;
            
{'fraction_non_alphanumeric': 0.12823249322715705, 'fraction_numerical': 0.01592644282078647, 'mean_word_length': 2.1494312306101344, 'pattern_counts': {'":': 11, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6862241', 'n_tokens_mistral': 3061, 'n_tokens_neox': 2766, 'n_words': 620}