Beispiel #1
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;

            if (element != null && item != null)
            {
                if (item.GetType() == typeof(VM_Playlist))
                {
                    return(element.FindResource("Playlist_PlaylistTemplate") as DataTemplate);
                }

                if (item.GetType() == typeof(VM_PlaylistItem))
                {
                    VM_PlaylistItem pli = item as VM_PlaylistItem;


                    if (pli.ItemType == PlaylistItemType.AnimeSeries)
                    {
                        return(element.FindResource("Playlist_AnimeSeriesTemplate") as DataTemplate);
                    }
                    if (pli.ItemType == PlaylistItemType.Episode)
                    {
                        return(element.FindResource("Playlist_AnimeEpisodeTemplate") as DataTemplate);
                    }
                }
            }

            return(null);
        }
Beispiel #2
0
        public void DragOver(IDropInfo dropInfo)
        {
            VM_PlaylistItem sourceItem = dropInfo.Data as VM_PlaylistItem;
            VM_PlaylistItem targetItem = dropInfo.TargetItem as VM_PlaylistItem;

            if (sourceItem != null && targetItem != null)
            {
                dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
                dropInfo.Effects           = DragDropEffects.Copy;
            }
        }
Beispiel #3
0
        /// <summary>
        /// This event bubbles up from PlayEpisodeControl
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommandBinding_ToggleWatchedStatus(object sender, ExecutedRoutedEventArgs e)
        {
            object obj = e.Parameter;

            if (obj == null)
            {
                return;
            }

            Cursor = Cursors.Wait;

            try
            {
                Window parentWindow         = Window.GetWindow(this);
                VM_AnimeSeries_User serTemp = null;
                bool newStatus = false;

                if (obj.GetType() == typeof(VM_VideoDetailed))
                {
                    VM_VideoDetailed vid = obj as VM_VideoDetailed;
                    newStatus = !vid.Watched;
                    VM_ShokoServer.Instance.ShokoServices.ToggleWatchedStatusOnVideo(vid.VideoLocalID, newStatus, VM_ShokoServer.Instance.CurrentUser.JMMUserID);

                    VM_MainListHelper.Instance.UpdateHeirarchy(vid);

                    serTemp = VM_MainListHelper.Instance.GetSeriesForVideo(vid.VideoLocalID);
                }

                if (obj.GetType() == typeof(VM_AnimeEpisode_User))
                {
                    VM_AnimeEpisode_User ep = obj as VM_AnimeEpisode_User;
                    newStatus = !ep.Watched;
                    CL_Response <CL_AnimeEpisode_User> response = VM_ShokoServer.Instance.ShokoServices.ToggleWatchedStatusOnEpisode(ep.AnimeEpisodeID,
                                                                                                                                     newStatus, VM_ShokoServer.Instance.CurrentUser.JMMUserID);
                    if (!string.IsNullOrEmpty(response.ErrorMessage))
                    {
                        MessageBox.Show(response.ErrorMessage, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    VM_MainListHelper.Instance.UpdateHeirarchy((VM_AnimeEpisode_User)response.Result);

                    serTemp = VM_MainListHelper.Instance.GetSeriesForEpisode(ep);
                }

                if (obj.GetType() == typeof(VM_PlaylistItem))
                {
                    VM_PlaylistItem      pli = obj as VM_PlaylistItem;
                    VM_AnimeEpisode_User ep  = pli.PlaylistItem as VM_AnimeEpisode_User;

                    newStatus = !ep.Watched;
                    CL_Response <CL_AnimeEpisode_User> response = VM_ShokoServer.Instance.ShokoServices.ToggleWatchedStatusOnEpisode(ep.AnimeEpisodeID,
                                                                                                                                     newStatus, VM_ShokoServer.Instance.CurrentUser.JMMUserID);
                    if (!string.IsNullOrEmpty(response.ErrorMessage))
                    {
                        MessageBox.Show(response.ErrorMessage, Shoko.Commons.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    VM_MainListHelper.Instance.UpdateHeirarchy((VM_AnimeEpisode_User)response.Result);

                    serTemp = VM_MainListHelper.Instance.GetSeriesForEpisode(ep);
                }

                VM_Playlist pl = DataContext as VM_Playlist;
                if (pl == null)
                {
                    return;
                }

                pl.PopulatePlaylistObjects();
                ShowNextEpisode();

                if (newStatus == true && serTemp != null)
                {
                    Utils.PromptToRateSeries(serTemp, parentWindow);
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
            finally
            {
                Cursor = Cursors.Arrow;
            }
        }
Beispiel #4
0
        private void CommandBinding_PlayEpisode(object sender, ExecutedRoutedEventArgs e)
        {
            Window parentWindow = Window.GetWindow(this);

            object obj = e.Parameter;

            if (obj == null)
            {
                return;
            }

            try
            {
                if (obj.GetType() == typeof(VM_PlaylistItem))
                {
                    VM_PlaylistItem pli = obj as VM_PlaylistItem;

                    VM_AnimeEpisode_User ep = null;

                    if (pli.ItemType == Models.Enums.PlaylistItemType.Episode)
                    {
                        ep = pli.PlaylistItem as VM_AnimeEpisode_User;
                    }
                    if (pli.ItemType == Models.Enums.PlaylistItemType.AnimeSeries)
                    {
                        VM_AnimeSeries_User ser = pli.PlaylistItem as VM_AnimeSeries_User;
                        if (ser == null)
                        {
                            return;
                        }

                        ep = (VM_AnimeEpisode_User)VM_ShokoServer.Instance.ShokoServices.GetNextUnwatchedEpisode(ser.AnimeSeriesID,
                                                                                                                 VM_ShokoServer.Instance.CurrentUser.JMMUserID);
                    }

                    if (ep == null)
                    {
                        return;
                    }
                    ep.SetTvDBInfo();
                    if (ep.FilesForEpisode.Count == 1)
                    {
                        bool force = true;
                        if (MainWindow.videoHandler.DefaultPlayer.Player.ToString() !=
                            Enum.GetName(typeof(VideoPlayer), VideoPlayer.WindowsDefault))
                        {
                            if (ep.FilesForEpisode[0].VideoLocal_ResumePosition > 0)
                            {
                                AskResumeVideo ask = new AskResumeVideo(ep.FilesForEpisode[0].VideoLocal_ResumePosition);
                                ask.Owner = Window.GetWindow(this);
                                if (ask.ShowDialog() == true)
                                {
                                    force = false;
                                }
                            }
                        }
                        MainWindow.videoHandler.PlayVideo(ep.FilesForEpisode[0], force);
                    }
                    else if (ep.FilesForEpisode.Count > 1)
                    {
                        if (AppSettings.AutoFileSingleEpisode)
                        {
                            VM_VideoDetailed vid = MainWindow.videoHandler.GetAutoFileForEpisode(ep);
                            if (vid != null)
                            {
                                bool force = true;
                                if (MainWindow.videoHandler.DefaultPlayer.Player.ToString() !=
                                    Enum.GetName(typeof(VideoPlayer), VideoPlayer.WindowsDefault))
                                {
                                    if (vid.VideoLocal_ResumePosition > 0)
                                    {
                                        AskResumeVideo ask = new AskResumeVideo(vid.VideoLocal_ResumePosition);
                                        ask.Owner = Window.GetWindow(this);
                                        if (ask.ShowDialog() == true)
                                        {
                                            force = false;
                                        }
                                    }
                                }
                                MainWindow.videoHandler.PlayVideo(vid, force);
                            }
                        }
                        else
                        {
                            PlayVideosForEpisodeForm frm = new PlayVideosForEpisodeForm();
                            frm.Owner = parentWindow;
                            frm.Init(ep);
                            frm.ShowDialog();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }
        }
Beispiel #5
0
        public void Drop(IDropInfo dropInfo)
        {
            PlaylistItemType itemType = PlaylistItemType.AnimeSeries;
            int objIDOld = -1;

            VM_PlaylistItem pli = dropInfo.Data as VM_PlaylistItem;

            if (pli == null)
            {
                return;
            }

            if (pli.ItemType == PlaylistItemType.Episode)
            {
                VM_AnimeEpisode_User ep = (VM_AnimeEpisode_User)pli.PlaylistItem;
                itemType = PlaylistItemType.Episode;
                objIDOld = ep.AnimeEpisodeID;
            }
            if (pli.ItemType == PlaylistItemType.AnimeSeries)
            {
                VM_AnimeSeries_User ep = (VM_AnimeSeries_User)pli.PlaylistItem;
                itemType = PlaylistItemType.AnimeSeries;
                objIDOld = ep.AnimeSeriesID;
            }

            int iType = (int)itemType;

            // find where this item was previously

            if (string.IsNullOrEmpty(PlaylistItems))
            {
                return;
            }

            string[] items = PlaylistItems.Split('|');

            // create a new list without the moved item
            string newItemList = "";

            foreach (string pitem in items)
            {
                string[] parms = pitem.Split(';');
                if (parms.Length != 2)
                {
                    continue;
                }

                int objType;
                int objID;

                if (!int.TryParse(parms[0], out objType))
                {
                    continue;
                }
                if (!int.TryParse(parms[1], out objID))
                {
                    continue;
                }

                if (objType == iType && objID == objIDOld)
                {
                    // skip the old item
                }
                else
                {
                    if (newItemList.Length > 0)
                    {
                        newItemList += "|";
                    }
                    newItemList += $"{objType};{objID}";
                }
            }

            // insert the moved item into it's new position
            items = newItemList.Split('|');

            PlaylistItems = "";
            int curPos = 0;

            if (string.IsNullOrEmpty(newItemList))
            {
                // means there was only one item in list to begin with
                PlaylistItems += $"{iType};{objIDOld}";
            }
            else
            {
                foreach (string pitem in items)
                {
                    string[] parms = pitem.Split(';');
                    if (parms.Length != 2)
                    {
                        continue;
                    }

                    int objType;
                    int objID;

                    int.TryParse(parms[0], out objType);
                    int.TryParse(parms[1], out objID);

                    if (curPos == dropInfo.InsertIndex)
                    {
                        // insert moved item
                        if (PlaylistItems.Length > 0)
                        {
                            PlaylistItems += "|";
                        }
                        PlaylistItems += $"{iType};{objIDOld}";
                    }


                    if (PlaylistItems.Length > 0)
                    {
                        PlaylistItems += "|";
                    }
                    PlaylistItems += $"{objType};{objID}";

                    curPos++;
                }
            }

            // moved to the end of the list
            if (dropInfo.InsertIndex > items.Length)
            {
                if (PlaylistItems.Length > 0)
                {
                    PlaylistItems += "|";
                }
                PlaylistItems += $"{iType};{objIDOld}";
            }

            Save();
            PopulatePlaylistObjects();

            VM_PlaylistHelper.Instance.OnPlaylistModified(new PlaylistModifiedEventArgs(PlaylistID));
        }