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>();
                }
            }
        }
Example #2
0
 async void FavoriteList_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Move)
     {
         return;
     }
     try
     {
         CachedClient.UpdateCachedUserFavoriteVolumes(FavoriteList);
         if (e.NewItems != null)
         {
             foreach (FavourVolume vol in e.NewItems)
             {
                 if (String.IsNullOrEmpty(vol.FavId))
                 {
                     await LightKindomHtmlClient.AddUserFavoriteVolume(vol.VolumeId);
                 }
             }
         }
         if (e.OldItems != null)
         {
             foreach (FavourVolume vol in e.OldItems)
             {
                 if (!String.IsNullOrEmpty(vol.FavId))
                 {
                     await LightKindomHtmlClient.DeleteUserFavorite(vol.FavId);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         Debug.WriteLine("Error : Failed to Sync User Favorite : " + exception.Message);
     }
 }
        public async Task <bool> RemoveUserFavriteAsync(string favId)
        {
            var vol = FavoriteList.FirstOrDefault(fav => fav.FavId == favId);

            if (String.IsNullOrEmpty(favId) || vol == null)
            {
                return(false);
            }
            try
            {
                await LightKindomHtmlClient.DeleteUserFavorite(favId);

                FavoriteList.Remove(vol);
                CachedClient.UpdateCachedUserFavoriteVolumes(FavoriteList);
                return(true);
            }
            catch (Exception exception)
            {
                Debug.WriteLine("Error : Failed to Remove User Favorite : " + exception.Message);
            }
            return(false);
        }
        public async Task <bool> AddUserFavriteAsync(Volume vol, string seriesTitle = null)
        {
            if (FavoriteList == null)
            {
                return(false);
            }
            if (FavoriteList.Any(fav => fav.VolumeId == vol.Id))
            {
                return(true);
            }
            try
            {
                var result = await LightKindomHtmlClient.AddUserFavoriteVolume(vol.Id);

                if (!result)
                {
                    return(false);
                }
                FavourVolume favol = new FavourVolume
                {
                    VolumeId      = vol.Id,
                    FavId         = null,
                    VolumeNo      = vol.VolumeNo.ToString(),
                    CoverImageUri = vol.CoverImageUri,
                    Description   = vol.Description,
                    VolumeTitle   = vol.Title,
                    SeriesTitle   = seriesTitle,
                    FavTime       = DateTime.Now.AddSeconds(-5)
                };
                FavoriteList.Add(favol);
                CachedClient.UpdateCachedUserFavoriteVolumes(FavoriteList);
                return(true);
            }
            catch (Exception exception)
            {
                Debug.WriteLine("Error : Failed to Add User Favorite : " + exception.Message);
            }
            return(false);
        }
        public async Task <bool> RemoveUserFavriteAsync(string[] favIds)
        {
            try
            {
                await LightKindomHtmlClient.DeleteUserFavorite(favIds);

                foreach (var favId in favIds)
                {
                    var f = FavoriteList.FirstOrDefault(fa => fa.FavId == favId);
                    if (f != null)
                    {
                        FavoriteList.Remove(f);
                    }
                }
                CachedClient.UpdateCachedUserFavoriteVolumes(FavoriteList);
                return(true);
            }
            catch (Exception exception)
            {
                Debug.WriteLine("Error : Failed to Remove User Favorite : " + exception.Message);
            }
            return(false);
        }
        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>();
                }
            }
        }
        public async Task ClearUserInfoAsync()
        {
            await LightKindomHtmlClient.LogoutAsync();

            await CachedClient.ClearUserFavoriteCacheAsync();
        }