diff --git a/feature/build.gradle.kts b/feature/build.gradle.kts index 1683c6a..a8c2728 100644 --- a/feature/build.gradle.kts +++ b/feature/build.gradle.kts @@ -35,7 +35,7 @@ android { } dependencies { - + implementation(project(":domain")) implementation(AndroidX.CORE) implementation(AndroidX.LIFECYCLE_RUNTIME_KTX) implementation(AndroidX.ACTIVITY_COMPOSE) diff --git a/feature/src/main/java/com/matzip/feature/base/BaseViewModel.kt b/feature/src/main/java/com/matzip/feature/base/BaseViewModel.kt new file mode 100644 index 0000000..822af4d --- /dev/null +++ b/feature/src/main/java/com/matzip/feature/base/BaseViewModel.kt @@ -0,0 +1,62 @@ +package com.matzip.feature.base + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.matzip.domain.base.ApiState +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.flow.update +import kotlinx.coroutines.launch + +abstract class BaseViewModel( + initialPageState : STATE, +) : ViewModel() { + + private val _uiState = MutableStateFlow(initialPageState) + val uiState = _uiState.asStateFlow() + + private val _eventFlow = EventFlow() + val eventFlow = _eventFlow.events + + private val _commonError = MutableLiveData() + val commonError: LiveData = _commonError + + protected fun updateState(state: STATE) { + viewModelScope.launch { + _uiState.update { state } + } + } + protected fun emitEventFlow(event: EVENT) { + viewModelScope.launch { + _eventFlow.emit(event) + } + } + + protected fun resultResponse( + response: ApiState, + successCallback : (D) -> Unit, + errorCallback : ((String) -> Unit)? = null, + needLoading : Boolean = true) + { + when(response){ + is ApiState.Error -> { + //TODO 에러 코드를 다룰 예정입니다. +// if(response.errorCode == StatusCode.ERROR_404 || +// response.errorCode == StatusCode.ERROR || +// response.errorCode == StatusCode.NETWORK_ERROR) { +// showCommonError(response.errorCode) +// } +// else errorCallback?.invoke(response.errorCode) +// endLoading() + } + // TODO Loading 상태일때 화면을 처리할 예정입니다. + ApiState.Loading -> if(needLoading) {} + is ApiState.Success -> { + successCallback.invoke(response.data) + //endLoading() + } + } + } +} \ No newline at end of file diff --git a/feature/src/main/java/com/matzip/feature/base/Event.kt b/feature/src/main/java/com/matzip/feature/base/Event.kt new file mode 100644 index 0000000..f193c9d --- /dev/null +++ b/feature/src/main/java/com/matzip/feature/base/Event.kt @@ -0,0 +1,53 @@ +package com.matzip.feature.base + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.SharedFlow +import kotlinx.coroutines.flow.asSharedFlow + +// 이벤트 단일 소비를 위한 래퍼 클래스 +class Event(private val content: T) { + + private var hasBeenHandled = false + + fun getContentIfNotHandled(): T? { + return if (hasBeenHandled) { + null + } else { + hasBeenHandled = true + content + } + } + + fun peekContent(): T = content +} + +// 이벤트 처리를 위한 Flow 클래스 +class EventFlow { + private val _events = MutableSharedFlow>( + // 이벤트를 단일 소비로 처리하기 위해 + replay = 1, + // 버퍼 크기를 1로 설정하여 최신 이벤트만 유지 + extraBufferCapacity = 1 + ) + + val events: SharedFlow> = _events.asSharedFlow() + + suspend fun emit(value: T) { + _events.emit(Event(value)) + } + + fun tryEmit(value: T) { + _events.tryEmit(Event(value)) + } +} + +suspend inline fun Flow>.collectEvent( + crossinline onEvent: (T) -> Unit +) { + collect { event -> + event.getContentIfNotHandled()?.let { value -> + onEvent(value) + } + } +} \ No newline at end of file diff --git a/feature/src/main/java/com/matzip/feature/base/PageState.kt b/feature/src/main/java/com/matzip/feature/base/PageState.kt new file mode 100644 index 0000000..8db898b --- /dev/null +++ b/feature/src/main/java/com/matzip/feature/base/PageState.kt @@ -0,0 +1,5 @@ +package com.matzip.feature.base + +interface PageState{ + object Default: PageState +} \ No newline at end of file diff --git a/feature/src/main/java/com/matzip/feature/base/base.kt b/feature/src/main/java/com/matzip/feature/base/base.kt deleted file mode 100644 index 1e48d40..0000000 --- a/feature/src/main/java/com/matzip/feature/base/base.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.matzip.feature.base - -class base { - //TODO 앞으로 사용될 Base나 공통 class 를 여기에 정의 -} \ No newline at end of file diff --git a/feature/src/main/java/com/matzip/feature/designSystem/Color.kt b/feature/src/main/java/com/matzip/feature/designSystem/Color.kt new file mode 100644 index 0000000..523a2f1 --- /dev/null +++ b/feature/src/main/java/com/matzip/feature/designSystem/Color.kt @@ -0,0 +1,16 @@ +package com.matzip.feature.designSystem + +import androidx.compose.ui.graphics.Color + +val Background = Color(0xFFFAFAFA) +val Box = Color(0xFFF0F0F0) +val Main = Color(0xFFFF8400) +val MainLight1 = Color(0xFFFFB273) +val MainLight2 = Color(0xFFFFDABB) +val Black = Color(0xFF111111) +val BlackBox = Color(0xFF282828) +val DarkGray = Color(0xFF3C3C3C) +val TextSub1 = Color(0xFF787878) +val TextSub2 = Color(0xFFA8A8A8) +val LightGray = Color(0xFFD9D9D9) +val Sub1 = Color(0xFFFFD000) \ No newline at end of file diff --git a/feature/src/main/java/com/matzip/feature/designSystem/Typo.kt b/feature/src/main/java/com/matzip/feature/designSystem/Typo.kt new file mode 100644 index 0000000..b73c33f --- /dev/null +++ b/feature/src/main/java/com/matzip/feature/designSystem/Typo.kt @@ -0,0 +1,110 @@ +package com.matzip.feature.designSystem + +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.Font +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp +import com.matzip.feature.R + +val matZipFontFamily = FontFamily( + Font(R.font.pretendard_bold, FontWeight.Bold), + Font(R.font.pretendard_light, FontWeight.Light), + Font(R.font.pretendard_medium, FontWeight.Medium), + Font(R.font.pretendard_semi_bold, FontWeight.SemiBold), + Font(R.font.pretendard_regular, FontWeight.Normal), +) + +object MatZipTypography { + val h1: TextStyle = TextStyle( + fontFamily = matZipFontFamily, + fontWeight = FontWeight.Bold, + lineHeight = 43.2.sp, + fontSize = 32.sp + ) + + val h2: TextStyle = TextStyle( + fontFamily = matZipFontFamily, + fontWeight = FontWeight.Bold, + lineHeight = 37.8.sp, + fontSize = 28.sp + ) + + val title1: TextStyle = TextStyle( + fontFamily = matZipFontFamily, + fontWeight = FontWeight.Bold, + lineHeight = 32.4.sp, + fontSize = 24.sp + ) + + val title2: TextStyle = TextStyle( + fontFamily = matZipFontFamily, + fontWeight = FontWeight.Bold, + lineHeight = 27.sp, + fontSize = 20.sp + ) + + val title3: TextStyle = TextStyle( + fontFamily = matZipFontFamily, + fontWeight = FontWeight.Bold, + lineHeight = 21.6.sp, + fontSize = 16.sp + ) + + val title4: TextStyle = TextStyle( + fontFamily = matZipFontFamily, + fontWeight = FontWeight.Bold, + lineHeight = 18.2.sp, + fontSize = 14.sp + ) + + val title5: TextStyle = TextStyle( + fontFamily = matZipFontFamily, + fontWeight = FontWeight.SemiBold, + lineHeight = 18.2.sp, + fontSize = 14.sp + ) + + val title6: TextStyle = TextStyle( + fontFamily = matZipFontFamily, + fontWeight = FontWeight.Bold, + lineHeight = 15.6.sp, + fontSize = 12.sp + ) + + val title7: TextStyle = TextStyle( + fontFamily = matZipFontFamily, + fontWeight = FontWeight.SemiBold, + lineHeight = 15.6.sp, + fontSize = 12.sp + ) + + val body1: TextStyle = TextStyle( + fontFamily = matZipFontFamily, + fontWeight = FontWeight.Normal, + lineHeight = 21.6.sp, + fontSize = 16.sp + ) + + val body2: TextStyle = TextStyle( + fontFamily = matZipFontFamily, + fontWeight = FontWeight.Normal, + lineHeight = 18.9.sp, + fontSize = 14.sp + ) + + val ex1: TextStyle = TextStyle( + fontFamily = matZipFontFamily, + fontWeight = FontWeight.Normal, + lineHeight = 15.6.sp, + fontSize = 12.sp + ) + + val ex2: TextStyle = TextStyle( + fontFamily = matZipFontFamily, + fontWeight = FontWeight.Normal, + lineHeight = 13.sp, + fontSize = 10.sp + ) + +} diff --git a/feature/src/main/java/com/matzip/feature/designSystem/designSystem.kt b/feature/src/main/java/com/matzip/feature/designSystem/designSystem.kt deleted file mode 100644 index 88eb591..0000000 --- a/feature/src/main/java/com/matzip/feature/designSystem/designSystem.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.matzip.feature.designSystem - -class designSystem { - //TODO color, 문자열, style 등 디자인 요소들의 집합 -} \ No newline at end of file diff --git a/feature/src/main/res/font/pretendard_bold.ttf b/feature/src/main/res/font/pretendard_bold.ttf new file mode 100644 index 0000000..fb07fc6 Binary files /dev/null and b/feature/src/main/res/font/pretendard_bold.ttf differ diff --git a/feature/src/main/res/font/pretendard_light.ttf b/feature/src/main/res/font/pretendard_light.ttf new file mode 100644 index 0000000..2e8541d Binary files /dev/null and b/feature/src/main/res/font/pretendard_light.ttf differ diff --git a/feature/src/main/res/font/pretendard_medium.ttf b/feature/src/main/res/font/pretendard_medium.ttf new file mode 100644 index 0000000..1db67c6 Binary files /dev/null and b/feature/src/main/res/font/pretendard_medium.ttf differ diff --git a/feature/src/main/res/font/pretendard_regular.ttf b/feature/src/main/res/font/pretendard_regular.ttf new file mode 100644 index 0000000..01147e9 Binary files /dev/null and b/feature/src/main/res/font/pretendard_regular.ttf differ diff --git a/feature/src/main/res/font/pretendard_semi_bold.ttf b/feature/src/main/res/font/pretendard_semi_bold.ttf new file mode 100644 index 0000000..9f2690f Binary files /dev/null and b/feature/src/main/res/font/pretendard_semi_bold.ttf differ