Skip to content

Commit

Permalink
[MERGE] : #322 -> develop
Browse files Browse the repository at this point in the history
[UI/#322] 시작하기 버튼 디자인 변경
  • Loading branch information
Chaeyeon authored Nov 6, 2023
2 parents d2c5eb8 + 7b327c7 commit 786c166
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.el.yello.R
import com.example.ui.intent.dpToPx
import com.example.ui.number.dpToPx

class ProfileItemDecoration(context: Context) : RecyclerView.ItemDecoration() {
private val dividerHeight = dpToPx(context, 1)
private val dividerMargin = dpToPx(context, 24)
private val dividerHeight = 1.dpToPx(context)
private val dividerMargin = 24.dpToPx(context)
private val dividerColor = ContextCompat.getColor(context, R.color.grayscales_800)
private val dividerPaint = Paint()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.el.yello.R
import com.example.ui.intent.dpToPx
import com.example.ui.number.dpToPx

class RecommendItemDecoration(context: Context) : RecyclerView.ItemDecoration() {
private val dividerHeight = dpToPx(context, 1)
private val dividerMargin = dpToPx(context, 24)
private val dividerHeight = 1.dpToPx(context)
private val dividerMargin = 24.dpToPx(context)
private val dividerColor = ContextCompat.getColor(context, R.color.grayscales_800)
private val dividerPaint = Paint()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package com.el.yello.presentation.main.yello.start

import android.content.Intent
import android.graphics.Point
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.ViewGroup.MarginLayoutParams
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
Expand All @@ -16,7 +14,10 @@ import com.el.yello.presentation.main.yello.vote.VoteActivity
import com.el.yello.util.amplitude.AmplitudeUtils
import com.example.domain.entity.type.YelloState
import com.example.ui.base.BindingFragment
import com.example.ui.context.setMargins
import com.example.ui.fragment.getCompatibleRealSize
import com.example.ui.view.UiState
import com.example.ui.view.dpToPx
import com.example.ui.view.setOnSingleClickListener
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
Expand Down Expand Up @@ -53,32 +54,27 @@ class YelloStartFragment :
private fun initEntranceLottie() {
with(binding.lottieStartEntrance) {
val size = Point()
// TODO: getCompatibleRealSize 확장함수로 추출
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowMetrics = requireActivity().windowManager.currentWindowMetrics
size.x = windowMetrics.bounds.width()
size.y = windowMetrics.bounds.height()
} else {
display.getRealSize(size)
}
getCompatibleRealSize(size)
val displayWidth = size.x
val displayHeight = size.y

layoutParams.width = (2.22 * displayWidth).toInt()
setMargins(this, (-0.435 * displayHeight).toInt())
setMargins(this, 0, 0, 0, (-0.435 * displayHeight).toInt())
}
}

private fun initShadowView() {
binding.shadowStart.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
}

private fun setMargins(v: View, b: Int) {
if (v.layoutParams is MarginLayoutParams) {
val p = v.layoutParams as MarginLayoutParams
p.setMargins(0, 0, 0, b)
v.requestLayout()
}
val size = Point()
getCompatibleRealSize(size)
val displayWidth = size.x
setMargins(
binding.layoutSubsDouble,
0,
displayWidth + MARGIN_SUBSCRIBE_LAYOUT.dpToPx(requireContext()),
0,
0,
)
}

private fun initVoteBtnClickListener() {
Expand All @@ -99,11 +95,11 @@ class YelloStartFragment :
.onEach { state ->
when (state) {
is UiState.Success -> {
if (state.data?.isSubscribe == true) {
if (state.data.isSubscribe) {
binding.layoutSubsDouble.visibility = View.VISIBLE
} else {
binding.layoutSubsDouble.visibility = View.GONE
return@onEach
}
binding.layoutSubsDouble.visibility = View.GONE
}

is UiState.Failure -> {
Expand All @@ -120,6 +116,8 @@ class YelloStartFragment :
companion object {
private const val EVENT_CLICK_VOTE_START = "click_vote_start"

private const val MARGIN_SUBSCRIBE_LAYOUT = 16

@JvmStatic
fun newInstance() = YelloStartFragment()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.el.yello.R
import com.example.ui.intent.dpToPx
import com.example.ui.number.dpToPx

class SearchItemDecoration(context: Context) : RecyclerView.ItemDecoration() {
private val dividerHeight = dpToPx(context, 1)
private val dividerMargin = dpToPx(context, 8)
private val dividerHeight = 1.dpToPx(context)
private val dividerMargin = 8.dpToPx(context)
private val dividerColor = ContextCompat.getColor(context, R.color.grayscales_800)
private val dividerPaint = Paint()

Expand Down Expand Up @@ -51,4 +51,4 @@ class SearchItemDecoration(context: Context) : RecyclerView.ItemDecoration() {
)
}
}
}
}
15 changes: 8 additions & 7 deletions app/src/main/res/layout/fragment_yello_start.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,14 @@

<TextView
android:id="@+id/btn_start_vote"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="73dp"
android:layout_marginHorizontal="22dp"
android:layout_marginBottom="50dp"
android:gravity="center"
android:background="@drawable/shape_yello500_fill_500_rect"
android:fontFamily="@font/unbounded_bold"
android:paddingHorizontal="50dp"
android:paddingVertical="18dp"
android:fontFamily="@font/pretendard_bold"
android:paddingVertical="22dp"
android:text="@string/yello_start_vote"
android:textColor="@color/black"
android:textSize="22sp"
Expand All @@ -240,7 +241,7 @@
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn_start_vote">
app:layout_constraintTop_toTopOf="@id/shadow_start">

<TextView
android:id="@+id/tv_start_plus_point"
Expand Down Expand Up @@ -277,4 +278,4 @@

</androidx.constraintlayout.widget.ConstraintLayout>

</layout>
</layout>
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<string name="yello_start_my_point">내 포인트</string>
<string name="yello_start_description">누구에게 어떤 메시지를 보낼까?</string>
<string name="yello_start_point_label">Point</string>
<string name="yello_start_vote">START!</string>
<string name="yello_start_vote">쪽지 보내기</string>
<string name="yello_start_balloon_top">오늘은</string>
<string name="yello_start_balloon_mid1">누구에게 어떤 쪽지</string>
<string name="yello_start_balloon_mid2">를</string>
Expand Down Expand Up @@ -328,4 +328,4 @@
<string name="note_friend_null">친구를 추가해주세요!</string>
<string name="note_msg_invalid_name">4명 이상의 친구를 가지면 선택지가 채워져요.</string>

</resources>
</resources>
9 changes: 9 additions & 0 deletions core-ui/src/main/java/com/example/ui/context/ContextExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.ui.context
import android.app.Activity
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
import androidx.annotation.ColorRes
Expand Down Expand Up @@ -33,3 +34,11 @@ fun Context.hideKeyboard(view: View) {
val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}

fun setMargins(view: View, left: Int, top: Int, right: Int, bottom: Int) {
if (view.layoutParams is ViewGroup.MarginLayoutParams) {
val p = view.layoutParams as ViewGroup.MarginLayoutParams
p.setMargins(left, top, right, bottom)
view.requestLayout()
}
}
13 changes: 13 additions & 0 deletions core-ui/src/main/java/com/example/ui/fragment/FragmentExt.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.ui.fragment

import android.graphics.Point
import android.os.Build
import android.view.View
import android.widget.Toast
import androidx.annotation.ColorRes
Expand Down Expand Up @@ -34,3 +36,14 @@ val Fragment.viewLifeCycle

val Fragment.viewLifeCycleScope
get() = viewLifecycleOwner.lifecycleScope

fun Fragment.getCompatibleRealSize(screenRealSize: Point) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowMetrics = requireActivity().windowManager.currentWindowMetrics
screenRealSize.x = windowMetrics.bounds.width()
screenRealSize.y = windowMetrics.bounds.height()
return
}

requireActivity().windowManager.defaultDisplay.getRealSize(screenRealSize)
}
10 changes: 0 additions & 10 deletions core-ui/src/main/java/com/example/ui/intent/ExtraExt.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.example.ui.intent

import android.app.Activity
import android.content.Context
import android.os.Parcelable
import android.util.TypedValue
import kotlin.properties.ReadOnlyProperty

fun intExtra(defaultValue: Int = -1) = ReadOnlyProperty<Activity, Int> { thisRef, property ->
Expand Down Expand Up @@ -41,11 +39,3 @@ fun <P : Parcelable> parcelableExtra(defaultValue: P? = null) =
ReadOnlyProperty<Activity, P?> { thisRef, property ->
thisRef.intent.extras?.getParcelable<P>(property.name) ?: defaultValue
}

fun dpToPx(context: Context, dp: Int): Int {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
dp.toFloat(),
context.resources.displayMetrics,
).toInt()
}
12 changes: 12 additions & 0 deletions core-ui/src/main/java/com/example/ui/number/IntExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.ui.number

import android.content.Context
import android.util.TypedValue

fun Int.dpToPx(context: Context): Int {
return TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
toFloat(),
context.resources.displayMetrics,
).toInt()
}

0 comments on commit 786c166

Please sign in to comment.