<commit_before>﻿using LLQ;
using Brook.DuDuRiBao.Events;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Controls;
using Brook.DuDuRiBao.Models;
using Brook.DuDuRiBao.Common;
using Windows.UI.Core;
using Brook.DuDuRiBao.Utils;
using Windows.UI.ViewManagement;
using Brook.DuDuRiBao.ViewModels;
using Brook.DuDuRiBao.Authorization;
using System.Threading.Tasks;
using Windows.Foundation.Metadata;
using System;
using LLM;
using System.Linq;
using DuDuRiBao.Utils;
using Windows.UI.Xaml.Media;
using Windows.ApplicationModel.Background;
using Windows.UI.Notifications;
using BackgroundComponent;

namespace Brook.DuDuRiBao.Pages
{
    public sealed partial class MainPage : PageBase
    {
        public MainViewModel VM { get { return GetVM<MainViewModel>(); } }

        public bool IsCommentPanelOpen { get { return true; } }

        public MainPage()
        {
            this.InitializeComponent();
            Initalize();
            NavigationCacheMode = NavigationCacheMode.Required;

            Loaded += MainPage_Loaded;
            SystemNavigationManager.GetForCurrentView().BackRequested += MainPage_BackRequested;

            LLQNotifier.Default.Register(this);
        }

        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            Searcher.Visibility = Visibility.Collapsed;
            if (IsUsingCachedWhenNavigate())
            {
                return;
            }
            await InitUI();

            var isLogin = await AuthorizationHelper.AutoLogin();
            if (isLogin)
                UpdateLoginInfo();
            RegisterLiveTileTask();
            TimeLineFrame.Navigate(typeof(TimeLinePage));
        }

        private void MainPage_BackRequested(object sender, BackRequestedEventArgs e)
        {
            if (Searcher.Visibility == Visibility.Visible)
            {
                HideSearcher();
                e.Handled = true;
            }
        }

        private void UpdateLoginInfo()
        {
            var info = StorageInfo.Instance.ZhiHuAuthoInfo;
            if (info == null)
                return;

            LLQNotifier.Default.Notify(new LoginEvent() { IsLogin = true, UserPhotoUrl = info.avatar });
        }

        private static async Task InitUI()
        {
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;

            var isStatusBarPresent = ApiInformation.IsTypePresent(typeof(StatusBar).ToString());
            if (isStatusBarPresent)
            {
                var statusBar = StatusBar.GetForCurrentView();
                if (statusBar != null)
                {
                    statusBar.BackgroundOpacity = 1;
                    statusBar.ForegroundColor = Windows.UI.Colors.White;
                    statusBar.BackgroundColor = StorageInfo.Instance.AppTheme == ElementTheme.Light ? ColorUtil.GetColorFromHexString("#1976D2") : ColorUtil.GetColorFromHexString("#0e0e0f");
                    await statusBar.ShowAsync();
                }
            }
        }

        private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (Config.IsPageSwitched(e.PreviousSize, e.NewSize) && !string.IsNullOrEmpty(ViewModelBase.CurrentStoryId))
            {
                MainContentFrame.Navigate(typeof(MainContentPage));
                CommentFrame.Navigate(typeof(CommentPage));
            }
        }

        private void DisplayStory(string storyId)
        {
            ViewModelBase.CurrentStoryId = storyId;
            if (Config.UIStatus == AppUIStatus.All || Config.UIStatus == AppUIStatus.ListAndContent)
            {
                MainContentFrame.Navigate(typeof(MainContentPage), storyId);
                CommentFrame.Navigate(typeof(CommentPage), storyId);
            }<commit_msg>try to fix black status bar issue<commit_after>﻿using LLQ;
using Brook.DuDuRiBao.Events;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Controls;
using Brook.DuDuRiBao.Models;
using Brook.DuDuRiBao.Common;
using Windows.UI.Core;
using Brook.DuDuRiBao.Utils;
using Windows.UI.ViewManagement;
using Brook.DuDuRiBao.ViewModels;
using Brook.DuDuRiBao.Authorization;
using System.Threading.Tasks;
using Windows.Foundation.Metadata;
using System;
using LLM;
using System.Linq;
using DuDuRiBao.Utils;
using Windows.UI.Xaml.Media;
using Windows.ApplicationModel.Background;
using Windows.UI.Notifications;
using BackgroundComponent;

namespace Brook.DuDuRiBao.Pages
{
    public sealed partial class MainPage : PageBase
    {
        public MainViewModel VM { get { return GetVM<MainViewModel>(); } }

        public bool IsCommentPanelOpen { get { return true; } }

        public MainPage()
        {
            this.InitializeComponent();
            Initalize();
            NavigationCacheMode = NavigationCacheMode.Required;

            Loaded += MainPage_Loaded;
            SystemNavigationManager.GetForCurrentView().BackRequested += MainPage_BackRequested;

            LLQNotifier.Default.Register(this);
        }

        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            Searcher.Visibility = Visibility.Collapsed;
            if (IsUsingCachedWhenNavigate())
            {
                return;
            }
            await InitUI();

            var isLogin = await AuthorizationHelper.AutoLogin();
            if (isLogin)
                UpdateLoginInfo();
            RegisterLiveTileTask();
            TimeLineFrame.Navigate(typeof(TimeLinePage));
        }

        private void MainPage_BackRequested(object sender, BackRequestedEventArgs e)
        {
            if (Searcher.Visibility == Visibility.Visible)
            {
                HideSearcher();
                e.Handled = true;
            }
        }

        private void UpdateLoginInfo()
        {
            var info = StorageInfo.Instance.ZhiHuAuthoInfo;
            if (info == null)
                return;

            LLQNotifier.Default.Notify(new LoginEvent() { IsLogin = true, UserPhotoUrl = info.avatar });
        }

        private static async Task InitUI()
        {
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;

            var isStatusBarPresent = ApiInformation.IsTypePresent(typeof(StatusBar).ToString()) || ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1, 0);
            if (isStatusBarPresent)
            {
                var statusBar = StatusBar.GetForCurrentView();
                if (statusBar != null)
                {
                    statusBar.BackgroundOpacity = 1;
                    statusBar.ForegroundColor = Windows.UI.Colors.White;
                    statusBar.BackgroundColor = StorageInfo.Instance.AppTheme == ElementTheme.Light ? ColorUtil.GetColorFromHexString("#1976D2") : ColorUtil.GetColorFromHexString("#0e0e0f");
                    await statusBar.ShowAsync();
                }
            }
        }

        private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (Config.IsPageSwitched(e.PreviousSize, e.NewSize) && !string.IsNullOrEmpty(ViewModelBase.CurrentStoryId))
            {
                MainContentFrame.Navigate(typeof(MainContentPage));
                CommentFrame.Navigate(typeof(CommentPage));
            }
        }

        private void DisplayStory(string storyId)
        {
            ViewModelBase.CurrentStoryId = storyId;
            if (Config.UIStatus == AppUIStatus.All || Config.UIStatus == AppUIStatus.ListAndContent)
            {
                MainContentFrame.Navigate(typeof(MainContentPage), storyId);
                CommentFrame.Navigate(typeof(CommentPage), storyId);
            }
{'fraction_non_alphanumeric': 0.08602287166454892, 'fraction_numerical': 0.0025412960609911056, 'mean_word_length': 2.2179067865903517, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '3375081', 'n_tokens_mistral': 2103, 'n_tokens_neox': 2030, 'n_words': 373}