public void Start(PurchasesQueryArgs queryArgs = null) { m_QueryArgs = queryArgs; m_IsInProgress = true; m_Timestamp = DateTime.Now.Ticks; if (!ApplicationUtil.instance.isUserLoggedIn) { OnOperationError(new UIError(UIErrorCode.AssetStoreOperationError, L10n.Tr("User not logged in"))); return; } AssetStoreRestAPI.instance.GetPurchases(queryArgs.ToString(), result => { if (!ApplicationUtil.instance.isUserLoggedIn) { OnOperationError(new UIError(UIErrorCode.AssetStoreOperationError, L10n.Tr("User not logged in"))); return; } m_Result = new AssetStorePurchases(this.queryArgs); m_Result.ParsePurchases(result); onOperationSuccess?.Invoke(this); FinalizedOperation(); }, error => OnOperationError(error)); }
public void OnProductListFetched(AssetStorePurchases assetStorePurchases, bool fetchDetailsCalled) { if (m_Total != (int)assetStorePurchases.total) { m_Total = (int)assetStorePurchases.total; } // This is a tweak, waiting for the filter to get the value from page if (m_NumberOfPackagesShown == 0) { m_NumberOfPackagesShown = assetStorePurchases.list.Count(); } else if (m_NumberOfPackagesShown != 0 && m_NumberOfPackagesShown != m_Total) { m_NumberOfPackagesShown += assetStorePurchases.list.Count(); } UpdateLoadBarMessage(); }
private void OnProductListFetched(AssetStorePurchases productList, bool fetchDetailsCalled) { GetPageFromTab <PaginatedPage>(PackageFilterTab.AssetStore).OnProductListFetched(productList, fetchDetailsCalled); }
public void OnProductListFetched(AssetStorePurchases purchases, bool fetchDetailsCalled) { var isSet = purchases.queryArgs?.isFilterSet == true; if (isSet && !filters.Equals(purchases.queryArgs)) { return; } if (purchases.startIndex > 0 && numTotalItems != purchases.total) { // if a new page has arrived but the total has changed or the searchText has changed, do a re-fetch var queryArgs = BuildQueryFromFilter((int)numCurrentItems, purchases.startIndex + purchases.list.Count); m_AssetStoreClient.ListPurchases(queryArgs); return; } var oldPackageIds = new HashSet <string>(m_VisualStateList.Select(v => v.packageUniqueId)); var newPackageIds = purchases.productIds.Select(id => id.ToString()).ToList(); if (purchases.startIndex == 0) { // override the result if the new list starts from index 0 (meaning it's a refresh) m_VisualStateList.Rebuild(newPackageIds); m_VisualStateList.ClearExtraItems(); m_VisualStateList.SetTotal(purchases.total); } else if (purchases.startIndex == numCurrentItems) { // append the result if it is the next page m_VisualStateList.AddRange(newPackageIds); m_VisualStateList.ClearExtraItems(); } else { // if the content is neither starting from zero or next page, we simply discard it return; } if (!fetchDetailsCalled && purchases.list.Any()) { m_AssetStoreClient.FetchDetails(purchases.productIds); } // only try to rebuild the list immediately if we are already on the `AssetStore` tab. // if not we'll just wait for tab switch which will trigger the rebuild as well if (m_PackageFiltering.currentFilterTab == PackageFilterTab.AssetStore) { HashSet <string> removed = null; List <string> added = null; if (purchases.startIndex == 0) { removed = oldPackageIds; added = new List <string>(); foreach (var id in newPackageIds) { if (removed.Contains(id)) { removed.Remove(id); } else { added.Add(id); } } } else if (purchases.startIndex == oldPackageIds.Count) { added = newPackageIds; } var addedPackages = added?.Select(id => m_PackageDatabase.GetPackage(id)); var removedPackages = removed?.Select(id => m_PackageDatabase.GetPackage(id)); TriggerOnListUpdate(addedPackages, removedPackages, false); } RefreshVisualStates(); }
public void OnProductListFetched(AssetStorePurchases 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 var queryArgs = new PurchasesQueryArgs { startIndex = 0, limit = productList.startIndex + productList.list.Count, searchText = PackageFiltering.instance.currentSearchText }; AssetStoreClient.instance.ListPurchases(queryArgs, 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.productIds); added = new List <long>(); foreach (var id in productList.productIds) { 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.queryArgs.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.productIds.ToList(); } } 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()) { AssetStoreClient.instance.FetchDetails(productList.productIds); } 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); } }