Exemple #1
0
        void StartIfStopped()
        {
            Task.Run(async() =>
            {
                if (await _viewModel.IsRunning() == false)
                {
                    await _viewModel.StartENService();

                    /// If EN is disabled, then the OS dialog will pop up.
                    /// Calling the StartENService method again seems to make the EN api properly update its state, before we update our UI.
                    /// This is not an optimal solution, but seems to work fine as a workaround for now.
                    /// A better way would be for us to be able to listen to state changes in the EN api.
                    if (await _viewModel.IsEnabled() == false)
                    {
                        await _viewModel.StartENService();
                    }

                    if (await _permissionManager.PoweredOff())
                    {
                        DialogHelper.ShowBluetoothTurnedOffDialog(this);
                    }

                    InvokeOnMainThread(() =>
                    {
                        UpdateUI();
                    });
                }
            });
        }
Exemple #2
0
        private async void StartStopButton_Click(object sender, EventArgs e)
        {
            await _semaphoreSlim.WaitAsync();

            bool isRunning = await _viewModel.IsEnabled();

            switch (isRunning)
            {
            case true when !_permissionUtils.AreAllPermissionsGranted():
                PreventMultiplePermissionsDialogsForAction(_permissionUtils.HasPermissions);
                _semaphoreSlim.Release();
                break;

            case true:
                await DialogUtils.DisplayDialogAsync(
                    this,
                    _viewModel.OffDialogViewModel,
                    StopGoogleAPI,
                    () => _semaphoreSlim.Release());

                break;

            default:
                await DialogUtils.DisplayDialogAsync(
                    this,
                    _viewModel.OnDialogViewModel,
                    StartGoogleAPI,
                    () => _semaphoreSlim.Release());

                break;
            }

            UpdateUI();
        }
        private async void StartGoogleAPI()
        {
            try
            {
                await _viewModel.StartENService();

                bool isRunning = await _viewModel.IsRunning();

                if (isRunning)
                {
                    BackgroundFetchScheduler.ScheduleBackgroundFetch();
                }

                if (await _viewModel.IsEnabled() &&
                    !await _viewModel.IsRunning() &&
                    await BluetoothStateBroadcastReceiver.GetBluetoothState(UpdateUI) == BluetoothState.OFF)
                {
                    await _permissionUtils.HasPermissions();

                    // wait until BT state change will be completed
                    await BluetoothStateBroadcastReceiver.GetBluetoothState(UpdateUI);
                }
            }
            finally
            {
                UpdateUI();
            }
        }