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

[FEAT] 7주차 필수 과제 #14

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 3 additions & 5 deletions app/src/main/java/org/sopt/and/core/extension/ContextExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package org.sopt.and.core.extension
import android.content.Context
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

fun Context.toast(@StringRes message: Int) {
Toast.makeText(this, getString(message), Toast.LENGTH_SHORT).show()
}

fun Context.serverToast(message: String? = "") {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}
Comment on lines +11 to +13

Choose a reason for hiding this comment

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

toast와 serverToast를 무슨 차이일까요 ?


Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.sopt.and.data.dataremote.model.request.RequestUserInfoRegisterDto
import org.sopt.and.data.dataremote.model.response.ResponseGetMyHobbyDto
import org.sopt.and.data.dataremote.model.response.ResponseSignInSuccessDto
import org.sopt.and.data.dataremote.model.response.ResponseUserInfoRegisterSuccessDto
import org.sopt.and.data.dataremote.service.AuthService
import org.sopt.and.data.service.AuthService
import javax.inject.Inject

class UserServiceRemoteDataSourceImpl @Inject constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.data.dataremote.service
package org.sopt.and.data.service

import org.sopt.and.data.dataremote.model.BaseResponse
import org.sopt.and.data.dataremote.model.request.RequestSignInDto
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/sopt/and/di/ApiModul.kt

Choose a reason for hiding this comment

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

저 이제 발견했는데요 파일명에 오타있음!!ㅋㅋㅋㅋ

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.sopt.and.BuildConfig
import org.sopt.and.data.dataremote.service.AuthService
import org.sopt.and.data.service.AuthService
import retrofit2.Retrofit
import javax.inject.Singleton

Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/org/sopt/and/domain/entity/UserLogInIfo.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package org.sopt.and.domain.entity

data class UserLogInInfo(
val userName: String = "",
val password: String = "",
)

data class UserToken(
val token: String = ""
)
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/org/sopt/and/presentation/home/HomeContract.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.sopt.and.presentation.home

import org.sopt.and.presentation.util.base.UiEvent
import org.sopt.and.presentation.util.base.UiSideEffect
import org.sopt.and.presentation.util.base.UiState

class HomeContract {
data class HomeUIState(
val genreList: List<String> = listOf(),
val mainBannerList: List<Int> = listOf(),
val editorRecommendList: List<Int> = listOf(),
val top20List: List<Int> = listOf()
) : UiState

sealed interface HomeSideEffect : UiSideEffect

sealed class HomeEvent : UiEvent
Comment on lines +15 to +17

Choose a reason for hiding this comment

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

효빈님께도 드린 질문인데, 만약 sideeffect와 event가 없더라도 만들어두는게 좋을까요 ? 저는 안만들어서 ..

}
36 changes: 25 additions & 11 deletions app/src/main/java/org/sopt/and/presentation/home/HomeScreen.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sopt.and.presentation.home

import androidx.compose.foundation.Image
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -24,6 +25,7 @@ import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -34,20 +36,32 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import org.sopt.and.R
import org.sopt.and.presentation.home.component.ContentLazyList
import org.sopt.and.presentation.home.component.MainBannerPager
import org.sopt.and.presentation.home.component.Top20LazyList


@Composable
fun HomeScreen(modifier: Modifier = Modifier) {
val homeViewModel = viewModel<HomeViewModel>()

val uiState = homeViewModel.uiState
fun HomeRoute(
viewModel: HomeViewModel = hiltViewModel()
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val scrollState = rememberScrollState()

HomeScreen(
uiState = uiState,
scrollState = scrollState,
)
}

@Composable
fun HomeScreen(
uiState: HomeContract.HomeUIState,
scrollState: ScrollState,
modifier: Modifier = Modifier
) {
Column(
modifier = modifier
.fillMaxSize()
Expand Down Expand Up @@ -87,7 +101,7 @@ fun HomeScreen(modifier: Modifier = Modifier) {
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
items(uiState.value.genreList) { genre ->
items(uiState.genreList) { genre ->
Text(
text = genre,
color = colorResource(R.color.gray_a3),
Expand All @@ -98,18 +112,18 @@ fun HomeScreen(modifier: Modifier = Modifier) {

Spacer(Modifier.height(20.dp))

MainBannerPager(uiState.value.mainBannerList)
MainBannerPager(uiState.mainBannerList)

Spacer(Modifier.height(20.dp))

RecommendedContent(stringResource(R.string.home_editor_recommend_content), true) {
ContentLazyList(uiState.value.editorRecomendList)
ContentLazyList(uiState.editorRecommendList)
}

Spacer(Modifier.height(20.dp))

RecommendedContent(stringResource(R.string.home_today_top20), false) {
Top20LazyList(uiState.value.top20List)
Top20LazyList(uiState.top20List)
}
}
}
Expand Down Expand Up @@ -149,6 +163,6 @@ fun RecommendedContent(
@Preview
@Composable
private fun HomeScreenPreview() {
HomeScreen()
HomeRoute()
Comment on lines -152 to +166
Copy link
Contributor

Choose a reason for hiding this comment

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

변경하신 이유가 있나요?

}

33 changes: 14 additions & 19 deletions app/src/main/java/org/sopt/and/presentation/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@ package org.sopt.and.presentation.home
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import org.sopt.and.R
import org.sopt.and.presentation.signup.SignUpContract
import org.sopt.and.presentation.util.base.BaseViewModel

class HomeViewModel :
BaseViewModel<HomeContract.HomeUIState, HomeContract.HomeSideEffect, HomeContract.HomeEvent>() {
override fun createInitialState(): HomeContract.HomeUIState = HomeContract.HomeUIState(
genreList = getGenreTextList(),
editorRecommendList = getEditorRecommendList(),
top20List = getTop20List(),
mainBannerList = getMainBannerImage()
)

override suspend fun handleEvent(event: HomeContract.HomeEvent) {
}

class HomeViewModel : ViewModel() {
private fun getGenreTextList() = listOf(
"뉴클래식", "드라마", "예능", "영화", "애니", "해외시리즈"
)
Expand Down Expand Up @@ -39,23 +52,5 @@ class HomeViewModel : ViewModel() {
R.drawable.img_top20_9,
R.drawable.img_top20_10,
)

private val _uiState =
mutableStateOf(
UIState(
getGenreTextList(),
getMainBannerImage(),
getEditorRecommendList(),
getTop20List()
)
)
val uiState = _uiState

}

data class UIState(
val genreList: List<String> = listOf(),
val mainBannerList: List<Int> = listOf(),
val editorRecomendList: List<Int> = listOf(),
val top20List: List<Int> = listOf()
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import org.sopt.and.presentation.home.HomeScreen
import org.sopt.and.core.navigation.MainTabRoute
import org.sopt.and.presentation.home.HomeRoute

fun NavHostController.navigateToHome(navOptions: NavOptions) =
navigate(MainTabRoute.Home, navOptions)

fun NavGraphBuilder.homeNavGraph() {
composable<MainTabRoute.Home> {
HomeScreen()
HomeRoute()
}
}
29 changes: 29 additions & 0 deletions app/src/main/java/org/sopt/and/presentation/login/LogInContract.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.sopt.and.presentation.login

import androidx.annotation.StringRes
import org.sopt.and.presentation.util.base.UiEvent
import org.sopt.and.presentation.util.base.UiSideEffect
import org.sopt.and.presentation.util.base.UiState

class LogInContract {
data class LoginUiState(
val isPasswordVisible: Boolean = false,
val emailValue: String = "",
val passwordValue: String = ""
) : UiState

sealed interface LogInSideEffect : UiSideEffect {
data object NavigateToHome : LogInSideEffect
data object NavigateToSignUp : LogInSideEffect
data class ShowToast(@StringRes val message: Int) : LogInSideEffect
data class ShowSnackBar(@StringRes val message: Int) : LogInSideEffect
}

sealed class LogInEvent : UiEvent {
data class OnEmailValueChanged(val emailValue: String) : LogInEvent()
data class OnPasswordValueChanged(val passwordValue: String) : LogInEvent()
data object OnPasswordVisibleButtonClicked : LogInEvent()
data object OnLogInButtonClicked : LogInEvent()
data object OnSignUpButtonClicked : LogInEvent()
}
}
Loading