Exemplo n.º 1
0
        public BaseViewModel(ILoggingService loggingService, IDialogService dialogService, IDVBTDriverManager driver, DVBTTelevizorConfiguration config)
            : base(config)
        {
            _loggingService = loggingService;
            _dialogService  = dialogService;
            _driver         = driver;

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;

                do
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(
                        new Action(
                            delegate
                    {
                        OnPropertyChanged(nameof(DataStreamInfo));
                    }));

                    // 2 secs delay
                    Thread.Sleep(2 * 1000);
                } while (true);
            }).Start();
        }
Exemplo n.º 2
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.º 3
0
        public TunePage(ILoggingService loggingService, IDialogService dialogService, IDVBTDriverManager driver, DVBTTelevizorConfiguration config, ChannelService channelService)
        {
            InitializeComponent();

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

            BindingContext           = _viewModel = new TunePageViewModel(_loggingService, _dialogService, _driver, _config, channelService);
            _viewModel.TuneFrequency = "730";

            ChannelsListView.ItemSelected += ChannelsListView_ItemSelected;

            Appearing += TunePage_Appearing;

            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.º 4
0
        public App(ILoggingService loggingService, DVBTTelevizorConfiguration config, IDVBTDriverManager driverManager)
        {
            InitializeComponent();

            _loggingService = loggingService;
            _config         = config;
            _driver         = driverManager;

            _mainPage = new MainPage(_loggingService, config, driverManager);
            MainPage  = new NavigationPage(_mainPage);
        }
Exemplo n.º 5
0
        public PlayerPage(IDVBTDriverManager driver, DVBTTelevizorConfiguration config)
        {
            InitializeComponent();

            BindingContext = _viewModel = new PlayerPageViewModel(config);

            _driver = driver;

            Appearing += PlayerPage_Appearing;

            Core.Initialize();

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

            CheckStreamCommand = new Command(async() => await CheckStream());

            BackgroundCommandWorker.RunInBackground(CheckStreamCommand, 3, 5);
        }
Exemplo n.º 6
0
        public TunePageViewModel(ILoggingService loggingService, IDialogService dialogService, IDVBTDriverManager driver, DVBTTelevizorConfiguration config, ChannelService channelService)
            : base(loggingService, dialogService, driver, config)
        {
            _channelService = channelService;

            TuneCommand        = new Command(async() => await Tune());
            AbortTuneCommand   = new Command(async() => await AbortTune());
            FinishTunedCommand = new Command(async() => await FinishTune());
        }
Exemplo n.º 7
0
 public TuneViewModel(ILoggingService loggingService, IDialogService dialogService, IDVBTDriverManager driver, DVBTTelevizorConfiguration config)
     : base(loggingService, dialogService, driver, config)
 {
     FillFrequencyChannels();
 }
Exemplo n.º 8
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);
            });
        }
Exemplo n.º 9
0
        public ChannelPage(ILoggingService loggingService, IDialogService dialogService, IDVBTDriverManager driver, DVBTTelevizorConfiguration config)
        {
            InitializeComponent();

            _loggingService = loggingService;
            _dialogService  = dialogService;

            BindingContext = _viewModel = new ChannelPageViewModel(_loggingService, _dialogService, driver, config);

            Appearing += ChannelPage_Appearing;
        }
Exemplo n.º 10
0
        public MainPageViewModel(ILoggingService loggingService, IDialogService dialogService, IDVBTDriverManager driver, DVBTTelevizorConfiguration config, ChannelService channelService)
            : base(loggingService, dialogService, driver, config)
        {
            _channelService = channelService;

            RefreshCommand        = new Command(async() => await Refresh());
            RefreshEPGCommand     = new Command(async() => await RefreshEPG());
            LongPressCommand      = new Command(async(itm) => await LongPress(itm));
            VideoLongPressCommand = new Command(async(itm) => await VideoLongPress());
            ShortPressCommand     = new Command(ShortPress);
            ImportCommand         = new Command(async(json) => await ImportList(json));

            UpCommand    = new Command(async(key) => await AnyKeyPressed("up"));
            DownCommand  = new Command(async(key) => await AnyKeyPressed("down"));
            LeftCommand  = new Command(async(key) => await AnyKeyPressed("left"));
            RightCommand = new Command(async(key) => await AnyKeyPressed("right"));

            OKCommand   = new Command(async() => await AnyKeyPressed("enter"));
            BackCommand = new Command(async() => await AnyKeyPressed("escape"));

            AnimeIconCommand = new Command(async() => await Anime());

            BackgroundCommandWorker.RunInBackground(RefreshEPGCommand, 2, 10);
            BackgroundCommandWorker.RunInBackground(AnimeIconCommand, 1, 1);
        }
Exemplo n.º 11
0
        public ServicePageViewModel(ILoggingService loggingService, IDialogService dialogService, IDVBTDriverManager driver, DVBTTelevizorConfiguration config)
            : base(loggingService, dialogService, driver, config)
        {
            FillDeliverySystemTypes();

            GetVersionCommand      = new Command(async() => await GetVersion());
            GetStatusCommand       = new Command(async() => await GetStatus());
            GetCapabilitiesCommand = new Command(async() => await GetCapabilities());
            TuneCommand            = new Command(async() => await Tune());

            SetPIDsCommand = new Command(async() => await SetPIDs());

            PlayCommand = new Command(async() => await Play());

            ScanPSICommand = new Command(async() => await ScanPSI());
            ScanEITCommand = new Command(async() => await ScanEIT());

            StartRecordCommand = new Command(async() => await StartRecord());
            StopRecordCommand  = new Command(async() => await StopRecord());
        }
Exemplo n.º 12
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            if (Intent != null &&
                InstanceAlreadyStarted &&
                (Intent.Action == Intent.ActionView ||
                 Intent.Action == Intent.ActionSend))
            {
                HandleImportFile(Intent);
                Finish();
                return;
            }

            Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, savedInstanceState);
            Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;

            _config = new DVBTTelevizorConfiguration();

#if DEBUG
            _config.ShowServiceMenu = true;
            _config.ScanEPG         = true;
            _config.EnableLogging   = true;
            //_config.AutoInitAfterStart = false;
#endif

            InitLogging();

            _loggingService.Info("DVBTTelevizor starting");

            // workaround for not using FileProvider (necessary for file sharing):
            // https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.SetVmPolicy(builder.Build());

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            // prevent sleep:
            Window window = (Forms.Context as Activity).Window;
            window.AddFlags(WindowManagerFlags.KeepScreenOn);

            // https://stackoverflow.com/questions/39248138/how-to-hide-bottom-bar-of-android-back-home-in-xamarin-forms
            _defaultUiOptions = (int)Window.DecorView.SystemUiVisibility;

            _fullscreenUiOptions  = _defaultUiOptions;
            _fullscreenUiOptions |= (int)SystemUiFlags.LowProfile;
            _fullscreenUiOptions |= (int)SystemUiFlags.Fullscreen;
            _fullscreenUiOptions |= (int)SystemUiFlags.HideNavigation;
            _fullscreenUiOptions |= (int)SystemUiFlags.ImmersiveSticky;

            if (_config.Fullscreen)
            {
                SetFullScreen(true);
            }

            try
            {
                UsbManager manager = (UsbManager)GetSystemService(Context.UsbService);

                var usbReciever   = new USBBroadcastReceiverSystem();
                var intentFilter  = new IntentFilter(UsbManager.ActionUsbDeviceAttached);
                var intentFilter2 = new IntentFilter(UsbManager.ActionUsbDeviceDetached);
                RegisterReceiver(usbReciever, intentFilter);
                RegisterReceiver(usbReciever, intentFilter2);
                usbReciever.UsbAttachedOrDetached += CheckIfUsbAttachedOrDetached;
            } catch (Exception ex)
            {
                _loggingService.Error(ex, "Error while initializing UsbManager");
            }

#if TestingDVBTDriverManager
            _driverManager = new TestingDVBTDriverManager();
#else
            _driverManager = new DVBTDriverManager(_loggingService, _config);
#endif

            _notificationHelper = new NotificationHelper(this);

            _app = new App(_loggingService, _config, _driverManager);
            LoadApplication(_app);

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_Init, (message) =>
            {
                InitDriver();
            });

            MessagingCenter.Subscribe <SettingsPage>(this, BaseViewModel.MSG_CheckBatterySettings, (sender) =>
            {
                try
                {
                    var pm        = (PowerManager)Android.App.Application.Context.GetSystemService(Context.PowerService);
                    bool ignoring = pm.IsIgnoringBatteryOptimizations(AppInfo.PackageName);

                    if (!ignoring)
                    {
                        MessagingCenter.Send <string>(string.Empty, BaseViewModel.MSG_RequestBatterySettings);
                    }
                }
                catch (Exception ex)
                {
                    _loggingService.Error(ex);
                }
            });

            MessagingCenter.Subscribe <SettingsPage>(this, BaseViewModel.MSG_SetBatterySettings, (sender) =>
            {
                try
                {
                    var intent = new Intent();
                    intent.SetAction(Android.Provider.Settings.ActionIgnoreBatteryOptimizationSettings);
                    intent.SetFlags(ActivityFlags.NewTask);
                    Android.App.Application.Context.StartActivity(intent);
                }
                catch (Exception ex)
                {
                    _loggingService.Error(ex);
                }
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_ToastMessage, (message) =>
            {
                ShowToastMessage(message);
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_LongToastMessage, (message) =>
            {
                ShowToastMessage(message, 8000);
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_EnableFullScreen, (msg) =>
            {
                SetFullScreen(true);
            });
            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_DisableFullScreen, (msg) =>
            {
                SetFullScreen(false);
            });

            MessagingCenter.Subscribe <MainPage, PlayStreamInfo>(this, BaseViewModel.MSG_PlayInBackgroundNotification, (sender, playStreamInfo) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Task.Run(async() => await ShowPlayingNotification(playStreamInfo));
                });
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_StopPlayInBackgroundNotification, (sender) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    StopPlayingNotification();
                });
            });

            MessagingCenter.Subscribe <string>(this, BaseViewModel.MSG_ShareFile, (fileName) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Task.Run(async() => await ShareFile(fileName));
                });
            });

            InstanceAlreadyStarted = true;

            if (Intent != null &&
                InstanceAlreadyStarted &&
                (Intent.Action == Intent.ActionView ||
                 Intent.Action == Intent.ActionSend))
            {
                HandleImportFile(Intent);
            }
        }
Exemplo n.º 13
0
 public ChannelPageViewModel(ILoggingService loggingService, IDialogService dialogService, IDVBTDriverManager driver, DVBTTelevizorConfiguration config)
     : base(loggingService, dialogService, driver, config)
 {
     _loggingService = loggingService;
     _dialogService  = dialogService;
 }