Example #1
0
        public async Task SyncFavoriteListAsync(bool forceRefresh = false)
        {
            try
            {
                var fav = await CachedClient.GetUserFavoriteVolumesAsync(!IsUserFavoriteValiad || forceRefresh);

                if (FavoriteList == null)
                {
                    FavoriteList = new ObservableCollection <FavourVolume>(fav);
                    //FavoriteList.CollectionChanged += FavoriteList_CollectionChanged;
                }
                else
                {
                    //FavoriteList.CollectionChanged -= FavoriteList_CollectionChanged;
                    FavoriteList.Clear();
                    foreach (var item in fav)
                    {
                        FavoriteList.Add(item);
                    }
                    //FavoriteList.CollectionChanged += FavoriteList_CollectionChanged;
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine("Error : Failed to Sync User Favorite : " + exception.Message);
                if (FavoriteList == null)
                {
                    FavoriteList = new ObservableCollection <FavourVolume>();
                }
            }
        }
        public async Task SyncFavoriteListAsync(bool forceRefresh = false)
        {
            try
            {
                var fav = await CachedClient.GetUserFavoriteVolumesAsync(!IsUserFavoriteValiad || forceRefresh);

                if (FavoriteList == null)
                {
                    FavoriteList = new ObservableCollection <FavourVolume>(fav);
                }
                else
                {
                    //FavoriteList.Clear();
                    var olds = FavoriteList.Except(fav, new FavItemEqualityComparer()).ToArray();
                    foreach (var item in olds)
                    {
                        FavoriteList.Remove(item);
                    }
                    var news = fav.Except(FavoriteList, new FavItemEqualityComparer()).ToArray();
                    foreach (var item in fav)
                    {
                        if (!FavoriteList.Any(f => f.VolumeId == item.VolumeId))
                        {
                            FavoriteList.Add(item);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine("Error : Failed to Sync User Favorite : " + exception.Message);
                if (FavoriteList == null)
                {
                    FavoriteList = new ObservableCollection <FavourVolume>();
                }
            }
        }