public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var ignore = base.OnCreateView(inflater, container, savedInstanceState);

            var view = this.BindingInflate(Resource.Layout.fragment_shopping_list, null);

            var recyclerView = view.FindViewById <MvxRecyclerView>(Resource.Id.fragment_shopping_list_recycler_view);

            if (recyclerView != null)
            {
                recyclerView.HasFixedSize = true;
                var layoutManager = new LinearLayoutManager(Activity);
                recyclerView.SetLayoutManager(layoutManager);
            }

            var swipeRefreshLayout = view.FindViewById <MvxSwipeRefreshLayout>(Resource.Id.fragment_shopping_list_refresher);

            var createShoppingItemButton = view.FindViewById <Button>(Resource.Id.fragment_shopping_list_button_create);

            createShoppingItemButton.Click += CreateShoppingItemButton_Click;

            var createShoppingItemFab = view.FindViewById <FloatingActionButton>(Resource.Id.fragment_shopping_list_fab_create);

            createShoppingItemFab.Click += CreateShoppingItemFab_Click;

            // listen for item selection
            IMvxNotifyPropertyChanged itemSelected = ViewModel as IMvxNotifyPropertyChanged;

            itemSelected.WeakSubscribe(OnItemSelected);

            return(view);
        }
示例#2
0
        Spinner attributeSpinner; // because the viewmodel can't reset the selection index :(

        protected override void OnViewModelSet()
        {
            System.Diagnostics.Debug.WriteLine("MainActivity.OnCreate()");

            SetContentView(Resource.Layout.activity_main);

            // Toolbar
            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            //Toolbar will now take on default actionbar characteristics
            SetSupportActionBar(toolbar);
            SupportActionBar.SetDisplayShowTitleEnabled(false);
            SupportActionBar.SetDisplayUseLogoEnabled(true);

            // Status Bar
            Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);

            // View Pager
            var viewPager = FindViewById <ViewPager>(Resource.Id.activity_main_viewpager);

            if (viewPager != null)
            {
                var fragments = new List <MvxFragmentPagerAdapter.FragmentInfo>
                {
                    new MvxFragmentPagerAdapter.FragmentInfo("", typeof(InventoryFragment), typeof(InventoryViewModel)),
                    new MvxFragmentPagerAdapter.FragmentInfo("", typeof(ShoppingListFragment), typeof(ShoppingListViewModel)),
                    //new MvxFragmentPagerAdapter.FragmentInfo("", typeof(SettingsFragment), typeof(SettingsViewModel))
                };

                // deprecated? still works for me :P
                viewPager.Adapter = new MvxFragmentPagerAdapter(this, SupportFragmentManager, fragments);
            }

            // Tabs
            var tabLayout = FindViewById <TabLayout>(Resource.Id.activity_main_tabs);

            tabLayout.SetupWithViewPager(viewPager);

            tabLayout.GetTabAt(0).SetIcon(ContextCompat.GetDrawable(this, Resource.Drawable.ic_home_white_24dp));
            tabLayout.GetTabAt(1).SetIcon(ContextCompat.GetDrawable(this, Resource.Drawable.ic_shopping_cart_white_24dp));
            //tabLayout.GetTabAt(2).SetIcon(ContextCompat.GetDrawable(this, Resource.Drawable.ic_settings_white_24dp));

            attributeSpinner = FindViewById <Spinner>(Resource.Id.activity_main_spinner_attributes);

            // Listen for spinner update
            IMvxNotifyPropertyChanged spinnerUpdated = ViewModel as IMvxNotifyPropertyChanged;

            spinnerUpdated.WeakSubscribe(OnSpinnerUpdated);


            // Clean up old pictures
            CreateDirectoryForPictures();
        }