Skip to content

Commit 965c421

Browse files
authored
오류 수정 (#169)
* 상태바 가림 오류 수정 * alias 문제 수정 * 상단바 통합 * 인코딩 오류 수정 * 축제 로직 복구 * 키워드 empty list 오류 해결 * 나의 평가 관리 애니메이션 추가
1 parent 72052ea commit 965c421

12 files changed

Lines changed: 122 additions & 24 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,4 @@
153153
</provider>
154154
</application>
155155

156-
</manifest>
156+
</manifest>

app/src/main/java/com/wafflestudio/siksha2/components/compose/TopBar.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ package com.wafflestudio.siksha2.components.compose
22

33
import androidx.compose.foundation.background
44
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.WindowInsets
6+
import androidx.compose.foundation.layout.displayCutout
57
import androidx.compose.foundation.layout.fillMaxWidth
68
import androidx.compose.foundation.layout.height
79
import androidx.compose.foundation.layout.padding
10+
import androidx.compose.foundation.layout.statusBars
11+
import androidx.compose.foundation.layout.union
12+
import androidx.compose.foundation.layout.windowInsetsPadding
813
import androidx.compose.material.Text
914
import androidx.compose.runtime.Composable
1015
import androidx.compose.ui.Alignment
@@ -21,13 +26,22 @@ import com.wafflestudio.siksha2.ui.SikshaTypography
2126
fun TopBar(
2227
title: String,
2328
modifier: Modifier = Modifier,
29+
applySystemTopInset: Boolean = true,
2430
navigationButton: @Composable () -> Unit = {}
2531
) {
32+
val insetsModifier = if (applySystemTopInset) {
33+
Modifier
34+
.windowInsetsPadding(WindowInsets.statusBars.union(WindowInsets.displayCutout))
35+
} else {
36+
Modifier
37+
}
38+
2639
Box(
2740
modifier = modifier
28-
.height(56.dp)
2941
.fillMaxWidth()
3042
.background(SikshaTheme.colors.BackgroundGNB)
43+
.then(insetsModifier)
44+
.height(56.dp)
3145
) {
3246
Text(
3347
text = title,

app/src/main/java/com/wafflestudio/siksha2/compose/ui/menudetail/MenuKeywordStats.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import androidx.compose.ui.unit.sp
2323
import com.wafflestudio.siksha2.ui.CancelIcon
2424
import com.wafflestudio.siksha2.ui.SikshaTheme
2525

26+
private val DefaultKeywords = listOf("", "가격", "음식구성")
27+
2628
@Composable
2729
fun MenuKeywordStat(
2830
keywordString: String,
@@ -35,11 +37,11 @@ fun MenuKeywordStat(
3537
modifier = modifier.fillMaxWidth()
3638
.background(color = SikshaTheme.colors.Gray100, shape = RoundedCornerShape(8.dp))
3739
) {
38-
if (keywordCount > 0) {
40+
if (keywordCount > 0 && keywordTotal > 0) {
3941
Box(modifier = Modifier.matchParentSize()) {
4042
Box(
4143
modifier = Modifier.fillMaxHeight()
42-
.fillMaxWidth(keywordCount.toFloat() / keywordTotal.toFloat())
44+
.fillMaxWidth((keywordCount.toFloat() / keywordTotal.toFloat()).coerceIn(0f, 1f))
4345
.align(Alignment.CenterStart)
4446
.background(color = SikshaTheme.colors.OrangeTint, shape = RoundedCornerShape(8.dp))
4547
)
@@ -56,7 +58,7 @@ fun MenuKeywordStat(
5658
text = keywordString,
5759
fontSize = 13.sp,
5860
fontWeight = FontWeight.Bold,
59-
color = if (keywordString in listOf("", "가격", "음식구성")) SikshaTheme.colors.Gray600 else SikshaTheme.colors.Gray800,
61+
color = if (keywordString in DefaultKeywords) SikshaTheme.colors.Gray600 else SikshaTheme.colors.Gray800,
6062
modifier = Modifier.weight(1f)
6163
)
6264
Text(
@@ -81,15 +83,16 @@ fun MenuKeywordStats(
8183
modifier = modifier,
8284
verticalArrangement = Arrangement.spacedBy(6.dp)
8385
) {
84-
// TODO: 빈 스트링일 때 처리
85-
for (i in keywords.ifEmpty { listOf("", "가격", "음식구성") }.indices) {
86-
var keyword = keywords[i]
87-
if (keyword == "") keyword = listOf("", "가격", "음식구성")[i]
86+
DefaultKeywords.forEachIndexed { i, defaultKeyword ->
87+
val keyword = keywords.getOrNull(i)
88+
?.takeIf { it.isNotBlank() }
89+
?: defaultKeyword
90+
8891
MenuKeywordStat(
8992
keywordString = keyword,
90-
keywordCount = keywordCounts.ifEmpty { listOf<Long>(0, 0, 0) }[i],
91-
keywordTotal = keywordTotals.ifEmpty { listOf<Long>(0, 0, 0) }[i],
92-
keywordIcon = keywordIcons[i]
93+
keywordCount = keywordCounts.getOrElse(i) { 0L },
94+
keywordTotal = keywordTotals.getOrElse(i) { 0L },
95+
keywordIcon = keywordIcons.getOrElse(i) { { CancelIcon() } }
9396
)
9497
}
9598
}

app/src/main/java/com/wafflestudio/siksha2/ui/RootActivity.kt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.wafflestudio.siksha2.ui
33
import android.os.Bundle
44
import android.widget.Toast
55
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.core.view.WindowCompat
67
import androidx.core.view.ViewCompat
78
import androidx.core.view.WindowInsetsCompat
89
import androidx.core.view.updatePadding
@@ -11,6 +12,8 @@ import androidx.lifecycle.lifecycleScope
1112
import com.wafflestudio.siksha2.R
1213
import com.wafflestudio.siksha2.repositories.MenuRepository
1314
import com.wafflestudio.siksha2.repositories.RestaurantRepository
15+
import com.wafflestudio.siksha2.utils.applyTopMarginForStatusBarSpacing
16+
import com.wafflestudio.siksha2.utils.applyStatusBarSpacing
1417
import com.wafflestudio.siksha2.utils.showToast
1518
import dagger.hilt.android.AndroidEntryPoint
1619
import kotlinx.coroutines.launch
@@ -27,6 +30,7 @@ class RootActivity : AppCompatActivity() {
2730

2831
override fun onCreate(savedInstanceState: Bundle?) {
2932
super.onCreate(savedInstanceState)
33+
WindowCompat.setDecorFitsSystemWindows(window, false)
3034
setContentView(R.layout.activity_root)
3135

3236
val navHost = findViewById<FragmentContainerView>(R.id.nav_host)
@@ -37,12 +41,27 @@ class RootActivity : AppCompatActivity() {
3741
)
3842
v.updatePadding(
3943
left = insets.left,
40-
top = insets.top,
4144
bottom = insets.bottom,
4245
right = insets.right
4346
)
44-
WindowInsetsCompat.CONSUMED
47+
windowInsets
4548
}
49+
ViewCompat.requestApplyInsets(navHost)
50+
supportFragmentManager.registerFragmentLifecycleCallbacks(
51+
object : androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks() {
52+
override fun onFragmentViewCreated(
53+
fm: androidx.fragment.app.FragmentManager,
54+
f: androidx.fragment.app.Fragment,
55+
v: android.view.View,
56+
savedInstanceState: Bundle?
57+
) {
58+
v.findViewById<android.view.View?>(R.id.top_bar)?.applyStatusBarSpacing(extraTopDp = 0)
59+
v.findViewById<android.view.View?>(R.id.tool_bar)?.applyStatusBarSpacing(extraTopDp = 0)
60+
v.findViewById<android.view.View?>(R.id.main_logo)?.applyTopMarginForStatusBarSpacing(extraTopDp = 0)
61+
}
62+
},
63+
true
64+
)
4665

4766
lifecycleScope.launch {
4867
menuRepository.sweepOldMenus()

app/src/main/java/com/wafflestudio/siksha2/ui/SplashActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class SplashActivity : AppCompatActivity() {
6565

6666
lifecycleScope.launch(Dispatchers.Main) {
6767
if (checkInternetConnection().not()) {
68-
showToast("네트워크 연결이 불안정합니다.")
68+
showToast(getString(R.string.common_network_error))
6969
delay(1000L)
7070
startActivity(Intent(this@SplashActivity, RootActivity::class.java))
7171
finish()
@@ -131,7 +131,7 @@ class SplashActivity : AppCompatActivity() {
131131
kakaoSignInLauncher = {
132132
val callback: (OAuthToken?, Throwable?) -> Unit = { token, error ->
133133
if (error != null) {
134-
showToast("카카오 로그인 실패")
134+
showToast(getString(R.string.splash_kakao_login_failed))
135135
Timber.e(error)
136136
} else if (token != null) {
137137
onOAuthSuccess(OAuthProvider.KAKAO, token.accessToken)
@@ -169,7 +169,7 @@ class SplashActivity : AppCompatActivity() {
169169
onOAuthSuccess(OAuthProvider.GOOGLE, token)
170170
}
171171
} catch (e: ApiException) {
172-
showToast("구글 로그인 실패")
172+
showToast(getString(R.string.splash_google_login_failed))
173173
Timber.e(e)
174174
}
175175
}

app/src/main/java/com/wafflestudio/siksha2/utils/ViewExt.kt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ package com.wafflestudio.siksha2.utils
33
import android.content.Context
44
import android.view.LayoutInflater
55
import android.view.View
6+
import android.view.ViewGroup.MarginLayoutParams
7+
import android.view.ViewGroup
68
import android.widget.ImageView
79
import android.widget.Toast
10+
import androidx.core.view.ViewCompat
11+
import androidx.core.view.WindowInsetsCompat
12+
import androidx.core.view.updatePadding
13+
import androidx.core.view.updateLayoutParams
814
import androidx.fragment.app.Fragment
915
import com.bumptech.glide.Glide
1016
import com.wafflestudio.siksha2.ui.common.ImageViewerActivity
17+
import kotlin.math.roundToInt
1118

1219
fun View.setVisibleOrGone(visible: Boolean) {
1320
visibility = if (visible) View.VISIBLE else View.GONE
@@ -38,3 +45,49 @@ fun ImageView.setImageUrl(url: String) {
3845
fun Context.showImageViewer(images: List<String>, initialPage: Int) {
3946
startActivity(ImageViewerActivity.createIntent(this, images, initialPage))
4047
}
48+
49+
fun View.applyStatusBarSpacing(extraTopDp: Int = 0) {
50+
val initialHeight = layoutParams.height
51+
val initialPaddingTop = paddingTop
52+
val extraTopPx = extraTopDp
53+
.times(resources.displayMetrics.density)
54+
.roundToInt()
55+
56+
ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets ->
57+
val topInset = windowInsets.getInsets(
58+
WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.displayCutout()
59+
).top
60+
61+
if (initialHeight > 0) {
62+
view.updateLayoutParams<ViewGroup.LayoutParams> {
63+
height = initialHeight + topInset + extraTopPx
64+
}
65+
}
66+
view.updatePadding(top = initialPaddingTop + topInset + extraTopPx)
67+
68+
windowInsets
69+
}
70+
71+
ViewCompat.requestApplyInsets(this)
72+
}
73+
74+
fun View.applyTopMarginForStatusBarSpacing(extraTopDp: Int = 0) {
75+
val initialTopMargin = (layoutParams as? MarginLayoutParams)?.topMargin ?: 0
76+
val extraTopPx = extraTopDp
77+
.times(resources.displayMetrics.density)
78+
.roundToInt()
79+
80+
ViewCompat.setOnApplyWindowInsetsListener(this) { view, windowInsets ->
81+
val topInset = windowInsets.getInsets(
82+
WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.displayCutout()
83+
).top
84+
85+
view.updateLayoutParams<MarginLayoutParams> {
86+
topMargin = initialTopMargin + topInset + extraTopPx
87+
}
88+
89+
windowInsets
90+
}
91+
92+
ViewCompat.requestApplyInsets(this)
93+
}

app/src/main/res/layout/fragment_favorite_menu.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
android:id="@+id/title"
3333
android:layout_width="wrap_content"
3434
android:layout_height="wrap_content"
35-
android:layout_marginHorizontal="10dp"
3635
android:layout_marginVertical="12dp"
36+
android:layout_marginEnd="10dp"
3737
android:layout_weight="1"
3838
android:fontFamily="@font/nanum_square_extra_bold"
3939
android:text="내가 찜한 메뉴"
@@ -45,7 +45,7 @@
4545
android:id="@+id/alarm_button"
4646
android:layout_width="wrap_content"
4747
android:layout_height="wrap_content"
48-
android:layout_marginEnd="20dp"
48+
android:layout_marginEnd="21dp"
4949
android:src="@drawable/ic_alarm" />
5050
</LinearLayout>
5151

app/src/main/res/layout/fragment_main.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
app:layout_constraintTop_toTopOf="parent" />
1818

1919
<ImageView
20+
android:id="@+id/main_logo"
2021
android:layout_width="wrap_content"
2122
android:layout_height="21dp"
2223
android:elevation="1dp"
@@ -60,4 +61,4 @@
6061

6162

6263

63-
</androidx.constraintlayout.widget.ConstraintLayout>
64+
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/fragment_my_review.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
android:layout_marginHorizontal="10dp"
3131
android:layout_marginVertical="12dp"
3232
android:layout_weight="1"
33-
android:fontFamily="@font/nanum_square_bold"
33+
android:fontFamily="@font/nanum_square_extra_bold"
3434
android:text="@string/my_review_title"
3535
android:textColor="@color/text_GNB"
3636
android:textAlignment="center"
37-
android:textSize="18dp" />
37+
android:textSize="16dp" />
3838

3939
<!-- textview 양옆 마진 맞추기용 -->
4040
<ImageView

app/src/main/res/navigation/nav_graph.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@
6565
app:popExitAnim="@anim/slide_right" />
6666
<action
6767
android:id="@+id/action_mainFragment_to_myReviewFragment"
68-
app:destination="@id/myReviewFragment" />
68+
app:destination="@id/myReviewFragment"
69+
app:enterAnim="@anim/slide_left"
70+
app:exitAnim="@anim/wait_anim"
71+
app:popEnterAnim="@anim/wait_anim"
72+
app:popExitAnim="@anim/slide_right" />
6973

7074
<action
7175
android:id="@+id/action_mainFragment_to_favoriteMenuFragment"

0 commit comments

Comments
 (0)