Skip to content

Commit

Permalink
Feature/signup network (#96)
Browse files Browse the repository at this point in the history
* [feat/signup_network] : 회원가입 서버 연결

* [feat/signup] : 스플래시 아이콘 변경

* [feat/signup] : 네이밍 변경

* [feat/signup] : viewmodel observer 필요 없는 부분 삭제
  • Loading branch information
jihyeonAnAn authored Jul 7, 2023
1 parent 4f674bf commit 6eb3ab4
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 47 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<activity
android:name=".feature.onboarding.OnBoardingActivity"
android:exported="true"
android:theme="@style/Theme.App.Popopopo.Starting">
android:theme="@style/Theme.App.Pophory.Starting">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.viewpager2.widget.ViewPager2
import com.teampophory.pophory.common.context.toast
import com.teampophory.pophory.common.view.viewBinding
import com.teampophory.pophory.databinding.ActivitySignUpBinding
import com.teampophory.pophory.feature.home.HomeActivity
import com.teampophory.pophory.feature.onboarding.OnBoardingActivity
import com.teampophory.pophory.feature.signup.adapter.SignUpViewPagerAdapter

Expand All @@ -22,11 +23,10 @@ class SignUpActivity : AppCompatActivity(), SignUpButtonInterface {
super.onCreate(savedInstanceState)
setContentView(binding.root)


viewModel.sampleLiveData.observe(this) {
toast(it)
viewModel.signUpResult.observe(this) {
val intent = Intent(this, HomeActivity::class.java)
startActivity((intent))
}

// 다음 버튼
clickNextButton()
// 뷰페이저
Expand All @@ -35,6 +35,7 @@ class SignUpActivity : AppCompatActivity(), SignUpButtonInterface {
clickToolbarBackButton()
}


private fun clickToolbarBackButton() {
binding.btnBack.setOnClickListener {
when (currentPosition) {
Expand Down Expand Up @@ -65,18 +66,16 @@ class SignUpActivity : AppCompatActivity(), SignUpButtonInterface {

1 -> {
// TODO 중복된 아이디가 존재하는 경우
val dialog = SignUpDialogFragment().apply {

}
supportFragmentManager.beginTransaction().add(dialog,"").commitAllowingStateLoss()
// 중복된 아이디가 존재하지 않을 경우
val dialog = SignUpDialogFragment()
supportFragmentManager.beginTransaction().add(dialog, "")
.commitAllowingStateLoss()
// TODO 중복된 아이디가 존재하지 않을 경우
val nextPosition = currentPosition + 1
binding.viewpager.currentItem = nextPosition
}

2 -> {
val intent = Intent(this, StartPophoryActivity::class.java)
startActivity(intent)
viewModel.signUp()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.teampophory.pophory.feature.signup

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.teampophory.pophory.BuildConfig
import com.teampophory.pophory.config.di.NetModule
import com.teampophory.pophory.data.network.interceptor.AuthInterceptor
import com.teampophory.pophory.network.retrofit.signup.RetrofitSignUpNetwork
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit

object SignUpApiFactory {

private const val POPHORY_BASE_URL = BuildConfig.POPHORY_BASE_URL

private val client by lazy {
OkHttpClient.Builder()
.addInterceptor(HttpLoggingInterceptor().apply {
level =
if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE
}).build()
}

val retrofitForSignUp: Retrofit by lazy {
Retrofit.Builder().baseUrl(POPHORY_BASE_URL)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.client(client).build()
}

inline fun <reified T> createSignUpService(): T = retrofitForSignUp.create<T>(T::class.java)
}

object ServicePool {
val signUpService = SignUpApiFactory.createSignUpService<RetrofitSignUpNetwork>()
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.teampophory.pophory.feature.signup

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -11,18 +10,19 @@ import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import com.teampophory.pophory.R
import com.teampophory.pophory.common.fragment.colorOf
import com.teampophory.pophory.common.fragment.toast
import com.teampophory.pophory.common.primitive.textAppearance
import com.teampophory.pophory.common.view.viewBinding
import com.teampophory.pophory.databinding.FragmentSignUpFirstBinding
import timber.log.Timber
import java.util.regex.Pattern

class SignUpFirstFragment : Fragment() {

private val binding by viewBinding(FragmentSignUpFirstBinding::bind)
private var buttonState: SignUpButtonInterface? = null
private val signUpViewModel by activityViewModels<SignUpViewModel>()

override fun onCreateView(
inflater: LayoutInflater,
Expand Down Expand Up @@ -62,6 +62,9 @@ class SignUpFirstFragment : Fragment() {
}
//edittext text 변화 감지
doAfterTextChanged {

signUpViewModel.setRealName(it.toString())

binding.btnDeleteEditText.isGone = it?.isEmpty() == true
// 글자 수 계산
binding.tvTextCount.text = "(${it.toString().length}/6)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.widget.doAfterTextChanged
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import com.teampophory.pophory.R
import com.teampophory.pophory.common.fragment.colorOf
import com.teampophory.pophory.common.primitive.textAppearance
Expand All @@ -20,6 +21,7 @@ import java.util.regex.Pattern
class SignUpSecondFragment : Fragment() {
private val binding by viewBinding(FragmentSignUpSecondBinding::bind)
private var buttonState: SignUpButtonInterface? = null
private val signUpViewModel by activityViewModels<SignUpViewModel>()

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -40,13 +42,13 @@ class SignUpSecondFragment : Fragment() {

private fun deleteAllEditText() {
binding.btnDeleteEditText.setOnClickListener {
binding.editTvName.text.clear()
binding.editTvId.text.clear()
}
}

private fun setEditText() {
// 텍스트창 활성화
binding.editTvName.apply {
binding.editTvId.apply {
setOnFocusChangeListener { _, hasFocus ->
// 포커스가 주어졌을 때
if (hasFocus) {
Expand All @@ -56,25 +58,25 @@ class SignUpSecondFragment : Fragment() {
}
}
doAfterTextChanged {
signUpViewModel.setNickName(it.toString())
//X버튼 생성 여부
binding.btnDeleteEditText.isGone = it?.isEmpty() == true
//글자 수 계산
binding.tvTextCount.text = "(${it.toString().length}/12)"

val textMatcher = HANGUL_REGEX.matcher(binding.editTvName.text)
val specialMatcher = SPECIAL_REGEX.matcher(binding.editTvName.text)
val textMatcher = HANGUL_REGEX.matcher(binding.editTvId.text)
if (!textMatcher.find()) {
binding.tvErrorMessage.text = "*올바른 형식의 아이디가 아닙니다"
binding.editTvName.setBackgroundResource(R.drawable.bg_sign_up_edit_text_error)
binding.editTvId.setBackgroundResource(R.drawable.bg_sign_up_edit_text_error)
binding.tvErrorMessage.isVisible = true
buttonState?.onChangeState(false)
} else if (it.toString().length < 4) {
binding.tvErrorMessage.text = "4-12글자 이내로 작성해주세요."
binding.editTvName.setBackgroundResource(R.drawable.bg_sign_up_edit_text_error)
binding.editTvId.setBackgroundResource(R.drawable.bg_sign_up_edit_text_error)
binding.tvErrorMessage.isVisible = true
buttonState?.onChangeState(false)
} else {
binding.editTvName.setBackgroundResource(R.drawable.bg_sign_up_edit_text_selected)
binding.editTvId.setBackgroundResource(R.drawable.bg_sign_up_edit_text_selected)
binding.tvErrorMessage.isVisible = false
buttonState?.onChangeState(true)
}
Expand Down Expand Up @@ -106,8 +108,5 @@ class SignUpSecondFragment : Fragment() {
companion object {
private const val HANGUL_PATTERN = "^[a-zA-Z0-9._]{4,12}\$"
val HANGUL_REGEX: Pattern = Pattern.compile(HANGUL_PATTERN)

private const val SPECIAL_PATTERN = "^[^._]*$"
val SPECIAL_REGEX: Pattern = Pattern.compile(SPECIAL_PATTERN)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.core.text.buildSpannedString
import androidx.core.text.color
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels

import com.teampophory.pophory.R
import com.teampophory.pophory.common.fragment.colorOf
Expand All @@ -17,6 +18,8 @@ import com.teampophory.pophory.databinding.FragmentSignUpThirdBinding

class SignUpThirdFragment : Fragment() {
private val binding by viewBinding(FragmentSignUpThirdBinding::bind)
private val signUpViewModel by activityViewModels<SignUpViewModel>()

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -72,21 +75,22 @@ class SignUpThirdFragment : Fragment() {

binding.ivAlbumCover1.setOnClickListener {
setAlbumSelectState(1)
signUpViewModel.setAlbumCover(1)
binding.ivAlbumCover.setImageResource(R.drawable.ic_album_cover_friends)
}
binding.ivAlbumCover2.setOnClickListener {
setAlbumSelectState(2)

signUpViewModel.setAlbumCover(2)
binding.ivAlbumCover.setImageResource(R.drawable.ic_album_cover_love)
}
binding.ivAlbumCover3.setOnClickListener {
setAlbumSelectState(3)

signUpViewModel.setAlbumCover(3)
binding.ivAlbumCover.setImageResource(R.drawable.ic_album_cover_myalbum)
}
binding.ivAlbumCover4.setOnClickListener {
setAlbumSelectState(4)

signUpViewModel.setAlbumCover(4)
binding.ivAlbumCover.setImageResource(R.drawable.ic_album_cover_collectbook)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,61 @@ package com.teampophory.pophory.feature.signup
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.teampophory.pophory.feature.signup.ServicePool.signUpService
import com.teampophory.pophory.network.model.SignUpRequest
import com.teampophory.pophory.network.model.SignUpResponse
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class SignUpViewModel : ViewModel() {

private val _sampleLiveData = MutableLiveData<String>()
val sampleLiveData: LiveData<String> get() = _sampleLiveData
private val _signUpResult: MutableLiveData<SignUpResponse> = MutableLiveData()
val signUpResult: LiveData<SignUpResponse> = _signUpResult

fun getToastMessage() {
_sampleLiveData.value = "테스트 입니다."
private val _realName: MutableLiveData<String> = MutableLiveData()
var realName: LiveData<String> = _realName

private val _nickName: MutableLiveData<String> = MutableLiveData()
var nickName: LiveData<String> = _nickName

private val _albumCover: MutableLiveData<Int> = MutableLiveData()
var albumCover: LiveData<Int> = _albumCover

fun setRealName(realName: String) {
_realName.value = realName
}

fun setNickName(nickName: String) {
_nickName.value = nickName
}

fun setAlbumCover(albumCover: Int) {
_albumCover.value = albumCover
}

fun signUp() {
signUpService.signUp(
SignUpRequest(
realName.value.orEmpty(),
nickName.value.orEmpty(),
albumCover.value ?: 0
)
).enqueue(object : Callback<SignUpResponse> {
override fun onResponse(
call: Call<SignUpResponse>,
response: Response<SignUpResponse>
) {
if (response.isSuccessful) {
_signUpResult.value = response.body()
}
}

override fun onFailure(call: Call<SignUpResponse>, t: Throwable) {
TODO("Not yet implemented")
}

})
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.teampophory.pophory.network.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class SignUpRequest(
@SerialName("realName")
val realName: String,
@SerialName("nickName")
val nickName: String,
@SerialName("albumCover")
val albumCover: Int
)

@Serializable
data class SignUpResponse(
@SerialName("status")
val status: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.teampophory.pophory.network.retrofit.signup

import com.teampophory.pophory.network.model.SignUpRequest
import com.teampophory.pophory.network.model.SignUpResponse
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.PATCH

interface RetrofitSignUpNetwork {

@PATCH("api/v1/member")
fun signUp(
@Body request : SignUpRequest
): Call<SignUpResponse>
}
Loading

0 comments on commit 6eb3ab4

Please sign in to comment.