Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State 와 Event 분리 #147

Merged
merged 12 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies {
projects.core.domain,
projects.core.network,
projects.core.ui,
projects.core.util,
projects.feature.complete,
projects.feature.home,
projects.feature.onboarding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package com.nexters.bandalart.android.core.data.di

import com.nexters.bandalart.android.core.data.service.BandalartService
import com.nexters.bandalart.android.core.data.service.GuestLoginService
import com.nexters.bandalart.android.core.network.di.BandalartApi
import com.nexters.bandalart.android.core.network.di.LoginApi
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton
import retrofit2.Retrofit
import javax.inject.Named
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
Expand All @@ -17,17 +18,15 @@ internal object ServiceModule {
@Singleton
@Provides
internal fun provideBandalartService(
@Named("HttpClient")
retrofit: Retrofit,
@BandalartApi retrofit: Retrofit,
): BandalartService {
return retrofit.create(BandalartService::class.java)
}

@Singleton
@Provides
internal fun provideGuestLoginService(
@Named("AuthHttpClient")
retrofit: Retrofit,
@LoginApi retrofit: Retrofit,
): GuestLoginService {
return retrofit.create(GuestLoginService::class.java)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import io.ktor.client.request.header
import io.ktor.http.ContentType
import io.ktor.http.contentType
import io.ktor.serialization.kotlinx.json.json
import java.util.concurrent.TimeUnit
import javax.inject.Singleton
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.Json
import okhttp3.Interceptor
Expand All @@ -29,7 +27,8 @@ import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import timber.log.Timber
import javax.inject.Named
import java.util.concurrent.TimeUnit
import javax.inject.Singleton

private const val MaxTimeoutMillis = 3000L
private const val MaxRetryCount = 3
Expand Down Expand Up @@ -91,10 +90,10 @@ internal object NetworkModule {
}
}

@LoginApi
@Singleton
@Provides
@Named("AuthHttpClient")
internal fun provideRetrofitAuthHttpClient(
internal fun provideLoginApiRetrofit(
httpLoggingInterceptor: HttpLoggingInterceptor,
): Retrofit {
val contentType = "application/json".toMediaType()
Expand All @@ -110,10 +109,10 @@ internal object NetworkModule {
.build()
}

@BandalartApi
@Singleton
@Provides
@Named("HttpClient")
internal fun provideRetrofitHttpClient(
internal fun provideBandalartApiRetrofit(
dataStoreProvider: DataStoreProvider,
httpLoggingInterceptor: HttpLoggingInterceptor,
): Retrofit {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.nexters.bandalart.android.core.network.di

import javax.inject.Qualifier

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

소규모 프로젝트에서는 쓸일이 없는가 싶다가도 이럴 때 한번씩 나온단 말이지 ㄷㄷ

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nAmed Annotation -> @qualifier Annotation 으로 변경

저거 왜 commit name이 @nAmed 로 안되어있고 @nAmed 로 되어있지.. 무튼 하드 코딩으로 provider 를 분류하는게 안정성 면에서 별로인것 같다는 생각이 들어

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 @ 뒤에 바로 대문자를 쓰면 저렇게 변하나보네 @ Named로 써도 그러네

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class BandalartApi

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class LoginApi
1 change: 1 addition & 0 deletions core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ android {
dependencies {
implementations(
projects.core.designsystem,
projects.core.util,
libs.kotlinx.datetime,
libs.androidx.core,
libs.lottie.compose,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.nexters.bandalart.android.core.ui.extension
package com.nexters.bandalart.android.core.ui

internal interface MultipleEventsCutter {
fun processEvent(event: () -> Unit)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.nexters.bandalart.android.core.ui

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext

// https://www.youtube.com/watch?v=njchj9d_Lf8&t=1218s
@Composable
fun <T> ObserveAsEvents(flow: Flow<T>, onEvent: (T) -> Unit) {
val lifecycleOwner = LocalLifecycleOwner.current
LaunchedEffect(flow, lifecycleOwner.lifecycle) {
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
withContext(Dispatchers.Main.immediate) {
flow.collect(onEvent)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.nexters.bandalart.android.core.ui.extension
package com.nexters.bandalart.android.core.ui

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalDensity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.nexters.bandalart.android.core.ui.extension
package com.nexters.bandalart.android.core.ui

data class ThemeColor(
val mainColor: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.nexters.bandalart.android.core.ui

import android.content.Context
import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource

sealed class UiText {
data class DirectString(val value: String) : UiText()

class StringResource(
@StringRes val resId: Int,
vararg val args: Any,
) : UiText()

@Composable
fun asString() = when (this) {
is DirectString -> value
is StringResource -> stringResource(resId, *args)
}

fun asString(context: Context) = when (this) {
is DirectString -> value
is StringResource -> context.getString(resId, *args)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.nexters.bandalart.android.core.ui.extension
package com.nexters.bandalart.android.core.ui

import android.app.Activity
import android.graphics.Rect
Expand All @@ -7,6 +7,8 @@ import androidx.compose.foundation.layout.systemBars
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

// https://sungbin.land/jetpack-compose-windowinsets-fa8f286f092b
val NavigationBarHeightDp
Expand All @@ -33,3 +35,9 @@ val StatusBarHeightDp
rectangle.top.toDp()
}
}

// https://stackoverflow.com/questions/75123079/how-do-i-detect-which-type-of-navigation-bar-is-active
@Composable
fun getNavigationBarPadding(): Dp {
return if (NavigationBarHeightDp == 0.dp) 32.dp else NavigationBarHeightDp - 16.dp
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.nexters.bandalart.android.core.ui.extension.clickableSingle
import com.nexters.bandalart.android.core.ui.extension.nonScaleSp
import com.nexters.bandalart.android.core.ui.nonScaleSp
import com.nexters.bandalart.android.core.designsystem.theme.Gray900
import com.nexters.bandalart.android.core.designsystem.theme.White
import com.nexters.bandalart.android.core.designsystem.theme.pretendard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import com.nexters.bandalart.android.core.ui.R
import com.nexters.bandalart.android.core.ui.extension.nonScaleSp
import com.nexters.bandalart.android.core.ui.nonScaleSp
import com.nexters.bandalart.android.core.designsystem.theme.Gray200
import com.nexters.bandalart.android.core.designsystem.theme.Gray400
import com.nexters.bandalart.android.core.designsystem.theme.Gray900
import com.nexters.bandalart.android.core.designsystem.theme.White

@Composable
fun BandalartDeleteAlertDialog(
modifier: Modifier = Modifier,
title: String,
message: String,
onDeleteClicked: () -> Unit,
onCancelClicked: () -> Unit,
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
Dialog(onDismissRequest = { onCancelClicked() }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.nexters.bandalart.android.core.ui.R
import com.nexters.bandalart.android.core.ui.extension.nonScaleSp
import com.nexters.bandalart.android.core.ui.nonScaleSp
import com.nexters.bandalart.android.core.designsystem.theme.Error
import com.nexters.bandalart.android.core.designsystem.theme.White
import com.nexters.bandalart.android.core.designsystem.theme.pretendard

@Composable
fun BandalartDropDownMenu(
modifier: Modifier = Modifier,
openDropDownMenu: (Boolean) -> Unit,
isDropDownMenuOpened: Boolean,
onDeleteClicked: () -> Unit,
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
MaterialTheme(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import androidx.compose.ui.text.style.LineBreak
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.nexters.bandalart.android.core.ui.extension.nonScaleSp
import com.nexters.bandalart.android.core.ui.nonScaleSp
import com.nexters.bandalart.android.core.designsystem.theme.pretendard

val cellLineBreak = LineBreak(
Expand All @@ -23,10 +23,10 @@ val cellLineBreak = LineBreak(

@Composable
fun CellText(
modifier: Modifier = Modifier,
cellText: String,
cellTextColor: Color,
fontWeight: FontWeight,
modifier: Modifier = Modifier,
textAlpha: Float = 1f,
) {
Text(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.nexters.bandalart.android.feature.home.ui
package com.nexters.bandalart.android.core.ui.component

import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.LinearOutSlowInEasing
Expand Down Expand Up @@ -29,6 +29,7 @@ import com.nexters.bandalart.android.core.designsystem.theme.Gray100
fun CompletionRatioProgressBar(
completionRatio: Int,
progressColor: Color,
modifier: Modifier = Modifier,
) {
var progress by remember { mutableFloatStateOf(0f) }

Expand All @@ -46,7 +47,7 @@ fun CompletionRatioProgressBar(
}

Column(
modifier = Modifier
modifier = modifier
.fillMaxWidth()
.wrapContentSize(),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package com.nexters.bandalart.android.core.ui.component

import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.TextUnit
import com.nexters.bandalart.android.core.ui.extension.nonScaleSp
import com.nexters.bandalart.android.core.ui.nonScaleSp

@Composable
fun EmojiText(
emojiText: String?,
fontSize: TextUnit,
modifier: Modifier = Modifier,
) {
Text(
text = emojiText ?: "",
modifier = modifier,
fontSize = fontSize.nonScaleSp,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.TextUnit
import com.nexters.bandalart.android.core.ui.extension.nonScaleSp
import com.nexters.bandalart.android.core.ui.nonScaleSp
import com.nexters.bandalart.android.core.designsystem.theme.pretendard

@Composable
fun FixedSizeText(
text: String,
modifier: Modifier = Modifier,
color: Color,
fontSize: TextUnit,
fontWeight: FontWeight,
modifier: Modifier = Modifier,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거들이 이동하게 된 이유는 무엇인가용

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/androidx/androidx/blob/androidx-main/compose/docs/compose-component-api-guidelines.md#modifier-parameter

내가 예전에 작업할때 해당 문서를 참고해서 modifier 를 최상단 파라미터로 올렸었는데, 문서를 내가 잘 못 이해 했던거 였음
modifier 는 first 'optional' paramter 여야 한다는 것인데, 이게 optional 의 의미가 만약에 함수를 사용할 때 해당 파라미터를 명시하지 않을 경우 default value로 선언된 값이 적용되는 파라미터들을 의미 하는데

일반적으로 Kotlin 함수의 매개변수는 default value가 없는 것들이 먼저 오고, 그 뒤에 default value가 있는 매개변수가 와야 합니다(Trailing lambda는 예외). Composable도 마찬가지로 default value가 없는 것, Modifier, default value가 있는 것 순서대로 와야 합니다.

와 같이 default value가 없는, 반드시 함수를 사용할 때 해당 파라미터를 명시해줘야하는 것들 다음에 modifier를 선언해주는 것을 권장하드라구

fontFamily: FontFamily = pretendard,
letterSpacing: TextUnit = TextUnit.Unspecified,
textAlign: TextAlign? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import com.nexters.bandalart.android.core.designsystem.theme.Black
import com.nexters.bandalart.android.core.designsystem.theme.White

@Composable
fun LoadingScreen(modifier: Modifier = Modifier) {
fun LoadingScreen(
modifier: Modifier = Modifier,
) {
Box(
modifier = modifier.noRippleClickable { },
contentAlignment = Alignment.Center,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import com.nexters.bandalart.android.core.ui.R
import com.nexters.bandalart.android.core.ui.extension.nonScaleSp
import com.nexters.bandalart.android.core.ui.nonScaleSp
import com.nexters.bandalart.android.core.designsystem.theme.Gray400
import com.nexters.bandalart.android.core.designsystem.theme.Gray900
import com.nexters.bandalart.android.core.designsystem.theme.White

@Composable
fun NetworkErrorAlertDialog(
modifier: Modifier = Modifier,
title: String,
message: String,
onConfirmClick: () -> Unit,
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
Dialog(onDismissRequest = {}) {
Expand All @@ -54,8 +54,8 @@ fun NetworkErrorAlertDialog(
)
Spacer(modifier = Modifier.height(8.dp))
FixedSizeText(
modifier = Modifier.align(Alignment.CenterHorizontally),
text = title,
modifier = Modifier.align(Alignment.CenterHorizontally),
color = Gray900,
fontSize = 20.sp,
fontWeight = FontWeight.W700,
Expand All @@ -65,8 +65,8 @@ fun NetworkErrorAlertDialog(
)
Spacer(modifier = Modifier.height(8.dp))
FixedSizeText(
modifier = Modifier.align(Alignment.CenterHorizontally),
text = message,
modifier = Modifier.align(Alignment.CenterHorizontally),
color = Gray400,
fontSize = 14.sp,
fontWeight = FontWeight.W500,
Expand Down
Loading