Skip to content

Commit

Permalink
Fix Friends Music
Browse files Browse the repository at this point in the history
Fix Messages Music
More Fix
  • Loading branch information
MaKrotos committed May 8, 2024
1 parent 81678b2 commit a011f74
Show file tree
Hide file tree
Showing 17 changed files with 222 additions and 103 deletions.
2 changes: 1 addition & 1 deletion VK UI3/Controllers/AudioPlayer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ private async static Task PlayTrack(long? v = null)
if (v != null) iVKGetAudio.currentTrack = (long)v;

var trackdata = await _TrackDataThisGet();

if (trackdata == null) return;

if (iVKGetAudio is PlayListVK)
{
Expand Down
24 changes: 11 additions & 13 deletions VK UI3/DownloadTrack/PlayListDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ public PlayListDownload(IVKGetAudio iVKGetAudio, string path, DispatcherQueue di
public async Task PlayListDownloadAsync()
{


_ = Task.Run(() =>
_ = Task.Run(async() =>
{
try
{
Expand All @@ -124,24 +123,22 @@ public async Task PlayListDownloadAsync()
string ffmpegPath = new CheckFFmpeg().getPathFfmpeg();


while (iVKGetAudio.countTracks > downloaded)
while (iVKGetAudio.listAudio.Count() > downloaded || !iVKGetAudio.itsAll)
{
pauseEvent.WaitOne();
if (cts.Token.IsCancellationRequested)
{
break;
}

while (downloaded >= iVKGetAudio.listAudioTrue.Count)
while (downloaded >= iVKGetAudio.listAudioTrue.Count && iVKGetAudio.countTracks != -1 && !iVKGetAudio.itsAll)
{
if (iVKGetAudio.itsAll) return;
if (iVKGetAudio.getLoadedTracks)
{

continue;
}
var tcsz = new TaskCompletionSource<bool>();
iVKGetAudio.tcs.Add(tcsz);
iVKGetAudio.GetTracks();
await tcsz.Task;
}
if (downloaded >= iVKGetAudio.listAudioTrue.Count) break;


var a = iVKGetAudio.listAudioTrue[downloaded].audio;
Expand Down Expand Up @@ -203,7 +200,7 @@ public async Task PlayListDownloadAsync()

dispatcherQueue.TryEnqueue(async () =>
{
OnTrackDownloaded?.Invoke(this, new TrackDownloadedEventArgs { Downloaded = downloaded, Total = (int)iVKGetAudio.countTracks });
OnTrackDownloaded?.Invoke(this, new TrackDownloadedEventArgs { Downloaded = downloaded, Total = (int?)iVKGetAudio.countTracks });
});


Expand All @@ -222,7 +219,8 @@ public async Task PlayListDownloadAsync()
{
PlayListDownloads.Remove(this);
PlayListDownloadsList.Remove(iVKGetAudio);
if (PlayListDownloads.Count() == 0) EndAllDownload();
//if (iVKGetAudio.listAudio.Count() == downloaded && iVKGetAudio.itsAll)
EndAllDownload();
});

}
Expand Down Expand Up @@ -341,7 +339,7 @@ public void Cancel()
public class TrackDownloadedEventArgs : EventArgs
{
public int Downloaded { get; set; }
public int Total { get; set; }
public int? Total { get; set; }
}

}
2 changes: 1 addition & 1 deletion VK UI3/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
Background="Transparent"
CornerRadius="5"
OriginalHeight="25"
OriginalMargin="0,0,0,5"
OriginalMargin="5,0,5,5"
OriginalWidth="35">
<Button.Flyout>
<Flyout>
Expand Down
17 changes: 13 additions & 4 deletions VK UI3/VKs/IVK/IVKGetAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ObservableRangeCollection<ExtendedAudio> listAudio

public long? countTracks { get
{
if (_countTracks == null) return null;
if (_countTracks == null) return -1;
if (_countTracks != -1) return _countTracks;
else return listAudio.Count;

Expand Down Expand Up @@ -243,6 +243,12 @@ public async void shareToVK()

public void NotifyOnListUpdate()
{
foreach (var item in tcs)
{
item.SetResult(true);
}
tcs.Clear();
getLoadedTracks = false;
onListUpdate?.Invoke(this, EventArgs.Empty);
}
public void updateNumbers()
Expand Down Expand Up @@ -351,7 +357,7 @@ public async Task<ExtendedAudio> GetTrackPlay()



TaskCompletionSource<bool> tcs;
public List<TaskCompletionSource<bool>> tcs = new();

public bool getLoadedTracks = false;
public async Task<ExtendedAudio> GetTrackPlayAsync(long tracI)
Expand All @@ -362,9 +368,12 @@ public async Task<ExtendedAudio> GetTrackPlayAsync(long tracI)
{
if (itsAll) return null;
else
{
var tcsz = new TaskCompletionSource<bool>();
tcs.Add(tcsz);
GetTracks();
tcs = new TaskCompletionSource<bool>();
await tcs.Task;
await tcsz.Task;
}
}

}
Expand Down
8 changes: 3 additions & 5 deletions VK UI3/VKs/IVK/MessagesAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,12 @@ public override void GetTracks()
Task.Run(async () =>
{

int count = 200;


int count = 10;
VkCollection<Audio> audios;

MessagesGetHistoryAttachmentsParams messagesGetHistoryAttachmentsParams = new MessagesGetHistoryAttachmentsParams()
{
Count = 200,
Count = count,
MediaType = MediaType.Audio,
PeerId = messConv.conversation.Peer.Id,
StartFrom = nextFrom
Expand All @@ -128,7 +126,7 @@ public override void GetTracks()
resetEvent.Reset(); // Ñáðàñûâàåò ñîáûòèå äëÿ ñëåäóþùåé èòåðàöèè
}

if (countTracks == listAudio.Count()) itsAll = true;
if (nextFrom == null) itsAll = true;


getLoadedTracks = false;
Expand Down
5 changes: 3 additions & 2 deletions VK UI3/VKs/IVK/PlayListVK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public class PlayListVK : IVKGetAudio
public PlayListVK(AudioPlaylist _playlist, DispatcherQueue dispatcher) : base(dispatcher)
{
waitCreate = true;
this.playlist = _playlist;
Task.Run(async () =>
{

try
{

Expand Down Expand Up @@ -151,12 +151,13 @@ public PlayListVK(AudioPlaylist _playlist, DispatcherQueue dispatcher) : base(di
finally
{
waitCreate = true;
getLoadedTracks = true;
NotifyOnListUpdate();
}



});
}).Wait();
}

public PlayListVK(RecommendedPlaylist _playlist, DispatcherQueue dispatcher) : base(dispatcher)
Expand Down
7 changes: 5 additions & 2 deletions VK UI3/Views/Download/DownloadController.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ private void updateUI()
if (!playListDownload.error)
DownloadProgressBar.ShowPaused = false;
}
dx.Text = $"{playListDownload.downloaded} из {playListDownload.iVKGetAudio.countTracks}";

dx.Text = $"{playListDownload.downloaded}";
if (playListDownload.iVKGetAudio.countTracks != null && playListDownload.iVKGetAudio.countTracks != -1)
{
dx.Text += $"из {playListDownload.iVKGetAudio.countTracks}";
}



Expand Down
2 changes: 1 addition & 1 deletion VK UI3/Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ private void NavWiv_SelectionChanged(NavigationView sender, NavigationViewSelect
break;

case "музыка друзей":
frame.Navigate(typeof(Share.FriendsList), null, new DrillInNavigationTransitionInfo());
OpenMyPage(SectionType.LoadFriends);
break;

case "вложения":
Expand Down
91 changes: 44 additions & 47 deletions VK UI3/Views/PlayListPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,60 +178,57 @@


</StackPanel>


<StackPanel
x:Name="AddInfo"
Margin="0,10,0,0"
Padding="10"
Background="{ThemeResource LayerOnAccentAcrylicFillColorDefault}"
CornerRadius="4"
Translation="0,0,16">

<StackPanel
x:Name="AddInfo"
Grid.Column="1"
Opacity="0.5"
Orientation="Vertical"
Translation="0,0,16"
Visibility="{Binding Path=VisibileAddInfo}">
<TextBlock
x:Name="FollowersText"
FontFamily="{StaticResource VKSansRegular}"
Text="{Binding Genres}"
Visibility="Collapsed" />
<TextBlock
x:Name="Genres"
FontFamily="{StaticResource VKSansRegular}"
Text="{Binding Genres}"
Visibility="Collapsed" />
<TextBlock
x:Name="Dot2"
Margin="0,0,0,0"
Opacity="0.5"
Orientation="Vertical"
Visibility="{Binding Path=VisibileAddInfo}">
<TextBlock
x:Name="FollowersText"
FontFamily="{StaticResource VKSansRegular}"
Text="{Binding Genres}"
Visibility="Collapsed" />
<TextBlock
x:Name="Genres"
FontFamily="{StaticResource VKSansRegular}"
Text="{Binding Genres}"
Visibility="Collapsed" />
<TextBlock
x:Name="Dot2"
Margin="0,0,0,0"
Text=""
Visibility="Collapsed" />
<TextBlock
x:Name="Year"
Margin="0,0,0,0"
FontFamily="{StaticResource VKSansRegular}"
Text="{Binding Year}"
Visibility="Collapsed" />
Text=""
Visibility="Collapsed" />
<TextBlock
x:Name="Year"
Margin="0,0,0,0"
FontFamily="{StaticResource VKSansRegular}"
Text="{Binding Year}"
Visibility="Collapsed" />

<TextBlock
x:Name="Plays"
Margin="0,0,0,0"
FontFamily="{StaticResource VKSansRegular}"
Text="{Binding Plays}"
Visibility="Collapsed" />
<TextBlock
x:Name="PlaysText"
Margin="3,0,0,0"
Text=""
Visibility="Collapsed" />
<TextBlock
x:Name="CountTrText"
FontFamily="{StaticResource VKSansRegular}"
Text="{Binding Genres}"
Visibility="Collapsed" />
</StackPanel>
<TextBlock
x:Name="Plays"
Margin="0,0,0,0"
FontFamily="{StaticResource VKSansRegular}"
Text="{Binding Plays}"
Visibility="Collapsed" />
<TextBlock
x:Name="PlaysText"
Margin="3,0,0,0"
Text=""
Visibility="Collapsed" />
<TextBlock
x:Name="CountTrText"
FontFamily="{StaticResource VKSansRegular}"
Text="{Binding Genres}"
Visibility="Collapsed" />
</StackPanel>

<GridView
x:Name="stackPanel"
Margin="0,10,0,0"
Expand Down
46 changes: 39 additions & 7 deletions VK UI3/Views/PlayListPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,13 @@ private void updateUI(bool load = false)


MainText.ChangeTextWithAnimation(vkGetAudio.name);
CountTrText.Text = $"Треков: {vkGetAudio.countTracks}";

if (vkGetAudio.countTracks == -1) {
CountTrText.Visibility = Visibility.Collapsed;
}
else
{
CountTrText.Text = $"Треков: {vkGetAudio.countTracks}";
}

}
if (vkGetAudio is UserAudio userAudio)
Expand All @@ -247,8 +252,6 @@ private void updateUI(bool load = false)
VK_UI3.Views.Upload.UploadTrack.addedTrack += addedTrack;
}
DescriptionText.Text = userAudio.user.Status;


if (
userAudio.user.Status != null &&
(userAudio.user.Status.Equals("") || DescriptionText.Text == null)
Expand All @@ -262,22 +265,51 @@ private void updateUI(bool load = false)


}
CheckAndHideGrid(AddInfo);



if (DescriptionText.Text is null || DescriptionText.Text == "") DescriptionText.Visibility = Visibility.Collapsed;
MainText.ChangeTextWithAnimation(vkGetAudio.name);
CountTrText.Visibility = Visibility.Visible;


});
}

public void CheckAndHideGrid(StackPanel grid)
{
bool allChildrenHidden = true;

foreach (UIElement child in grid.Children)
{
if (child.Visibility == Visibility.Visible)
{
if (child is TextBlock textblock && (textblock.Text is null || textblock.Text == ""))
{ textblock.Visibility = Visibility.Collapsed; }
else
{
allChildrenHidden = false;
break;
}
}
}

if (allChildrenHidden)
{
grid.Visibility = Visibility.Collapsed;
}
else
{
grid.Visibility = Visibility.Visible;
}
}


private void addedTrack(object sender, EventArgs e)
{
if (sender is Audio audio)
{
vkGetAudio.listAudio.Insert(0, new ExtendedAudio(audio, vkGetAudio));
vkGetAudio.NotifyOnListUpdate();
vkGetAudio.updateNumbers();
}
}

Expand Down
Loading

0 comments on commit a011f74

Please sign in to comment.