<commit_before>﻿using System;
using Caliburn.Micro;
using S1Nyan.Model;
using S1Nyan.Utils;
using S1Parser;

namespace S1Nyan.ViewModels
{

    public class ThreadListViewModel : S1NyanViewModelBase
    {
        private readonly IDataService _dataService;
        private readonly INavigationService _navigationService;

        /// <summary>
        /// Initializes a new instance of the ThreadListViewViewModel class.
        /// </summary>
        public ThreadListViewModel(IDataService dataService, IEventAggregator eventAggregator,INavigationService navigationService)
            : base(eventAggregator)
        {
            _dataService = dataService;
            _navigationService = navigationService;
        }

        private string _title = "";

        /// <summary>
        /// Sets and gets the Title property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public string Title
        {
            get { return _title; }

            set
            {
                if (_title == value) return;

                _title = value;
                NotifyOfPropertyChange(() => Title);
            }
        }

        private S1ThreadList _threadListData = null;

        /// <summary>
        /// Sets and gets the ThreadListViewData property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public S1ThreadList ThreadListData
        {
            get { return _threadListData; }
            set
            {
                if (_threadListData == value) return;

                _threadListData = value;
                NotifyOfPropertyChange(() => ThreadListData);
            }
        }

        public override async void RefreshData()
        {
            ThreadListData = null;
            if (null == _fid) return;
            Util.Indicator.SetLoading();
            try
            {
                var temp = await _dataService.GetThreadListAsync(_fid, CurrentPage);
                if (temp.CurrentPage == CurrentPage)
                {
                    ThreadListData = temp;
                    TotalPage = ThreadListData.TotalPage;
                    NotifyOfPropertyChange(() => CanNextPage);
                    NotifyOfPropertyChange(() => CanPrePage);
                    Util.Indicator.SetBusy(false);
                }
            }
            catch (Exception e)
            {
                if (!HandleUserException(e))
                    Util.Indicator.SetError(e);
            }
        }

        private string _fid = null;
        public void OnChangeFID(string fid, string title)
        {
            Title = title;
            if (fid != null)
            {
                _fid = fid;
                TotalPage = 0;
                CurrentPage = 1;
            }
        }

        public string Fid
        {
            get { return _fid; }
            set
            {
                if (value == null) return;
                _fid = value;
                TotalPage = 0;
                CurrentPage = 1;
            }
        }

        public int TotalPage { get; set; }

        //may change during async actions, disable optimization
        volatile int currentPage;
        public int CurrentPage
        {
            get { return currentPage; }
            set
            {
                if (value > 0 )
                {
                    currentPage = value;
                    RefreshData();
                }
            }
        }

        //public override void Cleanup()
        //{
        //    base.Cleanup();
        //    ThreadListViewData = null;
        //    PageChanged = null;
        //}


        #region Bind ApplicaionBar Actions

        public void RefreshThreadList()
        {
            RefreshData();
        }

        public void PrePage()
        {
            CurrentPage--;
        }

        public bool CanPrePage
        {
            get { return CurrentPage > 1 && TotalPage > 1; }
        }

        public void NextPage()
        {
            CurrentPage++;
        }

        public bool CanNextPage
        {
            get { return CurrentPage < TotalPage && TotalPage > 1; }
        }

        public void GoToSetting()
        {
            _navigationService.Navigate(new Uri("/Views/SettingView.xaml", UriKind.Relative));
        }

        #endregion

        public void GoToAccount()
        {
            _navigationService.Navigate(new Uri("/Views/SettingView.xaml?Pivot=Account", UriKind.Relative));
        }

        public void DoNavigation(S1ListItem item)
        {
            if (item == null) return;

            _navigationService.UriFor<PostViewModel>()
                .WithParam(vm => vm.Title, item.Title)
                .WithParam(vm => vm.Tid, item.Id)
                .Navigate();
        }

    }
}<commit_msg>Caliburn will set navigation params when view actived, walk around that by checking is the same fid<commit_after>﻿using System;
using Caliburn.Micro;
using S1Nyan.Model;
using S1Nyan.Utils;
using S1Parser;

namespace S1Nyan.ViewModels
{

    public class ThreadListViewModel : S1NyanViewModelBase
    {
        private readonly IDataService _dataService;
        private readonly INavigationService _navigationService;

        /// <summary>
        /// Initializes a new instance of the ThreadListViewViewModel class.
        /// </summary>
        public ThreadListViewModel(IDataService dataService, IEventAggregator eventAggregator,INavigationService navigationService)
            : base(eventAggregator)
        {
            _dataService = dataService;
            _navigationService = navigationService;
        }

        private string _title = "";

        /// <summary>
        /// Sets and gets the Title property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public string Title
        {
            get { return _title; }

            set
            {
                if (_title == value) return;

                _title = value;
                NotifyOfPropertyChange(() => Title);
            }
        }

        private S1ThreadList _threadListData = null;

        /// <summary>
        /// Sets and gets the ThreadListViewData property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public S1ThreadList ThreadListData
        {
            get { return _threadListData; }
            set
            {
                if (_threadListData == value) return;

                _threadListData = value;
                NotifyOfPropertyChange(() => ThreadListData);
            }
        }

        public override async void RefreshData()
        {
            ThreadListData = null;
            if (null == _fid) return;
            Util.Indicator.SetLoading();
            try
            {
                var temp = await _dataService.GetThreadListAsync(_fid, CurrentPage);
                if (temp.CurrentPage == CurrentPage)
                {
                    ThreadListData = temp;
                    TotalPage = ThreadListData.TotalPage;
                    NotifyOfPropertyChange(() => CanNextPage);
                    NotifyOfPropertyChange(() => CanPrePage);
                    Util.Indicator.SetBusy(false);
                }
            }
            catch (Exception e)
            {
                if (!HandleUserException(e))
                    Util.Indicator.SetError(e);
            }
        }

        private string _fid = null;

        public string Fid
        {
            get { return _fid; }
            set
            {
                if (value == null || value == _fid) return;
                _fid = value;
                TotalPage = 0;
                CurrentPage = 1;
            }
        }

        public int TotalPage { get; set; }

        //may change during async actions, disable optimization
        volatile int currentPage;
        public int CurrentPage
        {
            get { return currentPage; }
            set
            {
                if (value > 0 )
                {
                    currentPage = value;
                    RefreshData();
                }
            }
        }

        //public override void Cleanup()
        //{
        //    base.Cleanup();
        //    ThreadListViewData = null;
        //    PageChanged = null;
        //}


        #region Bind ApplicaionBar Actions

        public void RefreshThreadList()
        {
            RefreshData();
        }

        public void PrePage()
        {
            CurrentPage--;
        }

        public bool CanPrePage
        {
            get { return CurrentPage > 1 && TotalPage > 1; }
        }

        public void NextPage()
        {
            CurrentPage++;
        }

        public bool CanNextPage
        {
            get { return CurrentPage < TotalPage && TotalPage > 1; }
        }

        public void GoToSetting()
        {
            _navigationService.Navigate(new Uri("/Views/SettingView.xaml", UriKind.Relative));
        }

        #endregion

        public void GoToAccount()
        {
            _navigationService.Navigate(new Uri("/Views/SettingView.xaml?Pivot=Account", UriKind.Relative));
        }

        public void DoNavigation(S1ListItem item)
        {
            if (item == null) return;

            _navigationService.UriFor<PostViewModel>()
                .WithParam(vm => vm.Title, item.Title)
                .WithParam(vm => vm.Tid, item.Id)
                .Navigate();
        }

    }
}
{'fraction_non_alphanumeric': 0.07945561893325327, 'fraction_numerical': 0.003002101471029721, 'mean_word_length': 1.1863924742944651, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 37, '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': '6980739', 'n_tokens_mistral': 2552, 'n_tokens_neox': 2308, 'n_words': 581}