private async Task OnOtpAuthScan(string uri) { Authenticator auth; try { auth = Authenticator.FromOtpAuthUri(uri); } catch { ShowSnackbar(Resource.String.qrCodeFormatError, Snackbar.LengthShort); return; } if (_authSource.IsDuplicate(auth)) { ShowSnackbar(Resource.String.duplicateAuthenticator, Snackbar.LengthShort); return; } try { await _connection.InsertAsync(auth); } catch (SQLiteException) { ShowSnackbar(Resource.String.genericError, Snackbar.LengthShort); return; } if (_authSource.CategoryId != null) { await _authSource.AddToCategory(_authSource.CategoryId, auth.Secret); } await _authSource.Update(); var position = _authSource.GetPosition(auth.Secret); RunOnUiThread(() => { _authListAdapter.NotifyItemInserted(position); _authList.SmoothScrollToPosition(position); }); ShowSnackbar(Resource.String.scanSuccessful, Snackbar.LengthShort); }
private async Task ScanQRCode() { var options = new MobileBarcodeScanningOptions { PossibleFormats = new List <BarcodeFormat> { BarcodeFormat.QR_CODE } }; var result = await _barcodeScanner.Scan(options); if (result == null) { return; } Authenticator auth; try { auth = Authenticator.FromKeyUri(result.Text); } catch { ShowSnackbar(Resource.String.qrCodeFormatError, Snackbar.LengthShort); return; } if (_authenticatorSource.IsDuplicate(auth)) { ShowSnackbar(Resource.String.duplicateAuthenticator, Snackbar.LengthShort); return; } await _connection.InsertAsync(auth); await _authenticatorSource.Update(); await SwitchCategory(null); CheckEmptyState(); var position = _authenticatorSource.GetPosition(auth.Secret); _authenticatorListAdapter.NotifyItemInserted(position); _authList.SmoothScrollToPosition(position); await NotifyWearAppOfChange(); }