first version

This commit is contained in:
Vova
2024-01-28 20:00:36 +02:00
parent 1695c807c2
commit 709e14a2bd
11 changed files with 429 additions and 221 deletions
+66 -29
View File
@@ -8,12 +8,10 @@ namespace TV_Player
public class PlayerViewModel : ObservableViewModelBase, IDisposable
{
private M3UInfo _currentProgram;
public M3UInfo SelectedProgram
{
get => _currentProgram;
set => SetProperty(ref _currentProgram, value);
}
public delegate void SourceUrlChanged(string videoURL);
public event SourceUrlChanged SourceUrlChangedEvent;
private M3UInfo _currentProgram;
private string _topPaneTitle;
public string TopPanelTitle
@@ -50,40 +48,81 @@ namespace TV_Player
set => SetProperty(ref _endProgram, value);
}
public M3UInfo SelectedItem { get; set; }
private List<M3UInfo> _programs;
public ICommand BackCommand { get; }
public ICommand FullscreenCommand { get; }
public ICommand NextCommand { get; }
public ICommand PreviousCommand { get; }
private ProgramGuide _currentGuide;
private ProgramInfo _currentProgramInfo;
private IDisposable _programGuideDisposable;
private IDisposable _timer;
private IDisposable _programSubscriber;
private int _currentProgramIndex = 0;
public PlayerViewModel(M3UInfo selectedProgram)
{
_currentProgram = selectedProgram;
BackCommand = new RelayCommand(OnButtonBackClick);
TVPlayerViewModel.Instance.TopPanelVisible(false, selectedProgram.Name);
TopPanelTitle = selectedProgram.Name;
_programGuideDisposable = ProgramsData.Instance.ProgramGuideInfo.Subscribe(x =>
{
try
{
_currentGuide = x.FirstOrDefault(p => p.Id == selectedProgram.TvgID);
UpdateScreenInfo();
_timer = Observable.Interval(TimeSpan.FromMinutes(1)).Subscribe(x =>
{
UpdateScreenInfo();
});
}
catch { }
});
NextCommand = new RelayCommand(NextProgram);
PreviousCommand = new RelayCommand(PreviousProgram);
FullscreenCommand = new RelayCommand(TVPlayerViewModel.Instance.FullScreenToggle);
_programSubscriber = ProgramsData.Instance.AllPrograms.Subscribe(x =>
{
_programs = x.Where(p => p.GroupTitle == _currentProgram.GroupTitle).ToList();
_currentProgramIndex = _programs.Select((program, index) => new { program, index })
.Where(x => x.program.Name == _currentProgram.Name)
.Select(x => x.index)
.FirstOrDefault();
});
UpdateUI();
}
private void UpdateUI()
{
TVPlayerViewModel.Instance.TopPanelVisible(false, _currentProgram.Name);
TopPanelTitle = _currentProgram.Name;
SourceUrlChangedEvent?.Invoke(_currentProgram.Url);
_programGuideDisposable = ProgramsData.Instance.ProgramGuideInfo.Subscribe(x =>
{
try
{
_currentGuide = x.FirstOrDefault(p => p.Id == _currentProgram.TvgID);
UpdateScreenInfo();
_timer = Observable.Interval(TimeSpan.FromMinutes(1)).Subscribe(x =>
{
UpdateScreenInfo();
});
}
catch { }
});
}
private void PreviousProgram()
{
_currentProgramIndex -= 1;
if (_currentProgramIndex < 0)
_currentProgramIndex = _programs.Count - 1;
_currentProgram = _programs[_currentProgramIndex];
_programGuideDisposable?.Dispose();
UpdateUI();
}
private void NextProgram()
{
_currentProgramIndex += 1;
if (_currentProgramIndex > _programs.Count - 1)
_currentProgramIndex = 0;
_currentProgram = _programs[_currentProgramIndex];
_programGuideDisposable?.Dispose();
UpdateUI();
}
private void UpdateScreenInfo()
{
_currentProgramInfo = _currentGuide.Programs.FirstOrDefault(d => d.StartTime <= DateTime.Now && d.StopTime >= DateTime.Now);
@@ -96,8 +135,6 @@ namespace TV_Player
var programMinutes = (_currentProgramInfo.StopTime - _currentProgramInfo.StartTime).TotalMinutes;
DurationValue = (int)((DateTime.Now - _currentProgramInfo.StartTime).TotalMinutes / programMinutes * 100);
}
private void OnButtonBackClick()
{
var groupInfo = new GroupInfo() { Name = _currentProgram.GroupTitle, Count = 0 };
@@ -106,9 +143,9 @@ namespace TV_Player
var conrtrol = new ProgramsList();
TVPlayerViewModel.Instance.SetPageContext(conrtrol, programListViewModel);
}
public void Dispose()
{
_programSubscriber.Dispose();
_programGuideDisposable.Dispose();
_timer.Dispose();
}