Esempio n. 1
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            switch (item.ItemId)
            {
            case Resource.Id.menuSignout:
                AppPreferenceUser.RemoveUser();
                AuthenticateUser();
                break;

            case Resource.Id.menuRefresh:
                var ignoreTask = OnOptionsItemSelectedAsync(item);
                break;
            }
            return(base.OnOptionsItemSelected(item));
        }
Esempio n. 2
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);

            SetContentView(Resource.Layout.activity_main);

            _restService = new RestService();

            // Sign in
            // Check is signed in
            User user = AuthenticateUser();

            if (user == null)
            {
                Finish();
                return;
            }

            // Send token after user logged in
            if (await _restService.Authenticate(user, false) != null)
            {
                _restService.User = user;
                await _restService.RegisterFirebaseToken(Preferences.Get(Constants.FirebaseTokenPreferenceTag, null));
            }
            else
            {
                AppPreferenceUser.RemoveUser();
                AuthenticateUser();
                Finish();
                return;
            }

            // Navigation drawer
            DrawerLayout drawerLayout   = FindViewById <DrawerLayout>(Resource.Id.drawerLayout);
            var          navigationView = FindViewById <NavigationView>(Resource.Id.navigationView);

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

            SetActionBar(toolbar);
            //ActionBar.Title = Resources.GetString(Resource.String.app_name);
            ActionBar.Title = GetString(Resource.String.all_products);
            ActionBar.SetHomeButtonEnabled(true);
            ActionBar.SetDisplayHomeAsUpEnabled(true);
            ActionBar.SetHomeAsUpIndicator(GetDrawable(Resource.Drawable.baseline_menu_white_18dp));

            toolbar.NavigationOnClick += (s, e) =>
            {
                drawerLayout.OpenDrawer(Android.Support.V4.View.GravityCompat.Start);
            };


            // drawer
            var drawer = FindViewById <DrawerLayout>(Resource.Id.drawerLayout);

            // Fab
            var fab = FindViewById <FloatingActionButton>(Resource.Id.fabAdd);

            fab.Click += (sender, e) =>
            {
                var transaction    = FragmentManager.BeginTransaction();
                var dialogFragment = new AddDialogFragment();
                dialogFragment.onAddButtonClicked += OnAddButtonClickedHandler;
                dialogFragment.Show(transaction, "add_dialog_fragment");
            };

            // Product list
            List <Product> products = new List <Product>();

            products.AddRange(await _restService.Get());

            // Setting up RecyclerView
            var productRecyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerViewProducts);

            productRecyclerView.SetLayoutManager(new GridLayoutManager(this, 2));
            productAdapter = new ProductAdapter(products, this);
            productRecyclerView.SetAdapter(productAdapter);

            // Handling itemClick event
            productAdapter.ItemClick += OnItemClickHandler;

            //Filter list on Navigation drawer
            var filterListView = FindViewById <ListView>(Resource.Id.filterListView);
            var websites       = new List <string> {
                GetString(Resource.String.all_products)
            };

            websites.AddRange(productAdapter.GetWebsites());
            ArrayAdapter filterListAdapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItemActivated1, websites);

            filterListView.Adapter    = filterListAdapter;
            filterListView.ItemClick += FilterListView_ItemClick;
            filterListView.ItemClick += (s, e) => drawerLayout.CloseDrawer(Android.Support.V4.View.GravityCompat.Start);
            filterListView.ChoiceMode = ChoiceMode.Single;
            filterListView.SetItemChecked(0, true);

            productAdapter.OnListChanged += (s, e) =>
            {
                filterListAdapter.Clear();
                var websites = new List <string> {
                    GetString(Resource.String.all_products)
                };
                websites.AddRange(productAdapter.GetWebsites());
                filterListAdapter.AddAll(websites);
                filterListAdapter.NotifyDataSetChanged();
            };

            // Firebase messaging
            IsPlayServicesAvailable();
            CreateNotificationChannel();
        }