-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- ProfileEditActivity 추가 - 이름과 닉네임 입력이 가능하고, ViewModel 의 UiModel 을 뷰에 반영시키도록 함
- Loading branch information
Showing
14 changed files
with
335 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
app/src/main/java/com/moyerun/moyeorun_android/profile/ProfileEditActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.moyerun.moyeorun_android.profile | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.widget.EditText | ||
import androidx.activity.viewModels | ||
import androidx.core.widget.doAfterTextChanged | ||
import com.moyerun.moyeorun_android.R | ||
import com.moyerun.moyeorun_android.common.extension.repeatOnStart | ||
import com.moyerun.moyeorun_android.common.extension.setDrawableEnd | ||
import com.moyerun.moyeorun_android.common.extension.setTextIfNew | ||
import com.moyerun.moyeorun_android.databinding.ActivityProfileBinding | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
import kotlinx.coroutines.flow.map | ||
import kotlinx.coroutines.launch | ||
|
||
@AndroidEntryPoint | ||
class ProfileEditActivity : AppCompatActivity() { | ||
|
||
private val viewModel: ProfileEditViewModel by viewModels() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val binding = ActivityProfileBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
val originalProfile: ProfileUiModel? = intent.getParcelableExtra(EXTRA_PROFILE_UI_MODEL) | ||
val isNewProfile = originalProfile == null | ||
|
||
if (isNewProfile) { | ||
binding.textviewProfileTitle.text = "기본 정보" | ||
binding.buttonProfileConfirm.text = "다음" | ||
} else { | ||
binding.textviewProfileTitle.text = "프로필" | ||
binding.buttonProfileConfirm.text = "완료" | ||
} | ||
|
||
viewModel.updateProfile(originalProfile) | ||
|
||
binding.edittextProfileName.doAfterTextChanged { | ||
viewModel.onNameChanged(it?.toString().orEmpty()) | ||
} | ||
|
||
binding.edittextProfileNickname.doAfterTextChanged { | ||
viewModel.onNicknameChanged(it?.toString().orEmpty()) | ||
} | ||
|
||
repeatOnStart { | ||
launch { | ||
viewModel.profileUiModel | ||
.map { it.name } | ||
.distinctUntilChanged() | ||
.collect { | ||
binding.edittextProfileName.setTextAndCheckIcon(it) | ||
} | ||
} | ||
launch { | ||
viewModel.profileUiModel | ||
.map { it.nickname } | ||
.distinctUntilChanged() | ||
.collect { | ||
binding.edittextProfileNickname.setTextAndCheckIcon(it) | ||
} | ||
} | ||
launch { | ||
viewModel.profileUiModel | ||
.map { it.imageUrl } | ||
.distinctUntilChanged() | ||
.collect { | ||
binding.badgeimageviewProfileImage.setBigCircleImgSrc(it) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun isValidText(text: String): Boolean { | ||
// Todo: 유효성 검사 조건 추가 (ex. 정규 표현식, 글자 제한) | ||
return text.isNotEmpty() | ||
} | ||
|
||
private fun EditText.setTextAndCheckIcon(text: String) { | ||
val isValid = isValidText(text) | ||
val resId = if (isValid) { | ||
R.drawable.ic_check | ||
} else { | ||
null | ||
} | ||
setDrawableEnd(resId) | ||
setTextIfNew(text) | ||
} | ||
|
||
companion object { | ||
private const val EXTRA_PROFILE_UI_MODEL = "profileUiModel" | ||
|
||
fun startActivity(context: Context, profileUiModel: ProfileUiModel? = null) { | ||
context.startActivity(Intent(context, ProfileEditActivity::class.java).apply { | ||
putExtra(EXTRA_PROFILE_UI_MODEL, profileUiModel) | ||
}) | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/moyerun/moyeorun_android/profile/ProfileEditViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.moyerun.moyeorun_android.profile | ||
|
||
import androidx.lifecycle.ViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.update | ||
|
||
class ProfileEditViewModel: ViewModel() { | ||
|
||
private val _profileUiModel = MutableStateFlow(ProfileUiModel()) | ||
val profileUiModel: StateFlow<ProfileUiModel> | ||
get() = _profileUiModel | ||
|
||
private var oldProfileUiModel: ProfileUiModel? = null | ||
|
||
private var isNewPost = true | ||
|
||
fun updateProfile(profileUiModel: ProfileUiModel?) { | ||
if (profileUiModel == null) return | ||
_profileUiModel.update { profileUiModel } | ||
oldProfileUiModel = profileUiModel | ||
isNewPost = false | ||
} | ||
|
||
fun onNameChanged(name: String) { | ||
_profileUiModel.update { | ||
it.copy(name = name) | ||
} | ||
} | ||
|
||
fun onNicknameChanged(nickname: String) { | ||
_profileUiModel.update { | ||
it.copy(nickname = nickname) | ||
} | ||
} | ||
|
||
fun onImageUrlChanged(imageUrl: String) { | ||
_profileUiModel.update { | ||
it.copy(imageUrl = imageUrl) | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/moyerun/moyeorun_android/profile/ProfileUiModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.moyerun.moyeorun_android.profile | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
data class ProfileUiModel( | ||
val imageUrl: String = "", | ||
val name: String = "", | ||
val nickname: String = "" | ||
): Parcelable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="18dp" | ||
android:height="13dp" | ||
android:viewportWidth="18" | ||
android:viewportHeight="13"> | ||
<path | ||
android:pathData="M17,1L6,12L1,7" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="2" | ||
android:fillColor="#00000000" | ||
android:strokeColor="#1162FF" | ||
android:strokeLineCap="round"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="30dp" | ||
android:height="30dp" | ||
android:viewportWidth="30" | ||
android:viewportHeight="30"> | ||
<path | ||
android:pathData="M25.2084,15.5H5.2084" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="1.5" | ||
android:fillColor="#00000000" | ||
android:strokeColor="#000000" | ||
android:strokeLineCap="round"/> | ||
<path | ||
android:pathData="M12.5,22.7918L5.2084,15.5002L12.5,8.2085" | ||
android:strokeLineJoin="round" | ||
android:strokeWidth="1.5" | ||
android:fillColor="#00000000" | ||
android:strokeColor="#000000" | ||
android:strokeLineCap="round"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".profile.ProfileEditActivity"> | ||
|
||
<androidx.appcompat.widget.Toolbar | ||
android:id="@+id/toolbar_profile" | ||
style="@style/Toolbar.DefaultStyle" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:navigationIcon="@drawable/ic_toolbar_back"> | ||
|
||
<TextView | ||
android:id="@+id/textview_profile_title" | ||
style="@style/Toolbar.Title" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
tools:text="기본 정보" /> | ||
|
||
</androidx.appcompat.widget.Toolbar> | ||
|
||
<com.moyerun.moyeorun_android.views.BadgeRoundImageView | ||
android:id="@+id/badgeimageview_profile_image" | ||
android:layout_width="73dp" | ||
android:layout_height="73dp" | ||
android:layout_marginTop="25dp" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/toolbar_profile" /> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="25dp" | ||
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 | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/profile_name" /> | ||
|
||
<androidx.appcompat.widget.AppCompatEditText | ||
android:id="@+id/edittext_profile_name" | ||
style="@style/Profile.Input" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="12dp" | ||
android:hint="@string/profile_name" | ||
android:inputType="text" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="20dp" | ||
android:text="@string/profile_nickname" /> | ||
|
||
<androidx.appcompat.widget.AppCompatEditText | ||
android:id="@+id/edittext_profile_nickname" | ||
style="@style/Profile.Input" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="12dp" | ||
android:hint="@string/profile_nickname" | ||
android:inputType="text" /> | ||
|
||
</LinearLayout> | ||
|
||
<Button | ||
android:id="@+id/button_profile_confirm" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginHorizontal="21dp" | ||
android:layout_marginBottom="33dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
tools:text="다음" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<style name="Profile" /> | ||
|
||
<!-- Todo: 배경 이미지 변경. BorderEditText 머지 되면 parent 로 둬야함. --> | ||
<style name="Profile.Input"> | ||
<item name="android:textStyle">bold</item> | ||
<item name="android:textSize">18dp</item> | ||
<item name="android:paddingHorizontal">21dp</item> | ||
<item name="android:paddingVertical">15dp</item> | ||
<item name="android:background">@null</item> | ||
</style> | ||
</resources> |
Oops, something went wrong.