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

Week2 과제 ... #3

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
9 changes: 9 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.serialization)
}

android {
Expand Down Expand Up @@ -49,6 +50,14 @@ dependencies {
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation("androidx.navigation:navigation-compose:2.8.3")
implementation("com.google.accompanist:accompanist-pager:0.20.1")
implementation("com.google.accompanist:accompanist-pager-indicators:0.20.1")
implementation("io.coil-kt:coil-compose:2.4.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
implementation ("androidx.compose.runtime:runtime-livedata:1.7.4")
implementation ("androidx.lifecycle:lifecycle-livedata-ktx:2.8.6")
implementation ("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.6")
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
Expand Down
19 changes: 16 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,24 @@
android:supportsRtl="true"
android:theme="@style/Theme.ANDANDROID"
tools:targetApi="31">
<activity
android:name=".LoginActivity"
android:exported="false" />
<activity
android:name=".MyActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SearchActivity"
Comment on lines +17 to +32
Copy link
Contributor

Choose a reason for hiding this comment

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

이번주 과제가 SAA 적용이었죠?
Single Activity가 되려면 말 그대로 액티비티가 하나여야 합니다.
즉, manifest에 등록한 액티비티가 하나여야 해요!
이를 바탕으로 리팩해보시면 좋을 것 같아요!

android:exported="false" />
<activity
android:name=".MainActivity"
Expand Down
190 changes: 190 additions & 0 deletions app/src/main/java/org/sopt/and/HomeActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
@file:OptIn(ExperimentalMaterial3Api::class)

package org.sopt.and

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import kotlinx.serialization.Serializable
import org.sopt.and.ui.components.BottomBar.CustomBottomAppBar
import org.sopt.and.ui.components.HomeScreen.HomeLazyRow
import org.sopt.and.ui.components.TopBar.CustomTopAppBar
import org.sopt.and.ui.components.TopBar.CustomTopAppBarSecond
import org.sopt.and.ui.theme.ANDANDROIDTheme

@Serializable
data object HomeScreen

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun HomeScreen(
modifier: Modifier = Modifier,
navController: NavController, // navController를 넘겨 받아 사용
Copy link
Contributor

Choose a reason for hiding this comment

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

하위 컴포저블 함수에 NavController를 인자로 받는 것은 권장하지 않는 방법입니다.
필요한 동작들을 함수화해서 함수를 넘겨주세요!

) {
val context = LocalContext.current
val scrollState = rememberScrollState()

Scaffold(
topBar = {
Column {
CustomTopAppBar(navController = navController)
CustomTopAppBarSecond(navController = navController)
}
},
bottomBar = {
CustomBottomAppBar(navController = navController)
}
Comment on lines +53 to +62

Choose a reason for hiding this comment

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

이 코드가 Home, Search, My에서 중복되고 있는 것 같아요. 외부로 빼는건 어떨까요?
지금 방법의 문제점은 아래처럼 느껴져요.

  1. 같은 코드가 여러 화면에서 중복된다.
  2. 화면 이동을 할 때 bottomBar도 깜빡이며 화면이 재구성된다.

NavHost 자체를 Scaffold로 감싸는 방법도 있을 것 같아요. 그렇게 되면 SignUp과 같은 화면에도 topBar와 bottomBar가 나올거에요. 그 때 조건을 통해 특정 화면일 때에만 나오도록 설정할 수 있어요!

물론 다른 방법이 있다면 그렇게 하는 것도 좋아요! 저는 여러 방법중 하나를 제안드리는거지 절대 정답은 아닙니다 :)

) { innerPadding ->
Column(
Copy link
Contributor

Choose a reason for hiding this comment

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

LazyColumn을 사용하는 것이 성능상으로 더 좋을 것 같아요
(마찬가지로 자세한 내용은 세미나 자료 참고 부탁드립니다.)

modifier = Modifier
.fillMaxSize()
.verticalScroll(scrollState)
.background(Color(0xFF1B1B1B))
.padding(innerPadding) // 패딩 적용
.padding(all = 10.dp)
) {

val images = listOf(
R.drawable.food_pic1,
R.drawable.food_pic2,
R.drawable.food_pic3,
R.drawable.food_pic4,
R.drawable.food_pic5
)
Comment on lines +73 to +79
Copy link
Contributor

Choose a reason for hiding this comment

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

세미나 때 AAC 뷰모델에 대해 배웠었죠?
이 값은 뷰모델로 옮기면 좋을 것 같아요!!
(왜인지는 세미나 자료 참고)

Copy link
Contributor

Choose a reason for hiding this comment

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

추가적으로 persistentListOf에 대해 공부해보시는 걸 추천드려요


val pagerState = rememberPagerState { images.size }

HorizontalPager(
state = pagerState,
modifier = Modifier
.fillMaxWidth()
.height(400.dp)
) { idx ->
Image(
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
.clip(RoundedCornerShape(16.dp)),
painter = painterResource(id = images[idx]),
contentDescription = "imagePager",
contentScale = ContentScale.Crop
)
}

HomeLazyRow(
title = "믿고 보는 웨이브 에디터 추천작",
images = images,
height = 230,
width = 140,
)
Spacer(modifier = Modifier.height(10.dp))

HomeLazyRow(
title = "실시간 인기 콘텐츠",
images = images,
height = 230,
width = 140,
)
Spacer(modifier = Modifier.height(10.dp))

HomeLazyRow(
title = "오직 웨이브에서",
images = images,
height = 230,
width = 140,
)
Spacer(modifier = Modifier.height(10.dp))

HomeLazyRow(
title = "오늘의 TOP 20",
images = images,
height = 260,
width = 180,
)
Spacer(modifier = Modifier.height(10.dp))

HomeLazyRow(
title = "당한 대로 갚아줄게",
images = images,
height = 230,
width = 140,
)
Spacer(modifier = Modifier.height(10.dp))
}
}
}



@Preview(showBackground = true)
@Composable
fun HomeScreenPreview() {
val navController = rememberNavController()

ANDANDROIDTheme {
Scaffold(
modifier = Modifier.fillMaxSize(),
topBar = {
Column{
CustomTopAppBar(navController = navController)
CustomTopAppBarSecond(navController = navController)

}

},
bottomBar = {
CustomBottomAppBar(navController = navController)
}
) {
innerPadding ->
Column(
modifier = Modifier
.fillMaxSize()
.background(Color(0xFF1B1B1B))
.padding(innerPadding)
){
NavHost(
navController = navController,
startDestination = "home",
){
composable("home") {HomeScreen(
navController = navController
)}
composable("search") {SearchScreen(
navController = navController
)}
composable("profile") {MypageScreen(
navController = navController,
)}
}
}

}
}
}
Loading