Exemple #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Location_Activity);

            xamEssF = new XamEssentialFeatures(this);

            messages = new Messages(this);

            inflater = LayoutInflater.From(this);

            auth = inflater.Inflate(Resource.Layout.Authentication, null);

            logIn = auth.FindViewById <Button>(Resource.Id.logIn);

            Messages.ToastMessage(message: $"{logIn.Text}");

            allText = new MyTexts(this);

            email = auth.FindViewById <EditText>(Resource.Id.email);

            locationPersonalName = FindViewById <EditText>(Resource.Id.locationPersonalName);

            passeword = auth.FindViewById <EditText>(Resource.Id.passeword);

            dialog = new AlertDialog.Builder(this).Create();

            dialog.SetView(auth);

            db = new DataAccess("location.db3", this);

            locationPersonalName.TextChanged += delegate
            {
                if (string.IsNullOrEmpty(locationPersonalName.Text))
                {
                    locationPersonalName.Background = GetDrawable(Resource.Drawable.EditTextBackground);
                }
                else
                {
                    locationPersonalName.Background = GetDrawable(Resource.Drawable.TextEditing);
                }
            };


            locationDisplayer = FindViewById <TextView>(Resource.Id.locationDisplayer);

            formatedTime = FindViewById <TextView>(Resource.Id.formatedTime);

            btnGetLocation = FindViewById <Button>(Resource.Id.getLocation);

            todayLocations = FindViewById <Button>(Resource.Id.todayLocations);

            mapLauncher = FindViewById <Button>(Resource.Id.mapLauncher);

            saveLocation = FindViewById <Button>(Resource.Id.saveLocation);

            locationLayout = FindViewById <LinearLayout>(Resource.Id.locationLayout);

            progessLayout = FindViewById <LinearLayout>(Resource.Id.progessLayout);


            //Messages.ToastMessage($"{accessData.isConnected}");

            if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessCoarseLocation) != 0 || ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) != 0)
            {
                RequestPermissions(new string[] {
                    Manifest.Permission.AccessCoarseLocation,
                    Manifest.Permission.AccessFineLocation
                }, 2);
            }

            saveLocation.Click += (s, e) =>
            {
                LocationsRepository.UpdateTable(locationPersonalName.Text);
            };

            btnGetLocation.Click += (s, e) =>
            {
                btnGetLocation.Enabled = false;
                xamEssF.GetLocation(locationDisplayer, locationLayout, progessLayout, btnGetLocation);
            };

            mapLauncher.Click += delegate
            {
                xamEssF.navigateToMap();
            };
            todayLocations.Click += delegate
            {
                if (LocationsRepository.GetLastLocation() != null)
                {
                    Messages.ToastMessage($"Last location id={LocationsRepository.GetLastLocation()._id}");
                }
                else
                {
                    Messages.ToastMessage("No location in the location table");
                }

                intent = new Intent(this, typeof(locationActivity));

                StartActivity(intent);
            };


            passeword.TextChanged += delegate { passeword.Background = GetDrawable(Resource.Drawable.TextEditing); };
            email.TextChanged     += delegate { email.Background = GetDrawable(Resource.Drawable.TextEditing); };

            logIn.Click += (s, e) => {
                if (db.isLogedIn(email.Text, passeword.Text))
                {
                    dialog.Dismiss();
                    Messages.ToastMessage("LogIn successfully");
                }

                else
                {
                    email.Background     = GetDrawable(Resource.Drawable.ErrorBackground);
                    passeword.Background = GetDrawable(Resource.Drawable.ErrorBackground);
                    Log.Info("info", "LogIn Error");
                    Messages.ToastMessage("Email or passeword incorrect");
                };
            };
        }