Пример #1
0
        /// <summary>
        /// Get the slugs for each list selected by a user in the Multi-Select dialog
        /// </summary>
        /// <param name="username">username of user</param>
        /// <param name="lists">List of lists created by user</param>
        public static List <string> GetUserListSelections(List <TraktUserList> lists)
        {
            if (lists.Count == 0)
            {
                if (!GUIUtils.ShowYesNoDialog(Translation.Lists, Translation.NoListsFound, true))
                {
                    // nothing to do, return
                    return(null);
                }
                TraktList list = new TraktList();
                if (TraktLists.GetListDetailsFromUser(ref list))
                {
                    TraktLogger.Info("Creating new '{0}' list '{1}'", list.Privacy, list.Name);
                    TraktAddListResponse response = TraktAPI.TraktAPI.ListAdd(list);
                    TraktAPI.TraktAPI.LogTraktResponse <TraktResponse>(response);
                    if (response.Status == "success")
                    {
                        ClearCache(TraktSettings.Username);
                        return(new List <string> {
                            response.Slug
                        });
                    }
                }
                return(null);
            }

            List <MultiSelectionItem> selectedItems = GUIUtils.ShowMultiSelectionDialog(Translation.SelectLists, GetMultiSelectItems(lists));

            if (selectedItems == null)
            {
                return(null);
            }

            List <string> slugs = new List <string>();

            foreach (var item in selectedItems.Where(l => l.Selected == true))
            {
                slugs.Add(item.ItemID);
            }
            return(slugs);
        }
Пример #2
0
        /// <summary>
        /// Get the ids for each list selected by a user in the Multi-Select dialog
        /// </summary>
        public static List <int> GetUserListSelections(List <TraktListDetail> lists)
        {
            if (lists.Count == 0)
            {
                if (!GUIUtils.ShowYesNoDialog(Translation.Lists, Translation.NoListsFound, true))
                {
                    // nothing to do, return
                    return(null);
                }
                var list = new TraktListDetail();
                if (TraktLists.GetListDetailsFromUser(ref list))
                {
                    TraktLogger.Info("Creating new list for user online. Privacy = '{0}', Name = '{1}'", list.Privacy, list.Name);
                    var response = TraktAPI.TraktAPI.CreateCustomList(list);
                    if (response != null)
                    {
                        ClearListCache(TraktSettings.Username);
                        return(new List <int> {
                            (int)response.Ids.Trakt
                        });
                    }
                }
                return(null);
            }

            List <MultiSelectionItem> selectedItems = GUIUtils.ShowMultiSelectionDialog(Translation.SelectLists, GetMultiSelectItems(lists));

            if (selectedItems == null)
            {
                return(null);
            }

            var listIds = new List <int>();

            foreach (var item in selectedItems.Where(l => l.Selected == true))
            {
                listIds.Add(int.Parse(item.ItemID));
            }
            return(listIds);
        }
Пример #3
0
        internal static void AddRemoveItemInList(List <string> slugs, List <TraktListItem> items, bool remove)
        {
            Thread listThread = new Thread(delegate(object obj)
            {
                foreach (var slug in slugs)
                {
                    TraktList list = new TraktList
                    {
                        UserName = TraktSettings.Username,
                        Password = TraktSettings.Password,
                        Slug     = slug,
                        Items    = items
                    };
                    TraktSyncResponse response = null;
                    if (!remove)
                    {
                        response = TraktAPI.TraktAPI.ListAddItems(list);
                    }
                    else
                    {
                        response = TraktAPI.TraktAPI.ListDeleteItems(list);
                    }

                    TraktAPI.TraktAPI.LogTraktResponse <TraktSyncResponse>(response);
                    if (response.Status == "success")
                    {
                        // clear current items in any lists
                        // list items will be refreshed online if we try to request them
                        TraktLists.ClearItemsInList(TraktSettings.Username, slug);
                    }
                }
            })
            {
                Name         = remove ? "RemoveList" : "AddList",
                IsBackground = true
            };

            listThread.Start();
        }
Пример #4
0
        public static void AddRemoveEpisodeInUserList(string username, string title, string year, string season, string episode, string tvdbid, bool remove)
        {
            if (!GUICommon.CheckLogin(false))
            {
                return;
            }

            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                return(TraktLists.GetListsForUser(username));
            },
                                                                      delegate(bool success, object result)
            {
                if (success)
                {
                    IEnumerable <TraktUserList> customlists = result as IEnumerable <TraktUserList>;

                    // get slug of lists selected
                    List <string> slugs = TraktLists.GetUserListSelections(customlists.ToList());
                    if (slugs == null || slugs.Count == 0)
                    {
                        return;
                    }

                    TraktListItem item = new TraktListItem
                    {
                        Type    = TraktItemType.episode.ToString(),
                        Title   = title,
                        Year    = Convert.ToInt32(year),
                        Season  = Convert.ToInt32(season),
                        Episode = Convert.ToInt32(episode),
                        TvdbId  = tvdbid
                    };

                    AddRemoveItemInList(slugs, item, remove);
                }
            }, Translation.GettingLists, true);
        }