Skip to content

Commit

Permalink
Revert "Fix"
Browse files Browse the repository at this point in the history
This reverts commit e9dd17530cf387bb77af64b731aa51037632af90.
  • Loading branch information
MaKrotos committed Feb 28, 2024
1 parent 9d49357 commit 4c9bf3d
Showing 1 changed file with 96 additions and 26 deletions.
122 changes: 96 additions & 26 deletions VK UI3/Views/SectionView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using Microsoft.UI.Xaml.Navigation;
using MusicX.Core.Models;
using MusicX.Core.Models.General;
using MusicX.Core.Services;
using ProtoBuf.Meta;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -36,10 +34,49 @@ public SectionView()
this.InitializeComponent();


// this.Loading += SectionView_Loading;
// this.Loaded += SectionView_Loaded;
this.Loading += SectionView_Loading;
this.Loaded += SectionView_Loaded;
}

private void SectionView_Loaded(object sender, RoutedEventArgs e)
{
// scrollViewer = GetScrollViewer(ListBlocks);
// scrollViewer.ViewChanged += Scrollvi_ViewChanged;
if (this.section != null && this.section.Blocks != null && this.section.Blocks.Count != 0)
{
this.nextLoad = this.section.NextFrom;
loadBlocks(this.section.Blocks);

}
else
{

LoadAsync();
}
}

private void SectionView_Loading(FrameworkElement sender, object args)
{

}

ScrollViewer scrollViewer = null;

bool loadedAll = false;

private bool CheckIfAllContentIsVisible(ScrollViewer scrollViewer)
{
if (scrollVIew.ViewportHeight >= scrollVIew.ExtentHeight)
{
return true;
}
return false;
}





public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged(string propertyName)
Expand All @@ -60,7 +97,7 @@ public enum SectionType
MyListAudio,
PlayList
}
string SectionID;

protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
Expand All @@ -73,18 +110,25 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
if (section == null) return;

this.section = section;
// this.sectionType = section;
this.SectionID = section.Id;
// this.sectionType = section;

if (this.section != null && this.section.Blocks != null && this.section.Blocks.Count != 0)
{
loadBlocks(this.section.Blocks);
}
else

}



public static ScrollViewer GetScrollViewer(DependencyObject depObj)
{
if (depObj is ScrollViewer) return depObj as ScrollViewer;

for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
LoadAsync();
var child = VisualTreeHelper.GetChild(depObj, i);

var result = GetScrollViewer(child);
if (result != null) return result;
}
return;
return null;
}


Expand Down Expand Up @@ -163,11 +207,33 @@ public async Task LoadAsync()
}

bool blockLoad = false;



private void HideLoad()
{
// Ñîçäàåì Storyboard
LoadingIndicator.Visibility = Visibility.Collapsed;
}

bool hidedLoad = false;
private async Task loadSection(string sectionID, bool showTitle = false)
{
blocks.Clear();
var sectin = await VK.vkService.GetSectionAsync(sectionID);
if (nextLoad == null || loadedAll)
{
if (hidedLoad) return;
hidedLoad = true;
HideLoad();
return;
}
if (blockLoad) return;

blockLoad = true;
var sectin = await VK.vkService.GetSectionAsync(sectionID, nextLoad);
nextLoad = sectin.Section.NextFrom;
if (sectin.Section.NextFrom == null) {
loadedAll = true;
}
this.section = sectin.Section;
if (section.Blocks.Count() == 0)
{
Expand All @@ -182,9 +248,21 @@ private void loadBlocks(List<Block> block)
{
foreach (var item in block)
{
blocks.Add(item);
this.DispatcherQueue.TryEnqueue(() =>
{
blocks.Add(item);
});
}
if (CheckIfAllContentIsVisible(scrollViewer))
{
LoadAsync();
}
if (nextLoad == null || loadedAll)
{
if (hidedLoad) return;
hidedLoad = true;
HideLoad();
}
OnPropertyChanged(nameof(section));
}

private bool nowOpenSearchSug = false;
Expand Down Expand Up @@ -227,9 +305,6 @@ internal async void ReplaceBlocks(string replaceId)
}
}



bool loadedAll = false;
private void scrollVIew_ViewChanged(ScrollView sender, object args)
{
var scrollViewer = sender as ScrollView;
Expand All @@ -251,11 +326,6 @@ private void scrollVIew_ViewChanged(ScrollView sender, object args)
}
}
}

private void HideLoad()
{
LoadingIndicator.Visibility = Visibility.Collapsed;
}
}

public class BlockTemplateSelector : DataTemplateSelector
Expand Down

0 comments on commit 4c9bf3d

Please sign in to comment.