diff --git a/app/src/main/java/com/example/nemophila/LoginActivity.java b/app/src/main/java/com/example/nemophila/LoginActivity.java index cd63a63..6446c87 100644 --- a/app/src/main/java/com/example/nemophila/LoginActivity.java +++ b/app/src/main/java/com/example/nemophila/LoginActivity.java @@ -9,7 +9,9 @@ import android.widget.TextView; import com.example.nemophila.entities.Account; +import com.example.nemophila.entities.AccountJson; import com.example.nemophila.resources.AccountsRest; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import retrofit2.Call; import retrofit2.Callback; @@ -17,6 +19,7 @@ import retrofit2.Retrofit; import retrofit2.converter.jackson.JacksonConverterFactory; +@JsonIgnoreProperties(ignoreUnknown=true) public class LoginActivity extends AppCompatActivity { private Retrofit retrofit; @@ -43,11 +46,11 @@ String pw = editpw.getText().toString(); // 通信 - Call call = AccountsRest.getAccounts(uid,pw); + Call call = AccountsRest.getAccounts(uid,pw); - call.enqueue (new Callback() { + call.enqueue (new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { if (response.isSuccessful()) { System.out.println("通信成功:changeBelongsAndMaster"); Intent intent = new Intent(LoginActivity.this,MainActivity.class); @@ -56,15 +59,16 @@ System.out.println("通信可能:changeBelongsAndMaster: " + response.code()); if (response.code() == 500){ ((TextView) findViewById(R.id.textView)).setText("Invalid UserID or Password"); - }else if (response.code() == 404){ + } else if (response.code() == 404){ ((TextView) findViewById(R.id.textView)).setText("Login failed. Please enter the correct credentials."); } } } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { System.out.println("通信失敗:changeBelongsAndMaster"); + System.out.println(t); } }); } diff --git a/app/src/main/java/com/example/nemophila/SignUpActivity.java b/app/src/main/java/com/example/nemophila/SignUpActivity.java index 9a412a6..0b1aa70 100644 --- a/app/src/main/java/com/example/nemophila/SignUpActivity.java +++ b/app/src/main/java/com/example/nemophila/SignUpActivity.java @@ -9,6 +9,7 @@ import android.widget.TextView; import com.example.nemophila.entities.Account; +import com.example.nemophila.entities.AccountJson; import com.example.nemophila.resources.AccountsRest; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -17,6 +18,7 @@ import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.converter.jackson.JacksonConverterFactory; + @JsonIgnoreProperties(ignoreUnknown=true) public class SignUpActivity extends AppCompatActivity{ @@ -44,11 +46,11 @@ String pw = editpw.getText().toString(); // 通信 - Call call = AccountsRest.createAccounts(name,pw); + Call call = AccountsRest.createAccounts(name,pw); - call.enqueue(new Callback() { + call.enqueue(new Callback() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call call, Response response) { if (response.isSuccessful()) { System.out.println("通信成功:changeBelongsAndMaster"); Intent intent = new Intent(SignUpActivity.this,MainActivity.class); @@ -64,8 +66,9 @@ } @Override - public void onFailure(Call call, Throwable t) { + public void onFailure(Call call, Throwable t) { System.out.println("通信失敗:changeBelongsAndMaster"); + System.out.println(t); } }); } diff --git a/app/src/main/java/com/example/nemophila/entities/Account.java b/app/src/main/java/com/example/nemophila/entities/Account.java index 9ebbf12..e96a2ce 100644 --- a/app/src/main/java/com/example/nemophila/entities/Account.java +++ b/app/src/main/java/com/example/nemophila/entities/Account.java @@ -1,6 +1,7 @@ package com.example.nemophila.entities; import java.util.HashMap; +import java.util.Map; public class Account { private String name; @@ -43,4 +44,10 @@ public void setPosts(HashMap posts) { this.posts = posts; } + + public Account(AccountJson aj){ + this.name = aj.getName(); + this.id = aj.getId(); + this.token = aj.getToken(); + } } diff --git a/app/src/main/java/com/example/nemophila/resources/AccountsRest.java b/app/src/main/java/com/example/nemophila/resources/AccountsRest.java index 3d57bc1..fb95de5 100644 --- a/app/src/main/java/com/example/nemophila/resources/AccountsRest.java +++ b/app/src/main/java/com/example/nemophila/resources/AccountsRest.java @@ -3,6 +3,7 @@ //import android.accounts.Account; import com.example.nemophila.entities.Account; +import com.example.nemophila.entities.AccountJson; import com.example.nemophila.entities.Post; import java.util.Collection; @@ -24,7 +25,7 @@ @FormUrlEncoded @POST("accounts") - Call createAccounts( + Call createAccounts( @Field("name") String name, @Field("pw") String pw ); @@ -41,7 +42,7 @@ @FormUrlEncoded @POST("accounts/{uid}/login") - Call getAccounts( + Call getAccounts( @Path("uid") String uid, @Field("pw")String pw );