Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/khu-dev/khumu-android
Browse files Browse the repository at this point in the history
  • Loading branch information
gusrl4025 committed Aug 16, 2021
2 parents b9ae5be + 753ff0a commit d1273e6
Show file tree
Hide file tree
Showing 16 changed files with 903 additions and 251 deletions.
18 changes: 18 additions & 0 deletions app/src/main/java/com/khumu/android/data/Info21UserInfo.java
Original file line number Diff line number Diff line change
@@ -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;
}
55 changes: 7 additions & 48 deletions app/src/main/java/com/khumu/android/data/KhumuUser.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
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;
private String password;
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) {
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
@SerializedName("data")
Object data;
T data;
@SerializedName("message")
String message;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,4 +17,7 @@ public interface UserService {

@POST("users")
Call<UserResponse> signUp(@Header("Content-Type") String contentType, @Body KhumuUser user);

@POST("users/verify-new-student")
Call<DefaultResponse<Info21UserInfo>> verifyNewStudent(@Header("Content-Type") String contentType, @Body Info21AuthenticationRequest input);
}
115 changes: 115 additions & 0 deletions app/src/main/java/com/khumu/android/signUp/AdditionalFormFragment.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading

0 comments on commit d1273e6

Please sign in to comment.