Gabboxl / ClassevivaPCTO

An UWP app to consult Classeviva's website
https://www.microsoft.com/store/productId/9PNST3M88D1S
GNU General Public License v3.0
7 stars 1 forks source link

[NoticeListView] flicker nel caricamento dei dati #242

Closed alessandrocaseti closed 5 months ago

alessandrocaseti commented 5 months ago

La listview viene caricata due volte, causando un flicker. Ciò succede solo al primo caricamento della pagina, se si utilizza il controllo refresh il problema non accade.

Gabboxl commented 5 months ago

Dovrebbe essere causato dall'impostazione della posizione precedente nella listview, se è così allora non si può fare nulla

alessandrocaseti commented 5 months ago

Dovrebbe essere causato dall'impostazione della posizione precedente nella listview, se è così allora non si può fare nulla

però strano, lo fa solo con quella delle comunicazioni

alessandrocaseti commented 5 months ago

considera che la listview viene caricata la prima volta mentre il progressring è ancora attivo, la seconda appena sparisce. Ci potrebbe essere qualche ridondanza qui

private async Task LoadData()
{
    try

    {
        await CoreApplication.MainView.Dispatcher.RunAsync(
            CoreDispatcherPriority.Normal,
            async () => { AssenzeViewModel.IsLoadingAssenze = true; }
        );

        Card? cardResult = AppViewModelHolder.GetViewModel().SingleCardResult;

        AbsencesResult absencesResult = await apiWrapper.GetAbsences(
            cardResult.usrId.ToString()
        );

        _absencesResult = absencesResult;

        //create list based on isjustified bool value
        var justifiedAbsences = absencesResult.AbsenceEvents
            .OrderByDescending(n => n.evtDate)
            .Where(n => n.isJustified)
            .ToList();

        //not justified absences
        var notJustifiedAbsences = absencesResult.AbsenceEvents
            .OrderByDescending(n => n.evtDate)
            .Where(n => !n.isJustified)
            .ToList();

        //calendar thigs
        CalendarResult calendarResult = await apiWrapper.GetCalendar(
            cardResult.usrId.ToString()
        );

        _apiCalendarResult = calendarResult;

        //update UI on UI thread
        await CoreApplication.MainView.Dispatcher.RunAsync(
            CoreDispatcherPriority.Normal,
            async () =>
            {
                AbsencesToJustifyListView.ItemsSource = notJustifiedAbsences.Concat(justifiedAbsences).ToList();
                //AbsencesJustifiedListView.ItemsSource = justifiedAbsences;

                await UpdateCalendar();

                //select the current day of the calendar
                ColoredCalendarView.SetDisplayDate(DateTime.Now.Date);
            }
        );
    }
    finally
    {
        {
            await CoreApplication.MainView.Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                async () => 
                { 
                AssenzeViewModel.IsLoadingAssenze = false; 
                AssenzeViewModel.ShowShimmers = false;
                }
            );
        }
    }
}
Gabboxl commented 5 months ago

UpdateCalendar

ma il problema è per la listview delle assenze o della bacheca? questo sembra il codice delle assenze

alessandrocaseti commented 5 months ago

scusa ho sbagliato, è questo

private async Task LoadData()
        {
            try
            {
                bool showInactiveNotices = false;
                int readUnreadSegmentedIndex = 0;
                string? selectedCategory = null;

                await CoreApplication.MainView.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal, () =>
                    {
                        BachecaViewModel.IsLoadingBacheca = true;

                        selectedCategory = (string) CategoryComboBox.SelectionBoxItem;

                        readUnreadSegmentedIndex = ReadUnreadSegmented.SelectedIndex;

                        if (CheckboxAttive.IsChecked != null) showInactiveNotices = CheckboxAttive.IsChecked.Value;
                    }
                );

                Card? cardResult = AppViewModelHolder.GetViewModel().SingleCardResult;

                NoticeboardResult noticeboardResult = await apiWrapper.GetNotices(
                    cardResult.usrId.ToString()
                );

                var noticesToShow = noticeboardResult.Notices;

                if (!showInactiveNotices) //there are also notes that are deleted but still active (not expired), so we filter them out too
                {
                    //filter notices that are valid from the cntValidInRange property
                    noticesToShow = noticesToShow.Where(n => n.cntValidInRange && n.cntStatus != "deleted").ToList();
                }

                //filter notices by read status
                switch (readUnreadSegmentedIndex)
                {
                    case 1:
                        noticesToShow = noticesToShow.Where(n => !n.readStatus).ToList();
                        break;

                    case 2:
                        noticesToShow = noticesToShow.Where(n => n.readStatus).ToList();
                        break;
                }

                var noticeCategories = noticesToShow.Select(n => n.cntCategory).Distinct().OrderBy(o => o).ToList();

                if (!string.IsNullOrEmpty(selectedCategory))
                {
                    noticesToShow = noticesToShow.Where(n => n.cntCategory == selectedCategory).ToList();
                }

                await CoreApplication.MainView.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal, () =>
                    {
                        CategoryComboBox.SelectionChanged -= CategoryComboBox_OnSelectionChanged;

                        BachecaViewModel.Categories = noticeCategories;

                        CategoryComboBox.SelectionChanged += CategoryComboBox_OnSelectionChanged;

                        if(ReadUnreadSegmented.SelectedIndex != 0 || CategoryComboBox.SelectedIndex != -1)
                        {
                            ClearAllFiltersButton.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                        else
                        {
                            ClearAllFiltersButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                        }

                        //set the notices to show
                        BachecaViewModel.NoticesToShow = noticesToShow;
                    }
                );
            }
            finally
            {
                {
                    await CoreApplication.MainView.Dispatcher.RunAsync(
                        CoreDispatcherPriority.Normal, () => { BachecaViewModel.IsLoadingBacheca = false; }
                    );
                }
            }
        }
Gabboxl commented 5 months ago

scusa ho sbagliato, è questo

private async Task LoadData()
        {
            try
            {
                bool showInactiveNotices = false;
                int readUnreadSegmentedIndex = 0;
                string? selectedCategory = null;

                await CoreApplication.MainView.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal, () =>
                    {
                        BachecaViewModel.IsLoadingBacheca = true;

                        selectedCategory = (string) CategoryComboBox.SelectionBoxItem;

                        readUnreadSegmentedIndex = ReadUnreadSegmented.SelectedIndex;

                        if (CheckboxAttive.IsChecked != null) showInactiveNotices = CheckboxAttive.IsChecked.Value;
                    }
                );

                Card? cardResult = AppViewModelHolder.GetViewModel().SingleCardResult;

                NoticeboardResult noticeboardResult = await apiWrapper.GetNotices(
                    cardResult.usrId.ToString()
                );

                var noticesToShow = noticeboardResult.Notices;

                if (!showInactiveNotices) //there are also notes that are deleted but still active (not expired), so we filter them out too
                {
                    //filter notices that are valid from the cntValidInRange property
                    noticesToShow = noticesToShow.Where(n => n.cntValidInRange && n.cntStatus != "deleted").ToList();
                }

                //filter notices by read status
                switch (readUnreadSegmentedIndex)
                {
                    case 1:
                        noticesToShow = noticesToShow.Where(n => !n.readStatus).ToList();
                        break;

                    case 2:
                        noticesToShow = noticesToShow.Where(n => n.readStatus).ToList();
                        break;
                }

                var noticeCategories = noticesToShow.Select(n => n.cntCategory).Distinct().OrderBy(o => o).ToList();

                if (!string.IsNullOrEmpty(selectedCategory))
                {
                    noticesToShow = noticesToShow.Where(n => n.cntCategory == selectedCategory).ToList();
                }

                await CoreApplication.MainView.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal, () =>
                    {
                        CategoryComboBox.SelectionChanged -= CategoryComboBox_OnSelectionChanged;

                        BachecaViewModel.Categories = noticeCategories;

                        CategoryComboBox.SelectionChanged += CategoryComboBox_OnSelectionChanged;

                        if(ReadUnreadSegmented.SelectedIndex != 0 || CategoryComboBox.SelectedIndex != -1)
                        {
                            ClearAllFiltersButton.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        }
                        else
                        {
                            ClearAllFiltersButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                        }

                        //set the notices to show
                        BachecaViewModel.NoticesToShow = noticesToShow;
                    }
                );
            }
            finally
            {
                {
                    await CoreApplication.MainView.Dispatcher.RunAsync(
                        CoreDispatcherPriority.Normal, () => { BachecaViewModel.IsLoadingBacheca = false; }
                    );
                }
            }
        }

Non sembrano esserci ridondanze, però ho paura che il problema possa essere causato dal set dei valori per il combobox delle categorie

alessandrocaseti commented 5 months ago

probabile, infatti manco la combobox funziona

Gabboxl commented 5 months ago

probabile, infatti manco la combobox funziona

Non funziona più il filtro per categoria?

alessandrocaseti commented 5 months ago

@Gabboxl #106

Gabboxl commented 5 months ago

@Gabboxl #106

la combobox da me funziona, stai compilando dal branch main? manca soltanto la voce "nessuna categoria", ma per il resto sembra funzionare bene

alessandrocaseti commented 5 months ago

@Gabboxl #106

la combobox da me funziona, stai compilando dal branch main? manca soltanto la voce "nessuna categoria", ma per il resto sembra funzionare bene

main, funziona ma viene creato un elemento in più vuoto. guarda gli screen che ho mandato su l'issue

alessandrocaseti commented 5 months ago

succede ancora se si seleziona il primo elemento della combobox categorie

Gabboxl commented 5 months ago

fixato

alessandrocaseti commented 5 months ago

@Gabboxl hai fixato il doppio caricamento ma il filtro è rotto, perchè quando il selected index è 0 torna automaticamente a -1 e non viene applicato affatto. Io ad esempio seleziono il primo elemento che è "circolare" ma cliccandolo ritorna sul placeholder senza filtrare nulla (considera che la mia scuola usa solo questa categoria). Poi, se attivo la checkbox per quelle scadute me ne appare una sotto la categoria news, e di conseguenza la categoria circolare si sposta all'index 1 e se cliccato funziona correttamente.

alessandrocaseti commented 5 months ago
Gabboxl commented 5 months ago

fixato, il caricamento doppio rimane, bisogna trovare un modo per disattivare tutti i listener conemporaneamente