Beispiel #1
0
 private User AuthenticateUser()
 {
     if (AppPreferenceUser.IsLogged)
     {
         return(AppPreferenceUser.GetUser());
     }
     else
     {
         var intent = new Intent(this, typeof(SignInActivity));
         StartActivity(intent);
         return(null);
     }
 }
Beispiel #2
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));
        }
Beispiel #3
0
        private async void ButtonSignIn_Click(object sender, EventArgs e)
        {
            string email    = editTextEmail.Text;
            string password = editTextPassword.Text;

            buttonSignIn.Enabled = false;
            User user = await _restService.Authenticate(new User { Email = email, Password = password }, false);

            if (user != null)
            {
                user.Password = password;
                AppPreferenceUser.SetUser(user);
                var intent = new Intent(this, typeof(MainActivity));
                StartActivity(intent);
                Finish();
            }
            else
            {
                buttonSignIn.Enabled = true;
                Toast.MakeText(this, Resource.String.incorrect_pass_or_email, ToastLength.Long).Show();
            }
        }
Beispiel #4
0
        private async void ButtonCreateAccount_Click(object sender, EventArgs e)
        {
            string email    = editTextEmail.Text;
            string password = editTextPassword.Text;

            if (!IsValidEmail(email))
            {
                Toast.MakeText(this, Resource.String.invalid_email_format, ToastLength.Long).Show();
                return;
            }
            if (password.Length < 8)
            {
                Toast.MakeText(this, Resource.String.password_tooshort, ToastLength.Long).Show();
                return;
            }
            if (password != editTextConfirmPassword.Text)
            {
                Toast.MakeText(this, Resource.String.passwords_dont_match, ToastLength.Long).Show();
                return;
            }

            buttonCreateAccount.Enabled = false;
            User user = await _restServiceRegister.Authenticate(new User { Email = email, Password = password }, true);

            if (user != null)
            {
                user.Password = password;
                AppPreferenceUser.SetUser(user);
                var intent = new Intent(this, typeof(MainActivity));
                StartActivity(intent);
                Finish();
            }
            else
            {
                buttonCreateAccount.Enabled = true;
                Toast.MakeText(this, Resource.String.incorrect_pass_or_email, ToastLength.Long).Show();
            }
        }
Beispiel #5
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();
        }