Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into feature/onboarding-inv…
Browse files Browse the repository at this point in the history
…itation-ui

# Conflicts:
#	feature/main/src/main/java/com/goalpanzi/mission_mate/core/main/component/MainNavHost.kt
  • Loading branch information
eshc123 committed Aug 5, 2024
2 parents 84973f4 + 4274791 commit b8431c3
Show file tree
Hide file tree
Showing 47 changed files with 981 additions and 59 deletions.
6 changes: 0 additions & 6 deletions .idea/kotlinc.xml

This file was deleted.

1 change: 1 addition & 0 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {

implementation(libs.bundles.test)
implementation(libs.bundles.coroutines)
implementation(libs.retrofit)

ksp(libs.hilt.compiler)
implementation(libs.hilt.android)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.goalpanzi.mission_mate.core.data.di

import com.goalpanzi.mission_mate.core.data.repository.LoginRepositoryImpl
import com.goalpanzi.mission_mate.core.data.repository.ProfileRepositoryImpl
import com.goalpanzi.mission_mate.core.domain.repository.LoginRepository
import com.goalpanzi.mission_mate.core.domain.repository.ProfileRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -13,4 +15,7 @@ internal abstract class DataModule {

@Binds
abstract fun bindLoginRepository(impl: LoginRepositoryImpl): LoginRepository

@Binds
abstract fun bindProfileRepository(impl: ProfileRepositoryImpl): ProfileRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.goalpanzi.mission_mate.core.data.repository

import com.goalpanzi.mission_mate.core.domain.repository.ProfileRepository
import com.goalpanzi.mission_mate.core.network.service.ProfileService
import com.luckyoct.core.model.base.NetworkResult
import com.luckyoct.core.model.request.SaveProfileRequest
import javax.inject.Inject

class ProfileRepositoryImpl @Inject constructor(
private val profileService: ProfileService
): ProfileRepository {
override suspend fun saveProfile(nickname: String, index: Int): NetworkResult<Unit> = handleResult {
val request = SaveProfileRequest.createRequest(nickname, index)
profileService.saveProfile(request)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.goalpanzi.mission_mate.core.datastore.datasource

import android.util.Log
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -45,26 +47,32 @@ fun MissionMateTextField(
onValueChange: (String) -> Unit,
modifier: Modifier = Modifier,
@StringRes hintId : Int? = null,
@StringRes guidanceId : Int? = null,
isError : Boolean = false,
useMaxLength : Boolean = false,
textStyle: TextStyle = MissionMateTypography.body_lg_regular,
hintStyle: TextStyle = MissionMateTypography.body_lg_regular,
textColor: Color = ColorGray1_FF404249,
hintColor: Color = ColorGray3_FF727484,
guidanceColor : Color = Color(0xFF4F505C),
errorColor : Color = Color(0xFFFF6464),
containerColor: Color = ColorWhite_FFFFFFFF,
unfocusedHintColor: Color = ColorGray5_80F5F6F9,
borderStroke: BorderStroke = BorderStroke(1.dp, ColorGray4_FFE5E5E5),
focusedBorderStroke: BorderStroke = BorderStroke(1.dp, ColorGray4_FFE5E5E5),
errorBorderStroke: BorderStroke = BorderStroke(2.dp, ColorRed_FFFF5858),
shape: Shape = RoundedCornerShape(12.dp),
maxLength : Int = Int.MAX_VALUE,
isSingleLine: Boolean = true,
visualTransformation: VisualTransformation = VisualTransformation.None,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
textAlign : Alignment = Alignment.CenterStart,
contentPadding : PaddingValues = PaddingValues(horizontal = 16.dp)
) {
var isFocused by remember { mutableStateOf(false) }
BasicTextField(
modifier = modifier
.heightIn(min = 60.dp)
.onFocusChanged {
isFocused = it.isFocused
},
Expand All @@ -74,34 +82,48 @@ fun MissionMateTextField(
color = textColor
),
visualTransformation = visualTransformation,
keyboardActions = keyboardActions,
keyboardOptions = keyboardOptions,
onValueChange = onValueChange,
decorationBox = { innerTextField ->
Box(
modifier = Modifier
.clip(shape)
.border(
border = if (isError) errorBorderStroke
else if (isFocused) focusedBorderStroke
else borderStroke,
shape = shape
)
.background(
if (!isFocused && text.isEmpty()) unfocusedHintColor
else containerColor
)
.padding(contentPadding),
contentAlignment = textAlign
Column(
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
if(text.isBlank()){
Box(
modifier = Modifier
.fillMaxWidth()
.heightIn(min = 60.dp)
.clip(shape)
.border(
border = if (isError) errorBorderStroke
else if (isFocused) focusedBorderStroke
else borderStroke,
shape = shape
)
.background(
if (!isFocused && text.isEmpty()) unfocusedHintColor
else containerColor
)
.padding(contentPadding),
contentAlignment = textAlign
) {
if(text.isBlank()){
Text(
text = hintId?.let { stringResource(id = it) } ?: "",
style = hintStyle,
color = hintColor
)
}
innerTextField()
}
if(guidanceId != null){
Text(
text = hintId?.let { stringResource(id = it) } ?: "",
style = hintStyle,
color = hintColor
text = stringResource(id = guidanceId) + if(useMaxLength) "(${text.length}/$maxLength)" else "",
style = MissionMateTypography.body_md_regular,
color = if(isError) errorColor else guidanceColor
)
}
innerTextField()
}

}
)
}
Expand All @@ -119,15 +141,16 @@ fun MissionMateTextFieldGroup(
isError : Boolean = false,
titleColor : Color = Color(0xFF4F505C),
guidanceColor : Color = Color(0xFF4F505C),
errorColor : Color = Color(0xFFFF6464)
errorColor : Color = Color(0xFFFF6464),
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
){
Column(
modifier = modifier,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
if(titleId != null){
Text(
modifier = Modifier.padding(bottom = 4.dp),
text = stringResource(id = titleId),
style = MissionMateTypography.body_md_bold,
color = titleColor
Expand All @@ -138,15 +161,15 @@ fun MissionMateTextFieldGroup(
onValueChange = onValueChange,
modifier = Modifier.fillMaxWidth(),
hintId = hintId,
isError = isError
isError = isError,
useMaxLength = useMaxLength,
guidanceId = guidanceId,
maxLength = maxLength,
guidanceColor = guidanceColor,
errorColor = errorColor,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions
)
if(guidanceId != null){
Text(
text = stringResource(id = guidanceId) + if(useMaxLength) "(${text.length}/$maxLength)" else "",
style = MissionMateTypography.body_md_regular,
color = if(isError) errorColor else guidanceColor
)
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions core/designsystem/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>

<color name="rabbit_color">#FFFFE4E4</color>
<color name="cat_color">#FFBFD7FF</color>
<color name="dog_color">#FFFFE59A</color>
<color name="panda_color">#FFC2E792</color>
<color name="bear_color">#FFF7D8B3</color>
<color name="bird_color">#FFBCE7FF</color>
</resources>
2 changes: 2 additions & 0 deletions core/domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ dependencies {
implementation(libs.hilt.android)

implementation(project(":core:model"))
implementation(project(":core:datastore"))
implementation(project(":core:network"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.goalpanzi.mission_mate.core.domain.di

import android.content.Context
import android.content.res.TypedArray
import androidx.annotation.ArrayRes
import androidx.annotation.StringRes
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class ResourceProvider @Inject constructor(
@ApplicationContext private val context: Context
) {
fun getString(@StringRes stringResId: Int): String {
return context.getString(stringResId)
}

fun getIntArray(@ArrayRes arrayResId: Int): Array<Int> {
return context.resources.getIntArray(arrayResId).toTypedArray()
}

fun getDrawableArray(@ArrayRes arrayResId: Int): TypedArray {
return context.resources.obtainTypedArray(arrayResId)
}

fun getStringArray(@ArrayRes arrayResId: Int): Array<String> {
return context.resources.getStringArray(arrayResId)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.goalpanzi.mission_mate.core.domain.repository

import com.goalpanzi.mission_mate.core.network.ResultHandler
import com.luckyoct.core.model.base.NetworkResult

interface ProfileRepository: ResultHandler {
suspend fun saveProfile(nickname: String, index: Int): NetworkResult<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package com.goalpanzi.mission_mate.core.domain.usecase

import com.goalpanzi.mission_mate.core.datastore.datasource.AuthDataSource
import com.goalpanzi.mission_mate.core.domain.repository.LoginRepository
import com.luckyoct.core.model.GoogleLogin
import kotlinx.coroutines.flow.first
import javax.inject.Inject

class LoginUseCase @Inject constructor(
private val loginRepository: LoginRepository
private val loginRepository: LoginRepository,
private val authDataSource: AuthDataSource
) {

suspend fun requestGoogleLogin(token: String, email: String): GoogleLogin = loginRepository.requestGoogleLogin(token, email)
suspend fun requestGoogleLogin(token: String, email: String): GoogleLogin {
val response = loginRepository.requestGoogleLogin(token, email)
authDataSource.setAccessToken(response.accessToken).first()
authDataSource.setRefreshToken(response.refreshToken).first()
return response
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.goalpanzi.mission_mate.core.domain.usecase

import com.goalpanzi.mission_mate.core.domain.repository.ProfileRepository
import javax.inject.Inject

class ProfileUseCase @Inject constructor(
private val profileRepository: ProfileRepository
) {
suspend fun saveProfile(nickname: String, index: Int) = profileRepository.saveProfile(nickname, index)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.luckyoct.core.model.base

sealed interface NetworkResult<out T> {
data class Success<out T>(val data: T) : NetworkResult<T>
data class Error(val code: Int? = null, val message: String? = null) : NetworkResult<Nothing>
data class Exception(val error: Throwable) : NetworkResult<Nothing>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.luckyoct.core.model.request

import kotlinx.serialization.Serializable

enum class CharacterType {
RABBIT, CAT, DOG, PANDA, BEAR, BIRD
}

@Serializable
data class SaveProfileRequest(
val nickname: String,
val characterType: String,
) {
companion object {
fun createRequest(nickname: String, index: Int) = SaveProfileRequest(
nickname = nickname,
characterType = CharacterType.entries[index].name.uppercase()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ sealed interface RouteModel {

@Serializable
data object Onboarding : RouteModel

@Serializable
sealed interface Profile: RouteModel {
@Serializable
data object Create : Profile
@Serializable
data object Change : Profile
}
}

sealed interface OnboardingRouteModel {
Expand Down
1 change: 1 addition & 0 deletions core/network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies {
implementation(libs.hilt.android)

implementation(project(":core:model"))
implementation(project(":core:datastore"))
}

fun getMissionMateBaseUrl(): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.goalpanzi.mission_mate.core.network

import com.luckyoct.core.model.base.NetworkResult
import retrofit2.HttpException
import retrofit2.Response

interface ResultHandler {

suspend fun <T : Any> handleResult(execute: suspend () -> Response<T>): NetworkResult<T> {
return try {
val response = execute()
if (response.isSuccessful) {
val body = response.body()
if (body != null) {
NetworkResult.Success(body)
} else {
NetworkResult.Error(response.code(), "Response body is null")
}
} else {
NetworkResult.Error(response.code(), response.errorBody()?.string())
}
} catch (e: HttpException) {
NetworkResult.Error(e.code(), e.message())
} catch (e: Throwable) {
NetworkResult.Exception(e)
}
}
}
Loading

0 comments on commit b8431c3

Please sign in to comment.