public void UpdateView()
        {
            _view = _cache.GetItems();

            if (CategoryId != null)
            {
                _view = _view.Where(a => a.CategoryIds.Contains(CategoryId)).ToList();
            }
        }
Exemple #2
0
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.activityMain);

            try
            {
                await WearableClass.GetMessageClient(this).AddListenerAsync(this);
                await FindServerNode();
            }
            catch (ApiException) { }

            _loadingLayout = FindViewById <RelativeLayout>(Resource.Id.layoutLoading);
            _emptyLayout   = FindViewById <RelativeLayout>(Resource.Id.layoutEmpty);
            _offlineLayout = FindViewById <LinearLayout>(Resource.Id.layoutOffline);

            _authList = FindViewById <WearableRecyclerView>(Resource.Id.list);
            _authList.EdgeItemsCenteringEnabled = true;
            _authList.HasFixedSize = true;
            _authList.SetItemViewCacheSize(12);
            _authList.SetItemAnimator(null);

            var layoutCallback = new ScrollingListLayoutCallback(Resources.Configuration.IsScreenRound);

            _authList.SetLayoutManager(new WearableLinearLayoutManager(this, layoutCallback));

            _authCache       = new ListCache <WearAuthenticator>("authenticators", this);
            _categoryCache   = new ListCache <WearCategory>("categories", this);
            _customIconCache = new CustomIconCache(this);

            await _authCache.Init();

            _authSource = new AuthenticatorSource(_authCache);

            _authListAdapter              = new AuthenticatorListAdapter(_authSource, _customIconCache);
            _authListAdapter.ItemClick   += OnItemClick;
            _authListAdapter.HasStableIds = true;
            _authList.SetAdapter(_authListAdapter);

            if (_authCache.GetItems().Count > 0 || _serverNode == null)
            {
                UpdateViewState();
            }

            await _categoryCache.Init();

            var categoriesDrawer = FindViewById <WearableNavigationDrawerView>(Resource.Id.drawerCategories);

            _categoryListAdapter = new CategoryListAdapter(this, _categoryCache);
            categoriesDrawer.SetAdapter(_categoryListAdapter);
            categoriesDrawer.ItemSelected += OnCategorySelected;

            await Refresh();
        }
        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();
                });
            });
        }
        public void UpdateView()
        {
            var view = _cache.GetItems().AsEnumerable();

            if (CategoryId != null)
            {
                view = view.Where(a => a.Categories != null && a.Categories.Any(c => c.CategoryId == CategoryId));

                if (SortMode == SortMode.Custom)
                {
                    view = view.OrderBy(a => a.Categories.First(c => c.CategoryId == CategoryId).Ranking);
                }
            }

            view = SortMode switch
            {
                SortMode.AlphabeticalAscending => view.OrderBy(a => a.Issuer).ThenBy(a => a.Username),
                SortMode.AlphabeticalDescending => view.OrderByDescending(a => a.Issuer).ThenByDescending(a => a.Username),
                SortMode.Custom when CategoryId == null => view.OrderBy(a => a.Ranking).ThenBy(a => a.Issuer).ThenBy(a => a.Username),
                _ => view
            };

            _view = view.ToList();
        }
 public AuthenticatorSource(ListCache <WearAuthenticator> cache)
 {
     _cache = cache;
     _view  = cache.GetItems();
 }