Skip to content

Commit

Permalink
[#30] 로그인 기능 추가
Browse files Browse the repository at this point in the history
- 갤러리에서 이미지 선택 기능 추가
  • Loading branch information
ethan-223 committed Sep 4, 2022
1 parent b05ecc9 commit a0f8c76
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ 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.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.widget.doAfterTextChanged
import com.moyerun.moyeorun_android.R
import com.moyerun.moyeorun_android.common.Lg
Expand Down Expand Up @@ -41,6 +42,15 @@ class ProfileEditActivity : AppCompatActivity() {

viewModel.updateData(signUpMetaData, originalProfile)

val galleryLauncher =
registerForActivityResult(ActivityResultContracts.GetContent()) { imageUri ->
if (imageUri != null) {
viewModel.onImageUrlChanged(imageUri)
} else {
Lg.fw("Cannot get Image Uri from gallery")
}
}

binding.edittextProfileName.doAfterTextChanged {
viewModel.onNameChanged(it?.toString().orEmpty())
}
Expand All @@ -53,7 +63,7 @@ class ProfileEditActivity : AppCompatActivity() {
showAllowingStateLoss("selectImage") {
ProfileImageSelectDialogFragment.getInstance(
onGalleryClick = {
// Todo : 갤러리 선택 화면
galleryLauncher.launch("image/*")
},
onDefaultImagesClick = {
// Todo : 기본 이미지 선택 화면
Expand Down Expand Up @@ -87,7 +97,7 @@ class ProfileEditActivity : AppCompatActivity() {
}
launch {
viewModel.profileUiModel
.map { it.imageUrl }
.map { it.imageUri }
.distinctUntilChanged()
.collect {
binding.badgeimageviewProfileImage.setBigCircleImgSrc(it)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.moyerun.moyeorun_android.profile

import android.net.Uri
import androidx.lifecycle.ViewModel
import com.moyerun.moyeorun_android.common.EventLiveData
import com.moyerun.moyeorun_android.common.Lg
Expand Down Expand Up @@ -52,9 +53,9 @@ class ProfileEditViewModel: ViewModel() {
}
}

fun onImageUrlChanged(imageUrl: String) {
fun onImageUrlChanged(imageUri: Uri) {
_profileUiModel.update {
it.copy(imageUrl = imageUrl)
it.copy(imageUri = imageUri)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.moyerun.moyeorun_android.profile

import android.net.Uri
import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class ProfileUiModel(
val imageUrl: String = "",
val imageUri: Uri = Uri.EMPTY,
val name: String = "",
val nickname: String = ""
): Parcelable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.moyerun.moyeorun_android.views

import android.Manifest
import android.content.Context
import android.net.Uri
import android.util.AttributeSet
import android.util.Patterns
import android.view.LayoutInflater
Expand Down Expand Up @@ -95,6 +96,12 @@ class BadgeRoundImageView @JvmOverloads constructor(
.placeholder(R.drawable.user_profile_image_default_112dp).into(binding.imgBigCircle)
}

fun setBigCircleImgSrc(imageUri: Uri) {
Glide.with(context).load(imageUri).centerCrop()
.placeholder(R.drawable.user_profile_image_default_112dp)
.into(binding.imgBigCircle)
}

fun setBigCircleImageBg(@ColorRes bgResId: Int) {
binding.imgBigCircle.setBackgroundColor(resources.getColor(bgResId, context?.theme))
}
Expand Down

0 comments on commit a0f8c76

Please sign in to comment.