Exemplo n.º 1
0
        public ServicePage(ILoggingService loggingService, IDialogService dialogService, IDVBTDriverManager driver, DVBTTelevizorConfiguration config, PlayerPage playerPage)
        {
            InitializeComponent();

            _loggingService = loggingService;
            _dialogService  = dialogService;
            _driver         = driver;
            _config         = config;
            _playerPage     = playerPage;

            BindingContext           = _viewModel = new ServicePageViewModel(_loggingService, _dialogService, _driver, _config);
            _viewModel.TuneFrequency = "626";
            _viewModel.SelectedDeliverySystemType = _viewModel.DeliverySystemTypes[1];

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_UpdateDriverState, (message) =>
            {
                _viewModel.UpdateDriverState();
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_DVBTDriverConfigurationFailed, (message) =>
            {
                Device.BeginInvokeOnMainThread(delegate
                {
                    _viewModel.UpdateDriverState();
                });
            });
        }
Exemplo n.º 2
0
        public MainPage(ILoggingService loggingService, DVBTTelevizorConfiguration config, IDVBTDriverManager driverManager)
        {
            InitializeComponent();

            _dlgService = new DialogService(this);

            _loggingService = loggingService;

            _config = config;

            _driver = driverManager;

            try
            {
                _playerPage = new PlayerPage(_driver, _config);
            } catch (Exception ex)
            {
                _loggingService.Error(ex, "Error while initializing player page");
            }

            _channelService = new ConfigChannelService(_loggingService, _config);

            _tunePage        = new TunePage(_loggingService, _dlgService, _driver, _config, _channelService);
            _servicePage     = new ServicePage(_loggingService, _dlgService, _driver, _config, _playerPage);
            _settingsPage    = new SettingsPage(_loggingService, _dlgService, _config, _channelService);
            _editChannelPage = new ChannelPage(_loggingService, _dlgService, _driver, _config);

            Core.Initialize();

            _libVLC      = new LibVLC();
            _mediaPlayer = new MediaPlayer(_libVLC)
            {
                EnableHardwareDecoding = true
            };
            videoView.MediaPlayer = _mediaPlayer;

            BindingContext = _viewModel = new MainPageViewModel(_loggingService, _dlgService, _driver, _config, _channelService);

            if (_config.AutoInitAfterStart)
            {
                Task.Run(() =>
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(
                        new Action(
                            delegate
                    {
                        MessagingCenter.Send("", BaseViewModel.MSG_Init);
                    }));
                });
            }

            CheckStreamCommand = new Command(async() => await CheckStream());
            BackgroundCommandWorker.RunInBackground(CheckStreamCommand, 3, 5);

            _servicePage.Disappearing     += anyPage_Disappearing;
            _servicePage.Disappearing     += anyPage_Disappearing;
            _tunePage.Disappearing        += anyPage_Disappearing;
            _settingsPage.Disappearing    += anyPage_Disappearing;
            _editChannelPage.Disappearing += _editChannelPage_Disappearing;
            ChannelsListView.ItemSelected += ChannelsListView_ItemSelected;

            Appearing += MainPage_Appearing;

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_KeyDown, (key) =>
            {
                OnKeyDown(key);
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_EditChannel, (message) =>
            {
                Xamarin.Forms.Device.BeginInvokeOnMainThread(
                    delegate
                {
                    EditSelectedChannel();
                });
            });

            MessagingCenter.Subscribe <PlayStreamInfo> (this, BaseViewModel.MSG_PlayStream, (playStreamInfo) =>
            {
                Task.Run(async() =>
                {
                    await ActionPlay();
                });
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_DVBTDriverConfiguration, (message) =>
            {
                _loggingService.Debug($"Received DVBTDriverConfiguration message: {message}");

                if (!_driver.Started)
                {
                    _viewModel.ConnectDriver(message);
                }
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_UpdateDriverState, (message) =>
            {
                _viewModel.UpdateDriverState();
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_DVBTDriverConfigurationFailed, (message) =>
            {
                Device.BeginInvokeOnMainThread(delegate
                {
                    _viewModel.UpdateDriverState();

                    MessagingCenter.Send($"Device connection error ({message})", BaseViewModel.MSG_ToastMessage);
                });
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_PlayPreviousChannel, (msg) =>
            {
                OnKeyUp();
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_PlayNextChannel, (msg) =>
            {
                OnKeyDown();
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_StopStream, (msg) =>
            {
                StopPlayback();
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_ImportChannelsList, (message) =>
            {
                _viewModel.ImportCommand.Execute(message);
            });
        }