private async Task ListCustomIcons(string nodeId)
        {
            await _customIconSource.Update();

            var ids = new List <string>();

            _customIconSource.GetView().ForEach(i => ids.Add(i.Id));

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

            await WearableClass.GetMessageClient(this)
            .SendMessageAsync(nodeId, ListCustomIconsCapability, data);
        }
Beispiel #2
0
        private async Task GetSyncBundle(string nodeId)
        {
            await _authSource.Update();

            var auths = new List <WearAuthenticator>();

            foreach (var auth in _authSource.GetView())
            {
                var bindings = _authSource.CategoryBindings
                               .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);
            }

            await _categorySource.Update();

            var categories = _categorySource.GetAll().Select(c => new WearCategory(c.Id, c.Name)).ToList();

            await _customIconSource.Update();

            var customIconIds = _customIconSource.GetAll().Select(i => i.Id).ToList();

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

            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);
        }
Beispiel #3
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();
            });
        }
Beispiel #4
0
        private async Task Init()
        {
            _categorySource = new CategorySource(_connection);
            await _categorySource.Update();

            _customIconSource = new CustomIconSource(_connection);
            await _customIconSource.Update();

            _authSource = new AuthenticatorSource(_connection);
            RunOnUiThread(InitAuthenticatorList);
            await RefreshAuthenticators();

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

            _timer.Elapsed += Tick;
        }
Beispiel #5
0
        protected override async void OnResume()
        {
            base.OnResume();

            if (RequiresAuthentication())
            {
                if ((DateTime.Now - _pauseTime).TotalMinutes >= 1)
                {
                    _isAuthenticated = false;
                }

                if (!_isAuthenticated)
                {
                    _refreshOnActivityResume = true;
                    StartActivityForResult(typeof(LoginActivity), ResultLogin);
                    return;
                }
            }

            // Just launched
            if (_connection == null)
            {
                try
                {
                    _connection = await Database.Connect(this);
                }
                catch (SQLiteException)
                {
                    ShowDatabaseErrorDialog();
                    return;
                }

                await Init();
            }
            else if (_refreshOnActivityResume)
            {
                _refreshOnActivityResume = false;

                _authList.Visibility = ViewStates.Invisible;
                await RefreshAuthenticators();

                await _categorySource.Update();

                await _customIconSource.Update();

                // Currently visible category has been deleted
                if (_authSource.CategoryId != null &&
                    _categorySource.GetView().FirstOrDefault(c => c.Id == _authSource.CategoryId) == null)
                {
                    await SwitchCategory(null);
                }
            }

            CheckEmptyState();

            // Launch task that needs to wait for the activity to resume
            // Useful because an activity result is called before resume
            if (_onceResumedTask != null)
            {
                _onceResumedTask.Start();
                _onceResumedTask = null;
            }

            _timer.Start();
            Tick();

            var showBackupReminders = PreferenceManager.GetDefaultSharedPreferences(this)
                                      .GetBoolean("pref_showBackupReminders", true);

            if (showBackupReminders)
            {
                RemindBackup();
            }

            await DetectWearOSCapability();

            if (_hasWearAPIs)
            {
                await WearableClass.GetCapabilityClient(this).AddListenerAsync(this, WearRefreshCapability);
            }
        }