public override async void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
        {
            var auth = _authSource.Get(position);

            if (auth == null)
            {
                return;
            }

            var holder = (AuthenticatorListHolder)viewHolder;

            holder.Issuer.Text   = auth.Issuer;
            holder.Username.Text = auth.Username;

            holder.Username.Visibility = String.IsNullOrEmpty(auth.Username)
                ? ViewStates.Gone
                : ViewStates.Visible;

            holder.Code.Text = CodeUtil.PadCode(auth.GetCode(), auth.Digits);

            if (auth.Icon != null && auth.Icon.StartsWith(CustomIcon.Prefix))
            {
                var id         = auth.Icon.Substring(1);
                var customIcon = _customIconSource.Get(id);

                if (customIcon != null)
                {
                    holder.Icon.SetImageBitmap(await DecodeCustomIcon(customIcon));
                }
                else
                {
                    holder.Icon.SetImageResource(IconResolver.GetService(IconResolver.Default, _isDark));
                }
            }
            else
            {
                holder.Icon.SetImageResource(IconResolver.GetService(auth.Icon, _isDark));
            }

            switch (auth.Type.GetGenerationMethod())
            {
            case GenerationMethod.Time:
                holder.RefreshButton.Visibility = ViewStates.Gone;
                holder.ProgressBar.Visibility   = ViewStates.Visible;
                BindProgressBar(auth, holder.ProgressBar);
                break;

            case GenerationMethod.Counter:
                holder.RefreshButton.Visibility = auth.TimeRenew < DateTime.UtcNow
                        ? ViewStates.Visible
                        : ViewStates.Gone;

                holder.ProgressBar.Visibility = ViewStates.Invisible;
                break;
            }
        }
        public override async void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
        {
            var auth = _authSource.Get(position);

            if (auth == null)
            {
                return;
            }

            var holder = (AuthenticatorListHolder)viewHolder;

            holder.Issuer.Text = auth.Issuer;

            holder.DefaultImage.Visibility = DefaultAuth != null && auth.Secret.GetHashCode() == DefaultAuth
                ? ViewStates.Visible
                : ViewStates.Gone;

            if (String.IsNullOrEmpty(auth.Username))
            {
                holder.Username.Visibility = ViewStates.Gone;
            }
            else
            {
                holder.Username.Visibility = ViewStates.Visible;
                holder.Username.Text       = auth.Username;
            }

            if (!String.IsNullOrEmpty(auth.Icon))
            {
                if (auth.Icon.StartsWith(CustomIconCache.Prefix))
                {
                    var id         = auth.Icon.Substring(1);
                    var customIcon = await _customIconCache.GetBitmap(id);

                    if (customIcon != null)
                    {
                        holder.Icon.SetImageBitmap(customIcon);
                    }
                    else
                    {
                        holder.Icon.SetImageResource(IconResolver.GetService(IconResolver.Default, true));
                    }
                }
                else
                {
                    holder.Icon.SetImageResource(IconResolver.GetService(auth.Icon, true));
                }
            }
            else
            {
                holder.Icon.SetImageResource(IconResolver.GetService(IconResolver.Default, true));
            }
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view   = base.OnCreateView(inflater, container, savedInstanceState);
            var isDark = ((BaseActivity)Context).IsDark;

            var menu = view.FindViewById <RecyclerView>(Resource.Id.listMenu);

            SetupMenu(menu, new List <SheetMenuItem>
            {
                new SheetMenuItem(Resource.Drawable.ic_action_info_outline, Resource.String.about, ClickAbout, Resource.String.aboutSummary),
                new SheetMenuItem(IconResolver.GetService("googleplay", isDark), Resource.String.rate, ClickRate, Resource.String.rateSummary),
                new SheetMenuItem(IconResolver.GetService("github", isDark), Resource.String.viewGitHub, ClickViewGitHub, Resource.String.viewGitHubSummary)
            });

            return(view);
        }
Beispiel #4
0
        private void Update()
        {
            if (String.IsNullOrEmpty(_search))
            {
                _view = new Dictionary <string, int>(IconResolver.Service.Count);
                foreach (var(key, _) in IconResolver.Service)
                {
                    _view.Add(key, IconResolver.GetService(key, _isDark));
                }

                return;
            }

            var query = _search.ToLower();

            var keys = IconResolver.Service.Keys.Where(k => k.Contains(query)).ToList();

            _view = new Dictionary <string, int>(keys.Count);
            keys.ForEach(key => _view.Add(key, IconResolver.GetService(key, _isDark)));
        }
Beispiel #5
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.activityCode);

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

            _animationScale = Settings.Global.GetFloat(ContentResolver, Settings.Global.AnimatorDurationScale, 1.0f);

            var usernameText = FindViewById <TextView>(Resource.Id.textUsername);
            var username     = Intent.Extras.GetString("username");

            if (String.IsNullOrEmpty(username))
            {
                var issuer = Intent.Extras.GetString("issuer");
                usernameText.Text = issuer;
            }
            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)
            };

            _timer = new Timer
            {
                Interval  = 1000,
                AutoReset = true
            };

            _timer.Elapsed += Tick;
        }
        public override async void OnBindViewHolder(RecyclerView.ViewHolder viewHolder, int position)
        {
            var auth = _authSource.Get(position);

            if (auth == null)
            {
                return;
            }

            var holder = (AuthenticatorListHolder)viewHolder;

            holder.Issuer.Text   = auth.Issuer;
            holder.Username.Text = auth.Username;

            holder.Username.Visibility = String.IsNullOrEmpty(auth.Username)
                ? ViewStates.Gone
                : ViewStates.Visible;

            holder.Code.Text = CodeUtil.PadCode(auth.GetCode(), auth.Digits);

            if (auth.Icon != null && auth.Icon.StartsWith(CustomIcon.Prefix))
            {
                var id         = auth.Icon.Substring(1);
                var customIcon = _customIconSource.Get(id);

                if (customIcon != null)
                {
                    if (!_decodedCustomIcons.ContainsKey(customIcon.Id))
                    {
                        _decodedCustomIcons.Add(customIcon.Id, await BitmapFactory.DecodeByteArrayAsync(customIcon.Data, 0, customIcon.Data.Length));
                    }

                    holder.Icon.SetImageBitmap(_decodedCustomIcons[customIcon.Id]);
                }
                else
                {
                    holder.Icon.SetImageResource(IconResolver.GetService(IconResolver.Default, _isDark));
                }
            }
            else
            {
                holder.Icon.SetImageResource(IconResolver.GetService(auth.Icon, _isDark));
            }

            switch (auth.Type.GetGenerationMethod())
            {
            case GenerationMethod.Time:
                holder.RefreshButton.Visibility = ViewStates.Gone;
                holder.ProgressBar.Visibility   = ViewStates.Visible;
                AnimateProgressBar(holder.ProgressBar, auth.Period);
                break;

            case GenerationMethod.Counter:
                holder.RefreshButton.Visibility = auth.TimeRenew < DateTime.UtcNow
                        ? ViewStates.Visible
                        : ViewStates.Gone;

                holder.ProgressBar.Visibility = ViewStates.Invisible;
                break;
            }
        }
Beispiel #7
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;
        }