Skip to content

Commit

Permalink
[feat] #133 Find PW View & NicknameCheck & API Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
sodock00 committed Apr 5, 2022
1 parent d77f25a commit d24533c
Show file tree
Hide file tree
Showing 19 changed files with 551 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data class ResponseViewUserProfileData(
val user_prPhoto: String,
val user_nickname: String,
val user_prAbility: ArrayList<String>,
val user_grade: Int,
val user_grade: Float,
val user_prKeyword: ArrayList<String>,
)
}
12 changes: 12 additions & 0 deletions app/src/main/java/com/example/infraandroid/id/model/PWService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.infraandroid.id.model

import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.PATCH

interface PWService {
@PATCH("/user/reset-pw")
fun findPWInfo(
@Body body : RequestPWData
): Call<ResponsePWData>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.infraandroid.id.model

import com.google.gson.annotations.SerializedName

data class RequestPWData(
@SerializedName("user_phone")
var userPhone : String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.infraandroid.id.model

data class ResponsePWData(
val isSuccess: Boolean,
val code: Int,
val message: String,
val result: String,
)
101 changes: 101 additions & 0 deletions app/src/main/java/com/example/infraandroid/id/view/FindPWFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.example.infraandroid.id.view

import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.widget.EditText
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.findNavController
import com.example.infraandroid.R
import com.example.infraandroid.category.model.ResponseViewIdeaData
import com.example.infraandroid.databinding.FragmentFindPwBinding
import com.example.infraandroid.id.model.RequestPWData
import com.example.infraandroid.id.model.ResponsePWData
import com.example.infraandroid.id.viewmodel.SignUpViewModel
import com.example.infraandroid.myinfo.myideamanage.model.MyProjectViewModel
import com.example.infraandroid.util.BaseFragment
import com.example.infraandroid.util.ServiceCreator
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import retrofit2.http.Tag
import java.util.regex.Pattern

class FindPWFragment : BaseFragment<FragmentFindPwBinding>(R.layout.fragment_find_pw){
private lateinit var viewModel : MyProjectViewModel
private val TAG = "로그"

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

activity?.run{
viewModel = ViewModelProvider(this, ViewModelProvider.NewInstanceFactory())
.get(MyProjectViewModel::class.java)
}
}

override fun FragmentFindPwBinding.onCreateView() {
}

override fun FragmentFindPwBinding.onViewCreated() {
val inputPhoneNumEditText = binding.inputNumEditText
val nextButton = binding.goToSecondPwButton
val backButton = binding.findPwBackButton

//다음 버튼 활성화 설정
inputPhoneNumEditText.addTextChangedListener(object : TextWatcher{
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
nextButton.isEnabled = false
}

override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
if (Pattern.matches("^\\d{3}-\\d{3,4}-\\d{4}$", inputPhoneNumEditText.text.toString())) {
nextButton.isEnabled = true
}
}

override fun afterTextChanged(p0: Editable?) {
if (Pattern.matches("^\\d{3}-\\d{3,4}-\\d{4}$", inputPhoneNumEditText.text.toString())) {
nextButton.isEnabled = true
}
}
})

//뒤로 가기 눌렀을 때 로그인 화면
backButton.setOnClickListener {
it.findNavController().navigate(R.id.action_findPWFragment_to_login_fragment)
}

//비밀번호 조회 서버 연결
nextButton.setOnClickListener {
val requestPWData = RequestPWData(
userPhone = inputPhoneNumEditText.text.toString()
)
it.findNavController().navigate(R.id.action_findPWFragment_to_findPWSecondFragment)

val call: Call<ResponsePWData> = ServiceCreator.pwService
.findPWInfo(requestPWData)

call.enqueue(object: Callback<ResponsePWData>{
override fun onResponse(
call: Call<ResponsePWData>,
response: Response<ResponsePWData>
) {
if(response.isSuccessful){
Log.d(TAG, "onResponse: 서버 연결 성공" + response.body()?.code)
}
else{
Log.d(TAG, "onResponse: 실패" + response.body()?.code + response.body()?.message)
}
}

override fun onFailure(call: Call<ResponsePWData>, t: Throwable) {
Log.d(TAG, "onFailure: $t")
}
})
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.infraandroid.id.view

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.fragment.app.Fragment
import androidx.navigation.findNavController
import com.example.infraandroid.R
import com.example.infraandroid.databinding.FragmentSecondFindPwBinding

class FindPWSecondFragment : Fragment() {
private var mBinding : FragmentSecondFindPwBinding? = null

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val binding = FragmentSecondFindPwBinding.inflate(inflater, container, false)
mBinding = binding
return mBinding?.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val backButton = mBinding?.findPwBackButton as ImageView

//뒤로 가기 버튼 눌렀을 때 로그인 화면
backButton.setOnClickListener {
it.findNavController().navigate(R.id.action_findPWSecondFragment_to_login_fragment)
}
}

override fun onDestroyView() {
mBinding = null
super.onDestroyView()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ class LoginFragment : BaseFragment<FragmentLoginBinding>(R.layout.fragment_login
it.findNavController().navigate(R.id.action_login_fragment_to_sign_up_first_fragment)
}

//비밀번호 찾기 눌렀을 때
binding.loginFindIdPwTv.setOnClickListener{
it.findNavController().navigate(R.id.action_login_fragment_to_findPWFragment)
}

// binding.loginGoogleIv.setOnClickListener {
// oneTapClient.beginSignIn(signInRequest)
// .addOnSuccessListener(requireActivity()) { result ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import androidx.navigation.fragment.findNavController
import com.example.infraandroid.util.InfraApplication
import com.example.infraandroid.R
import com.example.infraandroid.databinding.FragmentMyInfoBinding
import com.google.android.gms.oss.licenses.OssLicensesActivity
import com.google.android.gms.oss.licenses.OssLicensesMenuActivity
//import com.google.android.gms.oss.licenses.OssLicensesActivity
//import com.google.android.gms.oss.licenses.OssLicensesMenuActivity

//작성자 : 이은진
//작성일 : 2022.02.03
Expand Down Expand Up @@ -70,8 +70,8 @@ class MyInfoFragment : Fragment() {
}

mBinding!!.ossLinearLayout.setOnClickListener{
val intent = Intent(this.context, OssLicensesMenuActivity::class.java)
startActivity(intent)
//val intent = Intent(this.context, OssLicensesMenuActivity::class.java)
//startActivity(intent)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.infraandroid.myinfo.myinfomodify.model

import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.POST

interface NicknameDoubleCheckService {
@POST("/user/valid-nickname")
fun doublecheck(
@Body body : RequestNicknameCheckData
): Call<ResponseNicknameCheckData>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.infraandroid.myinfo.myinfomodify.model

import com.google.gson.annotations.SerializedName

data class RequestNicknameCheckData(
@SerializedName("user_nickname")
val userNickname : String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.infraandroid.myinfo.myinfomodify.model

data class ResponseNicknameCheckData(
val isSuccess: Boolean,
val code: Int,
val message: String,
val result: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import androidx.fragment.app.Fragment
import androidx.navigation.findNavController
import com.example.infraandroid.R
import com.example.infraandroid.databinding.FragmentMyInfoModifyBinding
import com.example.infraandroid.id.viewmodel.SignUpViewModel
import com.example.infraandroid.myinfo.myinfomodify.model.RequestModifyMyInfoData
import com.example.infraandroid.myinfo.myinfomodify.model.RequestNicknameCheckData
import com.example.infraandroid.myinfo.myinfomodify.model.ResponseNicknameCheckData
import com.example.infraandroid.myinfo.myinfomodify.model.ResponseViewMyInfoData
import com.example.infraandroid.util.BaseFragment
import com.example.infraandroid.util.InfraApplication
Expand All @@ -45,12 +48,12 @@ class MyInfoModifyFragment : BaseFragment<FragmentMyInfoModifyBinding>(R.layout.
val overlapCheckButton = binding.overlapCheckButton as AppCompatButton
val modifyCompletedButton = binding.modifyCompletedButton as TextView
val doNotUseThisNicknameTextView = binding.doNotUseThisNicknameTextView as TextView

val canUserIcon = binding.canUseIconImageView

//내 정보 보기 서버 연결
val viewcall: Call<ResponseViewMyInfoData> = ServiceCreator.myinfoService
.viewMyInfo(InfraApplication.prefs.getString("jwt","null"),InfraApplication.prefs.getString("userId","null"))
/* .viewMyInfo("jwt","userId")*/
.viewMyInfo(InfraApplication.prefs.getString("jwt","null"),
InfraApplication.prefs.getString("userId","null"))

viewcall.enqueue(object : Callback<ResponseViewMyInfoData> {
override fun onResponse(
Expand All @@ -59,9 +62,12 @@ class MyInfoModifyFragment : BaseFragment<FragmentMyInfoModifyBinding>(R.layout.
) {
if(response.isSuccessful){
when(response.body()?.code){
1000 -> { binding.myInfoModify = response.body()?.result
userNickname = response.body()?.result?.user_nickname
userPrPhoto = response.body()?.result?.user_prPhoto
1000 -> {
binding.myInfoModify = response.body()?.result
//userNickname = response.body()?.result?.user_nickname

//userPrPhoto = response.body()?.result?.user_prPhoto

}
}
}
Expand All @@ -74,6 +80,43 @@ class MyInfoModifyFragment : BaseFragment<FragmentMyInfoModifyBinding>(R.layout.

} )

//닉네임 중복 서버 연결
overlapCheckButton.setOnClickListener {
val requestNicknameCheckData = RequestNicknameCheckData(
userNickname = inputNicknameEditText.text.toString(),
)

val checkcall: Call<ResponseNicknameCheckData> = ServiceCreator.nicknameDoubleCheckService
.doublecheck(requestNicknameCheckData)
checkcall.enqueue(object : Callback<ResponseNicknameCheckData>{
override fun onResponse(
call: Call<ResponseNicknameCheckData>,
response: Response<ResponseNicknameCheckData>
) {
if(response.isSuccessful){
val data = response.body()?.code
if(data==1000) {
isChecked = true
doNotUseThisNicknameTextView.isVisible = false
canUserIcon.isVisible = true
inputNicknameEditText.setBackgroundResource(R.drawable.can_use_this_id_background)
}
if(data==3104){
doNotUseThisNicknameTextView.isVisible = true
canUserIcon.isVisible = false
inputNicknameEditText.setBackgroundResource(R.drawable.double_check_id_background)
}
}
}

override fun onFailure(call: Call<ResponseNicknameCheckData>, t: Throwable) {

}

})

}

//내 정보 수정 서버 연결
val modifycall: Call<RequestModifyMyInfoData> = ServiceCreator.myinfoService
.ModifyMyInfo("jwt","userId")
Expand All @@ -84,6 +127,7 @@ class MyInfoModifyFragment : BaseFragment<FragmentMyInfoModifyBinding>(R.layout.
) {
if(response.isSuccessful){
when(response.body()?.code){

}
}
}
Expand Down Expand Up @@ -144,7 +188,7 @@ class MyInfoModifyFragment : BaseFragment<FragmentMyInfoModifyBinding>(R.layout.

override fun afterTextChanged(p0: Editable?) {
/*inputNicknameEditText.length() < 12 && inputNicknameEditText.length()>0*/
if (inputNicknameEditText.length() < 12) {
if (inputNicknameEditText.length() < 12 && isChecked) {
modifyCompletedButton.isEnabled = true
} else {
Toast.makeText(requireActivity(), "12자 이하로 입력해주세요.", Toast.LENGTH_SHORT).show()
Expand All @@ -153,29 +197,14 @@ class MyInfoModifyFragment : BaseFragment<FragmentMyInfoModifyBinding>(R.layout.

override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
//얘네는 나중에 수정 필요
if (inputNicknameEditText.length() < 12) {
if (inputNicknameEditText.length() < 12 && isChecked) {
modifyCompletedButton.isEnabled = true
} else {
Toast.makeText(requireActivity(), "12자 이하로 입력해주세요.", Toast.LENGTH_SHORT).show()
}
}
})

//닉네임 중복 서버 연결 필요
//닉네임 중복 버튼 누르면
overlapCheckButton.setOnClickListener {
//test용..
if(inputNicknameEditText.length() < 5){
isChecked = true
doNotUseThisNicknameTextView.isVisible = false
inputNicknameEditText.setBackgroundResource(R.drawable.can_use_this_id_background)
binding.canUseIconImageView?.isVisible = true
} else {
doNotUseThisNicknameTextView.isVisible = true
inputNicknameEditText.setBackgroundResource(R.drawable.double_check_id_background)
binding.canUseIconImageView?.isVisible = false
}
}
}

}
Loading

0 comments on commit d24533c

Please sign in to comment.