Ejemplo n.º 1
0
        public AuthenticatorListAdapter(Context context, IAuthenticatorService authenticatorService,
                                        IAuthenticatorView authenticatorView, ICustomIconRepository customIconRepository, bool isDark)
        {
            _authenticatorService = authenticatorService;
            _authenticatorView    = authenticatorView;
            _customIconRepository = customIconRepository;

            var preferences = new PreferenceWrapper(context);

            _viewMode      = ViewModeSpecification.FromName(preferences.ViewMode);
            _tapToReveal   = preferences.TapToReveal;
            _codeGroupSize = preferences.CodeGroupSize;
            _isDark        = isDark;

            _customIconDecodeLock = new SemaphoreSlim(1, 1);
            _decodedCustomIcons   = new Dictionary <string, Bitmap>();

            _generationOffsets      = new Dictionary <int, long>();
            _counterCooldownOffsets = new Dictionary <int, long>();
            _positionsToUpdate      = new Queue <int>();
            _offsetsToUpdate        = new Queue <int>();

            _animationScale =
                Settings.Global.GetFloat(context.ContentResolver, Settings.Global.AnimatorDurationScale, 1.0f);
        }
Ejemplo n.º 2
0
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            await _onCreateLock.WaitAsync();

            SetContentView(Resource.Layout.activityMain);
            _preferences = new PreferenceWrapper(this);

            _authCache       = new ListCache <WearAuthenticator>(AuthenticatorCacheName, this);
            _categoryCache   = new ListCache <WearCategory>(CategoryCacheName, this);
            _customIconCache = new CustomIconCache(this);

            await _authCache.Init();

            await _categoryCache.Init();

            _authSource = new AuthenticatorSource(_authCache);
            var defaultCategory = _preferences.DefaultCategory;

            if (defaultCategory != null)
            {
                _authSource.SetCategory(defaultCategory);
            }

            RunOnUiThread(InitViews);
            _onCreateLock.Release();
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = base.OnCreateView(inflater, container, savedInstanceState);

            SetupToolbar(view, Resource.String.prefPasswordTitle);

            _preferences = new PreferenceWrapper(Context);
            _hasPassword = _preferences.PasswordProtected;

            _progressBar = view.FindViewById <ProgressBar>(Resource.Id.appBarProgressBar);

            _setPasswordButton        = view.FindViewById <MaterialButton>(Resource.Id.buttonSetPassword);
            _setPasswordButton.Click += OnSetPasswordButtonClick;

            _passwordText              = view.FindViewById <TextInputEditText>(Resource.Id.editPassword);
            _passwordText.TextChanged += delegate { UpdateSetPasswordButton(); };

            _passwordConfirmLayout = view.FindViewById <TextInputLayout>(Resource.Id.editPasswordConfirmLayout);
            _passwordConfirmText   = view.FindViewById <TextInputEditText>(Resource.Id.editPasswordConfirm);
            TextInputUtil.EnableAutoErrorClear(_passwordConfirmLayout);

            _passwordConfirmText.EditorAction += (_, e) =>
            {
                if (_setPasswordButton.Enabled && e.ActionId == ImeAction.Done)
                {
                    OnSetPasswordButtonClick(null, null);
                }
            };

            _cancelButton        = view.FindViewById <MaterialButton>(Resource.Id.buttonCancel);
            _cancelButton.Click += delegate { Dismiss(); };

            UpdateSetPasswordButton();
            return(view);
        }
Ejemplo n.º 4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // If a setting that requires changes to the main activity has changed
            // return a result telling it to recreate.
            _shouldRecreateMain = savedInstanceState != null && savedInstanceState.GetBoolean("shouldRecreateMain", false);
            _preferences        = new PreferenceWrapper(this);

            SetContentView(Resource.Layout.activitySettings);
            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolbar);

            SupportActionBar.SetTitle(Resource.String.settings);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetDisplayShowHomeEnabled(true);
            SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_action_arrow_back);

            var prefs = PreferenceManager.GetDefaultSharedPreferences(this);

            prefs.RegisterOnSharedPreferenceChangeListener(this);

            _fragment = new SettingsFragment();
            _fragment.PreferencesCreated += delegate
            {
                UpdateBackupRemindersEnabled(prefs);
                UpdateSecuritySettingsEnabled();
            };

            SupportFragmentManager.BeginTransaction()
            .Replace(Resource.Id.layoutFragment, _fragment)
            .Commit();
        }
Ejemplo n.º 5
0
        private void OnNavigationItemSelected(object sender, BottomNavigationView.NavigationItemSelectedEventArgs e)
        {
            switch (e.Item.ItemId)
            {
            case Resource.Id.intro_prev:
                _pager.CurrentItem--;
                break;

            case Resource.Id.intro_next:
                _pager.CurrentItem++;
                break;

            case Resource.Id.intro_done:
            {
                _ = new PreferenceWrapper(this)
                {
                    FirstLaunch = false
                };
                Finish();
                break;
            }
            }

            OnPageSelected();
        }
Ejemplo n.º 6
0
        protected void UpdateTheme()
        {
            var preferences = new PreferenceWrapper(this);
            var theme       = preferences.Theme;

            if (theme == _lastTheme)
            {
                return;
            }

            switch (theme)
            {
            default:
                IsDark = (Resources.Configuration.UiMode & UiMode.NightMask) == UiMode.NightYes;
                AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightFollowSystem;
                break;

            case "light":
                IsDark = false;
                AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;
                break;

            case "dark":
                IsDark = true;
                AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightYes;
                break;
            }

            _lastTheme = theme;
        }
Ejemplo n.º 7
0
 public override void OnCreate()
 {
     base.OnCreate();
     ProcessLifecycleOwner.Get().Lifecycle.AddObserver(this);
     _preferences = new PreferenceWrapper(Context);
     IsLocked     = true;
 }
Ejemplo n.º 8
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            SetStyle(StyleNormal, Resource.Style.BottomSheetStyle);
            var prefs = new PreferenceWrapper(Context);

            Context.Theme.ApplyStyle(AccentColourMap.GetOverlay(prefs.AccentColour), true);
            return(inflater.Inflate(_layout, container, false));
        }
Ejemplo n.º 9
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = base.OnCreateView(inflater, container, savedInstanceState);

            SetupToolbar(view, Resource.String.prefAutoBackupTitle, true);

            _preferences = new PreferenceWrapper(Context);

            var selectLocationButton = view.FindViewById <LinearLayout>(Resource.Id.buttonSelectLocation);

            selectLocationButton.Click += OnSelectLocationClick;

            var setPasswordButton = view.FindViewById <LinearLayout>(Resource.Id.buttonSetPassword);

            setPasswordButton.Click += OnSetPasswordButtonClick;

            _locationStatusText = view.FindViewById <TextView>(Resource.Id.textLocationStatus);
            _passwordStatusText = view.FindViewById <TextView>(Resource.Id.textPasswordStatus);

            _backupNowButton        = view.FindViewById <MaterialButton>(Resource.Id.buttonBackupNow);
            _backupNowButton.Click += OnBackupNowButtonClick;

            _restoreNowButton        = view.FindViewById <MaterialButton>(Resource.Id.buttonRestoreNow);
            _restoreNowButton.Click += OnRestoreNowButtonClick;

            _okButton        = view.FindViewById <MaterialButton>(Resource.Id.buttonOk);
            _okButton.Click += delegate { Dismiss(); };

            void SwitchChecked(object sender, CompoundButton.CheckedChangeEventArgs args)
            {
                if (args.IsChecked)
                {
                    ShowBatteryOptimisationDialog();
                }
            }

            _backupEnabledSwitch = view.FindViewById <SwitchMaterial>(Resource.Id.switchBackupEnabled);
            _backupEnabledSwitch.CheckedChange += SwitchChecked;

            _restoreEnabledSwitch = view.FindViewById <SwitchMaterial>(Resource.Id.switchRestoreEnabled);
            _restoreEnabledSwitch.CheckedChange += SwitchChecked;

            UpdateLocationStatusText();
            UpdateSwitchesAndTriggerButton();

            if (_preferences.DatabasePasswordBackup)
            {
                setPasswordButton.Visibility = ViewStates.Gone;
            }
            else
            {
                UpdatePasswordStatusText();
            }

            return(view);
        }
Ejemplo n.º 10
0
        private async Task GetPreferences(string nodeId)
        {
            var preferences = new PreferenceWrapper(this);
            var settings    = new WearPreferences(preferences.DefaultCategory);
            var json        = JsonConvert.SerializeObject(settings);
            var data        = Encoding.UTF8.GetBytes(json);

            await WearableClass.GetMessageClient(this)
            .SendMessageAsync(nodeId, GetPreferencesCapability, data);
        }
Ejemplo n.º 11
0
        public override void OnCreate()
        {
            base.OnCreate();

            AppDomain.CurrentDomain.UnhandledException  += OnCurrentDomainUnhandledException;
            AndroidEnvironment.UnhandledExceptionRaiser += OnAndroidEnvironmentUnhandledExceptionRaised;
            TaskScheduler.UnobservedTaskException       += OnTaskSchedulerUnobservedTaskException;

            ProcessLifecycleOwner.Get().Lifecycle.AddObserver(this);
            _preferences = new PreferenceWrapper(Context);
        }
Ejemplo n.º 12
0
        public override View OnCreateView(LayoutInflater contextInflater, ViewGroup container,
                                          Bundle savedInstanceState)
        {
            var contextThemeWrapper = new ContextThemeWrapper(Activity, Resource.Style.BottomSheetStyle);
            var prefs = new PreferenceWrapper(Context);

            contextThemeWrapper.Theme.ApplyStyle(AccentColourMap.GetOverlayId(prefs.AccentColour), true);
            StyledInflater = contextInflater.CloneInContext(contextThemeWrapper);

            return(StyledInflater.Inflate(_layout, container, false));
        }
Ejemplo n.º 13
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activityUnlock);
            Window.SetSoftInputMode(SoftInput.AdjustPan);

            _preferences = new PreferenceWrapper(this);

            SetResult(Result.Canceled);

            _passwordLayout = FindViewById <TextInputLayout>(Resource.Id.editPasswordLayout);
            _passwordText   = FindViewById <TextInputEditText>(Resource.Id.editPassword);
            TextInputUtil.EnableAutoErrorClear(_passwordLayout);

            _passwordText.EditorAction += (_, e) =>
            {
                if (e.ActionId == ImeAction.Done)
                {
                    OnUnlockButtonClick(null, null);
                }
            };

            _passwordText.TextChanged += delegate
            {
                _unlockButton.Enabled = _passwordText.Text != "";
            };

            _unlockButton        = FindViewById <MaterialButton>(Resource.Id.buttonUnlock);
            _unlockButton.Click += OnUnlockButtonClick;

            var canUseBiometrics = false;

            if (_preferences.AllowBiometrics)
            {
                var biometricManager = BiometricManager.From(this);
                canUseBiometrics = biometricManager.CanAuthenticate() == BiometricManager.BiometricSuccess;
            }

            _useBiometricsButton         = FindViewById <MaterialButton>(Resource.Id.buttonUseBiometrics);
            _useBiometricsButton.Enabled = canUseBiometrics;
            _useBiometricsButton.Click  += delegate
            {
                ShowBiometricPrompt();
            };

            if (canUseBiometrics)
            {
                ShowBiometricPrompt();
            }
            else
            {
                await FocusPasswordText();
            }
        }
Ejemplo n.º 14
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activityManageCategories);

            _preferences = new PreferenceWrapper(this);

            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolbar);

            SupportActionBar.SetTitle(Resource.String.categories);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetDisplayShowHomeEnabled(true);
            SupportActionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_action_arrow_back);

            _rootLayout = FindViewById <RelativeLayout>(Resource.Id.layoutRoot);

            _addButton        = FindViewById <FloatingActionButton>(Resource.Id.buttonAdd);
            _addButton.Click += OnAddClick;

            var connection = await Database.GetSharedConnection();

            _categorySource                   = new CategorySource(connection);
            _categoryListAdapter              = new ManageCategoriesListAdapter(_categorySource);
            _categoryListAdapter.MenuClick   += OnMenuClick;
            _categoryListAdapter.HasStableIds = true;
            _categoryListAdapter.DefaultId    = _preferences.DefaultCategory;

            _categoryList     = FindViewById <RecyclerView>(Resource.Id.list);
            _emptyStateLayout = FindViewById <LinearLayout>(Resource.Id.layoutEmptyState);

            _categoryList.SetAdapter(_categoryListAdapter);
            _categoryList.HasFixedSize = true;

            var layout = new FixedGridLayoutManager(this, 1);

            _categoryList.SetLayoutManager(layout);

            var callback    = new ReorderableListTouchHelperCallback(this, _categoryListAdapter, layout);
            var touchHelper = new ItemTouchHelper(callback);

            touchHelper.AttachToRecyclerView(_categoryList);

            var decoration = new DividerItemDecoration(this, layout.Orientation);

            _categoryList.AddItemDecoration(decoration);

            var layoutAnimation = AnimationUtils.LoadLayoutAnimation(this, Resource.Animation.layout_animation_fade_in);

            _categoryList.LayoutAnimation = layoutAnimation;

            await Refresh();
        }
Ejemplo n.º 15
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = base.OnCreateView(inflater, container, savedInstanceState);

            SetupToolbar(view, Resource.String.unlock);

            _preferences = new PreferenceWrapper(Context);
            _progressBar = view.FindViewById <ProgressBar>(Resource.Id.appBarProgressBar);

            _passwordLayout = view.FindViewById <TextInputLayout>(Resource.Id.editPasswordLayout);
            _passwordText   = view.FindViewById <TextInputEditText>(Resource.Id.editPassword);
            TextInputUtil.EnableAutoErrorClear(_passwordLayout);

            _passwordText.EditorAction += (_, e) =>
            {
                if (e.ActionId == ImeAction.Done)
                {
                    UnlockAttempted?.Invoke(this, _passwordText.Text);
                }
            };

            _unlockButton        = view.FindViewById <MaterialButton>(Resource.Id.buttonUnlock);
            _unlockButton.Click += delegate
            {
                UnlockAttempted?.Invoke(this, _passwordText.Text);
            };

            if (_preferences.AllowBiometrics)
            {
                var biometricManager = BiometricManager.From(Context);
                _canUseBiometrics = biometricManager.CanAuthenticate(BiometricManager.Authenticators.BiometricStrong) ==
                                    BiometricManager.BiometricSuccess;
            }

            _useBiometricsButton         = view.FindViewById <MaterialButton>(Resource.Id.buttonUseBiometrics);
            _useBiometricsButton.Enabled = _canUseBiometrics;
            _useBiometricsButton.Click  += delegate
            {
                ShowBiometricPrompt();
            };

            if (_canUseBiometrics)
            {
                ShowBiometricPrompt();
            }
            else
            {
                FocusPasswordText();
            }

            return(view);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Window.SetSoftInputMode(SoftInput.AdjustResize);
            SetResult(Result.Canceled);

            _preferences       = new PreferenceWrapper(this);
            _unlockLayout      = FindViewById <LinearLayout>(Resource.Id.layoutUnlock);
            _progressIndicator = FindViewById <LinearProgressIndicator>(Resource.Id.progressIndicator);

            _passwordLayout = FindViewById <TextInputLayout>(Resource.Id.editPasswordLayout);
            _passwordText   = FindViewById <TextInputEditText>(Resource.Id.editPassword);
            TextInputUtil.EnableAutoErrorClear(_passwordLayout);

            _passwordText.EditorAction += (_, e) =>
            {
                if (e.ActionId == ImeAction.Done)
                {
                    OnUnlockButtonClick(null, null);
                }
            };

            _unlockButton        = FindViewById <MaterialButton>(Resource.Id.buttonUnlock);
            _unlockButton.Click += OnUnlockButtonClick;

            if (_preferences.AllowBiometrics)
            {
                var biometricManager = BiometricManager.From(this);
                _canUseBiometrics = biometricManager.CanAuthenticate(BiometricManager.Authenticators.BiometricStrong) == BiometricManager.BiometricSuccess;
            }

            _useBiometricsButton         = FindViewById <MaterialButton>(Resource.Id.buttonUseBiometrics);
            _useBiometricsButton.Enabled = _canUseBiometrics;
            _useBiometricsButton.Click  += delegate
            {
                ShowBiometricPrompt();
            };

            if (_canUseBiometrics)
            {
                ShowBiometricPrompt();
            }
            else
            {
                FocusPasswordText();
            }
        }
Ejemplo n.º 17
0
        public AutoBackupWorker(Context context, WorkerParameters workerParams) : base(context, workerParams)
        {
            _context     = context;
            _preferences = new PreferenceWrapper(context);

            _initTask = new Lazy <Task>(async delegate
            {
                var password      = await SecureStorageWrapper.GetDatabasePassword();
                _connection       = await Database.GetPrivateConnection(password);
                _customIconSource = new CustomIconSource(_connection);
                _categorySource   = new CategorySource(_connection);
                _authSource       = new AuthenticatorSource(_connection);

                await _categorySource.Update();
                await _customIconSource.Update();
                await _authSource.Update();
            });
        }
Ejemplo n.º 18
0
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            await _onCreateLock.WaitAsync();

            SetContentView(Resource.Layout.activityMain);
            _preferences = new PreferenceWrapper(this);

            _authCache       = new ListCache <WearAuthenticator>(AuthenticatorCacheName, this);
            _categoryCache   = new ListCache <WearCategory>(CategoryCacheName, this);
            _customIconCache = new CustomIconCache(this);

            await _authCache.Init();

            await _categoryCache.Init();

            _authSource = new AuthenticatorSource(_authCache);
            _authSource.SetSortMode(_preferences.SortMode);

            var defaultCategory = _preferences.DefaultCategory;

            if (defaultCategory != null)
            {
                _authSource.SetCategory(defaultCategory);
            }

            RunOnUiThread(delegate
            {
                InitViews();

                if (!_authCache.GetItems().Any())
                {
                    _onCreateLock.Release();
                    return;
                }

                AnimUtil.FadeOutView(_loadingLayout, AnimUtil.LengthShort, false, delegate
                {
                    CheckEmptyState();
                    _onCreateLock.Release();
                });
            });
        }
Ejemplo n.º 19
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.sheetAutoBackupSetup, null);

            SetupToolbar(view, Resource.String.prefAutoBackupTitle, true);

            _preferences = new PreferenceWrapper(Context);

            var selectLocationButton = view.FindViewById <LinearLayout>(Resource.Id.buttonSelectLocation);

            selectLocationButton.Click += OnSelectLocationClick;

            var setPasswordButton = view.FindViewById <LinearLayout>(Resource.Id.buttonSetPassword);

            setPasswordButton.Click += OnSetPasswordButtonClick;

            _locationStatusText = view.FindViewById <TextView>(Resource.Id.textLocationStatus);
            _passwordStatusText = view.FindViewById <TextView>(Resource.Id.textPasswordStatus);

            _backupNowButton        = view.FindViewById <MaterialButton>(Resource.Id.buttonBackupNow);
            _backupNowButton.Click += OnBackupNowButtonClick;

            _restoreNowButton        = view.FindViewById <MaterialButton>(Resource.Id.buttonRestoreNow);
            _restoreNowButton.Click += OnRestoreNowButtonClick;

            _batOptimLayout = view.FindViewById <LinearLayout>(Resource.Id.layoutBatOptim);
            var disableBatOptimButton = view.FindViewById <MaterialButton>(Resource.Id.buttonDisableBatOptim);

            disableBatOptimButton.Click += OnDisableBatOptimButtonClick;

            _okButton        = view.FindViewById <MaterialButton>(Resource.Id.buttonOk);
            _okButton.Click += delegate { Dismiss(); };

            _backupEnabledSwitch  = view.FindViewById <SwitchMaterial>(Resource.Id.switchBackupEnabled);
            _restoreEnabledSwitch = view.FindViewById <SwitchMaterial>(Resource.Id.switchRestoreEnabled);

            UpdateLocationStatusText();
            UpdatePasswordStatusText();
            UpdateSwitchesAndTriggerButton();

            return(view);
        }
Ejemplo n.º 20
0
        protected override void AttachBaseContext(Context context)
        {
            _preferences = new PreferenceWrapper(context);
            var language = _preferences.Language;

            var resources = context.Resources;
            var config    = resources?.Configuration;

            Locale locale;

            if (language == "system")
            {
                locale = Locale.Default;
            }
            else if (language.Contains('-'))
            {
                var parts = language.Split('-', 2);
                locale = new Locale(parts[0], parts[1]);
            }
            else
            {
                locale = new Locale(language);
            }

            config?.SetLocale(locale);

            if (Build.VERSION.SdkInt >= BuildVersionCodes.N)
            {
                if (config != null)
                {
                    context = context.CreateConfigurationContext(config);
                }
            }
            else
#pragma warning disable 618
            {
                resources?.UpdateConfiguration(config, resources.DisplayMetrics);
            }
#pragma warning restore 618

            base.AttachBaseContext(context);
        }
Ejemplo n.º 21
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            _preferences = new PreferenceWrapper(this);

            _checkedOnCreate = true;
            UpdateTheme();

            BaseApplication = (BaseApplication)Application;

            if (Build.VERSION.SdkInt < BuildVersionCodes.M)
            {
                Window.SetStatusBarColor(Android.Graphics.Color.Black);
            }

            var overlay = AccentColourMap.GetOverlay(_preferences.AccentColour);

            Theme.ApplyStyle(overlay, true);
            SetContentView(_layout);
        }
Ejemplo n.º 22
0
        public AutoBackupWorker(Context context, WorkerParameters workerParams) : base(context, workerParams)
        {
            _context             = context;
            _preferences         = new PreferenceWrapper(context);
            _shouldCloseDatabase = false;

            _database                        = Dependencies.Resolve <Database>();
            _restoreService                  = Dependencies.Resolve <IRestoreService>();
            _authenticatorRepository         = Dependencies.Resolve <IAuthenticatorRepository>();
            _categoryRepository              = Dependencies.Resolve <ICategoryRepository>();
            _authenticatorCategoryRepository = Dependencies.Resolve <IAuthenticatorCategoryRepository>();
            _customIconRepository            = Dependencies.Resolve <ICustomIconRepository>();

            _initTask = new Lazy <Task>(async delegate
            {
                if (!_database.IsOpen)
                {
                    var password = await SecureStorageWrapper.GetDatabasePassword();
                    await _database.Open(password);
                    _shouldCloseDatabase = true;
                }
            });
        }
Ejemplo n.º 23
0
        private async Task GetSyncBundle(string nodeId)
        {
            await _authenticatorView.LoadFromPersistenceAsync();

            var auths = new List <WearAuthenticator>();

            var authCategories = await _authenticatorCategoryRepository.GetAllAsync();

            foreach (var auth in _authenticatorView)
            {
                var bindings = authCategories
                               .Where(c => c.AuthenticatorSecret == auth.Secret)
                               .Select(c => new WearAuthenticatorCategory(c.CategoryId, c.Ranking))
                               .ToList();

                var item = new WearAuthenticator(
                    auth.Type, auth.Secret, auth.Icon, auth.Issuer, auth.Username, auth.Period, auth.Digits,
                    auth.Algorithm, auth.Ranking, bindings);

                auths.Add(item);
            }

            var categories = (await _categoryRepository.GetAllAsync()).Select(c => new WearCategory(c.Id, c.Name))
                             .ToList();
            var customIconIds = (await _customIconRepository.GetAllAsync()).Select(i => i.Id).ToList();

            var preferenceWrapper = new PreferenceWrapper(this);
            var preferences       = new WearPreferences(
                preferenceWrapper.DefaultCategory, preferenceWrapper.SortMode, preferenceWrapper.CodeGroupSize);

            var bundle = new WearSyncBundle(auths, categories, customIconIds, preferences);

            var json = JsonConvert.SerializeObject(bundle);
            var data = Encoding.UTF8.GetBytes(json);

            await WearableClass.GetMessageClient(this).SendMessageAsync(nodeId, GetSyncBundleCapability, data);
        }
Ejemplo n.º 24
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.activityCode);

            var preferences = new PreferenceWrapper(this);

            _codeGroupSize = preferences.CodeGroupSize;

            _authProgressLayout = FindViewById <AuthProgressLayout>(Resource.Id.layoutAuthProgress);

            _codeTextView = FindViewById <TextView>(Resource.Id.textCode);

            var issuerText   = FindViewById <TextView>(Resource.Id.textIssuer);
            var usernameText = FindViewById <TextView>(Resource.Id.textUsername);

            var username = Intent.Extras.GetString("username");
            var issuer   = Intent.Extras.GetString("issuer");

            issuerText.Text = issuer;

            if (String.IsNullOrEmpty(username))
            {
                usernameText.Visibility = ViewStates.Gone;
            }
            else
            {
                usernameText.Text = username;
            }

            var iconView      = FindViewById <ImageView>(Resource.Id.imageIcon);
            var hasCustomIcon = Intent.Extras.GetBoolean("hasCustomIcon");

            if (hasCustomIcon)
            {
                var bitmap = (Bitmap)Intent.Extras.GetParcelable("icon");

                if (bitmap != null)
                {
                    iconView.SetImageBitmap(bitmap);
                }
                else
                {
                    iconView.SetImageResource(IconResolver.GetService(IconResolver.Default, true));
                }
            }
            else
            {
                iconView.SetImageResource(IconResolver.GetService(Intent.Extras.GetString("icon"), true));
            }

            _period = Intent.Extras.GetInt("period");
            _digits = Intent.Extras.GetInt("digits");

            var algorithm = (HashAlgorithm)Intent.Extras.GetInt("algorithm");

            var secret = Intent.Extras.GetString("secret");
            var type   = (AuthenticatorType)Intent.Extras.GetInt("type");

            _generator = type switch
            {
                AuthenticatorType.MobileOtp => new MobileOtp(secret, _digits),
                AuthenticatorType.SteamOtp => new SteamOtp(secret),
                _ => new Totp(secret, _period, algorithm, _digits)
            };

            _authProgressLayout.Period         = _period * 1000;
            _authProgressLayout.TimerFinished += Refresh;
        }