private void OnProductListFetched(ProductList productList, bool fetchDetailsCalled) { GetPageFromFilterTab(PackageFilterTab.AssetStore).OnProductListFetched(productList, fetchDetailsCalled); }
public void OnProductListFetched(ProductList productList, bool fetchDetailsCalled) { var isSearchResult = !string.IsNullOrEmpty(productList.searchText); if (isSearchResult && productList.searchText != PackageFiltering.instance.currentSearchText) { return; } var targetList = isSearchResult ? m_FilteredList.searchList : m_FilteredList.baseList; if (productList.startIndex > 0 && (targetList.total != productList.total || (targetList.searchText ?? "") != (productList.searchText ?? ""))) { // if a new page has arrived but the total has changed or the searchText has changed, do a re-fetch AssetStore.AssetStoreClient.instance.List(0, productList.startIndex + productList.list.Count, PackageFiltering.instance.currentSearchText, true); return; } var rebuildList = PackageFiltering.instance.currentFilterTab == PackageFilterTab.AssetStore; HashSet <long> removed = null; List <long> added = null; if (productList.startIndex == 0) { if (rebuildList) { removed = new HashSet <long>(targetList.list); added = new List <long>(); foreach (var id in productList.list) { if (removed.Contains(id)) { removed.Remove(id); } else { added.Add(id); } } } // override the result if the new list starts from index 0 (meaning it's a refresh) targetList.list = productList.list; targetList.total = productList.total; targetList.searchText = productList.searchText; } else if (productList.startIndex == targetList.list.Count && (targetList.searchText ?? "") == (productList.searchText ?? "")) { // append the result if it is the next page targetList.list.AddRange(productList.list); if (rebuildList) { added = productList.list; } } else { // if the content is neither starting from zero or next page, we simply discard it return; } m_MorePackagesToFetch = m_FilteredList.baseList.total > m_FilteredList.baseList.list.Count; m_MoreSearchPackagesToFetch = m_FilteredList.searchList.total > m_FilteredList.searchList.list.Count; m_FilteredList.enabled = true; if (!fetchDetailsCalled && productList.list.Any()) { AssetStore.AssetStoreClient.instance.FetchDetails(productList.list); } if (rebuildList) { var addedPackages = added?.Select(id => PackageDatabase.instance.GetPackage(id.ToString())); var removedPackages = removed?.Select(id => PackageDatabase.instance.GetPackage(id.ToString())); RebuildList(addedPackages, removedPackages); } }
public void GetProductIDList(int startIndex, int limit, string searchText, Action <ProductList> doneCallbackAction) { var returnList = new ProductList { total = 0, startIndex = startIndex, isValid = false, searchText = searchText, list = new List <long>() }; AssetStoreOAuth.instance.FetchUserInfo(userInfo => { limit = limit > 0 ? limit : kDefaultLimit; searchText = string.IsNullOrEmpty(searchText) ? "" : searchText; var httpRequest = ApplicationUtil.instance.GetASyncHTTPClient($"{m_Host}{kListUri}?offset={startIndex}&limit={limit}&query={System.Uri.EscapeDataString(searchText)}"); httpRequest.header["Authorization"] = "Bearer " + userInfo.accessToken; httpRequest.doneCallback = httpClient => { var errorMessage = "Failed to parse JSON."; if (httpClient.IsSuccess() && httpClient.responseCode == 200) { try { var res = Json.Deserialize(httpClient.text) as Dictionary <string, object>; if (res != null) { var total = (long)res["total"]; returnList.total = total; returnList.isValid = true; if (total == 0) { doneCallbackAction?.Invoke(returnList); return; } var results = res["results"] as IList <object>; foreach (var result in results) { var item = result as Dictionary <string, object>; var packageId = item["packageId"]; returnList.list.Add((long)packageId); } doneCallbackAction?.Invoke(returnList); return; } } catch (Exception e) { errorMessage = e.Message; } } else { errorMessage = httpClient.text; } returnList.errorMessage = errorMessage; doneCallbackAction?.Invoke(returnList); }; httpRequest.Begin(); }, error => { returnList.errorMessage = error.message; doneCallbackAction?.Invoke(returnList); }); }