/// <summary>
        /// Get all details needed to create a new list or edit existing list
        /// </summary>
        /// <param name="list">returns list details</param>
        /// <returns>true if list details completed</returns>
        public static bool GetListDetailsFromUser(ref TraktListDetail list)
        {
            // the list will have ids if it exists online
            bool editing = list.Ids != null;

            // Show Keyboard for Name of list
            string name = editing ? list.Name : string.Empty;
            if (!GUIUtils.GetStringFromKeyboard(ref name)) return false;
            if ((list.Name = name) == string.Empty) return false;

            // Skip Description and get Privacy...this requires a custom dialog as
            // virtual keyboard does not allow very much text for longer descriptions.
            // We may create a custom dialog for this in future
            var items = new List<GUIListItem>();
            var item = new GUIListItem();
            int selectedItem = 0;

            // Public
            item = new GUIListItem { Label = Translation.PrivacyPublic, Label2 = Translation.Public };
            if (list.Privacy == "public") { selectedItem = 0; item.Selected = true; }
            items.Add(item);
            // Private
            item = new GUIListItem { Label = Translation.PrivacyPrivate, Label2 = Translation.Private };
            if (list.Privacy == "private") { selectedItem = 1; item.Selected = true; }
            items.Add(item);
            // Friends
            item = new GUIListItem { Label = Translation.PrivacyFriends, Label2 = Translation.Friends };
            if (list.Privacy == "friends") { selectedItem = 2; item.Selected = true; }
            items.Add(item);

            selectedItem = GUIUtils.ShowMenuDialog(Translation.Privacy, items, selectedItem);
            if (selectedItem == -1) return false;

            list.Privacy = GetPrivacyLevelFromTranslation(items[selectedItem].Label2);

            // Skip 'Show Shouts' and 'Use Numbering' until we have Custom Dialog for List edits

            return true;
        }
Example #2
0
        private void SendListsToFacade(IEnumerable<TraktListDetail> lists)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (lists == null)
            {
                GUIUtils.ShowNotifyDialog(Translation.Error, Translation.ErrorGeneral);
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            if (lists.Count() == 0 && TraktSettings.Username != CurrentUser)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), string.Format(Translation.NoUserLists, CurrentUser));
                CurrentUser = TraktSettings.Username;
                GUIWindowManager.ShowPreviousWindow();
                return;
            }

            if (lists.Count() == 0)
            {
                if (!GUIUtils.ShowYesNoDialog(Translation.Lists, Translation.NoListsFound, true))
                {
                    // nothing to do, exit
                    GUIWindowManager.ShowPreviousWindow();
                    return;
                }

                var list = new TraktListDetail();
                if (TraktLists.GetListDetailsFromUser(ref list))
                {
                    TraktLogger.Info("Creating new list online. Privacy = '{0}', Name = '{1}'", list.Privacy, list.Name);
                    CreateList(list);
                }
                return;
            }

            int itemId = 0;

            // Add each list
            foreach (var list in lists)
            {
                var item = new GUIListItem(list.Name);

                item.Label2 = string.Format("{0} {1}", list.ItemCount, list.ItemCount != 1 ? Translation.Items : Translation.Item);
                item.TVTag = list;
                item.ItemId = Int32.MaxValue - itemId;
                item.PinImage = TraktLists.GetPrivacyLevelIcon(list.Privacy);
                item.IconImage = "defaultFolder.png";
                item.IconImageBig = "defaultFolderBig.png";
                item.ThumbnailImage = "defaultFolderBig.png";
                item.OnItemSelected += OnItemSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout("List");
            GUIControl.FocusControl(GetID, Facade.GetID);

            if (PreviousSelectedIndex >= lists.Count())
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            else
                Facade.SelectIndex(PreviousSelectedIndex);

            // set facade properties
            GUIUtils.SetProperty("#itemcount", lists.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", lists.Count().ToString(), lists.Count() > 1 ? Translation.Lists : Translation.List));
        }
Example #3
0
 private void PublishListProperties(TraktListDetail list)
 {
     if (list == null) return;
     GUICommon.SetListProperties(list, CurrentUser);
 }
Example #4
0
        private void EditList(TraktListDetail list)
        {
            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                return TraktAPI.TraktAPI.UpdateCustomList(list);
            },
            delegate(bool success, object result)
            {
                if (success)
                {
                    var response = result as TraktListDetail;
                    if (response == null)
                    {
                        // reload with new list
                        TraktLists.ClearListCache(TraktSettings.Username);
                        LoadLists();

                        var thread = new Thread((o) =>
                        {
                            TraktCache.ClearCustomListCache();

                            // updated MovingPictures categories and filters menu
                            if (TraktHelper.IsMovingPicturesAvailableAndEnabled)
                            {
                                TraktHandlers.MovingPictures.UpdateCategoriesMenu(SyncListType.CustomList);
                                TraktHandlers.MovingPictures.UpdateFiltersMenu(SyncListType.CustomList);
                            }
                        })
                        {
                            Name = "EditList",
                            IsBackground = true
                        };
                        thread.Start();
                    }
                    else
                    {
                        GUIUtils.ShowNotifyDialog(Translation.Lists, Translation.FailedUpdateList);
                    }
                }
            }, Translation.EditingList, true);
        }
Example #5
0
        private void DeleteList(TraktListDetail list)
        {
            if (!GUIUtils.ShowYesNoDialog(Translation.Lists, Translation.ConfirmDeleteList, false))
            {
                return;
            }

            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                TraktLogger.Info("Deleting list from online. Name = '{0}', Id = '{1}'", list.Name, list.Ids.Trakt);
                return TraktAPI.TraktAPI.DeleteUserList("me", list.Ids.Trakt.ToString());
            },
            delegate(bool success, object result)
            {
                if (success)
                {
                    if ((result as bool?) == true)
                    {
                        // remove from MovingPictures categories and filters menu
                        if (TraktHelper.IsMovingPicturesAvailableAndEnabled)
                        {
                            // not very thread safe if we tried to delete more than one before response!
                            TraktHandlers.MovingPictures.RemoveCustomListNode(list.Name);
                        }

                        // reload with new list
                        TraktLists.ClearListCache(TraktSettings.Username);
                        LoadLists();
                    }
                    else
                    {
                        GUIUtils.ShowNotifyDialog(Translation.Lists, Translation.FailedDeleteList);
                    }
                }
            }, Translation.DeletingList, true);
        }
Example #6
0
        private void CopyList(TraktListDetail sourceList, TraktListDetail newList)
        {
            var copyList = new CopyList { Username = CurrentUser, Source = sourceList, Destination = newList };

            var copyThread = new Thread((obj) =>
            {
                var copyParams = obj as CopyList;

                // first create new list
                TraktLogger.Info("Creating new list online. Privacy = '{0}', Name = '{1}'", copyParams.Destination.Privacy, copyParams.Destination.Name);
                var response = TraktAPI.TraktAPI.CreateCustomList(copyParams.Destination);
                if (response != null)
                {
                    // get items from other list
                    var userListItems = TraktAPI.TraktAPI.GetUserListItems(copyParams.Username, copyParams.Source.Ids.Trakt.ToString(), "min");

                    // copy items to new list
                    var itemsToAdd = new TraktSyncAll();
                    foreach (var item in userListItems)
                    {
                        var listItem = new TraktListItem();
                        listItem.Type = item.Type;

                        switch (item.Type)
                        {
                            case "movie":
                                if (itemsToAdd.Movies == null)
                                    itemsToAdd.Movies = new List<TraktMovie>();

                                itemsToAdd.Movies.Add(new TraktMovie { Ids = item.Movie.Ids });
                                break;

                            case "show":
                                if (itemsToAdd.Shows == null)
                                    itemsToAdd.Shows = new List<TraktShow>();

                                itemsToAdd.Shows.Add(new TraktShow { Ids = item.Show.Ids });
                                break;

                            case "season":
                                if (itemsToAdd.Seasons == null)
                                    itemsToAdd.Seasons = new List<TraktSeason>();

                                itemsToAdd.Seasons.Add(new TraktSeason { Ids = item.Season.Ids });
                                break;

                            case "episode":
                                if (itemsToAdd.Episodes == null)
                                    itemsToAdd.Episodes = new List<TraktEpisode>();

                                itemsToAdd.Episodes.Add(new TraktEpisode { Ids = item.Episode.Ids });
                                break;

                            case "person":
                                if (itemsToAdd.People == null)
                                    itemsToAdd.People = new List<TraktPerson>();

                                itemsToAdd.People.Add(new TraktPerson { Ids = item.Person.Ids });
                                break;
                        }
                    }

                    // add items to the list
                    var ItemsAddedResponse = TraktAPI.TraktAPI.AddItemsToList("me", response.Ids.Trakt.ToString(), itemsToAdd);

                    if (ItemsAddedResponse != null)
                    {
                        TraktLists.ClearListCache(TraktSettings.Username);
                        TraktCache.ClearCustomListCache();

                        // updated MovingPictures categories and filters menu
                        if (TraktHelper.IsMovingPicturesAvailableAndEnabled)
                        {
                            TraktHandlers.MovingPictures.UpdateCategoriesMenu(SyncListType.CustomList);
                            TraktHandlers.MovingPictures.UpdateFiltersMenu(SyncListType.CustomList);
                        }
                    }
                }
            })
            {
                Name = "CopyList",
                IsBackground = true
            };
            copyThread.Start(copyList);
        }
Example #7
0
        protected override void OnShowContextMenu()
        {
            if (GUIBackgroundTask.Instance.IsBusy) return;

            GUIListItem selectedItem = this.Facade.SelectedListItem;
            if (selectedItem == null) return;

            var selectedList = selectedItem.TVTag as TraktListDetail;
            if (selectedItem == null) return;

            var dlg = (IDialogbox)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (dlg == null) return;

            dlg.Reset();
            dlg.SetHeading(GUIUtils.PluginName());

            GUIListItem listItem = null;

            // only allow add/delete/update if viewing your own lists
            if (CurrentUser == TraktSettings.Username)
            {
                listItem = new GUIListItem(Translation.CreateList);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Create;

                listItem = new GUIListItem(Translation.EditList);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Edit;

                listItem = new GUIListItem(Translation.DeleteList);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Delete;
            }
            else
            {
                // like list
                if (!selectedList.IsLiked())
                {
                    listItem = new GUIListItem(Translation.Like);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.Like;
                }
                else
                {
                    // unLike list
                    listItem = new GUIListItem(Translation.UnLike);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.Unlike;
                }

                // copy a friends list
                listItem = new GUIListItem(Translation.CopyList);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Copy;
            }

            // Show Context Menu
            dlg.DoModal(GUIWindowManager.ActiveWindow);
            if (dlg.SelectedId < 0) return;

            var currentList = new TraktListDetail
            {
                Ids = selectedList.Ids,
                Name = selectedList.Name,
                Description = selectedList.Description,
                Privacy = selectedList.Privacy,
                AllowComments = selectedList.AllowComments,
                DisplayNumbers = selectedList.DisplayNumbers,
                ItemCount = selectedList.ItemCount,
                Likes = selectedList.Likes,
                UpdatedAt = selectedList.UpdatedAt
            };

            switch (dlg.SelectedId)
            {
                case ((int)ContextMenuItem.Create):
                    var list = new TraktListDetail();
                    if (TraktLists.GetListDetailsFromUser(ref list))
                    {
                        if (Lists.Any(l => l.Name == list.Name))
                        {
                            // list with that name already exists
                            GUIUtils.ShowNotifyDialog(Translation.Lists, Translation.ListNameAlreadyExists);
                            return;
                        }
                        TraktLogger.Info("Creating new list for user online. Privacy = '{0}', Name = '{1}'", list.Privacy, list.Name);
                        CreateList(list);
                    }
                    break;

                case ((int)ContextMenuItem.Delete):
                    DeleteList(selectedList);
                    break;

                case ((int)ContextMenuItem.Edit):
                    if (TraktLists.GetListDetailsFromUser(ref currentList))
                    {
                        TraktLogger.Info("Editing list. Name = '{0}', Id = '{1}'", currentList.Name);
                        EditList(currentList);
                    }
                    break;

                case ((int)ContextMenuItem.Copy):
                    if (TraktLists.GetListDetailsFromUser(ref currentList))
                    {
                        CopyList(selectedList, currentList);
                    }
                    break;

                case ((int)ContextMenuItem.Like):
                    GUICommon.LikeList(selectedList, CurrentUser);
                    selectedList.Likes++;
                    PublishListProperties(selectedList);
                    break;

                case ((int)ContextMenuItem.Unlike):
                    GUICommon.UnLikeList(selectedList, CurrentUser);
                    if (selectedList.Likes > 0)
                    {
                        selectedList.Likes--;
                        PublishListProperties(selectedList);
                    }
                    break;

                default:
                    break;
            }

            base.OnShowContextMenu();
        }
Example #8
0
        public static void LikeList(TraktListDetail list, string username)
        {
            var likeThread = new Thread((obj) =>
            {
                // all list to likes cache
                TraktCache.AddListToLikes((TraktListDetail)obj);

                TraktAPI.TraktAPI.LikeList(username, ((TraktListDetail)obj).Ids.Trakt.Value);
            })
            {
                Name = "LikeList",
                IsBackground = true
            };

            likeThread.Start(list);
        }
Example #9
0
 internal static void SetListProperties(TraktListDetail list, string username)
 {
     SetProperty("#Trakt.List.Name", list.Name);
     SetProperty("#Trakt.List.Description", list.Description);
     SetProperty("#Trakt.List.Privacy", list.Privacy);
     SetProperty("#Trakt.List.Slug", list.Ids.Slug);
     SetProperty("#Trakt.List.Url", string.Format("http://trakt.tv/users/{0}/lists/{1}", username, list.Ids.Trakt));
     SetProperty("#Trakt.List.AllowShouts", list.AllowComments);
     SetProperty("#Trakt.List.ShowNumbers", list.DisplayNumbers);
     SetProperty("#Trakt.List.UpdatedAt", list.UpdatedAt.FromISO8601().ToShortDateString());
     SetProperty("#Trakt.List.ItemCount", list.ItemCount);
     SetProperty("#Trakt.List.Comments", list.Comments);
     SetProperty("#Trakt.List.Likes", list.Likes);
     SetProperty("#Trakt.List.Id", list.Ids.Trakt);
     SetProperty("#Trakt.List.Slug", list.Ids.Slug);
 }
Example #10
0
        public static void UnLikeList(TraktListDetail list, string username)
        {
            var unlikeThread = new Thread((obj) =>
            {
                // remove list from likes cache
                TraktCache.RemoveListFromLikes((TraktListDetail)obj);

                TraktAPI.TraktAPI.UnLikeList(username, ((TraktListDetail)obj).Ids.Trakt.Value);
            })
            {
                Name = "UnLikeList",
                IsBackground = true
            };

            unlikeThread.Start(list);
        }
Example #11
0
 public static TraktListDetail UpdateCustomList(TraktListDetail list, string username = "******")
 {
     var response = ReplaceOnTrakt(string.Format(TraktURIs.UserListEdit, username), list.ToJSON());
     return response.FromJSON<TraktListDetail>();
 }
Example #12
0
        internal static void RemoveListFromLikes(TraktListDetail list)
        {
            if (_LikedLists == null)
                return;

            var likedLists = _LikedLists.ToList();
            likedLists.RemoveAll(l => l.List.Ids.Trakt == list.Ids.Trakt);

            _LikedLists = likedLists;
        }
Example #13
0
        internal static void AddListToLikes(TraktListDetail list)
        {
            var likedLists = (_LikedLists ?? new List<TraktLike>()).ToList();

            likedLists.Add(new TraktLike
            {
                LikedAt = DateTime.UtcNow.ToISO8601(),
                List = list,
                Type = "list"
            });

            _LikedLists = likedLists;
        }
Example #14
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;
        }