Skip to content

Commit

Permalink
마이페이지 (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
junjange authored and takoyakimchi committed Oct 23, 2024
1 parent c77d014 commit 5bb0039
Show file tree
Hide file tree
Showing 12 changed files with 442 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.woowacourse.friendogly.presentation.ui.mypage

interface MyPageActionHandler {
fun navigateToDogDetail()
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
package com.woowacourse.friendogly.presentation.ui.mypage

import androidx.fragment.app.viewModels
import com.woowacourse.friendogly.R
import com.woowacourse.friendogly.databinding.FragmentMyPageBinding
import com.woowacourse.friendogly.presentation.base.BaseFragment
import com.woowacourse.friendogly.presentation.base.observeEvent
import com.woowacourse.friendogly.presentation.ui.mypage.adapter.DogProfileAdapter

class MyPageFragment : BaseFragment<FragmentMyPageBinding>(R.layout.fragment_my_page) {
override fun initViewCreated() {}
private val viewModel: MyPageViewModel by viewModels()

private val adapter: DogProfileAdapter by lazy { DogProfileAdapter(viewModel) }

override fun initViewCreated() {
initDataBinding()
initAdapter()
initObserve()
}

private fun initDataBinding() {
binding.vm = viewModel
}

private fun initAdapter() {
binding.rvDogProfile.adapter = adapter
}

private fun initObserve() {
viewModel.navigateAction.observeEvent(this) { action ->
when (action) {
is MyPageNavigationAction.NavigateToSetting -> TODO()
is MyPageNavigationAction.NavigateToDogDetail -> TODO()
is MyPageNavigationAction.NavigateToDogRegister -> TODO()
is MyPageNavigationAction.NavigateToProfileEdit -> TODO()
}
}

viewModel.uiState.observe(viewLifecycleOwner) { uiState ->
adapter.submitList(uiState.dogs)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.woowacourse.friendogly.presentation.ui.mypage

sealed interface MyPageNavigationAction {
data object NavigateToProfileEdit : MyPageNavigationAction

data object NavigateToSetting : MyPageNavigationAction

data object NavigateToDogRegister : MyPageNavigationAction

data object NavigateToDogDetail : MyPageNavigationAction
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.woowacourse.friendogly.presentation.ui.mypage

import java.time.LocalDate

data class MyPageUiState(
val nickname: String = "",
val email: String = "",
val profilePath: String? = null,
val dogs: List<Dog> = emptyList(),
)

// TODO 더미 데이터 모델
data class Dog(
val name: String,
val description: String,
val birthDate: LocalDate,
val sizeType: String,
val gender: String,
val isNeutered: Boolean,
val image: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.woowacourse.friendogly.presentation.ui.mypage

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.woowacourse.friendogly.presentation.base.BaseViewModel
import com.woowacourse.friendogly.presentation.base.Event
import com.woowacourse.friendogly.presentation.base.emit
import java.time.LocalDate

class MyPageViewModel : BaseViewModel(), MyPageActionHandler {
private val _uiState: MutableLiveData<MyPageUiState> = MutableLiveData(MyPageUiState())
val uiState: LiveData<MyPageUiState> get() = _uiState

private val _navigateAction: MutableLiveData<Event<MyPageNavigationAction>> =
MutableLiveData(null)
val navigateAction: LiveData<Event<MyPageNavigationAction>> get() = _navigateAction

init {
fetchDummy()
}

private fun fetchDummy() {
val state = _uiState.value ?: return

_uiState.value =
state.copy(
nickname = "손흥민",
email = "[email protected]",
dogs = dogs,
)
}

fun navigateToDogRegister() {
_navigateAction.emit(MyPageNavigationAction.NavigateToDogRegister)
}

override fun navigateToDogDetail() {
_navigateAction.emit(MyPageNavigationAction.NavigateToDogDetail)
}

companion object {
val dog =
Dog(
name = "땡이",
description = "강인해요",
birthDate = LocalDate.now(),
sizeType = "",
gender = "",
isNeutered = true,
image = "https://github.com/user-attachments/assets/9329234e-e47d-4fc5-b4b5-9f2a827b60b1",
)
val dogs =
listOf<Dog>(
dog,
dog.copy(
name = "초코",
image = "https://github.com/user-attachments/assets/a344d355-8b00-4e08-a33f-08db58010b07",
),
dog.copy(
name = "도토리",
image = "https://petsstore.co.kr/web/product/big/202401/dc7c18de083f0ab58060b4ec82321028.jpg",
),
dog.copy(
name = "도토리",
image = "https://petsstore.co.kr/web/product/big/202401/dc7c18de083f0ab58060b4ec82321028.jpg",
),
dog.copy(
name = "도토리",
image = "https://petsstore.co.kr/web/product/big/202401/dc7c18de083f0ab58060b4ec82321028.jpg",
),
dog.copy(
name = "도토리",
image = "https://petsstore.co.kr/web/product/big/202401/dc7c18de083f0ab58060b4ec82321028.jpg",
),
dog.copy(
name = "도토리",
image = "https://petsstore.co.kr/web/product/big/202401/dc7c18de083f0ab58060b4ec82321028.jpg",
),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.woowacourse.friendogly.presentation.ui.mypage.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.woowacourse.friendogly.databinding.ItemDogBinding
import com.woowacourse.friendogly.presentation.ui.mypage.Dog
import com.woowacourse.friendogly.presentation.ui.mypage.MyPageActionHandler

class DogProfileAdapter(
private val actionHandler: MyPageActionHandler,
) : ListAdapter<Dog, DogProfileAdapter.ViewHolder>(DogItemDiffCallback) {
init {
setHasStableIds(true)
}

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int,
): ViewHolder {
val inflater = LayoutInflater.from(parent.context)
val binding = ItemDogBinding.inflate(inflater, parent, false)
binding.actionHandler = actionHandler
return ViewHolder(binding)
}

override fun onBindViewHolder(
holder: ViewHolder,
position: Int,
) {
holder.bind(getItem(position))
}

class ViewHolder(private val binding: ItemDogBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(item: Dog) {
binding.dog = item
}
}

internal object DogItemDiffCallback : DiffUtil.ItemCallback<Dog>() {
override fun areItemsTheSame(
oldItem: Dog,
newItem: Dog,
): Boolean = oldItem.name == newItem.name

override fun areContentsTheSame(
oldItem: Dog,
newItem: Dog,
): Boolean = oldItem == newItem
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,27 @@ fun ImageView.bindProfile1000(bitmap: Bitmap?) {
.transform(CenterCrop(), RoundedCorners(1000))
.into(this)
}

@BindingAdapter("glideProfile1000")
fun ImageView.bindProfile1000(profilePath: String?) {
if (profilePath == null) {
this.setImageResource(R.drawable.img_dog)
return
}

Glide.with(context)
.asBitmap()
.load(profilePath)
.transform(CenterCrop(), RoundedCorners(1000))
.into(this)
}

@BindingAdapter("urlToImage")
fun ImageView.bindUrlToImage(imageUrl: String?) {
imageUrl?.let { url ->
Glide.with(context)
.load(url)
.centerCrop()
.into(this)
}
}
11 changes: 11 additions & 0 deletions android/app/src/main/res/drawable/rect_black_gradient_fill.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<gradient
android:angle="90"
android:centerColor="#70000000"
android:endColor="#00000000"
android:startColor="#80000000"
android:type="linear" />
</shape>
6 changes: 6 additions & 0 deletions android/app/src/main/res/drawable/rect_gray01_fill_16.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="16dp" />
<solid android:color="@color/gray03" />
</shape>
Loading

0 comments on commit 5bb0039

Please sign in to comment.