-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c77d014
commit 5bb0039
Showing
12 changed files
with
442 additions
and
2 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
...pp/src/main/java/com/woowacourse/friendogly/presentation/ui/mypage/MyPageActionHandler.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,5 @@ | ||
package com.woowacourse.friendogly.presentation.ui.mypage | ||
|
||
interface MyPageActionHandler { | ||
fun navigateToDogDetail() | ||
} |
36 changes: 35 additions & 1 deletion
36
...oid/app/src/main/java/com/woowacourse/friendogly/presentation/ui/mypage/MyPageFragment.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 |
---|---|---|
@@ -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) | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...src/main/java/com/woowacourse/friendogly/presentation/ui/mypage/MyPageNavigationAction.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.woowacourse.friendogly.presentation.ui.mypage | ||
|
||
sealed interface MyPageNavigationAction { | ||
data object NavigateToProfileEdit : MyPageNavigationAction | ||
|
||
data object NavigateToSetting : MyPageNavigationAction | ||
|
||
data object NavigateToDogRegister : MyPageNavigationAction | ||
|
||
data object NavigateToDogDetail : MyPageNavigationAction | ||
} |
21 changes: 21 additions & 0 deletions
21
android/app/src/main/java/com/woowacourse/friendogly/presentation/ui/mypage/MyPageUiState.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,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, | ||
) |
81 changes: 81 additions & 0 deletions
81
...id/app/src/main/java/com/woowacourse/friendogly/presentation/ui/mypage/MyPageViewModel.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,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", | ||
), | ||
) | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
.../main/java/com/woowacourse/friendogly/presentation/ui/mypage/adapter/DogProfileAdapter.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,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 | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
android/app/src/main/res/drawable/rect_black_gradient_fill.xml
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 @@ | ||
<?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> |
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,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> |
Oops, something went wrong.