POS-30 Dodano obsługę błędów - klient

This commit is contained in:
Wojciech Przybyła 2021-01-02 20:21:03 +01:00
parent da4287973e
commit 6586dc6170
4 changed files with 753 additions and 688 deletions

View File

@ -47,13 +47,18 @@ namespace Klient.Droid
if (Login.Length < 3 || Login.Length > 12)
{
SetContentView(Resource.Layout.ekranLogowania);
FindViewById<TextView>(Resource.Id.ErrorLogIn).Text = "Hasło musi mieć od 3 do 12 znaków!";
FindViewById<EditText>(Resource.Id.Login).Text = "";
FindViewById<EditText>(Resource.Id.Password).Text = "";
}
if (string.IsNullOrWhiteSpace(new NetworkCredential("", Password).Password))
else if (string.IsNullOrWhiteSpace(new NetworkCredential("", Password).Password))
{
SetContentView(Resource.Layout.ekranLogowania);
FindViewById<TextView>(Resource.Id.ErrorLogIn).Text = "Hasło musi mieć od 3 do 12 znaków!";
FindViewById<EditText>(Resource.Id.Login).Text = "";
FindViewById<EditText>(Resource.Id.Password).Text = "";
}
else
{
var values = new Dictionary<string, string>
{
{ "login", Login },
@ -76,6 +81,15 @@ namespace Klient.Droid
userToken = jsonObject.jwt.token;
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", userToken);
}
else
{
string msg = await response.Content.ReadAsStringAsync();
FindViewById<TextView>(Resource.Id.ErrorLogIn).Text = msg;
FindViewById<EditText>(Resource.Id.Login).Text = "";
FindViewById<EditText>(Resource.Id.Password).Text = "";
}
}
}
[Java.Interop.Export("SignUp")]
@ -90,9 +104,13 @@ namespace Klient.Droid
if (new NetworkCredential("", Password).Password != new NetworkCredential("", Password2).Password)
{
SetContentView(Resource.Layout.ekranRejestracji);
FindViewById<TextView>(Resource.Id.ErrorRegister).Text = "Hasła muszą być identyczne!";
FindViewById<EditText>(Resource.Id.NewLogin).Text = "";
FindViewById<EditText>(Resource.Id.Password).Text = "";
FindViewById<EditText>(Resource.Id.RepeatPassword).Text = "";
}
else
{
var values = new Dictionary<string, string>
{
{ "email", Email },
@ -109,6 +127,15 @@ namespace Klient.Droid
var responseString = await response.Content.ReadAsStringAsync();
if (response.StatusCode == HttpStatusCode.OK) SetContentView(Resource.Layout.ekranLogowania);
else
{
string msg = await response.Content.ReadAsStringAsync();
FindViewById<TextView>(Resource.Id.ErrorRegister).Text = msg;
FindViewById<EditText>(Resource.Id.NewLogin).Text = "";
FindViewById<EditText>(Resource.Id.Password).Text = "";
FindViewById<EditText>(Resource.Id.RepeatPassword).Text = "";
}
}
}
[Java.Interop.Export("HelpLoginScreen")]
@ -179,6 +206,15 @@ namespace Klient.Droid
break;
}
var response = await client.PostAsync("http://10.0.2.2:5001/api/Image/Process", formDataContent);
if(response.StatusCode == HttpStatusCode.OK)
{
FindViewById<TextView>(Resource.Id.ErrorPhoto).Text = "Przesłano zdjęcie!";
}
else
{
string msg = await response.Content.ReadAsStringAsync();
FindViewById<TextView>(Resource.Id.ErrorPhoto).Text = msg;
}
}
}
@ -232,6 +268,11 @@ namespace Klient.Droid
savedEmail = jsonObject.email;
savedSurname = jsonObject.surname;
}
else
{
string msg = await response.Content.ReadAsStringAsync();
FindViewById<TextView>(Resource.Id.NullValueProfile).Text = msg;
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -82,6 +82,15 @@
android:textColor="#fffcfcfc"
android:gravity="center"
android:onClick="GoToStart"/>
<TextView
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ErrorLogIn"
android:textColor="#ffd60000"
android:layout_below="@id/In"
android:layout_centerHorizontal="true" />
<TextView
android:text="Poszukiwacz 2020"
android:textAppearance="?android:attr/textAppearanceSmall"

View File

@ -140,6 +140,15 @@
android:textColor="#ff000000"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<TextView
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ErrorRegister"
android:textColor="#ffd60000"
android:layout_below="@id/SignUp"
android:layout_centerHorizontal="true" />
<Button
android:text="?"
android:layout_width="35.0dp"