public void OnClick(JToken jData, ThumbnailHelper thumbnail) { //todo: determine the item type send to respective scene [content type identifier] and show the content[hook to systems other developers have created] var catObj = jData.TryAndFind <Category>(x => x.HasValues); var item = jData.TryAndFind <Item>(x => x["Data"] != null); thumbnail.IsDownloading = false; //need to set to true onClick implementation foreach (var supportedContentType in SupportedContentTypes) { if (supportedContentType.ActionOnClick == null) { continue; } ICategoryClickable click = null; //for custom category click [very few use case] if (catObj != null) { if (supportedContentType.Name.Equals(catObj.Name)) { click = thumbnail.gameObject.GetComponent(supportedContentType.ActionOnClick.GetType()) as ICategoryClickable ?? thumbnail.gameObject.AddComponent(supportedContentType.ActionOnClick.GetType()) as ICategoryClickable; } } //for item click [primary use] if (item != null) { if (supportedContentType.MatchWithName) { if (supportedContentType.Name.Equals(item.Name)) { click = thumbnail.gameObject.GetComponent(supportedContentType.ActionOnClick.GetType()) as ICategoryClickable ?? thumbnail.gameObject.AddComponent(supportedContentType.ActionOnClick.GetType()) as ICategoryClickable; } } else { if (supportedContentType.Name.Equals(item.ContentType)) { click = thumbnail.gameObject.GetComponent(supportedContentType.ActionOnClick.GetType()) as ICategoryClickable ?? thumbnail.gameObject.AddComponent(supportedContentType.ActionOnClick.GetType()) as ICategoryClickable; } } } if (click != null) { click.OnClick(this, thumbnail); } } }
public ThumbnailHelper SetThumbnailType(ThumbnailTypes type) { switch (type) { case ThumbnailTypes.Category: { CategoryThumbnail.Activate(); _thumbnailHelper = CategoryThumbnail.GetComponent <ThumbnailHelper>(); } break; case ThumbnailTypes.Item: { ItemThumbnail.Activate(); _thumbnailHelper = ItemThumbnail.GetComponent <ThumbnailHelper>(); } break; } return(ThumbnailHelper); }
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); } }
//call to public IEnumerator PopulateContents(JArray inJData, bool subLevel = true, string parentName = "", bool createNewPanel = true, Category parentData = null, ThumbnailHelper parentThumbnail = null, bool updateInBg = false, bool forceBase = false, bool forceNumberThumbnails = false) { //Debug.Log(inJData); if (inJData == null) { //if there is no data, there is a possibility, it can be a custom category //add custom on click if (parentData != null) { OnClick(JToken.FromObject(parentData), parentThumbnail); } yield break; } #region Organising @inJData //organising the category and item data for proper sorting when displayed var jList = inJData.ToList(); var allCategories = JArray.FromObject(jList.TryAndFindList <Category>(cat => cat.HasValues)); var allItems = jList.TryAndFindList <Item>(item => item["Data"] != null); /*//sorting the item list -> newest always at top * allItems.Sort((a, b) => b.UploadDate.FromUnixTime().CompareTo(a.UploadDate.FromUnixTime())); //descending order*/ if (ItemPosFromJson) { allItems = (from item in allItems orderby item.PositionInList select item).ToList(); } var freeItems = allItems.FindAll(x => x.IsFree); var premiumItems = allItems.FindAll(x => !x.IsFree); var organisedItems = JArray.FromObject(freeItems.Concat(premiumItems)); var organisedData = allCategories.Concat(organisedItems).ToList(); #endregion CurrentParent = parentData; if (createNewPanel) { CreateSubPanel(parentData != null ? parentData.Name : parentName, parentData); } var holderPanel = subLevel ? SubLevelContent : CategoryContent; yield return(new WaitForEndOfFrame()); if (holderPanel == null) { yield break; //if no panel is there return } if (!updateInBg) //activate the panel if this is false { ViewController.Activate(holderPanel, UIType.NormalView, () => { if (ShowLoader) { UILoader.Instance.StartLoader(); } }); } var thumbnailPrefab = HybridPrefab; if (ContainsOnlyItems) { thumbnailPrefab = ItemPrefab; } //getting the override script var overrideRule = GetComponent <CategoryPopulateOverride>(); //applying override populate script if (overrideRule != null && !forceBase) { overrideRule.OverrideCreateAndFill(holderPanel, thumbnailPrefab, organisedData, ContainsOnlyItems, forceNumberThumbnails); } else { CreateAndFill(holderPanel, thumbnailPrefab, organisedData, ContainsOnlyItems, forceNumberThumbnails); } CallBackOnPopulate.Invoke(); yield return(new WaitForSeconds(0.5f)); if (ShowLoader) { UILoader.Instance.StopLoader(true); } }