Esempio n. 1
0
        public override void OnCreate()
        {
            base.OnCreate();

            if (_schedule == null)
            {
                var intent     = new Intent(ApplicationContext, typeof(RadioStationScheduleService));
                var connection = ServiceConnectionFactory.Create <RadioStationScheduleService>(service =>
                {
                    if (service != null)
                    {
                        _schedule          = service;
                        _schedule.Changed += OnScheduleChanged;
                    }
                    else if (_schedule != null)
                    {
                        _schedule.Changed -= OnScheduleChanged;
                        _schedule          = null;
                    }
                });

                if (BindService(intent, connection, Bind.AutoCreate))
                {
                    _connections.Add(connection);
                }
            }

            if (_playingHandler == null)
            {
                _playingHandler = new Handler();
                _playingHandler.Post(OnPlaying);
            }
        }
Esempio n. 2
0
        protected override void OnDestroy()
        {
            if (_view != null)
            {
                _view.Detach(OnDetachView);
                _view = null;
            }

            if (_networkStatus != null)
            {
                _networkStatus.Dispose();
                _networkStatus = null;
            }

            if (_connections != null)
            {
                foreach (var connection in _connections)
                {
                    UnbindService(connection);
                }

                _connections = null;
            }

            _service  = null;
            _schedule = null;

            base.OnDestroy();
        }
Esempio n. 3
0
        public override void OnDestroy()
        {
            if (_connections != null)
            {
                foreach (var connection in _connections)
                {
                    UnbindService(connection);
                }

                _connections = null;
            }

            if (_playingHandler != null)
            {
                _playingHandler.Dispose();
                _playingHandler = null;
            }

            if (_player != null)
            {
                _player.Dispose();
                _player = null;
            }

            if (_schedule != null)
            {
                _schedule.Dispose();
                _schedule = null;
            }

            if (_notificationManager != null)
            {
                _notificationManager.Stop();
                _notificationManager = null;
            }

            if (_mediaSession != null)
            {
                _mediaSession.Dispose();
                _mediaSession = null;
            }

            base.OnDestroy();
        }
Esempio n. 4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            if (!string.IsNullOrEmpty(AppCenterConfig.AppSecret))
            {
                AppCenter.Start(AppCenterConfig.AppSecret, typeof(Analytics), typeof(Crashes));
            }

            base.Window.RequestFeature(Android.Views.WindowFeatures.ActionBar);
            base.SetTheme(Resource.Style.AppTheme);

            base.OnCreate(savedInstanceState);

            if (_connections == null)
            {
                _connections = new List <IServiceConnection>();

                var intent            = new Intent(ApplicationContext, typeof(RadioStationService));
                var serviceConnection = ServiceConnectionFactory.Create <RadioStationService>(service =>
                {
                    if (service != null)
                    {
                        _service               = service;
                        _service.Playing      += OnRadioStationPlaying;
                        _service.StateChanged += OnRadioStationStateChanged;
                        _service.Error        += OnRadioStationError;
                    }
                    else if (_service != null)
                    {
                        _service.Playing      -= OnRadioStationPlaying;
                        _service.StateChanged -= OnRadioStationStateChanged;
                        _service.Error        -= OnRadioStationError;
                        _service = null;
                    }
                });

                if (BindService(intent, serviceConnection, Bind.AutoCreate))
                {
                    _connections.Add(serviceConnection);
                }

                intent = new Intent(ApplicationContext, typeof(RadioStationScheduleService));
                var scheduleConnection = ServiceConnectionFactory.Create <RadioStationScheduleService>(service =>
                {
                    if (service != null)
                    {
                        _schedule          = service;
                        _schedule.Changed += OnRadioStationScheduleChanged;
                    }
                    else if (_service != null)
                    {
                        _schedule.Changed -= OnRadioStationScheduleChanged;
                        _schedule          = null;
                    }
                });

                if (BindService(intent, scheduleConnection, Bind.AutoCreate))
                {
                    _connections.Add(scheduleConnection);
                }
            }

            SetContentView(Resource.Layout.MainActivity);

            if (_view == null)
            {
                _view = new MainActivityView(this).Attach(OnAttachView);
            }

            if (_networkStatus == null)
            {
                _networkStatus = new NetworkStatus(ApplicationContext, connected: OnNetworkConnected, disconnected: OnNetworkDisconnected);
            }

            _view.UpdateNetworkStatus(_networkStatus.IsConnected);

            if (_service != null)
            {
                _view.UpdateState(_service.IsPlaying);
            }

            if (_schedule != null)
            {
                RunOnUiThread(() => _view.UpdateNowPlaying(_schedule.NowPlaying));
            }
        }