Skip to content

Commit

Permalink
#92/소원권 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
sub101 committed Sep 3, 2023
1 parent a4c48c5 commit 51b8f9c
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 61 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class MultiViewWishHolder1(private val binding: ItemWishSmallBinding) :
binding.apply {
tvItemWlColor.text = "새 소원권 ${item.newWishCoupon}"
}
binding.root.setOnClickListener {
clickListener(WishActivity.WishTypeId(item.type, -1, false, true))
if (item.newWishCoupon != 0) {
binding.root.setOnClickListener {
clickListener(WishActivity.WishTypeId(item.type, -1, false, true))
}
}
}
}
43 changes: 25 additions & 18 deletions app/src/main/java/sopt/uni/presentation/wish/WishActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import android.content.Intent
import android.os.Bundle
import android.os.Parcelable
import android.view.View
import android.widget.TextView
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SimpleItemAnimator
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -76,37 +78,42 @@ class WishActivity : BindingActivity<ActivityWishBinding>(R.layout.activity_wish
}
}

with(binding) {
val animator = rvWish.itemAnimator
if (animator is SimpleItemAnimator) {
animator.supportsChangeAnimations = false
fun setupRecyclerView(rv: RecyclerView, adapter: RecyclerView.Adapter<*>) {
rv.itemAnimator?.let { animator ->
if (animator is SimpleItemAnimator) {
animator.supportsChangeAnimations = false
}
}
rv.adapter = adapter
rv.layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
}

fun updateTextStyles(tv1: TextView, tv2: TextView) {
tv1.setTextColor(resources.getColor(R.color.Lightblue_600))
tv2.setTextColor(resources.getColor(R.color.Gray_300))
tv1.setTextAppearance(R.style.Subtitle)
tv2.setTextAppearance(R.style.Body1_Regular)
}

with(binding) {
tvWishMyWish.setOnClickListener {
tvWishMyWish.setTextColor(resources.getColor(R.color.Lightblue_600))
tvWishYourWish.setTextColor(resources.getColor(R.color.Gray_300))
tvWishMyWish.setTextAppearance(R.style.Subtitle)
tvWishYourWish.setTextAppearance(R.style.Body1_Regular)
updateTextStyles(tvWishMyWish, tvWishYourWish)
lifecycleScope.launch {
wishViewModel.getMyWishList(userId).join()
}
rvWish.adapter = multiviewAdapter
rvWish.layoutManager =
StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
setupRecyclerView(rvWish, multiviewAdapter)
multiviewAdapter.submitData(_wishList)
}

tvWishYourWish.setOnClickListener {
tvWishMyWish.setTextColor(resources.getColor(R.color.Gray_300))
tvWishYourWish.setTextColor(resources.getColor(R.color.Lightblue_600))
tvWishMyWish.setTextAppearance(R.style.Body1_Regular)
tvWishYourWish.setTextAppearance(R.style.Subtitle)
updateTextStyles(tvWishYourWish, tvWishMyWish)
lifecycleScope.launch {
wishViewModel.getPartnerWishList(partnerId!!).join()
}
setupRecyclerView(rvWish, yourMultiviewAdapter)
yourMultiviewAdapter.submitData(_wishList)
rvWish.adapter = yourMultiviewAdapter
rvWish.layoutManager =
StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
}

btnWishBack.setOnClickListener {
startActivity<HomeActivity>()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,8 @@ class WishNewWishFragment : Fragment() {
}

override fun afterTextChanged(s: Editable?) {
val trimmedText = s?.toString()?.trim()
val length = trimmedText?.length ?: 0
binding.tvNewWishContentLength.text = "$length/54"

if (length >= 54) {
binding.tvNewWishContentLength.setTextColor(Color.RED)
} else {
binding.tvNewWishContentLength.setTextColor(Color.GRAY)
}

if (s?.isNotEmpty() == true || length <= 54) {
binding.btnNewWishFinish.isEnabled = true
binding.btnNewWishFinish.backgroundTintList =
resources.getColorStateList(R.color.Lightblue_500)
} else {
binding.btnNewWishFinish.isEnabled = false
binding.btnNewWishFinish.backgroundTintList =
resources.getColorStateList(R.color.Gray_300)
}
val text = s?.toString()
updateTextLength(text)
}
})
btnNewWishClose.setOnClickListener {
Expand All @@ -80,6 +63,30 @@ class WishNewWishFragment : Fragment() {
}
}

private fun updateTextLength(text: String?) {
val trimmedText = text?.trim()
val length = trimmedText?.length ?: 0
binding.tvNewWishContentLength.text = "$length/54"

if (length >= 54) {
binding.tvNewWishContentLength.setTextColor(Color.RED)
} else {
binding.tvNewWishContentLength.setTextColor(Color.GRAY)
}

val isTextNotEmpty = !trimmedText.isNullOrEmpty()
val isLengthValid = length <= 54

binding.btnNewWishFinish.isEnabled = isTextNotEmpty || isLengthValid

val backgroundTint = if (isTextNotEmpty && isLengthValid) {
R.color.Lightblue_500
} else {
R.color.Gray_300
}
binding.btnNewWishFinish.backgroundTintList = resources.getColorStateList(backgroundTint)
}

private fun createWishCoupon(content: String) {
createWishCouponViewModel.patchCreateWishCoupon(content)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_wish.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
android:layout_marginBottom="4dp"
android:paddingVertical="7dp"
android:text="@string/wish_contour"
android:textColor="@color/Gray_300"
android:textColor="@color/Gray_200"
app:layout_constraintLeft_toRightOf="@id/tv_wish_my_wish"
app:layout_constraintTop_toBottomOf="@id/tv_wish_ment_sub" />

Expand Down
15 changes: 7 additions & 8 deletions app/src/main/res/layout/fragment_wish_new_wish.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,30 @@
style="@style/Body2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="89dp"
android:layout_marginTop="70dp"
android:text="나의 소원은"
android:textColor="@color/Gray_400"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<!-- 비율로 그리기 -->
<EditText
android:id="@+id/edt_new_wish_cv"
style="@style/Subtitle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="28dp"
android:layout_marginBottom="267dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="200dp"
android:background="@android:color/transparent"
android:gravity="center"
android:hint="@string/wish_write_ask"
android:imeOptions="actionDone"
android:importantForAutofill="no"
android:maxLength="60"
android:inputType="textMultiLine"
android:imeOptions="actionDone"
android:textColorHint="@color/Gray_300"
android:maxLength="60"
android:textColor="@color/Gray_600"
android:textColorHint="@color/Gray_300"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_new_wish_cv" />

Expand All @@ -151,7 +150,7 @@
android:id="@+id/iv_new_wish_dotted_line"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_marginTop="104dp"
android:layout_marginTop="50dp"
android:src="@drawable/wish_dotted_line"
app:layout_constraintTop_toBottomOf="@id/tv_new_wish_content_length"
tools:layout_editor_absoluteX="0dp" />
Expand Down
17 changes: 8 additions & 9 deletions app/src/main/res/layout/fragment_wish_use_my.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
android:layout_height="0dp"
android:layout_marginHorizontal="30dp"
android:layout_marginTop="82dp"
android:layout_marginBottom="142dp"
android:layout_marginBottom="121dp"
android:background="@drawable/bg_wish_card"
android:elevation="8dp"
app:layout_constraintBottom_toBottomOf="parent"
Expand All @@ -113,9 +113,9 @@
<ImageView
android:id="@+id/iv_wish_use_my"
setImage="@{vm.wishCouponImage}"
android:layout_width="140dp"
android:layout_height="140dp"
android:layout_marginTop="62dp"
android:layout_width="130dp"
android:layout_height="130dp"
android:layout_marginTop="42dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -125,7 +125,6 @@
style="@style/Body2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="4dp"
android:text="나의 소원은"
android:textColor="@color/Gray_400"
Expand All @@ -138,7 +137,7 @@
android:id="@+id/tv_wish_use_my_description"
style="@style/Subtitle"
android:layout_width="match_parent"
android:layout_height="72dp"
android:layout_height="65dp"
android:gravity="center"
android:text="@{vm.wishCouponContent}"
android:textColor="@color/Gray_600"
Expand All @@ -150,7 +149,7 @@
android:id="@+id/iv_wish_use_my_dotted_line"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_marginTop="15dp"
android:layout_marginTop="10dp"
android:src="@drawable/wish_dotted_line"
app:layout_constraintTop_toBottomOf="@id/tv_wish_use_my_description" />

Expand Down Expand Up @@ -197,8 +196,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="74dp"
android:layout_marginBottom="40dp"
android:layout_marginTop="60dp"
android:layout_marginBottom="16dp"
android:background="@drawable/btn_wish"
android:backgroundTint="@color/Lightblue_500"
android:paddingHorizontal="16dp"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_wish_use_your.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
android:layout_height="140dp"
setImage="@{vm.wishCouponImage}"
android:layout_marginTop="62dp"
android:background="@color/Gray_150"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/layout/item_wish_small.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
android:id="@+id/iv_item_ws"
android:background="@color/Gray_000"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_height="40dp"
android:src="@drawable/wish_amount"
android:layout_marginTop="24dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="57dp"
android:layout_marginHorizontal="58dp"
android:layout_marginHorizontal="10dp"
android:scaleType="fitCenter"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand Down

0 comments on commit 51b8f9c

Please sign in to comment.