示例#1
0
        public async Task <bool> AddUserFavriteAsync(Volume vol, string seriesTitle = "Untitled")
        {
            if (FavoriteList.Any(fav => fav.VolumeId == vol.Id))
            {
                return(true);
            }
            try
            {
                var favId = await LightKindomHtmlClient.AddUserFavoriteVolume(vol.Id);
                await SyncFavoriteListAsync(true);

                //FavourVolume favol = new FavourVolume
                //{
                //	VolumeId = vol.Id,
                //	FavId = favId,
                //	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> 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 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 <bool> AddUserFavriteAsync(string volId)
        {
            if (FavoriteList.Any(fav => fav.VolumeId == volId))
            {
                return(true);
            }
            try
            {
                var result = await LightKindomHtmlClient.AddUserFavoriteVolume(volId);

                if (!result)
                {
                    return(false);
                }
                await SyncFavoriteListAsync(true);

                return(true);
            }
            catch (Exception exception)
            {
                Debug.WriteLine("Error : Failed to Add User Favorite : " + exception.Message);
            }
            return(false);
        }