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/week04 compose #6

Open
wants to merge 22 commits into
base: develop-compose
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
34 changes: 30 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.0'
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

android {
namespace 'com.sopt.now.compose'
compileSdk 34
Expand All @@ -13,6 +17,7 @@ android {
targetSdk 34
versionCode 1
versionName "1.0"
buildConfigField "String", "AUTH_BASE_URL", properties["base.url"]

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand All @@ -35,6 +40,8 @@ android {
}
buildFeatures {
compose true
viewBinding true
buildConfig true
}
composeOptions {
kotlinCompilerExtensionVersion '1.5.1'
Expand All @@ -47,20 +54,39 @@ android {
}

dependencies {
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.core:core-ktx:1.13.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.7.0'
implementation 'androidx.activity:activity-compose:1.8.2'
implementation platform('androidx.compose:compose-bom:2024.03.00')
implementation 'androidx.activity:activity-compose:1.9.0'
implementation platform('androidx.compose:compose-bom:2024.04.01')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3'
implementation 'androidx.navigation:navigation-compose:2.7.7'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.7'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation platform('androidx.compose:compose-bom:2024.03.00')
androidTestImplementation platform('androidx.compose:compose-bom:2024.04.01')
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
implementation "androidx.navigation:navigation-compose:2.7.7"

Choose a reason for hiding this comment

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

์ค‘๋ณต์„ ์–ธ์ž…๋‹ˆ๋‹ค.


implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1'
implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0'

// define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0"))

// define any required OkHttp artifacts without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")

}
18 changes: 6 additions & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -11,29 +13,21 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NOWSOPTAndroid"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.NOWSOPTAndroid">
</activity>


<activity
android:name=".LoginActivity"
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.NOWSOPTAndroid">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".SignupActivity"
android:exported="true"
android:theme="@style/Theme.NOWSOPTAndroid"/>


</application>

</manifest>
23 changes: 23 additions & 0 deletions app/src/main/java/com/sopt/now/compose/ApiFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.sopt.now.compose

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import retrofit2.Retrofit

object ApiFactory {
private const val BASE_URL: String = BuildConfig.AUTH_BASE_URL

val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.build()
}

inline fun <reified T> create(): T = retrofit.create(T::class.java)
}

object ServicePool {
val authService = ApiFactory.create<AuthService>()
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/sopt/now/compose/AuthService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.sopt.now.compose

import com.sopt.now.compose.data.RequestLogInDto
import com.sopt.now.compose.data.RequestPasswordDto
import com.sopt.now.compose.data.RequestSignUpDto
import com.sopt.now.compose.data.ResponseDto
import com.sopt.now.compose.data.ResponseInfoDto
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.PATCH
import retrofit2.http.POST

interface AuthService {
@POST("member/join")
fun signUp(
@Body request: RequestSignUpDto,
): Call<ResponseDto>

@POST("member/login")
fun logIn(
@Body request: RequestLogInDto,
): Call<ResponseDto>

@GET("member/info")
fun info(@Header("memberId") memberId: Int): Call<ResponseInfoDto>

@PATCH("member/password")
fun changePassword(
@Header("memberId") memberId: Int,
@Body request: RequestPasswordDto
): Call<ResponseDto>
}
85 changes: 85 additions & 0 deletions app/src/main/java/com/sopt/now/compose/BottomBar.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.sopt.now.compose

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState


@Composable
fun BottomBar(
navController: NavHostController,
modifier: Modifier = Modifier,
isLoggedIn: Boolean
) {
Comment on lines +22 to +26

Choose a reason for hiding this comment

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

Kotlin์—์„œ๋Š” ๋ชจ๋“  ์„ ํƒ์  ํŒจ๋Ÿฌ๋ฏธํ„ฐ(Optional Parameter, ๋””ํดํŠธ ๊ฐ’์ด ์ฃผ์–ด์ง„ ํŒจ๋Ÿฌ๋ฏธํ„ฐ)๋Š” ํ•„์ˆ˜ ํŒจ๋Ÿฌ๋ฏธํ„ฐ ๋’ค์— ๋ฐฐ์น˜๋˜์–ด์•ผํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ปดํฌ์ฆˆ์—์„œ๋Š” ๋ชจ๋“  ์„ ํƒ์  ํŒจ๋Ÿฌ๋ฏธํ„ฐ ์ œ์ผ ์œ„์— Modifier๊ฐ€ ๋ฐฐ์น˜๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค...๋ผ๊ณ  ์ฝ”๋”ฉ ์ปจ๋ฒค์…˜์—๋Š” ์ ํ˜€ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•„์ˆ˜๋Š” ์•„๋‹ˆ์ง€๋งŒ ๊ณตํ†ต ๋ฃฐ์„ ์ง€์ผœ๋ณด๋ฉด์„œ ์ฝ”๋“œ ๊ฐ€๋…์„ฑ ์˜ฌ๋ฆฌ๋Š” ๊ฒƒ์— ๋„์›€์ด ๋  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์„œ ๊ณต์œ ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

Suggested change
fun BottomBar(
navController: NavHostController,
modifier: Modifier = Modifier,
isLoggedIn: Boolean
) {
fun BottomBar(
navController: NavHostController,
isLoggedIn: Boolean,
modifier: Modifier = Modifier,
) {


val screens = listOf(
BottomNavItem.Home, BottomNavItem.Search, BottomNavItem.MyPage
)
Comment on lines +28 to +30

Choose a reason for hiding this comment

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

(์•„์ฃผ ์‚ฌ์†Œํ•œ ๋ฆฌ๋ทฐ) ์ด ๋ฆฌ์ŠคํŠธ๋Š” ์ปดํฌ์ €๋ธ” ํ•จ์ˆ˜ ๊ทธ๋ ค์ง€๋Š” ๋™์•ˆ ๋‹จ ํ•œ๋ฒˆ๋งŒ ํ• ๋‹น ์—ฐ์‚ฐ์ด ์‹คํ–‰๋ ๊นŒ์š”?


if (isLoggedIn) {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentRoute = navBackStackEntry?.destination?.route
NavigationBar(
modifier = modifier,
containerColor = Color.LightGray,
) {
screens.forEach { screen ->

NavigationBarItem(
label = {
Text(text = screen.title!!)
},
icon = {
Icon(imageVector = screen.icon!!, contentDescription = "")
},
selected = currentRoute == screen.route,
onClick = {
navController.navigate(screen.route)
},
colors = NavigationBarItemDefaults.colors(
unselectedTextColor = Color.Gray, selectedTextColor = Color.White
),
)
}
}
}
Comment on lines +32 to +58

Choose a reason for hiding this comment

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

๋งŒ์•ฝ ๋ฐ”ํ…€๋ฐ”๊ฐ€ ๋กœ๊ทธ์ธ๋œ ์ƒํƒœ ์ด์™ธ์—๋„ ๋ณด์—ฌ์•ผ ํ•œ๋‹ค๋ผ๋Š” ์š”๊ตฌ์‚ฌํ•ญ ๋ณ€๊ฒฝ์ด ๋“ค์–ด์˜ค๋ฉด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”? ๊ทธ๋ฆฌ๊ณ  ํŠน์ • ์กฐ๊ฑด์—์„œ๋„ ๋ณด์ด์ง€ ์•Š์•„์•ผ ํ•œ๋‹ค๋ผ๋Š” ์กฐ๊ฑด์ด ์ถ”๊ฐ€๋œ๋‹ค๋ฉด์š”? ์ปดํฌ๋„ŒํŠธ ๋‹จ์—์„œ ์ด๋Ÿฐ ์•ฑ ๋‚ด ๊ธฐ๋Šฅ ์š”๊ตฌ์‚ฌํ•ญ๋“ค์„ ์•Œ์•„์•ผ ํ•  ํ•„์š”๊ฐ€ ์žˆ์„๊นŒ์š”?


}

sealed class BottomNavItem(
val route: String,
val title: String? = null,
val icon: ImageVector? = null
) {
data object Home : BottomNavItem(
route = Routes.Home.route,
title = "Home",
icon = Icons.Default.Home
)

data object Search : BottomNavItem(
route = Routes.Search.route,
title = "Search",
icon = Icons.Default.Search
)

data object MyPage : BottomNavItem(
route = Routes.MyPage.route,
title = "MyPage",
icon = Icons.Default.Person
)

}
Comment on lines +62 to +85

Choose a reason for hiding this comment

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

enum class๋กœ๋„ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Choose a reason for hiding this comment

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

ํ•ด๋‹น ๊ตฌ์กฐ๋ฅผ sealed๋กœ ๋งŒ๋“œ์‹  ์ด์œ ๊ฐ€ ์žˆ์„๊นŒ์š”?

8 changes: 8 additions & 0 deletions app/src/main/java/com/sopt/now/compose/Friend.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sopt.now.compose

data class Friend(
val profileImageRes: Int,

Choose a reason for hiding this comment

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

Suggested change
val profileImageRes: Int,
@DrawableRes val profileImageRes: Int,

๋ฆฌ์†Œ์Šค ์•„์ด๋””์˜ ๊ฒฝ์šฐ์—๋Š” ์•ž์— ์ด๋Ÿฐ์‹์œผ๋กœ ์–ด๋…ธํ…Œ์ด์…˜ ๋ถ™์ด๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์ถ”๊ฐ€๋กœ ํ•ด๋‹น ์•„์ดํ…œ์ด ๋กœ์ปฌ ์ด๋ฏธ์ง€๊ฐ€ ์•„๋‹Œ ์™ธ๋ถ€ ์ €์žฅ์†Œ์—์„œ ๊ฐ€์ ธ์™€์•ผ ํ•˜๋Š” ์ด๋ฏธ์ง€๋ผ๋ฉด ํŒจ๋Ÿฌ๋ฏธํ„ฐ๊ฐ€ Int๋งŒ ๋ฐ›์œผ๋ฉด ์•ˆ๋ ํ…๋ฐ ์–ด๋–ป๊ฒŒ ๋Œ€์‘ํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”?

Copy link
Member Author

Choose a reason for hiding this comment

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

ํ—‰ ์™ธ๋ถ€์—์„œ ๊ฐ€์ ธ์™€์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๋Š” ์ƒ๊ฐํ•ด๋ณด์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค...
์ฐพ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

val name: String,
val description: String

)
Loading