private async Task Refresh()
        {
            _progressBar.Visibility = ViewStates.Visible;

            await _categorySource.Update();

            CheckEmptyState();

            _categoryListAdapter.NotifyDataSetChanged();
            _categoryList.ScheduleLayoutAnimation();
            _progressBar.Visibility = ViewStates.Invisible;
        }
Beispiel #2
0
        private async Task Refresh()
        {
            await _categorySource.Update();

            RunOnUiThread(delegate
            {
                CheckEmptyState();

                _categoryListAdapter.NotifyDataSetChanged();
                _categoryList.ScheduleLayoutAnimation();
            });
        }
        private async Task ListCategories(string nodeId)
        {
            await _categorySource.Update();

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

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

            await WearableClass.GetMessageClient(this)
            .SendMessageAsync(nodeId, ListCategoriesCapability, data);
        }
Beispiel #4
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 #5
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;
        }
        private async Task Init()
        {
            _authenticatorSource = new AuthenticatorSource(_connection);
            await _authenticatorSource.Update();

            _categorySource = new CategorySource(_connection);
            await _categorySource.Update();

            InitAuthenticatorList();
            await RefreshAuthenticators();

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

            _timer.Elapsed += Tick;
            _timer.Start();
        }
Beispiel #7
0
        private async Task UpdateCategories(bool updateSource = true)
        {
            await _categorySource.UpdateTask;

            if (updateSource)
            {
                await _categorySource.Update();
            }

            _categoriesMenu.Clear();

            var allItem = _categoriesMenu.Add(Menu.None, -1, Menu.None, Resource.String.categoryAll);

            allItem.SetChecked(true);

            for (var i = 0; i < _categorySource.Count(); ++i)
            {
                _categoriesMenu.Add(0, i, i, _categorySource.Categories[i].Name);
            }
        }
Beispiel #8
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);
        }
        private async void AddDialogPositive(object sender, EventArgs e)
        {
            if (_addDialog.Name.Trim() == "")
            {
                _addDialog.Error = GetString(Resource.String.noCategoryName);
                return;
            }

            var category = new Category(_addDialog.Name.Truncate(32));

            if (_categorySource.IsDuplicate(category))
            {
                _addDialog.Error = GetString(Resource.String.duplicateCategory);
                return;
            }

            _addDialog.Dismiss();
            await _connection.InsertAsync(category);

            await _categorySource.Update();

            _categoryAdapter.NotifyDataSetChanged();
            CheckEmptyState();
        }
Beispiel #10
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);
            }
        }
        protected override async void OnResume()
        {
            base.OnResume();

            if ((DateTime.Now - _pauseTime).TotalMinutes >= 1 && PerformLogin())
            {
                return;
            }

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

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

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

                await _categorySource.Update();

                // Currently visible category has been deleted
                if (_authenticatorSource.CategoryId != null &&
                    _categorySource.Categories.FirstOrDefault(c => c.Id == _authenticatorSource.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();

            await DetectWearOSCapability();

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