Skip to content

Commit

Permalink
Do less unnecessary UI refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
kinsi55 committed Jun 26, 2021
1 parent 5119c05 commit f43f6ed
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions UI/DownloadHistoryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using IPA.Utilities;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using TMPro;
Expand Down Expand Up @@ -80,10 +81,17 @@ public async void ProcessDownloads(bool forceTableReload = false) {

await Task.Run(async () => {
try {
var updateRateLimiter = new Stopwatch();
updateRateLimiter.Start();
await SongDownloader.BeatmapDownload(firstEntry, BSSFlowCoordinator.closeCancelSource.Token, (float progress) => {
firstEntry.statusDetails = string.Format("({0:0%}{1})", progress, firstEntry.retries == 0 ? "" : $", retry #{firstEntry.retries} / ");
firstEntry.downloadProgress = progress;
if(updateRateLimiter.ElapsedMilliseconds < 0.05)
return;
updateRateLimiter.Restart();
IPA.Utilities.Async.UnityMainThreadTaskScheduler.Factory.StartNew(firstEntry.UpdateProgress);
});
Expand All @@ -100,7 +108,7 @@ await SongDownloader.BeatmapDownload(firstEntry, BSSFlowCoordinator.closeCancelS
});

if(firstEntry.status == DownloadHistoryEntry.DownloadStatus.Downloaded) {
BSSFlowCoordinator.songListView.RefreshTable();
BSSFlowCoordinator.songListView.songList.RefreshCells(false, true);

// NESTING HELLLL
var selectedSongView = BSSFlowCoordinator.songListView.selectedSongView;
Expand All @@ -111,14 +119,22 @@ await SongDownloader.BeatmapDownload(firstEntry, BSSFlowCoordinator.closeCancelS
ProcessDownloads(true);
}

public void RefreshTable(bool fullReload = true) {
BSMLStuff.UnleakTable(downloadHistoryTable.gameObject);
RatelimitCoroutine limitedFullTableReload;

downloadHistoryData.data = downloadList.OrderBy(x => x.orderValue).Cast<object>().ToList();
void Awake() {
limitedFullTableReload = new RatelimitCoroutine(() => {
BSMLStuff.UnleakTable(downloadHistoryTable.gameObject);
downloadHistoryData.data = downloadList.OrderBy(x => x.orderValue).Cast<object>().ToList();
if(fullReload) {
downloadHistoryTable.ReloadData();
downloadHistoryTable.ScrollToCellWithIdx(0, TableView.ScrollPositionType.Beginning, false);
}, 0.2f);
}

public void RefreshTable(bool fullReload = true) {
if(fullReload) {
StartCoroutine(limitedFullTableReload.Call());
} else {
downloadHistoryTable.RefreshCells(false, true);
}
Expand Down

0 comments on commit f43f6ed

Please sign in to comment.