Skip to content

Commit

Permalink
Merge pull request #35 from team-haribo/feature/34-write-the-logic-main
Browse files Browse the repository at this point in the history
🔀 :: (#34) - write the logic main
  • Loading branch information
diejdkll authored Jan 30, 2024
2 parents 3d03ca7 + 698d577 commit dfd1299
Show file tree
Hide file tree
Showing 52 changed files with 1,302 additions and 468 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ android {
}

dependencies {
implementation(project(":core:common"))
implementation(project(":core:design-system"))
implementation(project(":core:data"))
implementation(project(":core:model"))
implementation(project(":feature:login"))
implementation(project(":feature:sign-up"))
implementation(project(":feature:main"))
Expand Down
39 changes: 35 additions & 4 deletions app/src/main/java/com/goms/goms_android_v2/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.OnBackPressedCallback
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.goms.design_system.theme.GomsTheme
import com.goms.goms_android_v2.ui.GomsApp
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
Expand All @@ -23,15 +32,37 @@ class MainActivity : ComponentActivity() {
}
}

private val viewModel: MainActivityViewModel by viewModels()

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.onBackPressedDispatcher.addCallback(this, onBackPressedCallback)

var uiState: MainActivityUiState by mutableStateOf(MainActivityUiState.Loading)

lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.uiState
.onEach { uiState = it }
.collect {}
}
}

setContent {
installSplashScreen()
CompositionLocalProvider {
GomsTheme { _, _ ->
GomsApp(windowSizeClass = calculateWindowSizeClass(this))
installSplashScreen().apply {
setKeepOnScreenCondition {
uiState is MainActivityUiState.Loading
}
}
if (uiState !is MainActivityUiState.Loading) {
CompositionLocalProvider {
GomsTheme { _, _ ->
GomsApp(
windowSizeClass = calculateWindowSizeClass(this),
uiState = uiState
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.goms.goms_android_v2

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.goms.common.result.Result
import com.goms.common.result.asResult
import com.goms.data.repository.account.AccountRepository
import com.goms.model.response.account.ProfileResponse
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject

@HiltViewModel
class MainActivityViewModel @Inject constructor(
private val accountRepository: AccountRepository
) : ViewModel() {
val uiState: StateFlow<MainActivityUiState> = flow {
accountRepository.getProfile().collect { profileResponse ->
emit(profileResponse)
}
}
.asResult()
.map { result ->
when (result) {
Result.Loading -> MainActivityUiState.Loading
is Result.Success -> MainActivityUiState.Success(result.data)
is Result.Error -> MainActivityUiState.Error(result.exception)
}
}
.stateIn(
scope = viewModelScope,
initialValue = MainActivityUiState.Loading,
started = SharingStarted.WhileSubscribed(5_000),
)
}

sealed interface MainActivityUiState {
object Loading : MainActivityUiState
data class Success(val getProfileResponse: ProfileResponse) : MainActivityUiState
data class Error(val exception: Throwable) : MainActivityUiState
}
15 changes: 13 additions & 2 deletions app/src/main/java/com/goms/goms_android_v2/ui/GomsApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@ package com.goms.goms_android_v2.ui
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.runtime.Composable
import com.goms.design_system.theme.GomsTheme
import com.goms.goms_android_v2.MainActivityUiState
import com.goms.goms_android_v2.navigation.GomsNavHost
import com.goms.login.navigation.loginRoute
import com.goms.main.navigation.mainRoute

@Composable
fun GomsApp(
windowSizeClass: WindowSizeClass,
appState: GomsAppState = rememberBitgoeulAppState(
windowSizeClass = windowSizeClass
)
),
uiState: MainActivityUiState
) {
GomsTheme { _,_ ->
GomsNavHost(appState = appState)
GomsNavHost(
appState = appState,
startDestination = when (uiState) {
is MainActivityUiState.Success -> mainRoute
is MainActivityUiState.Error -> loginRoute
else -> loginRoute
}
)
}
}
21 changes: 21 additions & 0 deletions core/data/src/main/java/com/goms/data/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.goms.data.di

import com.goms.data.repository.account.AccountRepository
import com.goms.data.repository.account.AccountRepositoryImpl
import com.goms.data.repository.auth.AuthRepository
import com.goms.data.repository.auth.AuthRepositoryImpl
import com.goms.data.repository.late.LateRepository
import com.goms.data.repository.late.LateRepositoryImpl
import com.goms.data.repository.outing.OutingRepository
import com.goms.data.repository.outing.OutingRepositoryImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -14,4 +20,19 @@ abstract class RepositoryModule {
abstract fun bindAuthRepository(
authRepositoryImpl: AuthRepositoryImpl
): AuthRepository

@Binds
abstract fun bindAccountRepository(
accountRepositoryImpl: AccountRepositoryImpl
): AccountRepository

@Binds
abstract fun bindLateRepository(
lateRepositoryImpl: LateRepositoryImpl
): LateRepository

@Binds
abstract fun bindOutingRepository(
outingRepositoryImpl: OutingRepositoryImpl
): OutingRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.goms.data.repository.account

import com.goms.model.response.account.ProfileResponse
import kotlinx.coroutines.flow.Flow

interface AccountRepository {
suspend fun getProfile(): Flow<ProfileResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.goms.data.repository.account

import com.goms.model.response.account.ProfileResponse
import com.goms.network.datasource.account.AccountDataSource
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class AccountRepositoryImpl @Inject constructor(
private val remoteAccountDataSource: AccountDataSource
) : AccountRepository {
override suspend fun getProfile(): Flow<ProfileResponse> {
return remoteAccountDataSource.getProfile()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.goms.data.repository.late

import com.goms.model.response.late.RankResponse
import kotlinx.coroutines.flow.Flow

interface LateRepository {
suspend fun getLateRankList(): Flow<List<RankResponse>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.goms.data.repository.late

import com.goms.model.response.late.RankResponse
import com.goms.network.datasource.late.LateDataSource
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class LateRepositoryImpl @Inject constructor(
private val remoteLateDataSource: LateDataSource
) : LateRepository {
override suspend fun getLateRankList(): Flow<List<RankResponse>> {
return remoteLateDataSource.getLateRankList()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.goms.data.repository.outing

import com.goms.model.response.outing.CountResponse
import com.goms.model.response.outing.OutingResponse
import kotlinx.coroutines.flow.Flow

interface OutingRepository {
suspend fun getOutingList(): Flow<List<OutingResponse>>

suspend fun getOutingCount(): Flow<CountResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.goms.data.repository.outing

import com.goms.model.response.outing.CountResponse
import com.goms.model.response.outing.OutingResponse
import com.goms.network.datasource.outing.OutingDataSource
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class OutingRepositoryImpl @Inject constructor(
private val remoteOutingDataSource: OutingDataSource
) : OutingRepository {
override suspend fun getOutingList(): Flow<List<OutingResponse>> {
return remoteOutingDataSource.getOutingList()
}

override suspend fun getOutingCount(): Flow<CountResponse> {
return remoteOutingDataSource.getOutingCount()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AuthTokenDataSource @Inject constructor(
suspend fun setRefreshTokenExp(refreshTokenExp: String) {
authToken.updateData {
it.toBuilder()
.setRefreshToken(refreshTokenExp)
.setRefreshExp(refreshTokenExp)
.build()
}
}
Expand Down
21 changes: 21 additions & 0 deletions core/design-system/src/main/res/drawable/ic_profile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="256dp"
android:height="256dp"
android:viewportWidth="256"
android:viewportHeight="256">
<group>
<clip-path
android:pathData="M128,0L128,0A128,128 0,0 1,256 128L256,128A128,128 0,0 1,128 256L128,256A128,128 0,0 1,0 128L0,128A128,128 0,0 1,128 0z"/>
<path
android:pathData="M0,0h256v256h-256z"
android:fillColor="#FFA600"/>
<path
android:pathData="M0,256a128,100 0,1 0,256 0a128,100 0,1 0,-256 0z"
android:fillColor="#ffffff"
android:fillAlpha="0.6"/>
<path
android:pathData="M128,80m-60,0a60,60 0,1 1,120 0a60,60 0,1 1,-120 0"
android:fillColor="#ffffff"
android:fillAlpha="0.6"/>
</group>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.goms.domain.account

import com.goms.data.repository.account.AccountRepository
import com.goms.model.response.account.ProfileResponse
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class GetProfileUseCase @Inject constructor(
private val accountRepository: AccountRepository
) {
suspend operator fun invoke(): Flow<ProfileResponse> =
accountRepository.getProfile()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.goms.domain.late

import com.goms.data.repository.late.LateRepository
import com.goms.model.response.late.RankResponse
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class GetLateRankListUseCase @Inject constructor(
private val lateRepository: LateRepository
) {
suspend operator fun invoke(): Flow<List<RankResponse>> =
lateRepository.getLateRankList()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.goms.domain.outing

import com.goms.data.repository.outing.OutingRepository
import com.goms.model.response.outing.CountResponse
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class GetOutingCountUseCase @Inject constructor(
private val outingRepository: OutingRepository
) {
suspend operator fun invoke(): Flow<CountResponse> =
outingRepository.getOutingCount()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.goms.domain.outing

import com.goms.data.repository.outing.OutingRepository
import com.goms.model.response.outing.OutingResponse
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class GetOutingListUseCase @Inject constructor(
private val outingRepository: OutingRepository
) {
suspend operator fun invoke(): Flow<List<OutingResponse>> =
outingRepository.getOutingList()
}
8 changes: 8 additions & 0 deletions core/model/src/main/java/com/goms/model/enum/Major.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ enum class Major(val value: String) {
SW_DEVELOP("SW"),
SMART_IOT("IoT"),
AI("AI")
}

fun Major.toText(): String {
return when (this) {
Major.SW_DEVELOP -> "SW개발"
Major.SMART_IOT -> "IoT"
Major.AI -> "AI"
}
}
Loading

0 comments on commit dfd1299

Please sign in to comment.