예제 #1
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();
        }