Пример #1
0
        //checking internet connection ended

        public async Task <string> Geolocation()
        {
            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 50;

            //var position = await locator.GetPositionAsync(timeoutMilliseconds: 10000);
            var position = await locator.GetPositionAsync();


            if (position == null)
            {
                return("");
            }
            lat = position.Latitude.ToString();
            lon = position.Longitude.ToString();

            /*
             *          //static coordinates of Washington:
             *          lat = "38.8951100"; lon = "-77.0363700";
             *          //Vinnitsya coords:
             *          lat = "49.2316534"; lon = "28.4986605";*/

            //replacing dot instead of comma in coordinates
            if (lat.Contains(","))
            {
                lat = lat.Replace(',', '.');
            }
            if (lon.Contains(","))
            {
                lon = lon.Replace(',', '.');
            }

            if (lat == null)
            {
            }
            else
            {
                //here we create DB
                dbr.CreateDB();
                textView1.Text = "Getting user`s info";
                await gettingJSON.VictorSologoob(lat, lon);

                StartActivity(typeof(RecyclerViewSample.MainActivity));
                //StartActivity(typeof(Login));
            }

            return("");
        }
Пример #2
0
        public async Task <string> Logining(string email, string password)
        {
            /*string email_val = email;
             * string password_val = password;*/
            var client  = new RestClient("http://api.xplorpal.com");
            var request = new RestRequest("/login", Method.POST);

            /*
             *          request.AddParameter("email", "*****@*****.**");
             *          request.AddParameter("password", "dontoretto23");
             */
            request.AddParameter("email", email);
            request.AddParameter("password", password);

            IRestResponse response = await client.ExecuteTaskAsync(request);

            var content = response.Content;

            // Toast.MakeText(this, content, ToastLength.Long).Show();
            //Console.WriteLine(content.ToString());

            if (content.Length > 100)//response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var usr  = JsonConvert.DeserializeObject <List <User> >(content);
                var usr_ = usr[0];
                try
                {
                    RecyclerViewSample.Login.token = usr_.api_token;
                }
                catch { }
                try
                {
                    RecyclerViewSample.Login.name = usr_.name;
                }
                catch { }
                try
                {
                    RecyclerViewSample.Login.email_ = usr_.email;
                }
                catch { }
                try
                {
                    RecyclerViewSample.Login.user_id = usr_.id;
                }
                catch { }
                try
                {
                    RecyclerViewSample.Login.user_country_id = Convert.ToInt32(usr_.user_country_id);
                }
                catch { }
                try
                {
                    RecyclerViewSample.Login.birth_date = usr_.birth_date.ToString();
                }
                catch { }
                try
                {
                    RecyclerViewSample.Login.gender = usr_.gender.ToString();
                }
                catch { }
                try
                {
                    RecyclerViewSample.Login.phone_num = usr_.phone_num.ToString();
                }
                catch { }
                try
                {
                    RecyclerViewSample.Login.interests = usr_.bio;
                }
                catch { }
                try
                {
                    RecyclerViewSample.Login.password = password;
                }
                catch { }
                try
                {
                    //removing this part of the content
                    RecyclerViewSample.Login.avatar = Convert.FromBase64String(usr_.avatar_base64.Replace("data:image/jpeg;base64,", ""));
                }
                catch { }

                //declaring path for RETRIEVING DATA
                string dbPath     = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "ormdemo.db3");
                var    db         = new SQLiteConnection(dbPath);
                var    user_table = db.Table <RecyclerViewSample.ORM.UsersDataTable>();

                RecyclerViewSample.MainActivity.isLogined = false;

                //clearing table
                foreach (var item in user_table)
                {
                    dbr.RemoveUsersData(item.Id);
                }

                dbr.InsertRecord(RecyclerViewSample.Login.name,
                                 RecyclerViewSample.Login.email_,
                                 RecyclerViewSample.Login.avatar,
                                 RecyclerViewSample.Login.token,
                                 RecyclerViewSample.Login.birth_date,
                                 RecyclerViewSample.Login.gender,
                                 RecyclerViewSample.Login.phone_num,
                                 RecyclerViewSample.Login.interests,
                                 RecyclerViewSample.Login.user_country_id,
                                 RecyclerViewSample.Login.user_id,
                                 RecyclerViewSample.Login.password);
                RecyclerViewSample.MainActivity.isLogined = true;
                GettingJSON gj = new GettingJSON();


                //await gj.VictorSologoob(token, lat, lon);
                //await gj.VictorSologoob(token, "38.8951100", "-77.0363700");
                if (RecyclerViewSample.Login.lat_For_places_of_interest_table != null)
                {
                    await gj.VictorSologoob(
                        RecyclerViewSample.Login.token,
                        RecyclerViewSample.Login.lat_For_places_of_interest_table,
                        RecyclerViewSample.Login.lng_For_places_of_interest_table);

                    login.addTo_placesOfInterest();
                }
                else
                {
                    //gj.VictorSologoob(token, "38.8951100", "-77.0363700");
                    await gj.VictorSologoob(
                        RecyclerViewSample.Login.token,
                        RecyclerViewSample.Activities.NEWstartActivity.lat,
                        RecyclerViewSample.Activities.NEWstartActivity.lon);

                    login.addTo_placesOfInterest();
                }

                string path     = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                var    filePath = System.IO.Path.Combine(path, "iootext.txt");
                using (var streamWriter = new StreamWriter(filePath, true))
                {
                    streamWriter.WriteLine(RecyclerViewSample.Login.token.ToString());
                }
                using (var streamReader = new StreamReader(filePath))
                {
                    string containing = streamReader.ReadToEnd();
                    System.Diagnostics.Debug.WriteLine(containing);
                }
                activityIndicator.Visibility = Android.Views.ViewStates.Gone;
                StartActivity(typeof(RecyclerViewSampl.ImageUpload));
                //StartActivity(typeof(MainActivity));
            }
            else
            {
                try
                {
                    activityIndicator.Visibility = Android.Views.ViewStates.Gone;
                }
                catch { }
                string toast = "Check your Email and Password";
                Toast.MakeText(this, toast, ToastLength.Long).Show();
            }
            return("");
        }
Пример #3
0
        public async Task <string> Logining()
        {
            Button   login              = FindViewById <Button>(Resource.Id.login_button);
            Button   cancelBn           = FindViewById <Button>(Resource.Id.cancelBn);
            TextView forgetYourPassword = FindViewById <TextView>(Resource.Id.forgetYourPassword);
            EditText email              = FindViewById <EditText>(Resource.Id.login_email);
            EditText passwordET         = FindViewById <EditText>(Resource.Id.login_password);

            if (String.IsNullOrWhiteSpace(email.Text) || String.IsNullOrWhiteSpace(passwordET.Text))
            {
                try
                {
                    activityIndicator.Visibility = Android.Views.ViewStates.Gone;
                }
                catch { }
                Toast.MakeText(this, "Credentials must not be empty", ToastLength.Short).Show();
            }
            else
            {
                activityIndicator.Visibility  = Android.Views.ViewStates.Visible;
                login.Visibility              = Android.Views.ViewStates.Gone;
                cancelBn.Visibility           = Android.Views.ViewStates.Gone;
                forgetYourPassword.Visibility = ViewStates.Gone;

                string   path2 = "fonts/HelveticaNeueLight.ttf";
                Typeface tf    = Typeface.CreateFromAsset(Assets, path2);
                email.Typeface      = tf;
                passwordET.Typeface = tf;

                string email_val    = email.Text;
                string password_val = passwordET.Text;
                var    client       = new RestClient("http://api.xplorpal.com");
                var    request      = new RestRequest("/login", Method.POST);

                /*
                 *          request.AddParameter("email", "*****@*****.**");
                 *          request.AddParameter("password", "dontoretto23");
                 */
                request.AddParameter("email", email.Text);
                request.AddParameter("password", passwordET.Text);

                IRestResponse response = await client.ExecuteTaskAsync(request);

                var content = response.Content;
                // Toast.MakeText(this, content, ToastLength.Long).Show();
                Console.WriteLine(content.ToString());

                if (content.Length > 100)//response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    try
                    {
                        var usr  = JsonConvert.DeserializeObject <List <User> >(content);
                        var usr_ = usr[0];
                        try
                        {
                            token = usr_.api_token;
                        }
                        catch { }
                        try
                        {
                            name = usr_.name;
                        }
                        catch { }
                        try
                        {
                            email_ = usr_.email;
                        }
                        catch { }
                        try
                        {
                            user_id = usr_.id;
                        }
                        catch { }
                        try

                        {
                            birth_date = usr_.birth_date.ToString();
                        }
                        catch { }
                        try
                        {
                            gender = usr_.gender.ToString();
                        }
                        catch { }
                        try
                        {
                            phone_num = usr_.phone_num.ToString();
                        }
                        catch { }
                        try
                        {
                            interests = usr_.bio;
                        }
                        catch { }
                        try
                        {
                            password = passwordET.Text;
                        }
                        catch { }
                        try
                        {
                            avatar = Convert.FromBase64String(usr_.avatar_base64.Replace("data:image/jpeg;base64,", ""));
                        }
                        catch { }
                        try{
                            user_country_id = Convert.ToInt32(usr_.user_country_id);
                        }catch {}
                    }
                    catch { }

                    /*ImageView Image = FindViewById<ImageView>(Resource.Id.imageView1);
                     * /*  Glide.With(Application.Context)
                     * .Load(avatar)
                     * .Into(Image);
                     * //WE NEED ALL OF THIS TO WRITE IMAGE TO DATABASE
                     * Image.BuildDrawingCache(true);
                     * Bitmap bitmap = Image.GetDrawingCache(true);
                     * Image.SetImageBitmap(bitmap);
                     * Bitmap b = Bitmap.CreateBitmap(Image.GetDrawingCache(true));
                     * MemoryStream memStream = new MemoryStream();
                     * b.Compress(Bitmap.CompressFormat.Webp, 100, memStream);
                     * //WE NEED ALL OF THIS TO WRITE IMAGE TO DATABASE ENDED
                     */

                    //declaring path for RETRIEVING DATA
                    string dbPath     = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "ormdemo.db3");
                    var    db         = new SQLiteConnection(dbPath);
                    var    user_table = db.Table <ORM.UsersDataTable>();

                    MainActivity.isLogined = false;

                    //clearing table
                    foreach (var item in user_table)
                    {
                        dbr.RemoveUsersData(item.Id);
                    }

                    dbr.InsertRecord(name, email_, avatar, token, birth_date, gender, phone_num, interests,
                                     RecyclerViewSample.Login.user_country_id, user_id, password);
                    MainActivity.isLogined = true;
                    GettingJSON gj = new GettingJSON();


                    //await gj.VictorSologoob(token, lat, lon);
                    //await gj.VictorSologoob(token, "38.8951100", "-77.0363700");
                    if (lat_For_places_of_interest_table != null)
                    {
                        await gj.VictorSologoob(token, lat_For_places_of_interest_table, lng_For_places_of_interest_table);

                        addTo_placesOfInterest();
                    }
                    else
                    {
                        //await gj.VictorSologoob(token, "38.8951100", "-77.0363700");
                        await gj.VictorSologoob(token, Activities.NEWstartActivity.lat, Activities.NEWstartActivity.lon);

                        addTo_placesOfInterest();
                    }

                    string path     = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    var    filePath = System.IO.Path.Combine(path, "iootext.txt");
                    using (var streamWriter = new StreamWriter(filePath, true))
                    {
                        streamWriter.WriteLine(token.ToString());
                    }
                    using (var streamReader = new StreamReader(filePath))
                    {
                        string containing = streamReader.ReadToEnd();
                        System.Diagnostics.Debug.WriteLine(containing);
                    }
                    activityIndicator.Visibility = Android.Views.ViewStates.Gone;
                    login.Visibility             = Android.Views.ViewStates.Visible;
                    cancelBn.Visibility          = Android.Views.ViewStates.Visible; forgetYourPassword.Visibility = ViewStates.Visible;
                    //StartActivity(typeof(MainActivity));

                    if (String.IsNullOrEmpty(Tours_detail.titleStatic))
                    {
                        StartActivity(typeof(MainActivity));
                    }
                    else
                    {
                        StartActivity(typeof(SelectAvialability));
                    }
                }
                else
                {
                    try
                    {
                        login.Visibility             = Android.Views.ViewStates.Visible;
                        cancelBn.Visibility          = Android.Views.ViewStates.Visible; forgetYourPassword.Visibility = ViewStates.Visible;
                        activityIndicator.Visibility = Android.Views.ViewStates.Gone;
                    }
                    catch { }
                    string toast = "Check your Email and Password";
                    Toast.MakeText(this, toast, ToastLength.Long).Show();
                }
            }
            return("");
        }
Пример #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.ChangeLocation);
            EditText change_location = FindViewById <EditText>(Resource.Id.change_location);
            Button   get_coordinates = FindViewById <Button>(Resource.Id.change_button);

            activityIndicator = FindViewById <ProgressBar>(Resource.Id.activityIndicator);

            //creating table of places of interest
            dbr.CreatePlacesOfInterestTable();

            is_places_of_interest_table_empty = true;

            string   path = "fonts/HelveticaNeueLight.ttf";
            Typeface tf   = Typeface.CreateFromAsset(Assets, path);

            get_coordinates.Typeface = tf;
            change_location.Typeface = tf;

            //declaring path for RETRIEVING THE IT OF THE LAST RECORD
            string dbPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "ormdemo.db3");
            var    db     = new SQLiteConnection(dbPath);
            var    places_of_interest_table = db.Table <PlacesOfInterestTable>();

            foreach (var item in places_of_interest_table)
            {
                is_places_of_interest_table_empty = false;
                last_places_of_interest_id        = item.Id;
            }

            get_coordinates.Click += async delegate
            {
                if (!String.IsNullOrWhiteSpace(change_location.Text))
                {
                    //dissmissing keyboard
                    InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
                    imm.HideSoftInputFromWindow(change_location.WindowToken, 0);
                    //dissmissing keyboard ENDED
                    try
                    {
                        SearchAdapter.experiencesStatic.Clear();
                    }
                    catch { }

                    activityIndicator.Visibility = Android.Views.ViewStates.Visible;
                    get_coordinates.Visibility   = Android.Views.ViewStates.Gone;
                    changedDestinationIndicator  = true;
                    string        city_val = change_location.Text;
                    var           client   = new RestClient("https://maps.googleapis.com/maps/api/geocode/json?address=");
                    var           request  = new RestRequest(city_val, Method.GET);
                    IRestResponse response = await client.ExecuteTaskAsync(request);

                    var content = response.Content;

                    var responseData1 = JsonConvert.DeserializeObject <RootObjectChangeLocation>(content);

                    if (content == null || content == "" || responseData1.results.Count == 0)
                    {
                        Toast.MakeText(this, "City is empty or incorrect", ToastLength.Short).Show();
                        activityIndicator.Visibility = Android.Views.ViewStates.Gone;
                        get_coordinates.Visibility   = Android.Views.ViewStates.Visible;
                    }
                    else
                    {
                        foreach (var data in responseData1.results)
                        {
                            if (!String.IsNullOrWhiteSpace(Login.token))
                            {
                                //replacing dot insead of comma in coordinates
                                foreach (char c in data.geometry.location.lat.ToString())
                                {
                                    if (c == ',')
                                    {
                                        lat_temp += ".";
                                    }
                                    else
                                    {
                                        lat_temp += c;
                                    }
                                }
                                foreach (char c in data.geometry.location.lng.ToString())
                                {
                                    if (c == ',')
                                    {
                                        lng_temp += ".";
                                    }
                                    else
                                    {
                                        lng_temp += c;
                                    }
                                }
                                //replacing dot insead of comma in coordinates ENDED
                                await gj.VictorSologoob(Login.token, lat_temp, lng_temp);
                            }
                            else if (String.IsNullOrWhiteSpace(Login.token))
                            {
                                //replacing dot insead of comma in coordinates
                                foreach (char c in data.geometry.location.lat.ToString())
                                {
                                    if (c == ',')
                                    {
                                        lat_temp += ".";
                                    }
                                    else
                                    {
                                        lat_temp += c;
                                    }
                                }
                                foreach (char c in data.geometry.location.lng.ToString())
                                {
                                    if (c == ',')
                                    {
                                        lng_temp += ".";
                                    }
                                    else
                                    {
                                        lng_temp += c;
                                    }
                                }
                                //replacing dot insead of comma in coordinates ENDED
                                await gj.VictorSologoob(lat_temp, lng_temp);
                            }

                            lat = data.geometry.location.lat + 0.005;
                            lng = data.geometry.location.lng + 0.005;

                            /*
                             * //replacing dot insead of comma in coordinates
                             * foreach (char c in lat.ToString())
                             * {
                             *  if (c == ',')
                             *  {
                             *      lat_temp += ".";
                             *  }
                             *  else
                             *  {
                             *      lat_temp += c;
                             *  }
                             * }
                             * foreach (char c in lng.ToString())
                             * {
                             *  if (c == ',')
                             *  {
                             *      lng_temp += ".";
                             *  }
                             *  else
                             *  {
                             *      lng_temp += c;
                             *  }
                             * }
                             * //replacing dot insead of comma in coordinates ENDED
                             *
                             * lat = Convert.ToDouble(lat_temp);
                             * lng = Convert.ToDouble(lng_temp);*/
                            lat_temp = null;
                            lng_temp = null;

                            foreach (var place_of_interest in await getData())
                            {
                                place_of_interestTitle  = place_of_interest.title;
                                place_of_interest_price = place_of_interest.price;
                            }
                            if (is_places_of_interest_table_empty == false)
                            {
                                //updating coordinats for PlacesOfInterestTable
                                dbr.updatePlacesOfInterestTable(last_places_of_interest_id, place_of_interestTitle, place_of_interest_price, data.geometry.location.lat.ToString(), data.geometry.location.lng.ToString());
                            }
                            else if (is_places_of_interest_table_empty == true)
                            {
                                dbr.InsertPlacesOfInterestRecord(place_of_interestTitle, place_of_interest_price, data.geometry.location.lat.ToString(), data.geometry.location.lng.ToString());
                            }

                            foreach (var item in places_of_interest_table)
                            {
                                last_places_of_interest_id = item.Id;
                            }

                            login.addTo_placesOfInterest();

                            Fragments.SearchFragment.searchByWordIndicator = false;
                            Tours_detail.searchOrMovieAdapterIndicator     = "MovieAdapter";
                            activityIndicator.Visibility = Android.Views.ViewStates.Gone;
                            get_coordinates.Visibility   = Android.Views.ViewStates.Visible;
                            StartActivity(typeof(MainActivity));
                        }
                    }
                    // Toast.MakeText(this, content, ToastLength.Long).Show();
                    Console.WriteLine(content.ToString());
                }
            };
        }