Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT/seminar6] 필수과제 #13

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/src/main/java/org/sopt/dosopttemplate/base/BaseActivity.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.sopt.dosopttemplate.base

import android.content.Context
import android.graphics.Rect
import android.os.Bundle
import android.view.MotionEvent
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import androidx.activity.OnBackPressedCallback
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -31,8 +34,12 @@ abstract class BaseActivity<T : ViewDataBinding>(
}

private fun hideKeyboard() {
val inputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(currentFocus?.windowToken, 0)
val currentFocus = currentFocus
if (currentFocus is EditText) {
currentFocus.clearFocus()
val inputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0)
}
Comment on lines +37 to +42
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 👍

}

private fun initPressedBackBtn() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.sopt.dosopttemplate.presentation.signUp

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.activity.viewModels
import dagger.hilt.android.AndroidEntryPoint
import org.sopt.dosopttemplate.R
Expand All @@ -20,10 +19,36 @@ class SignUpActivity : BaseActivity<ActivitySignupBinding>(R.layout.activity_sig
super.onCreate(savedInstanceState)
binding.viewModel = viewModel

initSetSignUpErrorCondition()
initSignUpBtnClickListener()
initObserveSignUpEnabled()
}

private fun initSetSignUpErrorCondition() {
checkUserNameValid()
checkPassWordValid()
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 함수를 또 묶어서 사용하는 건 생각도 못하고 따로 따로 함수만 만들어놨는데..! 저도 한 번 이렇게 해봐야겠어용!!

private fun checkUserNameValid() {
viewModel.username.observe(this) {
if (!viewModel.isUserNameValid()) {
binding.layoutSignUpID.error = MESSAGE_USERNAME_CONDITION
} else {
binding.layoutSignUpID.error = null
}
}
}

private fun checkPassWordValid() {
viewModel.password.observe(this) {
if (!viewModel.isPassWordValid()) {
binding.layoutSignUpPW.error = MESSAGE_PASSWORD_CONDITION
} else {
binding.layoutSignUpPW.error = null
}
}
}

private fun initSignUpBtnClickListener() {
binding.btnSignUpDoSignUp.setOnClickListener {
if (viewModel.isSignUpValid()) {
Expand Down Expand Up @@ -52,5 +77,8 @@ class SignUpActivity : BaseActivity<ActivitySignupBinding>(R.layout.activity_sig
companion object {
const val MESSAGE_SIGNUP_SUCCESS = "회원가입 성공"
const val MESSAGE_SIGNUP_FAIL = "회원가입 실패: 모든 정보를 기입해야 합니다"

const val MESSAGE_USERNAME_CONDITION = "영문, 숫자 포함 6-10글자"
const val MESSAGE_PASSWORD_CONDITION = "영문, 숫자, 특수문자 포함 6-12글자"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package org.sopt.dosopttemplate.presentation.signUp

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import org.sopt.dosopttemplate.data.repository.AuthRepository
import java.util.regex.Pattern
import javax.inject.Inject

@HiltViewModel
Expand All @@ -23,18 +25,29 @@ class SignUpViewModel @Inject constructor(
private val _signUpEnabled = MutableLiveData<Boolean>()
val signUpEnabled: LiveData<Boolean> = _signUpEnabled

val checkBtnEnabled = MediatorLiveData<Boolean>().apply {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MediatorLiveData 는 처음 보네요.. 여러 개의 LiveData를 결합해서 관리한다... 좋은 정보 얻고갑니다

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MediatorLiveData 사용 너무 좋아요~!!

addSource(username) { value = isSignUpValid() }
addSource(nickname) { value = isSignUpValid() }
addSource(password) { value = isSignUpValid() }
addSource(mbti) { value = isSignUpValid() }
}

fun isSignUpValid(): Boolean {
return isUserNameValid()
&& isPassWordValid()
&& !nickname.value.isNullOrBlank()
&& !mbti.value.isNullOrBlank()
}

private fun isUserNameValid(): Boolean =
username.value?.length in 6..10 && !username.value.isNullOrBlank()
fun isUserNameValid(): Boolean {
val usernameMatcher = USERNAME_PATTERN.matcher(username.value.orEmpty())
return username.value.isNullOrBlank() || usernameMatcher.find()
}

private fun isPassWordValid(): Boolean =
password.value?.length in 8..12 && !password.value.isNullOrBlank()
fun isPassWordValid(): Boolean {
val passwordMatcher = PASSWORD_PATTERN.matcher(password.value.orEmpty())
return password.value.isNullOrBlank() || passwordMatcher.find()
}

fun doSignUp(
username: String,
Expand All @@ -55,4 +68,11 @@ class SignUpViewModel @Inject constructor(
}
}
}

companion object {
const val USERNAME_REGEX = "^(?=.*[0-9])(?=.*[a-zA-Z]).{6,10}\$"
const val PASSWORD_REGEX = "^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[!@#$%^+\\-=]).{6,12}\$"
val USERNAME_PATTERN: Pattern = Pattern.compile(USERNAME_REGEX)
val PASSWORD_PATTERN: Pattern = Pattern.compile(PASSWORD_REGEX)
}
}
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/rect_storage_btn_active.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid android:color="@color/blue_5"/>
<corners android:radius="5dp"/>
</shape>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/rect_storage_btn_inactive.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid android:color="@color/gray_2"/>
<corners android:radius="5dp"/>
</shape>
10 changes: 7 additions & 3 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
app:counterEnabled="true"
app:counterMaxLength="10"
app:endIconMode="clear_text"
app:endIconTint="@color/secondary_1">
app:endIconTint="@color/gray_2">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_logIn_id"
Expand Down Expand Up @@ -100,22 +100,26 @@

</com.google.android.material.textfield.TextInputLayout>

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_logIn_doLogIn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="@string/logIn_button_logIn"
android:textColor="@color/white"
android:background="@drawable/rect_storage_btn_active"
app:layout_constraintStart_toStartOf="@id/tv_logIn_title"
app:layout_constraintEnd_toEndOf="@id/tv_logIn_title"
app:layout_constraintBottom_toTopOf="@id/btn_logIn_doSignUp" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_logIn_doSignUp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:text="@string/logIn_button_signUp"
android:textColor="@color/white"
android:background="@drawable/rect_storage_btn_active"
app:layout_constraintStart_toStartOf="@id/tv_logIn_title"
app:layout_constraintEnd_toEndOf="@id/tv_logIn_title"
app:layout_constraintBottom_toBottomOf="parent" />
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/res/layout/activity_signup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
app:counterEnabled="true"
app:counterMaxLength="10"
app:endIconMode="clear_text"
app:endIconTint="@color/secondary_1">
app:endIconTint="@color/gray_2">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_signUp_ID"
Expand Down Expand Up @@ -103,7 +103,7 @@
app:counterEnabled="true"
app:counterMaxLength="12"
app:endIconMode="clear_text"
app:endIconTint="@color/secondary_1">
app:endIconTint="@color/gray_2">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_signUp_PW"
Expand Down Expand Up @@ -141,7 +141,7 @@
app:counterEnabled="true"
app:counterMaxLength="12"
app:endIconMode="clear_text"
app:endIconTint="@color/secondary_1">
app:endIconTint="@color/gray_2">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_signUp_nickName"
Expand Down Expand Up @@ -179,7 +179,7 @@
app:counterEnabled="true"
app:counterMaxLength="4"
app:endIconMode="clear_text"
app:endIconTint="@color/secondary_1">
app:endIconTint="@color/gray_2">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edt_signUp_MBTI"
Expand All @@ -198,13 +198,16 @@



<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_signUp_doSignUp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:layout_marginHorizontal="30dp"
android:text="@string/signUp_bt_signUp"
android:textColor="@{viewModel.checkBtnEnabled ? @color/white : @color/black}"
android:enabled="@{viewModel.checkBtnEnabled}"
android:background="@{viewModel.checkBtnEnabled ? @drawable/rect_storage_btn_active : @drawable/rect_storage_btn_inactive}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
Expand Down
18 changes: 13 additions & 5 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
<color name="primary_2">#4F378A</color>
<color name="primary_3">#381E72</color>

<color name="secondary_1">#5C5E62</color>
<color name="secondary_2">#353638</color>
<color name="gray_1">#5C5E62</color>
<color name="gray_2">#4A4D63</color>
<color name="gray_3">#4A4D63</color>
<color name="gray_4">#36394F</color>
<color name="gray_5">#353638</color>
<color name="gray_6">#292C3C</color>
<color name="gray_7">#1D1F29</color>

<color name="tertiary_1">#A3C9FF</color>
<color name="tertiary_2">#004882</color>
<color name="tertiary_3">#00315C</color>

<color name="blue_1">#A3C9FF</color>
<color name="blue_2">#5085FF</color>
<color name="blue_3">#004882</color>
<color name="blue_4">#00315C</color>
<color name="blue_5">#1D366D</color>

<color name="error_1">#FFB3B2</color>
<color name="error_2">#7E2A2E</color>
Expand Down