client/src/Iri.Modernisation.Controls/ViewModel/ConsultationBookView/ConsultationBookViewVM.cs
changeset 42 594fdedecf7f
parent 35 43bb1b8ed555
child 46 ab3057b82260
equal deleted inserted replaced
41:b51a10574e7f 42:594fdedecf7f
    52                 
    52                 
    53                 return _selectedIndex;
    53                 return _selectedIndex;
    54             }
    54             }
    55             set
    55             set
    56             {
    56             {
    57                 _selectedIndex = value;
    57                 if (value != null)
    58                 _selectedIndexTitle = ((SegmentIndex)value).Title;
    58                 {
    59                 _selectedIndexDescription = ((SegmentIndex)value).Description;
    59                     _selectedIndex = value;
    60                 _selectedIndexTags = ((SegmentIndex)value).Tags;
    60                     _selectedIndexTitle = ((SegmentIndex)value).Title;
    61                 _selectedBook = _selectedIndex.Chapter.Book;
    61                     _selectedIndexDescription = ((SegmentIndex)value).Description;
    62                 _title = _selectedIndex.Chapter.Book.Title;
    62                     _selectedIndexTags = ((SegmentIndex)value).Tags;
    63                 _author = _selectedIndex.Chapter.Book.Author;
    63                     _selectedBook = _selectedIndex.Chapter.Book;
    64                 _chapters = _selectedIndex.Chapter.Book.Chapters;
    64                     _title = _selectedIndex.Chapter.Book.Title;
    65                 _selectedIndexAnnotation.Clear();
    65                     _author = _selectedIndex.Chapter.Book.Author;
    66                 List<AnnotationViewerVM> _temp = new List<AnnotationViewerVM>();
    66                     _chapters = _selectedIndex.Chapter.Book.Chapters;
    67                 foreach (Annotation An in ((SegmentIndex)value).Chapter.Annotations)
    67                     _selectedIndexAnnotation.Clear();
    68                 {
    68                     List<AnnotationViewerVM> _temp = new List<AnnotationViewerVM>();
    69                     if (An.TimerIn <= ((SegmentIndex)value).TimerOut && An.TimerOut >= ((SegmentIndex)value).TimerIn)
    69                     foreach (Annotation An in ((SegmentIndex)value).Chapter.Annotations)
    70                     {
    70                     {
    71                           _temp.Add(new AnnotationViewerVM (An));
    71                         if (An.TimerIn <= ((SegmentIndex)value).TimerOut && An.TimerOut >= ((SegmentIndex)value).TimerIn)
       
    72                         {
       
    73                             _temp.Add(new AnnotationViewerVM(An));
       
    74                         }
    72                     }
    75                     }
    73                 }
    76                     SelectedIndexAnnotation = _temp;
    74                 SelectedIndexAnnotation = _temp;
    77                 }
    75 
    78                 else
       
    79                 {
       
    80                     _selectedIndex = null;
       
    81                     _selectedIndexTitle = String.Empty;
       
    82                     _selectedIndexDescription = String.Empty;
       
    83                     _selectedIndexTags = new List<string>();
       
    84                     _selectedBook = null;
       
    85                     _title = null;
       
    86                     _author = null;
       
    87                     _chapters = null;
       
    88                     _selectedIndexAnnotation.Clear();
       
    89                   
       
    90                     SelectedIndexAnnotation = new List<AnnotationViewerVM>();
       
    91                 }
    76                 OnPropertyChanged(null);
    92                 OnPropertyChanged(null);
    77             
    93             
    78          
    94          
    79             }
    95             }
    80         }
    96         }
   167                 return _title;
   183                 return _title;
   168             }
   184             }
   169             private set
   185             private set
   170             {
   186             {
   171                 _title = value;
   187                 _title = value;
   172                 _selectedBook.Title = value;
   188            
   173                 OnPropertyChanged("Title");
   189                 OnPropertyChanged("Title");
   174             }
   190             }
   175         }
   191         }
   176 
   192 
   177         private User _author;
   193         private User _author;
   185                 return _author;
   201                 return _author;
   186             }
   202             }
   187             private set
   203             private set
   188             {
   204             {
   189                 _author = value;
   205                 _author = value;
   190                 _selectedBook.Author = value;
   206             
   191                 OnPropertyChanged("Author");
   207                 OnPropertyChanged("Author");
   192             }
   208             }
   193 
   209 
   194         }
   210         }
   195 
   211 
   204                 return _chapters;
   220                 return _chapters;
   205             }
   221             }
   206             private set
   222             private set
   207             {
   223             {
   208                 _chapters = value;
   224                 _chapters = value;
   209                 _selectedBook.Chapters = value;
   225         
   210                 OnPropertyChanged("Chapters");
   226                 OnPropertyChanged("Chapters");
   211             }
   227             }
   212         }
   228         }
   213 
   229 
   214         private List<SegmentIndex>[] _segmentIndex = new List<SegmentIndex>[4];
   230         private List<SegmentIndex>[] _segmentIndex = new List<SegmentIndex>[4];
   255             {
   271             {
   256                 return _selectedBookVM;
   272                 return _selectedBookVM;
   257             }
   273             }
   258             set
   274             set
   259             {
   275             {
   260                 _selectedBookVM = value;
   276                 if (value != null)
   261              
   277                 {
   262                 _selectedBook = value.SelectedBook;
   278                     _selectedBookVM = value;
   263                 _title = value.SelectedBook.Title;
   279 
   264                 _author = value.SelectedBook.Author;
   280                     _selectedBook = value.SelectedBook;
   265                 _chapters = value.SelectedBook.Chapters;
   281                     _title = value.SelectedBook.Title;
   266                 ActualVideoSourceVM.Source = value.SelectedBook.MediaPath;
   282                     _author = value.SelectedBook.Author;
       
   283                     _chapters = value.SelectedBook.Chapters;
       
   284                     ActualVideoSourceVM.Source = value.SelectedBook.MediaPath;
   267                     ActualVideoSourceVM.Position = TimeSpan.FromMilliseconds(value.Position);
   285                     ActualVideoSourceVM.Position = TimeSpan.FromMilliseconds(value.Position);
   268                
   286 
   269                
   287 
   270                 
   288 
   271                 SelectedIndex = value.SelectedBook.Chapters[0].Index[0];
   289                     SelectedIndex = value.SelectedBook.Chapters[0].Index[0];
   272              
   290                     Commands.GoToTime.Execute(value.Position);
   273                 OnPropertyChanged(null);
   291                 }
   274                 Commands.GoToTime.Execute(value.Position);
   292                 else
       
   293                 {
       
   294                     _selectedBookVM = null;
       
   295                     _selectedBook = null;
       
   296                     _title = null;
       
   297                     _author = null;
       
   298                     _chapters = null;
       
   299                     ActualVideoSourceVM.Source = null;
       
   300                     ActualVideoSourceVM.Position = TimeSpan.Zero;
       
   301                     SelectedIndex = null;
       
   302                 }
       
   303                 OnPropertyChanged(String.Empty);
       
   304               
   275             }
   305             }
   276         }
   306         }
   277         private VideoViewerVM _actualVideoSourceVM;
   307         private VideoViewerVM _actualVideoSourceVM;
   278         /// <summary>
   308         /// <summary>
   279         /// Video Actuellement en visionnage
   309         /// Video Actuellement en visionnage
   311                 ActualVideoSourceVM = new VideoViewerVM(true,false) { Source = param.SelectedBook.MediaPath }; 
   341                 ActualVideoSourceVM = new VideoViewerVM(true,false) { Source = param.SelectedBook.MediaPath }; 
   312             }
   342             }
   313             SelectedIndex = param.SelectedBook.Chapters[0].Index[0];
   343             SelectedIndex = param.SelectedBook.Chapters[0].Index[0];
   314             
   344             
   315             InitializeCommands();
   345             InitializeCommands();
   316 
   346            
   317 
   347           
       
   348 
       
   349         }
       
   350 
       
   351         void ActualVideoSourceVM_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
       
   352         {
       
   353          
       
   354             if (e.PropertyName == "Position")
       
   355             {
       
   356                 if (SelectedBook != null)
       
   357                 {
       
   358                     TimeSpan Pos = TimeSpan.FromMilliseconds(SelectedBookVM.Position);
       
   359                     SelectedBookVM.Position = Pos.TotalMilliseconds;
       
   360                     if (SelectedIndex.TimerOut < Pos || SelectedIndex.TimerIn > Pos)
       
   361                     {
       
   362                         foreach (SegmentIndex Index in SelectedIndex.Chapter.Index)
       
   363                         {
       
   364                             if (Index.TimerIn <= Pos && Index.TimerOut >= Pos)
       
   365                             {
       
   366                                 SelectedIndex = Index;
       
   367                             }
       
   368 
       
   369                         }
       
   370                     }
       
   371                 }
       
   372             }
   318         }
   373         }
   319         private void InitializeCommands()
   374         private void InitializeCommands()
   320         {
   375         {
   321             ActualVideoSourceVM.Tick += new EventHandler<VideoViewerVMEventArgs>(ActualVideoSourceVM_Tick);
   376             ActualVideoSourceVM.Tick += new EventHandler<VideoViewerVMEventArgs>(ActualVideoSourceVM_Tick);
   322               }
   377             Commands.TimeChange.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(TimeChange_Executed);
   323 
   378         }
   324         private void ActualVideoSourceVM_Tick(object sender, VideoViewerVMEventArgs e)
   379 
   325         {
   380         void TimeChange_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
   326             if(SelectedBook!=null)
   381         {
   327             {
   382             BookTimeLineVM BookTimeLineVM = (BookTimeLineVM)e.Source;
   328                 TimeSpan Pos = e.Position; 
   383 
       
   384             if (BookTimeLineVM == this.SelectedBookVM)
       
   385             {
       
   386                 UpdateAnnotation();
       
   387             }
       
   388         }
       
   389 
       
   390         private void UpdateAnnotation()
       
   391         {
       
   392             if (SelectedBook != null)
       
   393             {
       
   394                 TimeSpan Pos = TimeSpan.FromMilliseconds(SelectedBookVM.Position);
   329                 SelectedBookVM.Position = Pos.TotalMilliseconds;
   395                 SelectedBookVM.Position = Pos.TotalMilliseconds;
   330                 if (SelectedIndex.TimerOut < Pos || SelectedIndex.TimerIn > Pos)
   396                 if (SelectedIndex.TimerOut < Pos || SelectedIndex.TimerIn > Pos)
   331                 {
   397                 {
   332                     foreach (SegmentIndex Index in SelectedIndex.Chapter.Index)
   398                     foreach (SegmentIndex Index in SelectedIndex.Chapter.Index)
   333                     {
   399                     {
   338 
   404 
   339                     }
   405                     }
   340                 }
   406                 }
   341             }
   407             }
   342         }
   408         }
       
   409 
       
   410         private void ActualVideoSourceVM_Tick(object sender, VideoViewerVMEventArgs e)
       
   411         {
       
   412             SelectedBookVM.Position =  e.Position.TotalMilliseconds;
       
   413             UpdateAnnotation();
       
   414         }
   343        
   415        
   344     }
   416     }
   345 }
   417 }