Exemplo n.º 1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.NewMessage);

            preferences = PreferenceManager.GetDefaultSharedPreferences(ApplicationContext);
            token = JsonConvert.DeserializeObject<AuthenticationToken>(preferences.GetString("token", null));

            mTimeTextView = FindViewById<TextView>(Resource.Id.timeTextView);
            mStartPlaceEditText = FindViewById<EditText>(Resource.Id.startPlaceEditText);
            mEndPlaceEditText = FindViewById<EditText>(Resource.Id.endPlaceEditText);
            mAddButton = FindViewById<Button>(Resource.Id.addButton);

            mTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
            mTimeTextView.Text = $"Czas: {mTime.ToString("HH:mm")}";

            mTimeTextView.Click += (object sender, EventArgs e) =>
            {
                var timePickerFragment = new TimePickerDialogFragment(this, mTime, this);
                timePickerFragment.Show(FragmentManager, null);
            };

            mAddButton.Click += async (object sender, EventArgs e) =>
            {   //sprawdzenie poprawnoœci wprowadzonych przez u¿ytkownika danych
                if (!mStartPlaceEditText.Text.Equals("") && !mEndPlaceEditText.Text.Equals(""))
                {
                    mStartPlace = mStartPlaceEditText.Text;
                    mEndPlace = mEndPlaceEditText.Text;
                    var traveler = JsonConvert.DeserializeObject<Traveler>(preferences.GetString("traveler", null));
                    if (traveler == null || token == null)
                    {
                        Toast.MakeText(this, GetString(Resource.String.LoginTokenOrTravelerFailure), ToastLength.Long).Show();
                        Finish();
                        StartActivity(typeof(LoginActivity));
                    }
                    else
                    {
                        //utworzenie nowego obiektu - wiadomoœci
                        newMessage = new Information
                        {
                            TravelerId = traveler.Id,
                            StartPlace = mStartPlace,
                            EndPlace = mEndPlace,
                            Time = mTime
                        };
                        //sprawdzenie, czy œrodowisko jest po³¹czone z sieci¹ Internet
                        var connectivityManager = (ConnectivityManager) GetSystemService(ConnectivityService);
                        var activeNetworkInfo = connectivityManager.ActiveNetworkInfo;
                        if (activeNetworkInfo == null || !activeNetworkInfo.IsConnected)
                        {
                            Toast.MakeText(this, GetString(Resource.String.NoConnectionInfo), ToastLength.Long).Show();
                            return;
                        }
                        //wywo³anie okna dialogowego progresu
                        var loadingMessage = ProgressDialog.Show(this, GetString(Resource.String.SendingMessageTitle),
                            GetString(Resource.String.SendingMessageContent), true, false);

                        //wywo³anie metody obs³uguj¹cej ¿¹danie http i oczekiwanie na wiadomoœæ
                        var apiMessage = await SaveMyMessage(newMessage);
                        loadingMessage.Dismiss();
                        if (apiMessage.IsSuccessStatusCode)
                        {
                            //ustawienie pozytywnego rezultatu operacji i zakoñczenie aktywnoœci
                            SetResult(Result.Ok);
                        }
                        Finish();
                    }
                }
                else Toast.MakeText(this, GetString(Resource.String.NewMessageNoDataInfo), ToastLength.Long).Show();
            };
        }
Exemplo n.º 2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.FindOtherTravelers);

            preferences = PreferenceManager.GetDefaultSharedPreferences(ApplicationContext);

            mTimeTextView            = FindViewById <TextView>(Resource.Id.otherTravelerTimeTextView);
            mFindOtherTravelerButton = FindViewById <Button>(Resource.Id.findOtherTravelerButton);
            mStartPlaceEdit          = FindViewById <EditText>(Resource.Id.OtherTravelerStartPlaceEditText);
            mEndPlaceEdit            = FindViewById <EditText>(Resource.Id.OtherTravelerEndPlaceEditText);

            mTravelTime        = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
            mTimeTextView.Text = $"Czas: {mTravelTime.ToString("HH:mm")}";

            mTimeTextView.Click += (object sender, EventArgs e) =>
            {
                var timePickerFragment = new TimePickerDialogFragment(this, mTravelTime, this);
                timePickerFragment.Show(FragmentManager, null);
            };

            mFindOtherTravelerButton.Click += async(object sender, EventArgs e) =>
            {
                if (mStartPlaceEdit.Text.Equals("") || mEndPlaceEdit.Text.Equals(""))
                {
                    Toast.MakeText(this, GetString(Resource.String.OtherTravelersNoDataInfo), ToastLength.Long).Show();
                }
                else
                {
                    mStartPlace = mStartPlaceEdit.Text;
                    mEndPlace   = mEndPlaceEdit.Text;
                    var token = JsonConvert.DeserializeObject <AuthenticationToken>(preferences.GetString("token", null));
                    if (token == null)
                    {
                        Toast.MakeText(this, GetString(Resource.String.LoginTokenOrTravelerFailure), ToastLength.Long)
                        .Show();
                        Finish();
                        StartActivity(typeof(LoginActivity));
                    }
                    var connectivityManager = (ConnectivityManager)GetSystemService(ConnectivityService);
                    var activeNetworkInfo   = connectivityManager.ActiveNetworkInfo;
                    if (activeNetworkInfo == null || !activeNetworkInfo.IsConnected)
                    {
                        Toast.MakeText(this, GetString(Resource.String.NoConnectionInfo), ToastLength.Long).Show();
                        return;
                    }
                    var url = string.Format(GetString(Resource.String.ApiLink)
                                            + "/api/information/getothertravelersbyinformations?travelHour={0}&travelMinutes={1}&startPlace={2}&endPlace={3}",
                                            mTravelTime.Hour, mTravelTime.Minute, mStartPlace, mEndPlace);
                    client = new HttpClient();
                    client.DefaultRequestHeaders.Authorization =
                        new AuthenticationHeaderValue(token.TokenType, token.AccessToken);

                    var loadingMessage = ProgressDialog.Show(this,
                                                             GetString(Resource.String.OtherTravelersListLoadingTitle),
                                                             GetString(Resource.String.OtherTravelersListLoadingContent), true, false);
                    var response = await client.GetAsync(new Uri(url));

                    loadingMessage.Dismiss();

                    if (response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStringAsync();

                        var otherTravelersActivityIntent = new Intent(this, typeof(OtherTravelersActivity));
                        var putContent = new Bundle();
                        putContent.PutString("ResponseContent", content);
                        putContent.PutString("StartPlace", mStartPlace);
                        putContent.PutString("EndPlace", mEndPlace);
                        otherTravelersActivityIntent.PutExtras(putContent);
                        StartActivity(otherTravelersActivityIntent);
                    }
                    else if (response.StatusCode == HttpStatusCode.NotFound)
                    {
                        Toast.MakeText(this, GetString(Resource.String.OtherTravelersNotFoundInfo), ToastLength.Long)
                        .Show();
                    }
                    else
                    {
                        Toast.MakeText(this, GetString(Resource.String.OtherTravelersNotOkInfo), ToastLength.Long)
                        .Show();
                    }
                }
            };
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.FindOtherTravelers);

            preferences = PreferenceManager.GetDefaultSharedPreferences(ApplicationContext);

            mTimeTextView = FindViewById<TextView>(Resource.Id.otherTravelerTimeTextView);
            mFindOtherTravelerButton = FindViewById<Button>(Resource.Id.findOtherTravelerButton);
            mStartPlaceEdit = FindViewById<EditText>(Resource.Id.OtherTravelerStartPlaceEditText);
            mEndPlaceEdit = FindViewById<EditText>(Resource.Id.OtherTravelerEndPlaceEditText);

            mTravelTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
            mTimeTextView.Text = $"Czas: {mTravelTime.ToString("HH:mm")}";

            mTimeTextView.Click += (object sender, EventArgs e) =>
            {
                var timePickerFragment = new TimePickerDialogFragment(this, mTravelTime, this);
                timePickerFragment.Show(FragmentManager, null);
            };

            mFindOtherTravelerButton.Click += async (object sender, EventArgs e) =>
            {
                if (mStartPlaceEdit.Text.Equals("") || mEndPlaceEdit.Text.Equals(""))
                    Toast.MakeText(this, GetString(Resource.String.OtherTravelersNoDataInfo), ToastLength.Long).Show();
                else
                {
                    mStartPlace = mStartPlaceEdit.Text;
                    mEndPlace = mEndPlaceEdit.Text;
                    var token = JsonConvert.DeserializeObject<AuthenticationToken>(preferences.GetString("token", null));
                    if (token == null)
                    {
                        Toast.MakeText(this, GetString(Resource.String.LoginTokenOrTravelerFailure), ToastLength.Long)
                            .Show();
                        Finish();
                        StartActivity(typeof(LoginActivity));
                    }
                    var connectivityManager = (ConnectivityManager) GetSystemService(ConnectivityService);
                    var activeNetworkInfo = connectivityManager.ActiveNetworkInfo;
                    if (activeNetworkInfo == null || !activeNetworkInfo.IsConnected)
                    {
                        Toast.MakeText(this, GetString(Resource.String.NoConnectionInfo), ToastLength.Long).Show();
                        return;
                    }
                    var url = string.Format(GetString(Resource.String.ApiLink)
                        + "/api/information/getothertravelersbyinformations?travelHour={0}&travelMinutes={1}&startPlace={2}&endPlace={3}",
                        mTravelTime.Hour, mTravelTime.Minute, mStartPlace, mEndPlace);
                    client = new HttpClient();
                    client.DefaultRequestHeaders.Authorization =
                        new AuthenticationHeaderValue(token.TokenType, token.AccessToken);

                    var loadingMessage = ProgressDialog.Show(this,
                        GetString(Resource.String.OtherTravelersListLoadingTitle),
                        GetString(Resource.String.OtherTravelersListLoadingContent), true, false);
                    var response = await client.GetAsync(new Uri(url));
                    loadingMessage.Dismiss();

                    if (response.IsSuccessStatusCode)
                    {
                        var content = await response.Content.ReadAsStringAsync();
                        var otherTravelersActivityIntent = new Intent(this, typeof (OtherTravelersActivity));
                        var putContent = new Bundle();
                        putContent.PutString("ResponseContent", content);
                        putContent.PutString("StartPlace", mStartPlace);
                        putContent.PutString("EndPlace", mEndPlace);
                        otherTravelersActivityIntent.PutExtras(putContent);
                        StartActivity(otherTravelersActivityIntent);
                    }
                    else if (response.StatusCode == HttpStatusCode.NotFound)
                        Toast.MakeText(this, GetString(Resource.String.OtherTravelersNotFoundInfo), ToastLength.Long)
                            .Show();
                    else
                        Toast.MakeText(this, GetString(Resource.String.OtherTravelersNotOkInfo), ToastLength.Long)
                            .Show();
                }
            };
        }
Exemplo n.º 4
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.NewMessage);

            preferences = PreferenceManager.GetDefaultSharedPreferences(ApplicationContext);
            token       = JsonConvert.DeserializeObject <AuthenticationToken>(preferences.GetString("token", null));

            mTimeTextView       = FindViewById <TextView>(Resource.Id.timeTextView);
            mStartPlaceEditText = FindViewById <EditText>(Resource.Id.startPlaceEditText);
            mEndPlaceEditText   = FindViewById <EditText>(Resource.Id.endPlaceEditText);
            mAddButton          = FindViewById <Button>(Resource.Id.addButton);

            mTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0);
            mTimeTextView.Text = $"Czas: {mTime.ToString("HH:mm")}";

            mTimeTextView.Click += (object sender, EventArgs e) =>
            {
                var timePickerFragment = new TimePickerDialogFragment(this, mTime, this);
                timePickerFragment.Show(FragmentManager, null);
            };

            mAddButton.Click += async(object sender, EventArgs e) =>
            {   //sprawdzenie poprawnoœci wprowadzonych przez u¿ytkownika danych
                if (!mStartPlaceEditText.Text.Equals("") && !mEndPlaceEditText.Text.Equals(""))
                {
                    mStartPlace = mStartPlaceEditText.Text;
                    mEndPlace   = mEndPlaceEditText.Text;
                    var traveler = JsonConvert.DeserializeObject <Traveler>(preferences.GetString("traveler", null));
                    if (traveler == null || token == null)
                    {
                        Toast.MakeText(this, GetString(Resource.String.LoginTokenOrTravelerFailure), ToastLength.Long).Show();
                        Finish();
                        StartActivity(typeof(LoginActivity));
                    }
                    else
                    {
                        //utworzenie nowego obiektu - wiadomoœci
                        newMessage = new Information
                        {
                            TravelerId = traveler.Id,
                            StartPlace = mStartPlace,
                            EndPlace   = mEndPlace,
                            Time       = mTime
                        };
                        //sprawdzenie, czy œrodowisko jest po³¹czone z sieci¹ Internet
                        var connectivityManager = (ConnectivityManager)GetSystemService(ConnectivityService);
                        var activeNetworkInfo   = connectivityManager.ActiveNetworkInfo;
                        if (activeNetworkInfo == null || !activeNetworkInfo.IsConnected)
                        {
                            Toast.MakeText(this, GetString(Resource.String.NoConnectionInfo), ToastLength.Long).Show();
                            return;
                        }
                        //wywo³anie okna dialogowego progresu
                        var loadingMessage = ProgressDialog.Show(this, GetString(Resource.String.SendingMessageTitle),
                                                                 GetString(Resource.String.SendingMessageContent), true, false);

                        //wywo³anie metody obs³uguj¹cej ¿¹danie http i oczekiwanie na wiadomoœæ
                        var apiMessage = await SaveMyMessage(newMessage);

                        loadingMessage.Dismiss();
                        if (apiMessage.IsSuccessStatusCode)
                        {
                            //ustawienie pozytywnego rezultatu operacji i zakoñczenie aktywnoœci
                            SetResult(Result.Ok);
                        }
                        Finish();
                    }
                }
                else
                {
                    Toast.MakeText(this, GetString(Resource.String.NewMessageNoDataInfo), ToastLength.Long).Show();
                }
            };
        }