Ejemplo n.º 1
0
        protected override void OnShowContextMenu()
        {
            if (GUIBackgroundTask.Instance.IsBusy)
            {
                return;
            }

            GUIListItem selectedItem = this.Facade.SelectedListItem;

            if (selectedItem == null)
            {
                return;
            }

            TraktListDetail selectedList = null;
            string          username     = CurrentUser;

            if (selectedItem.TVTag is TraktListDetail)
            {
                selectedList = selectedItem.TVTag as TraktListDetail;
            }
            else if (selectedItem.TVTag is TraktListTrending)
            {
                var trending = selectedItem.TVTag as TraktListTrending;
                selectedList = trending.List;
                username     = trending.List.User.Username;
            }
            else if (selectedItem.TVTag is TraktListPopular)
            {
                var popular = selectedItem.TVTag as TraktListPopular;
                selectedList = popular.List;
                username     = popular.List.User.Username;
            }
            else if (selectedItem.TVTag is TraktLike)
            {
                var likedItem = selectedItem.TVTag as TraktLike;
                selectedList = likedItem.List;
                username     = likedItem.List.User.Username;
            }

            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 (username == 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;
            }

            // allow viewing comments for any type of lists
            // if comments are not allowed there will most like be no comments
            if (selectedList.AllowComments)
            {
                listItem = new GUIListItem(Translation.Comments + "...");
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Comments;
            }

            // 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);
                selectedList.Likes++;
                PublishListProperties(selectedList);
                break;

            case ((int)ContextMenuItem.Unlike):
                GUICommon.UnLikeList(selectedList);
                if (selectedList.Likes > 0)
                {
                    // different behaviour basis the current view
                    if (ListType == TraktListType.Liked)
                    {
                        // remove liked list from cache and reload
                        TraktLists.RemovedItemFromLikedListCache(selectedList.Ids.Trakt);
                        LoadLists();
                    }
                    else
                    {
                        // update selected list properties as we have unliked it now.
                        selectedList.Likes--;
                        PublishListProperties(selectedList);
                    }
                }
                break;

            case ((int)ContextMenuItem.Comments):
                ReturningFromListItemsOrComments = true;
                TraktHelper.ShowListShouts(selectedList);
                break;

            default:
                break;
            }

            base.OnShowContextMenu();
        }
Ejemplo n.º 2
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();
        }