diff --git a/app/src/main/java/com/khumu/android/data/Info21UserInfo.java b/app/src/main/java/com/khumu/android/data/Info21UserInfo.java new file mode 100644 index 0000000..8f85eb6 --- /dev/null +++ b/app/src/main/java/com/khumu/android/data/Info21UserInfo.java @@ -0,0 +1,18 @@ +package com.khumu.android.data; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import java.io.Serializable; + +import lombok.Builder; +import lombok.Data; + +@JsonSerialize +@Data +@Builder +public class Info21UserInfo implements Serializable { + String name; + String StudentNum; + String Dept; + Boolean verified; +} diff --git a/app/src/main/java/com/khumu/android/data/KhumuUser.java b/app/src/main/java/com/khumu/android/data/KhumuUser.java index f5cee94..b675707 100644 --- a/app/src/main/java/com/khumu/android/data/KhumuUser.java +++ b/app/src/main/java/com/khumu/android/data/KhumuUser.java @@ -1,13 +1,19 @@ package com.khumu.android.data; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.io.Serializable; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; // 현재는 Sign up 할 때에만 사용하기때문에 json => Java instance로의 변환은 구현하지않음. @NoArgsConstructor +@Getter +@Setter +@JsonSerialize public class KhumuUser implements Serializable { private String username; private String nickname; @@ -15,6 +21,7 @@ public class KhumuUser implements Serializable { private String email; private String studentNumber; private String department; + private String kind; public KhumuUser(String username, String nickname, String password, String email, @JsonProperty("student_number") String studentNumber, String department) { @@ -25,52 +32,4 @@ public KhumuUser(String username, String nickname, String password, String email this.studentNumber = studentNumber; this.department = department; } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getNickname() { - return nickname; - } - - public void setNickname(String nickname) { - this.nickname = nickname; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getStudentNumber() { - return studentNumber; - } - - public void setStudentNumber(String studentNumber) { - this.studentNumber = studentNumber; - } - - public String getDepartment() { - return department; - } - - public void setDepartment(String department) { - this.department = department; - } } diff --git a/app/src/main/java/com/khumu/android/data/rest/DefaultResponse.java b/app/src/main/java/com/khumu/android/data/rest/DefaultResponse.java index 20b55b7..9da0a0d 100644 --- a/app/src/main/java/com/khumu/android/data/rest/DefaultResponse.java +++ b/app/src/main/java/com/khumu/android/data/rest/DefaultResponse.java @@ -2,14 +2,20 @@ import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; @Getter @Setter -public class DefaultResponse { +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DefaultResponse { @SerializedName("data") - Object data; + T data; @SerializedName("message") String message; } diff --git a/app/src/main/java/com/khumu/android/data/rest/Info21AuthenticationRequest.java b/app/src/main/java/com/khumu/android/data/rest/Info21AuthenticationRequest.java new file mode 100644 index 0000000..3f3c27e --- /dev/null +++ b/app/src/main/java/com/khumu/android/data/rest/Info21AuthenticationRequest.java @@ -0,0 +1,16 @@ +package com.khumu.android.data.rest; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +import java.io.Serializable; + +import lombok.Builder; +import lombok.Data; + +@JsonSerialize +@Data +@Builder +public class Info21AuthenticationRequest implements Serializable { + String username; + String password; +} diff --git a/app/src/main/java/com/khumu/android/data/rest/UserResponse.java b/app/src/main/java/com/khumu/android/data/rest/UserResponse.java index 6c0e7b3..860e41f 100644 --- a/app/src/main/java/com/khumu/android/data/rest/UserResponse.java +++ b/app/src/main/java/com/khumu/android/data/rest/UserResponse.java @@ -7,11 +7,13 @@ import java.util.List; +import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor +@AllArgsConstructor public class UserResponse { @SerializedName("data") @Expose diff --git a/app/src/main/java/com/khumu/android/di/component/ApplicationComponent.java b/app/src/main/java/com/khumu/android/di/component/ApplicationComponent.java index efcbf26..1631f5a 100644 --- a/app/src/main/java/com/khumu/android/di/component/ApplicationComponent.java +++ b/app/src/main/java/com/khumu/android/di/component/ApplicationComponent.java @@ -29,7 +29,10 @@ import com.khumu.android.repository.LikeArticleRepository; import com.khumu.android.di.module.RetrofitModule; import com.khumu.android.search.CommunitySearchActivity; +import com.khumu.android.signUp.AdditionalFormFragment; +import com.khumu.android.signUp.Info21AuthenticationFragment; import com.khumu.android.signUp.Info21SignUpActivity; +import com.khumu.android.signUp.SignUpAgreementFragment; import com.khumu.android.study.StudyAdapter; import com.khumu.android.study.StudyFragment; @@ -80,6 +83,9 @@ public interface ApplicationComponent { void inject(MyPageFragment myPageFragment); void inject(BoardListFragment boardListFragment); void inject(HotBoardFeedFragment fragment); + void inject(SignUpAgreementFragment fragment); + void inject(Info21AuthenticationFragment fragment); + void inject(AdditionalFormFragment fragment); void inject(KhumuApplication application); void inject(LoginActivity loginActivity); diff --git a/app/src/main/java/com/khumu/android/repository/UserService.java b/app/src/main/java/com/khumu/android/repository/UserService.java index ea8fa95..f232539 100644 --- a/app/src/main/java/com/khumu/android/repository/UserService.java +++ b/app/src/main/java/com/khumu/android/repository/UserService.java @@ -1,8 +1,11 @@ package com.khumu.android.repository; import com.khumu.android.data.Comment; +import com.khumu.android.data.Info21UserInfo; import com.khumu.android.data.KhumuUser; import com.khumu.android.data.SimpleComment; +import com.khumu.android.data.rest.DefaultResponse; +import com.khumu.android.data.rest.Info21AuthenticationRequest; import com.khumu.android.data.rest.UserResponse; import retrofit2.Call; @@ -14,4 +17,7 @@ public interface UserService { @POST("users") Call signUp(@Header("Content-Type") String contentType, @Body KhumuUser user); + + @POST("users/verify-new-student") + Call> verifyNewStudent(@Header("Content-Type") String contentType, @Body Info21AuthenticationRequest input); } diff --git a/app/src/main/java/com/khumu/android/signUp/AdditionalFormFragment.java b/app/src/main/java/com/khumu/android/signUp/AdditionalFormFragment.java new file mode 100644 index 0000000..ecde755 --- /dev/null +++ b/app/src/main/java/com/khumu/android/signUp/AdditionalFormFragment.java @@ -0,0 +1,115 @@ +/** + * BaseFeedFragment를 상속받아 크게 추가할 내용은 없고, abstract method인 provideViewModel작업만 정의해주면됨. + * 기본적인 feed의 layout인 layout_feed.xml을 이용. + */ +package com.khumu.android.signUp; + +import android.content.Context; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; +import androidx.databinding.DataBindingUtil; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.ViewModelProvider; + +import com.khumu.android.KhumuApplication; +import com.khumu.android.R; +import com.khumu.android.component.AutoDismissAlertDialog; +import com.khumu.android.data.Info21UserInfo; +import com.khumu.android.data.rest.DefaultResponse; +import com.khumu.android.data.rest.UserResponse; +import com.khumu.android.databinding.FragmentSignUpAdditionalFormBinding; + +import cn.pedant.SweetAlert.SweetAlertDialog; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class AdditionalFormFragment extends Fragment { + private final static String TAG = "AdditionalFormFragment"; + private SignUpViewModel signUpViewModel; + private FragmentSignUpAdditionalFormBinding binding; + + public AdditionalFormFragment(SignUpViewModel viewModel) { + this.signUpViewModel = viewModel; + } + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + // Layout inflate 이전 + // savedInstanceState을 이용해 다룰 데이터가 있으면 다룸. + super.onCreate(savedInstanceState); + Log.d(TAG, "onCreate: "); + KhumuApplication.applicationComponent.inject(this); + this.signUpViewModel = new ViewModelProvider(this.getActivity()).get(SignUpViewModel.class); + } + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + binding = DataBindingUtil.inflate(inflater, R.layout.fragment_sign_up_additional_form, container, false); + // binding하며 사용할 Fragment가 사용하는 변수인 viewModel을 설정해줌. + binding.setViewModel(this.signUpViewModel); + binding.setFragment(this); + // LiveData를 이용해 Observe하기 위해선 그 LifeCyclerOwner가 꼭 필요하다! + // 그렇지 않으면 유효하게 Observer로 동작하지 않고 아무 변화 없음... + binding.setLifecycleOwner(this.getActivity()); + View root = binding.getRoot(); + return root; + } + + public void onClickNextBTN(View view) { + Context context = AdditionalFormFragment.this.getActivity(); + Info21SignUpActivity activity = (Info21SignUpActivity) context; + SweetAlertDialog progressDialog = new SweetAlertDialog(context, SweetAlertDialog.PROGRESS_TYPE); + progressDialog.getProgressHelper().setBarColor(ContextCompat.getColor(context, R.color.red_500)); + progressDialog.setTitleText("회원가입 중입니다"); + progressDialog.setCancelable(false); + progressDialog.show(); + new Thread(){ + @Override + public void run() { + UserResponse resp = signUpViewModel.signUp(); + progressDialog.dismiss(); + // 가입 실패 + if (resp.getData() == null && resp.getMessage() != null) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + AutoDismissAlertDialog errorDialog = new AutoDismissAlertDialog(context, SweetAlertDialog.ERROR_TYPE, "회원가입을 완료하지 못했습니다.", resp.getMessage(), 2000L); + errorDialog.getProgressHelper().setBarColor(ContextCompat.getColor(context, R.color.red_500)); + errorDialog.setCancelable(false); + errorDialog.show(); + } + }); + } else{ + // 가입 성공 + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + SweetAlertDialog successDialog = new SweetAlertDialog(context, SweetAlertDialog.BUTTON_CONFIRM); + successDialog.setTitle("회원가입을 성공했습니다."); + successDialog.setContentText(signUpViewModel.getUser().getValue().getNickname() + "님 환영합니다 >_<"); + successDialog.setCancelable(false); + successDialog.setConfirmText("로그인하러 가기"); + successDialog.show(); + successDialog.setOnDismissListener(v ->{ + activity.proceedSignUpStep(); + }); + } + }); + + } + } + }.start(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/khumu/android/signUp/Info21AuthenticationFragment.java b/app/src/main/java/com/khumu/android/signUp/Info21AuthenticationFragment.java new file mode 100644 index 0000000..8b19573 --- /dev/null +++ b/app/src/main/java/com/khumu/android/signUp/Info21AuthenticationFragment.java @@ -0,0 +1,109 @@ +/** + * BaseFeedFragment를 상속받아 크게 추가할 내용은 없고, abstract method인 provideViewModel작업만 정의해주면됨. + * 기본적인 feed의 layout인 layout_feed.xml을 이용. + */ +package com.khumu.android.signUp; + +import android.content.Context; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; +import androidx.databinding.DataBindingUtil; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.ViewModelProvider; + +import com.khumu.android.KhumuApplication; +import com.khumu.android.R; +import com.khumu.android.component.AutoDismissAlertDialog; +import com.khumu.android.data.Info21UserInfo; +import com.khumu.android.data.rest.DefaultResponse; +import com.khumu.android.databinding.FragmentInfo21AuthenticationFormBinding; + +import cn.pedant.SweetAlert.SweetAlertDialog; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Info21AuthenticationFragment extends Fragment { + private final static String TAG = "Info21AuthenticationFragment"; + private SignUpViewModel signUpViewModel; + private FragmentInfo21AuthenticationFormBinding binding; + + public Info21AuthenticationFragment(SignUpViewModel viewModel) { + this.signUpViewModel = viewModel; + } + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + // Layout inflate 이전 + // savedInstanceState을 이용해 다룰 데이터가 있으면 다룸. + super.onCreate(savedInstanceState); + Log.d(TAG, "onCreate: "); + KhumuApplication.applicationComponent.inject(this); + this.signUpViewModel = new ViewModelProvider(this.getActivity()).get(SignUpViewModel.class); + } + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + binding = DataBindingUtil.inflate(inflater, R.layout.fragment_info21_authentication_form, container, false); + // binding하며 사용할 Fragment가 사용하는 변수인 viewModel을 설정해줌. + binding.setViewModel(this.signUpViewModel); + binding.setFragment(this); + // LiveData를 이용해 Observe하기 위해선 그 LifeCyclerOwner가 꼭 필요하다! + // 그렇지 않으면 유효하게 Observer로 동작하지 않고 아무 변화 없음... + binding.setLifecycleOwner(this.getActivity()); + View root = binding.getRoot(); + return root; + } + + public void onClickNextBTN(View view) { + Context context = Info21AuthenticationFragment.this.getActivity(); + Info21SignUpActivity activity = (Info21SignUpActivity) context; + SweetAlertDialog progressDialog = new SweetAlertDialog(context, SweetAlertDialog.PROGRESS_TYPE); + progressDialog.getProgressHelper().setBarColor(ContextCompat.getColor(context, R.color.red_500)); + progressDialog.setTitleText("인포21 인증 중입니다"); + progressDialog.setCancelable(false); + progressDialog.setContentText("인포21 서버의 상태에 따라 소요시간이 상이할 수 있습니다"); + progressDialog.show(); + new Thread(){ + @Override + public void run() { + if (false) { + // 개발 중이라 바로 스킵 + signUpViewModel.getUser().getValue().setKind("guest"); + progressDialog.dismiss(); + activity.proceedSignUpStep(); + } + else { + DefaultResponse resp = signUpViewModel.verifyNewStudent(); + progressDialog.dismiss(); + // 인포 21 인증 실패 + if (resp.getData() == null && resp.getMessage() != null) { + new Handler(Looper.getMainLooper()).post(new Runnable() { + @Override + public void run() { + AutoDismissAlertDialog errorDialog = new AutoDismissAlertDialog(context, SweetAlertDialog.ERROR_TYPE, "인포 21인증에 실패했습니다.", resp.getMessage(), 2000L); + errorDialog.getProgressHelper().setBarColor(ContextCompat.getColor(context, R.color.red_500)); + errorDialog.setCancelable(false); + errorDialog.show(); + } + }); + } else{ + // 인포21 인증 성공 + activity.proceedSignUpStep(); + } + } + } + }.start(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/khumu/android/signUp/Info21SignUpActivity.java b/app/src/main/java/com/khumu/android/signUp/Info21SignUpActivity.java index eac9a6b..b02f424 100644 --- a/app/src/main/java/com/khumu/android/signUp/Info21SignUpActivity.java +++ b/app/src/main/java/com/khumu/android/signUp/Info21SignUpActivity.java @@ -1,12 +1,8 @@ package com.khumu.android.signUp; -import android.app.ProgressDialog; -import android.content.Intent; import android.os.Bundle; -import android.view.Gravity; + import android.view.View; -import android.view.ViewGroup; -import android.view.Window; import android.widget.Toast; import androidx.annotation.NonNull; @@ -14,6 +10,9 @@ import androidx.appcompat.widget.AppCompatButton; import androidx.core.content.ContextCompat; import androidx.databinding.DataBindingUtil; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModelProvider; @@ -37,12 +36,18 @@ import retrofit2.Callback; import retrofit2.Converter; import retrofit2.Response; +import retrofit2.Retrofit; public class Info21SignUpActivity extends AppCompatActivity { SignUpViewModel viewModel; ActivityInfo21SignUpBinding binding; @Inject + Retrofit retrofit; + @Inject UserService userService; + SignUpAgreementFragment signUpAgreementFragment; + Info21AuthenticationFragment info21AuthenticationFragment; + AdditionalFormFragment additionalFormFragment; @Override protected void onCreate(Bundle savedInstanceState) { @@ -55,65 +60,87 @@ protected void onCreate(Bundle savedInstanceState) { @NonNull @Override public T create(@NonNull Class modelClass) { - return (T) new SignUpViewModel(Info21SignUpActivity.this, userService); + return (T) new SignUpViewModel(Info21SignUpActivity.this, retrofit, userService); } }).get(SignUpViewModel.class); binding.setViewModel(viewModel); + signUpAgreementFragment = new SignUpAgreementFragment(viewModel); + info21AuthenticationFragment = new Info21AuthenticationFragment(viewModel); + additionalFormFragment = new AdditionalFormFragment(viewModel); + FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); + transaction.replace(R.id.sign_up_frame_layout, signUpAgreementFragment); + transaction.commit(); } - public void onClickSignUpBTN(View view) { - SweetAlertDialog progressDialog = new SweetAlertDialog(Info21SignUpActivity.this, SweetAlertDialog.PROGRESS_TYPE); - progressDialog.getProgressHelper().setBarColor(ContextCompat.getColor(Info21SignUpActivity.this, R.color.red_500)); - progressDialog.setTitleText("회원가입 중입니다"); - progressDialog.setCancelable(false); - progressDialog.show(); - userService.signUp("application/json", viewModel.getUser().getValue()).enqueue(new Callback() { - @Override - public void onResponse(Call call, Response response) { - progressDialog.dismiss(); - if (response.isSuccessful() && response.code() == 201) { - new SweetAlertDialog(Info21SignUpActivity.this, SweetAlertDialog.SUCCESS_TYPE) - .setTitleText("쿠뮤 회원가입 완료") - .setContentText(viewModel.getUser().getValue().getNickname() + "님 환영합니다 >_<") - .show(); - Intent intent = new Intent(Info21SignUpActivity.this, LoginActivity.class); - intent.addFlags(intent.FLAG_ACTIVITY_CLEAR_TOP); - Info21SignUpActivity.this.startActivity(intent); - } else { - // 400은 validation error. wrong value - if (response.code() == 400) { - // wrong value 에러 메시지 출력 - // di container 속 retrofit instance를 load - Converter errorConverter = - KhumuApplication.applicationComponent.getRetrofit().responseBodyConverter(UserResponse.class, new Annotation[0]); - try { - UserResponse errorBody = errorConverter.convert(response.errorBody()); - SweetAlertDialog errorDialog = new AutoDismissAlertDialog(Info21SignUpActivity.this, SweetAlertDialog.ERROR_TYPE, "회원가입에 실패했습니다 ㅜㅜ", errorBody.getMessage(), 1000L); -// .hideConfirmButton() -// .setTitleText() -// .setContentText(); -// Window window = errorDialog.getWindow(); -// window.setGravity(Gravity.BOTTOM); -// window.setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); - errorDialog.show(); - } catch (IOException e) { - // 에러 바디 없는 경우. - Toast.makeText(Info21SignUpActivity.this, "알 수 없는 오류가 발생했습니다. 쿠뮤에 문의해주세요.", Toast.LENGTH_SHORT).show(); - e.printStackTrace(); - } - } else{ - Toast.makeText(Info21SignUpActivity.this, "알 수 없는 오류가 발생했습니다. 쿠뮤에 문의해주세요.", Toast.LENGTH_SHORT).show(); - } - } - } +// public void onClickNextBTN(View view) { +// proceedSignUp(); +// SweetAlertDialog progressDialog = new SweetAlertDialog(Info21SignUpActivity.this, SweetAlertDialog.PROGRESS_TYPE); +// progressDialog.getProgressHelper().setBarColor(ContextCompat.getColor(Info21SignUpActivity.this, R.color.red_500)); +// progressDialog.setTitleText("회원가입 중입니다"); +// progressDialog.setCancelable(false); +// progressDialog.show(); +// userService.signUp("application/json", viewModel.getUser().getValue()).enqueue(new Callback() { +// @Override +// public void onResponse(Call call, Response response) { +// progressDialog.dismiss(); +// if (response.isSuccessful() && response.code() == 201) { +// new SweetAlertDialog(Info21SignUpActivity.this, SweetAlertDialog.SUCCESS_TYPE) +// .setTitleText("쿠뮤 회원가입 완료") +// .setContentText(viewModel.getUser().getValue().getNickname() + "님 환영합니다 >_<") +// .show(); +// Intent intent = new Intent(Info21SignUpActivity.this, LoginActivity.class); +// intent.addFlags(intent.FLAG_ACTIVITY_CLEAR_TOP); +// Info21SignUpActivity.this.startActivity(intent); +// } else { +// // 400은 validation error. wrong value +// if (response.code() == 400) { +// // wrong value 에러 메시지 출력 +// // di container 속 retrofit instance를 load +// Converter errorConverter = +// KhumuApplication.applicationComponent.getRetrofit().responseBodyConverter(UserResponse.class, new Annotation[0]); +// try { +// UserResponse errorBody = errorConverter.convert(response.errorBody()); +// SweetAlertDialog errorDialog = new AutoDismissAlertDialog(Info21SignUpActivity.this, SweetAlertDialog.ERROR_TYPE, "회원가입에 실패했습니다 ㅜㅜ", errorBody.getMessage(), 1000L); +//// .hideConfirmButton() +//// .setTitleText() +//// .setContentText(); +//// Window window = errorDialog.getWindow(); +//// window.setGravity(Gravity.BOTTOM); +//// window.setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); +// errorDialog.show(); +// } catch (IOException e) { +// // 에러 바디 없는 경우. +// Toast.makeText(Info21SignUpActivity.this, "알 수 없는 오류가 발생했습니다. 쿠뮤에 문의해주세요.", Toast.LENGTH_SHORT).show(); +// e.printStackTrace(); +// } +// } else{ +// Toast.makeText(Info21SignUpActivity.this, "알 수 없는 오류가 발생했습니다. 쿠뮤에 문의해주세요.", Toast.LENGTH_SHORT).show(); +// } +// } +// } +// +// @Override +// public void onFailure(Call call, Throwable t) { +// progressDialog.dismiss(); +// t.printStackTrace(); +// Toast.makeText(Info21SignUpActivity.this, "서버와 통신할 수 없습니다. 쿠뮤에 문의해주세요.", Toast.LENGTH_SHORT).show(); +// } +// }); +// } - @Override - public void onFailure(Call call, Throwable t) { - progressDialog.dismiss(); - t.printStackTrace(); - Toast.makeText(Info21SignUpActivity.this, "서버와 통신할 수 없습니다. 쿠뮤에 문의해주세요.", Toast.LENGTH_SHORT).show(); - } - }); + // 회원가입하는 동안 next 버튼이 할 일들 + public void proceedSignUpStep() { + FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction transaction = fragmentManager.beginTransaction(); + if (signUpAgreementFragment.isVisible()) { + transaction.replace(R.id.sign_up_frame_layout, info21AuthenticationFragment); + transaction.commit(); + } else if (info21AuthenticationFragment.isVisible()) { + transaction.replace(R.id.sign_up_frame_layout, additionalFormFragment); + transaction.commit(); + } else{ + this.finish(); + } } } diff --git a/app/src/main/java/com/khumu/android/signUp/SignUpAgreementFragment.java b/app/src/main/java/com/khumu/android/signUp/SignUpAgreementFragment.java new file mode 100644 index 0000000..f267c45 --- /dev/null +++ b/app/src/main/java/com/khumu/android/signUp/SignUpAgreementFragment.java @@ -0,0 +1,65 @@ +/** + * BaseFeedFragment를 상속받아 크게 추가할 내용은 없고, abstract method인 provideViewModel작업만 정의해주면됨. + * 기본적인 feed의 layout인 layout_feed.xml을 이용. + */ +package com.khumu.android.signUp; + +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.databinding.DataBindingUtil; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.ViewModelProvider; + +import com.khumu.android.KhumuApplication; +import com.khumu.android.R; +import com.khumu.android.databinding.FragmentSignUpConsensusBinding; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class SignUpAgreementFragment extends Fragment { + private final static String TAG = "SignUpAgreementFragment"; + private SignUpViewModel signUpViewModel; + private FragmentSignUpConsensusBinding binding; + + public SignUpAgreementFragment(SignUpViewModel viewModel) { + this.signUpViewModel = viewModel; + } + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + // Layout inflate 이전 + // savedInstanceState을 이용해 다룰 데이터가 있으면 다룸. + super.onCreate(savedInstanceState); + Log.d(TAG, "onCreate: "); + KhumuApplication.applicationComponent.inject(this); + this.signUpViewModel = new ViewModelProvider(this.getActivity()).get(SignUpViewModel.class); + } + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, + ViewGroup container, Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + binding = DataBindingUtil.inflate(inflater, R.layout.fragment_sign_up_consensus, container, false); + // binding하며 사용할 Fragment가 사용하는 변수인 viewModel을 설정해줌. + binding.setViewModel(this.signUpViewModel); + binding.setFragment(this); + // LiveData를 이용해 Observe하기 위해선 그 LifeCyclerOwner가 꼭 필요하다! + // 그렇지 않으면 유효하게 Observer로 동작하지 않고 아무 변화 없음... + binding.setLifecycleOwner(this.getActivity()); + View root = binding.getRoot(); + return root; + } + + public void onClickNextBTN(View view) { + Info21SignUpActivity activity = (Info21SignUpActivity) this.getActivity(); + activity.proceedSignUpStep(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/khumu/android/signUp/SignUpViewModel.java b/app/src/main/java/com/khumu/android/signUp/SignUpViewModel.java index 3672314..ce67b23 100644 --- a/app/src/main/java/com/khumu/android/signUp/SignUpViewModel.java +++ b/app/src/main/java/com/khumu/android/signUp/SignUpViewModel.java @@ -10,7 +10,11 @@ import com.google.android.gms.common.api.Api; import com.khumu.android.KhumuApplication; +import com.khumu.android.R; +import com.khumu.android.data.Info21UserInfo; import com.khumu.android.data.KhumuUser; +import com.khumu.android.data.rest.DefaultResponse; +import com.khumu.android.data.rest.Info21AuthenticationRequest; import com.khumu.android.data.rest.QrCodeGetResponse; import com.khumu.android.data.rest.UserResponse; import com.khumu.android.login.LoginActivity; @@ -21,25 +25,78 @@ import java.lang.annotation.Annotation; import lombok.Getter; +import lombok.NonNull; import lombok.Setter; import okhttp3.ResponseBody; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Converter; import retrofit2.Response; +import retrofit2.Retrofit; @Getter @Setter public class SignUpViewModel extends ViewModel { - final String TAG = "QrCodeViewModel"; - MutableLiveData user; - Context context; - UserService userService; + private final String TAG = "QrCodeViewModel"; + private MutableLiveData user; + private MutableLiveData isAgreedPolicy; + private MutableLiveData isAgreedPrivacy; - public SignUpViewModel(Context context, UserService userService) { + private Context context; + private UserService userService; + private Retrofit retrofit; + + + public SignUpViewModel(Context context, Retrofit retrofit, UserService userService) { this.context = context; + this.retrofit = retrofit; this.userService = userService; Log.w(TAG, "QrCodeViewModel: " + userService ); this.user = new MutableLiveData<>(new KhumuUser()); + this.isAgreedPolicy = new MutableLiveData<>(false); + this.isAgreedPrivacy = new MutableLiveData<>(false); + } + + public String getWelcomeMessage() { + KhumuUser user = this.user.getValue(); + return user.getDepartment() + "학과 " + user.getStudentNumber() + "님\n" + "환영합니다!"; + } + + public UserResponse signUp() { + Call call= userService.signUp("application/json", user.getValue()); + try { + Response response = call.execute(); + if (!response.isSuccessful()) { + UserResponse errorResp = (UserResponse) retrofit.responseBodyConverter(UserResponse.class, UserResponse.class.getAnnotations()).convert(response.errorBody()); + return errorResp; + + } else{ + return response.body(); + } + } catch (IOException e) { + e.printStackTrace(); + return new UserResponse(null, "서버의 응답을 해석할 수 없습니다."); + } + } + public DefaultResponse verifyNewStudent() { + Call> call= userService.verifyNewStudent("application/json", Info21AuthenticationRequest.builder().username(user.getValue().getUsername()).password(user.getValue().getPassword()).build()); + try { + Response> response = call.execute(); + if (!response.isSuccessful()) { + DefaultResponse errorResp = (DefaultResponse) retrofit.responseBodyConverter(DefaultResponse.class, DefaultResponse.class.getAnnotations()).convert(response.errorBody()); + return errorResp; + + } else{ + Info21UserInfo userInfo = response.body().getData(); + KhumuUser user = this.user.getValue(); + user.setStudentNumber(userInfo.getStudentNum()); + user.setDepartment(userInfo.getDept()); + + return response.body(); + } + } catch (IOException e) { + e.printStackTrace(); + return new DefaultResponse(null, "서버의 응답을 해석할 수 없습니다."); + } } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_info21_sign_up.xml b/app/src/main/res/layout/activity_info21_sign_up.xml index bfe8bec..380de61 100644 --- a/app/src/main/res/layout/activity_info21_sign_up.xml +++ b/app/src/main/res/layout/activity_info21_sign_up.xml @@ -14,6 +14,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/red_500"> + - - - - - - - - - - - - - - - - - - - - - - - - - - - + > + + + + diff --git a/app/src/main/res/layout/fragment_info21_authentication_form.xml b/app/src/main/res/layout/fragment_info21_authentication_form.xml new file mode 100644 index 0000000..2d207a1 --- /dev/null +++ b/app/src/main/res/layout/fragment_info21_authentication_form.xml @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_sign_up_additional_form.xml b/app/src/main/res/layout/fragment_sign_up_additional_form.xml new file mode 100644 index 0000000..4fb43e5 --- /dev/null +++ b/app/src/main/res/layout/fragment_sign_up_additional_form.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_sign_up_consensus.xml b/app/src/main/res/layout/fragment_sign_up_consensus.xml new file mode 100644 index 0000000..435ee4a --- /dev/null +++ b/app/src/main/res/layout/fragment_sign_up_consensus.xml @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +