public void OnInitialize(Item item, ThumbnailHelper thumbnail) { // using regex to parse every http url and check if they are all download to show if the item is downloaded var linkParser = new Regex(@"\b(?:https?://|www\.)\S+(\.mp4|.mp3|.png)\b", RegexOptions.Multiline | RegexOptions.IgnoreCase); var parsedLinks = linkParser.Matches(item.Data.ToString()).Cast <Match>().Select(x => x.Value).ToList(); var isFavorite = FavoriteItems.Any(x => x.UID.Equals(item.UID)); //Debug.Log("Item: " + item.UID + ", downloaded: " + FileManager.IsFileDownloaded(parsedLinks)); /*foreach (var parsedLink in parsedLinks) * { * Debug.Log(parsedLink); * }*/ if (parsedLinks.Any()) { thumbnail.SetThumbnailState(FileManager.IsFileDownloaded(parsedLinks), true, isFavorite, isOn => { if (isOn) { AddFavoriteTag(item); } else { RemoveFavoriteTag(item); } }); if (FileManager.IsDownloadInitiated(parsedLinks.ToArray())) { thumbnail.IsDownloading = true; var imageUrls = parsedLinks.Where(x => x.Contains(".png")).ToArray(); var videoUrls = parsedLinks.Where(x => x.Contains(".mp4")).ToArray(); var soundUrls = parsedLinks.Where(x => x.Contains(".mp3")).ToArray(); var downloadFactor = 0; if (imageUrls.Any()) { downloadFactor++; FileManager.Instance.GetImage(urls: imageUrls, onComplete: (downloadedUrls) => thumbnail.SetThumbnailState(true), owner: this, onFail: () => { Debug.Log("file Retrival error!!"); UIToastNotification.Instance.TriggerToast(LocalizedText.GetLocalizedText("OnDownloadInterrupt") ?? "Oops Download failed, please try again.", 2f); thumbnail.SetThumbnailState(false); }, onProgress: (progress) => thumbnail.ShowProgress(progress / downloadFactor), needDataOnComplete: false); } if (videoUrls.Any()) { downloadFactor++; FileManager.Instance.GetVideo(urls: videoUrls, onComplete: (downloadedUrls) => thumbnail.SetThumbnailState(true), owner: this, onFail: () => { Debug.Log("file Retrival error!!"); UIToastNotification.Instance.TriggerToast(LocalizedText.GetLocalizedText("OnDownloadInterrupt") ?? "Oops Download failed, please try again.", 2f); thumbnail.SetThumbnailState(false); }, onProgress: (progress) => thumbnail.ShowProgress(progress / downloadFactor), needDataOnComplete: false); } if (soundUrls.Any()) { downloadFactor++; FileManager.Instance.GetVideo(urls: soundUrls, onComplete: (downloadedUrls) => thumbnail.SetThumbnailState(true), owner: this, onFail: () => { Debug.Log("file Retrival error!!"); UIToastNotification.Instance.TriggerToast(LocalizedText.GetLocalizedText("OnDownloadInterrupt") ?? "Oops Download failed, please try again.", 2f); thumbnail.SetThumbnailState(false); }, onProgress: (progress) => thumbnail.ShowProgress(progress / downloadFactor), needDataOnComplete: false); } //thumbnail.SetThumbnailState(downloadComplete); } } thumbnail.SetRelatedData(item); if (!item.IsFree && !LocalDataManager.Instance.SaveData.GetPremiumStatus()) { thumbnail.SetFreeContent(false); } else { thumbnail.SetFreeContent(true); } }