-
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
Showing
21 changed files
with
468 additions
and
12 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
...ain/java/com/woowacourse/friendogly/presentation/ui/dogdetail/DogDetailBindingAdapters.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,87 @@ | ||
package com.woowacourse.friendogly.presentation.ui.dogdetail | ||
|
||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import android.widget.LinearLayout | ||
import android.widget.TextView | ||
import androidx.core.content.ContextCompat | ||
import androidx.databinding.BindingAdapter | ||
import com.woowacourse.friendogly.R | ||
import java.time.LocalDate | ||
import java.time.format.DateTimeFormatter | ||
|
||
@BindingAdapter("setUpIndicator") | ||
fun LinearLayout.bindSetUpIndicator(size: Int) { | ||
removeAllViews() | ||
|
||
val layoutParams = | ||
LinearLayout.LayoutParams( | ||
ViewGroup.LayoutParams.WRAP_CONTENT, | ||
ViewGroup.LayoutParams.WRAP_CONTENT, | ||
).apply { | ||
leftMargin = 30 | ||
} | ||
|
||
repeat(size) { index -> | ||
ImageView(context).apply { | ||
val drawableId = | ||
if (index == 0) R.drawable.shape_indicator_active else R.drawable.shape_indicator_inactive | ||
|
||
setImageDrawable(ContextCompat.getDrawable(context, drawableId)) | ||
this.layoutParams = layoutParams | ||
addView(this) | ||
} | ||
} | ||
} | ||
|
||
@BindingAdapter("currentIndicator") | ||
fun LinearLayout.bindCurrentIndicator(currentPage: Int) { | ||
if (childCount == 0) return | ||
val position = currentPage % childCount | ||
for (idx in 0 until childCount) { | ||
val imageView = getChildAt(idx) as ImageView | ||
val drawableId = | ||
if (idx == position) R.drawable.shape_indicator_active else R.drawable.shape_indicator_inactive | ||
imageView.setImageDrawable(ContextCompat.getDrawable(context, drawableId)) | ||
} | ||
} | ||
|
||
@BindingAdapter("genderDrawable") | ||
fun ImageView.bindGenderDrawable(gender: String) { | ||
if (gender == "수컷") { | ||
this.setImageResource(R.drawable.img_dog_male) | ||
} else { | ||
this.setImageResource(R.drawable.img_dog_female) | ||
} | ||
} | ||
|
||
@BindingAdapter("neuteredTitle") | ||
fun TextView.bindNeuteredTitle(isNeutered: Boolean) { | ||
if (isNeutered) { | ||
this.apply { | ||
text = "중성화를 했어요" | ||
visibility = View.VISIBLE | ||
} | ||
} else { | ||
this.visibility = View.GONE | ||
} | ||
} | ||
|
||
@BindingAdapter("dogSize") | ||
fun TextView.bindDogSize(sizeType: String) { | ||
text = | ||
when (sizeType) { | ||
"소형견" -> "소형견이에요" | ||
"중형견" -> "중현견이에요" | ||
"대형견" -> "대형견이에요" | ||
else -> "" | ||
} | ||
} | ||
|
||
@BindingAdapter("dogBirthday") | ||
fun TextView.binDogBirthday(birthday: LocalDate) { | ||
val formatter = DateTimeFormatter.ofPattern("yyyy.MM") | ||
val formattedDate = birthday.format(formatter) | ||
this.text = formattedDate | ||
} |
47 changes: 47 additions & 0 deletions
47
...p/src/main/java/com/woowacourse/friendogly/presentation/ui/dogdetail/DogDetailFragment.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,47 @@ | ||
package com.woowacourse.friendogly.presentation.ui.dogdetail | ||
|
||
import androidx.fragment.app.viewModels | ||
import androidx.navigation.fragment.navArgs | ||
import androidx.viewpager2.widget.ViewPager2 | ||
import com.woowacourse.friendogly.R | ||
import com.woowacourse.friendogly.databinding.FragmentDogDetailBinding | ||
import com.woowacourse.friendogly.presentation.base.BaseFragment | ||
import com.woowacourse.friendogly.presentation.ui.dogdetail.adapter.DogDetailAdapter | ||
import com.woowacourse.friendogly.presentation.ui.mypage.MyPageViewModel.Companion.dogs | ||
|
||
class DogDetailFragment : BaseFragment<FragmentDogDetailBinding>(R.layout.fragment_dog_detail) { | ||
private val viewModel: DogDetailViewModel by viewModels() | ||
private val args: DogDetailFragmentArgs by navArgs() | ||
|
||
private val adapter: DogDetailAdapter by lazy { DogDetailAdapter() } | ||
|
||
override fun initViewCreated() { | ||
initDataBinding() | ||
initObserve() | ||
initAdapter() | ||
} | ||
|
||
private fun initDataBinding() { | ||
binding.vm = viewModel | ||
|
||
binding.vpDogDetail.registerOnPageChangeCallback( | ||
object : ViewPager2.OnPageChangeCallback() { | ||
override fun onPageSelected(position: Int) { | ||
super.onPageSelected(position) | ||
viewModel.updateCurrentPage(position) | ||
} | ||
}, | ||
) | ||
} | ||
|
||
private fun initAdapter() { | ||
binding.vpDogDetail.adapter = adapter | ||
} | ||
|
||
private fun initObserve() { | ||
viewModel.uiState.observe(this) { uiState -> | ||
adapter.submitList(uiState.dogs) | ||
binding.vpDogDetail.setCurrentItem(uiState.dogs.size, false) | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...pp/src/main/java/com/woowacourse/friendogly/presentation/ui/dogdetail/DogDetailUiState.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,7 @@ | ||
package com.woowacourse.friendogly.presentation.ui.dogdetail | ||
|
||
import com.woowacourse.friendogly.presentation.ui.mypage.Dog | ||
|
||
data class DogDetailUiState( | ||
val dogs: List<Dog> = emptyList(), | ||
) |
32 changes: 32 additions & 0 deletions
32
.../src/main/java/com/woowacourse/friendogly/presentation/ui/dogdetail/DogDetailViewModel.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,32 @@ | ||
package com.woowacourse.friendogly.presentation.ui.dogdetail | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import com.woowacourse.friendogly.presentation.base.BaseViewModel | ||
import com.woowacourse.friendogly.presentation.ui.mypage.MyPageViewModel.Companion.dogs | ||
|
||
class DogDetailViewModel : BaseViewModel() { | ||
private val _uiState: MutableLiveData<DogDetailUiState> = MutableLiveData(DogDetailUiState()) | ||
val uiState: LiveData<DogDetailUiState> get() = _uiState | ||
|
||
private val _currentPage: MutableLiveData<Int> = MutableLiveData(MIDDLE_PAGE) | ||
val currentPage: LiveData<Int> get() = _currentPage | ||
|
||
init { | ||
fetchDummy() | ||
} | ||
|
||
private fun fetchDummy() { | ||
val state = _uiState.value ?: return | ||
_uiState.value = state.copy(dogs = dogs) | ||
_currentPage.value = MIDDLE_PAGE - (MIDDLE_PAGE) % dogs.size | ||
} | ||
|
||
fun updateCurrentPage(page: Int) { | ||
_currentPage.value = page | ||
} | ||
|
||
companion object { | ||
private const val MIDDLE_PAGE = Int.MAX_VALUE / 2 | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ain/java/com/woowacourse/friendogly/presentation/ui/dogdetail/adapter/DogDetailAdapter.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,52 @@ | ||
package com.woowacourse.friendogly.presentation.ui.dogdetail.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.ItemDogDetailBinding | ||
import com.woowacourse.friendogly.presentation.ui.mypage.Dog | ||
|
||
class DogDetailAdapter : ListAdapter<Dog, DogDetailAdapter.ViewHolder>(DogItemDiffCallback) { | ||
init { | ||
setHasStableIds(true) | ||
} | ||
|
||
override fun onCreateViewHolder( | ||
parent: ViewGroup, | ||
viewType: Int, | ||
): ViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
val binding = ItemDogDetailBinding.inflate(inflater, parent, false) | ||
return ViewHolder(binding) | ||
} | ||
|
||
override fun getItemCount(): Int = Int.MAX_VALUE | ||
|
||
override fun onBindViewHolder( | ||
holder: ViewHolder, | ||
position: Int, | ||
) { | ||
holder.bind(getItem(position % currentList.size)) | ||
} | ||
|
||
class ViewHolder(private val binding: ItemDogDetailBinding) : | ||
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 | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.woowacourse.friendogly.presentation.ui.mypage | ||
|
||
interface MyPageActionHandler { | ||
fun navigateToDogDetail() | ||
fun navigateToDogDetail(id: Long) | ||
} |
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
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,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<set xmlns:android="http://schemas.android.com/apk/res/android" > | ||
<translate | ||
android:duration="300" | ||
android:fromXDelta="0" | ||
android:toXDelta="-100%p" /> | ||
</set> |
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,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<set xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<objectAnimator | ||
android:duration="300" | ||
android:propertyName="x" | ||
android:valueFrom="0" | ||
android:valueTo="400dp" | ||
android:valueType="floatType" /> | ||
</set> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions
9
android/app/src/main/res/drawable/rect_black_gradient_start.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,9 @@ | ||
<?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:startColor="#80000000" | ||
android:type="linear" /> | ||
</shape> |
10 changes: 10 additions & 0 deletions
10
android/app/src/main/res/drawable/shape_indicator_active.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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="oval"> | ||
<solid android:color="@color/blue" /> | ||
|
||
<size | ||
android:width="8dp" | ||
android:height="8dp" /> | ||
|
||
</shape> |
10 changes: 10 additions & 0 deletions
10
android/app/src/main/res/drawable/shape_indicator_inactive.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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="oval"> | ||
<solid android:color="@color/gray05" /> | ||
|
||
<size | ||
android:width="5dp" | ||
android:height="5dp" /> | ||
|
||
</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,44 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout 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"> | ||
|
||
<data> | ||
|
||
<variable | ||
name="vm" | ||
type="com.woowacourse.friendogly.presentation.ui.dogdetail.DogDetailViewModel" /> | ||
|
||
</data> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.viewpager2.widget.ViewPager2 | ||
android:id="@+id/vp_dog_detail" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<LinearLayout | ||
android:id="@+id/linearLayout_indicator" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:layout_marginBottom="16dp" | ||
android:gravity="center" | ||
android:orientation="horizontal" | ||
android:padding="15dp" | ||
app:currentIndicator="@{vm.currentPage}" | ||
app:layout_constraintBottom_toBottomOf="@+id/vp_dog_detail" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:setUpIndicator="@{vm.uiState.dogs.size()}" /> | ||
|
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
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
Oops, something went wrong.