Skip to content

Commit

Permalink
[#30] 로그인 기능 추가
Browse files Browse the repository at this point in the history
- 성별 선택 기능 추가
- 바뀐 디자인 가이드 소폭 적용
  • Loading branch information
ethan-223 committed Aug 4, 2022
1 parent 9adb904 commit 3d4b20d
Show file tree
Hide file tree
Showing 24 changed files with 257 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.EditText
import android.widget.RadioButton
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -72,6 +73,15 @@ class ProfileEditActivity : AppCompatActivity() {
}
}

binding.radiogroupProfileGender.setOnCheckedChangeListener { _, checkedId ->
val gender = when (checkedId) {
R.id.radiobutton_profile_man -> Gender.MAN
R.id.radiobutton_profile_woman -> Gender.WOMAN
else -> Gender.NONE
}
viewModel.onGenderChanged(gender)
}

binding.buttonProfileConfirm.setOnDebounceClickListener {
if (isNewProfile) {
viewModel.signUp()
Expand Down Expand Up @@ -103,6 +113,18 @@ class ProfileEditActivity : AppCompatActivity() {
binding.badgeimageviewProfileImage.setBigCircleImgSrc(it)
}
}
launch {
viewModel.profileUiModel
.map { it.gender }
.distinctUntilChanged()
.collect {
when (it) {
Gender.MAN -> binding.radiobuttonProfileMan.setCheckIfNew(true)
Gender.WOMAN -> binding.radiobuttonProfileWoman.setCheckIfNew(true)
Gender.NONE -> binding.radiogroupProfileGender.clearCheck()
}
}
}
}

observeEvent(viewModel.profileEvent) {
Expand All @@ -115,7 +137,7 @@ class ProfileEditActivity : AppCompatActivity() {
when (it.error) {
ProfileError.WRONG_ACCESS -> {
Lg.fw("Wrong access. signUpMetadata: $signUpMetaData, originProfile: $originalProfile")
toast("잘못된 접근입니다.")
toast(getString(R.string.profile_toast_wrong_access))
finish()
}
}
Expand All @@ -140,6 +162,13 @@ class ProfileEditActivity : AppCompatActivity() {
setTextIfNew(text)
}

private fun RadioButton.setCheckIfNew(check: Boolean) {
val oldValue = isChecked
if (oldValue != check) {
isChecked = check
}
}

companion object {
private const val EXTRA_PROFILE_UI_MODEL = "profileUiModel"
private const val EXTRA_SIGN_UP_META_DATA = "signUpMetaData"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class ProfileEditViewModel: ViewModel() {
}
}

fun onGenderChanged(gender: Gender) {
_profileUiModel.update {
it.copy(gender = gender)
}
}

fun signUp() {
// Todo: 회원가입 API 호출
Lg.d("SignUp : ${profileUiModel.value}, $signUpMetaData")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.moyerun.moyeorun_android.profile

import android.net.Uri
import android.os.Parcelable
import androidx.annotation.IdRes
import kotlinx.parcelize.Parcelize

@Parcelize
data class ProfileUiModel(
val imageUri: Uri = Uri.EMPTY,
val name: String = "",
val nickname: String = ""
val nickname: String = "",
val gender: Gender = Gender.NONE
): Parcelable

sealed class ProfileEvent {
Expand All @@ -18,4 +20,8 @@ sealed class ProfileEvent {

enum class ProfileError {
WRONG_ACCESS
}

enum class Gender {
MAN, WOMAN, NONE
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/gender_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="@android:color/transparent" />
<stroke
android:width="1dp"
android:color="@color/line_border_round" />
</shape>
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/gender_background_checked.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="@color/main_blue" />
</shape>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/gender_button_man.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/gender_background" />

<item
android:drawable="@drawable/ic_gender_man"
android:gravity="center" />

</layer-list>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/gender_button_man_checked.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/gender_background_checked" />

<item
android:drawable="@drawable/ic_gender_man_white"
android:gravity="center" />

</layer-list>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/gender_button_woman.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/gender_background" />

<item
android:drawable="@drawable/ic_gender_woman"
android:gravity="center" />

</layer-list>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/gender_button_woman_checked.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/gender_background_checked" />

<item
android:drawable="@drawable/ic_gender_woman_white"
android:gravity="center" />

</layer-list>
16 changes: 16 additions & 0 deletions app/src/main/res/drawable/ic_gender_man.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="21dp"
android:height="20dp"
android:viewportWidth="21"
android:viewportHeight="20">
<path
android:pathData="M6.4516,13.5483m-5.7016,0a5.7016,5.7016 0,1 1,11.4032 0a5.7016,5.7016 0,1 1,-11.4032 0"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="#D4D4D4"/>
<path
android:pathData="M10.4791,9.5802L17.3221,2.7372M17.3221,2.7372L11.8477,2.7372M17.3221,2.7372L17.3221,8.2116"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="#D4D4D4"/>
</vector>
16 changes: 16 additions & 0 deletions app/src/main/res/drawable/ic_gender_man_white.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="21dp"
android:height="20dp"
android:viewportWidth="21"
android:viewportHeight="20">
<path
android:pathData="M6.4516,13.5483m-5.7016,0a5.7016,5.7016 0,1 1,11.4032 0a5.7016,5.7016 0,1 1,-11.4032 0"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="#ffffff"/>
<path
android:pathData="M10.4791,9.5802L17.3221,2.7372M17.3221,2.7372L11.8477,2.7372M17.3221,2.7372L17.3221,8.2116"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="#ffffff"/>
</vector>
16 changes: 16 additions & 0 deletions app/src/main/res/drawable/ic_gender_woman.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="13dp"
android:height="20dp"
android:viewportWidth="13"
android:viewportHeight="20">
<path
android:pathData="M6.0606,6.0606m-5.3106,0a5.3106,5.3106 0,1 1,10.6212 0a5.3106,5.3106 0,1 1,-10.6212 0"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="#D4D4D4"/>
<path
android:pathData="M6.0606,11.5151V20M2.1212,14.5454H10"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="#D4D4D4"/>
</vector>
16 changes: 16 additions & 0 deletions app/src/main/res/drawable/ic_gender_woman_white.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="13dp"
android:height="20dp"
android:viewportWidth="13"
android:viewportHeight="20">
<path
android:pathData="M6.0606,6.0606m-5.3106,0a5.3106,5.3106 0,1 1,10.6212 0a5.3106,5.3106 0,1 1,-10.6212 0"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="#FFFFFF"/>
<path
android:pathData="M6.0606,11.5151V20M2.1212,14.5454H10"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="#FFFFFF"/>
</vector>
13 changes: 5 additions & 8 deletions app/src/main/res/drawable/round_background_12.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="12dp" />
<solid android:color="@color/main_white" />
</shape>
</item>
</layer-list>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="12dp" />
<solid android:color="@color/main_white" />
</shape>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/selector_gender_man.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/gender_button_man" android:state_checked="false" />
<item android:drawable="@drawable/gender_button_man_checked" android:state_checked="true" />
</selector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/selector_gender_woman.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/gender_button_woman" android:state_checked="false" />
<item android:drawable="@drawable/gender_button_woman_checked" android:state_checked="true" />
</selector>
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/toolbar_divider_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="1dp"
android:left="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/line_border_round" />
</shape>
</item>
</layer-list>
48 changes: 43 additions & 5 deletions app/src/main/res/layout/activity_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_profile"
style="@style/Toolbar.DefaultStyle"
style="@style/Toolbar.DividerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -28,8 +28,8 @@

<com.moyerun.moyeorun_android.views.BadgeRoundImageView
android:id="@+id/badgeimageview_profile_image"
android:layout_width="73dp"
android:layout_height="73dp"
android:layout_width="112dp"
android:layout_height="112dp"
android:layout_marginTop="25dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -38,14 +38,15 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginTop="20dp"
android:orientation="vertical"
android:paddingHorizontal="21dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/badgeimageview_profile_image">

<TextView
style="@style/Profile.InputLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/profile_name" />
Expand All @@ -60,6 +61,7 @@
android:inputType="text" />

<TextView
style="@style/Profile.InputLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
Expand All @@ -74,9 +76,45 @@
android:hint="@string/profile_nickname"
android:inputType="text" />

<TextView
style="@style/Profile.InputLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/profile_gender" />

<RadioGroup
android:id="@+id/radiogroup_profile_gender"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="8dp"
android:orientation="horizontal">

<RadioButton
android:id="@+id/radiobutton_profile_woman"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector_gender_woman"
android:button="@android:color/transparent" />

<Space
android:layout_width="9dp"
android:layout_height="match_parent" />

<RadioButton
android:id="@+id/radiobutton_profile_man"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/selector_gender_man"
android:button="@android:color/transparent" />

</RadioGroup>

</LinearLayout>

<Button
<com.moyerun.moyeorun_android.views.RoundButton
android:id="@+id/button_profile_confirm"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

<!-- Line colors -->
<color name="line_dialog_divider">#EBECEF</color>
<color name="line_border_round">#D4D4D4</color>
<color name="line_toolbar_divider">#D4D4D4</color>

<!-- button colors -->
<color name="button_pressed_true">#0047D0</color>
Expand Down
Loading

0 comments on commit 3d4b20d

Please sign in to comment.