๐Ÿ“ฑ ์•ฑ ๊ฐœ๋ฐœ ๐ŸŒฑ ์ž…๋ฌธ

Kotlin Android ๊ฐœ๋ฐœ

Kotlin์œผ๋กœ ์•ˆ๋“œ๋กœ์ด๋“œ ์•ฑ ๊ฐœ๋ฐœ

โฑ๏ธ 15์‹œ๊ฐ„ ๐Ÿ‘๏ธ 20 ์กฐํšŒ
๐Ÿ“– ๊ฐ•์ขŒ ๋‚ด์šฉ
# Kotlin Android ๊ฐœ๋ฐœ ๊ฐ€์ด๋“œ

## ํ•™์Šต ๋ชฉํ‘œ
Kotlin๊ณผ Jetpack Compose๋กœ Android ์•ฑ์„ ๊ฐœ๋ฐœํ•ฉ๋‹ˆ๋‹ค.

## 1. Kotlin์ด๋ž€?
JetBrains๊ฐ€ ๋งŒ๋“  ํ˜„๋Œ€์  JVM ์–ธ์–ด์ž…๋‹ˆ๋‹ค.
- Java์™€ 100% ํ˜ธํ™˜
- ๊ฐ„๊ฒฐํ•˜๊ณ  ์•ˆ์ „ํ•œ ๋ฌธ๋ฒ•
- Null Safety ์ง€์›
- ์ฝ”๋ฃจํ‹ด์œผ๋กœ ๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ

## 2. Android Studio ์„ค์น˜
1. developer.android.com์—์„œ ๋‹ค์šด๋กœ๋“œ
2. SDK ์„ค์น˜
3. ์ƒˆ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ (Empty Compose Activity)

## 3. ๊ธฐ๋ณธ ๋ฌธ๋ฒ•

```kotlin
// ๋ณ€์ˆ˜
val name = "Kim" // ๋ถˆ๋ณ€ (๊ถŒ์žฅ)
var age = 25 // ๊ฐ€๋ณ€

// ํƒ€์ž… ๋ช…์‹œ
val score: Int = 100
val price: Double = 19.99

// Null Safety
var email: String? = null
val length = email?.length ?: 0

// ์กฐ๊ฑด๋ฌธ
val result = if (age >= 18) "์„ฑ์ธ" else "๋ฏธ์„ฑ๋…„"

// when (switch ๋Œ€์ฒด)
when (score) {
in 90..100 -> "A"
in 80..89 -> "B"
else -> "C"
}
```

## 4. ํ•จ์ˆ˜

```kotlin
fun greet(name: String): String {
return "Hello, $name!"
}

// ๋‹จ์ผ ํ‘œํ˜„์‹
fun add(a: Int, b: Int) = a + b

// ๊ธฐ๋ณธ๊ฐ’
fun greet(name: String = "Guest") = "Hello, $name"

// ๋žŒ๋‹ค
val double = { x: Int -> x * 2 }
```

## 5. ํด๋ž˜์Šค

```kotlin
// ๊ธฐ๋ณธ ํด๋ž˜์Šค
class User(val name: String, var age: Int) {
fun greet() = "Hello, $name"
}

// ๋ฐ์ดํ„ฐ ํด๋ž˜์Šค (equals, hashCode, copy ์ž๋™ ์ƒ์„ฑ)
data class Product(val id: Int, val name: String, val price: Double)

// ์‚ฌ์šฉ
val user = User("Kim", 25)
val product = Product(1, "Laptop", 999.99)
val copy = product.copy(price = 899.99)
```

## 6. Jetpack Compose ๊ธฐ์ดˆ

```kotlin
@Composable
fun Greeting(name: String) {
Text(
text = "Hello, $name!",
fontSize = 24.sp,
color = Color.Blue
)
}

@Preview
@Composable
fun PreviewGreeting() {
Greeting("Android")
}
```

## 7. ์ƒํƒœ ๊ด€๋ฆฌ

```kotlin
@Composable
fun Counter() {
var count by remember { mutableStateOf(0) }

Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("Count: $count", fontSize = 24.sp)

Button(onClick = { count++ }) {
Text("Add")
}
}
}
```

## 8. ๋ ˆ์ด์•„์›ƒ

```kotlin
// ์„ธ๋กœ ๋ฐฐ์น˜
Column(
modifier = Modifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text("Title")
Text("Subtitle")
}

// ๊ฐ€๋กœ ๋ฐฐ์น˜
Row(
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
) {
Text("Left")
Text("Right")
}

// ๊ฒน์น˜๊ธฐ
Box(contentAlignment = Alignment.Center) {
Image(painter = painterResource(R.drawable.bg), contentDescription = null)
Text("Overlay")
}
```

## 9. ๋ฆฌ์ŠคํŠธ

```kotlin
@Composable
fun ProductList(products: List<Product>) {
LazyColumn(
contentPadding = PaddingValues(16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
items(products) { product ->
ProductCard(product)
}
}
}

@Composable
fun ProductCard(product: Product) {
Card(modifier = Modifier.fillMaxWidth()) {
Column(modifier = Modifier.padding(16.dp)) {
Text(product.name, fontWeight = FontWeight.Bold)
Text("$${product.price}")
}
}
}
```

## 10. ๋„ค๋น„๊ฒŒ์ด์…˜

```kotlin
@Composable
fun AppNavigation() {
val navController = rememberNavController()

NavHost(navController = navController, startDestination = "home") {
composable("home") {
HomeScreen(onNavigate = { navController.navigate("detail/$it") })
}
composable("detail/{id}") { backStackEntry ->
val id = backStackEntry.arguments?.getString("id")
DetailScreen(id = id)
}
}
}
```

## 11. Retrofit API ์—ฐ๋™

```kotlin
// API ์ธํ„ฐํŽ˜์ด์Šค
interface ApiService {
@GET("users")
suspend fun getUsers(): List<User>

@POST("users")
suspend fun createUser(@Body user: User): User
}

// Retrofit ์„ค์ •
val retrofit = Retrofit.Builder()
.baseUrl("https://api.example.com/")
.addConverterFactory(GsonConverterFactory.create())
.build()

val api = retrofit.create(ApiService::class.java)

// ViewModel์—์„œ ์‚ฌ์šฉ
class UserViewModel : ViewModel() {
private val _users = MutableStateFlow<List<User>>(emptyList())
val users: StateFlow<List<User>> = _users

fun loadUsers() {
viewModelScope.launch {
_users.value = api.getUsers()
}
}
}
```

## 12. ์•ฑ ๋ฐฐํฌ
1. Build > Generate Signed Bundle / APK
2. ํ‚ค์Šคํ† ์–ด ์ƒ์„ฑ ๋˜๋Š” ์„ ํƒ
3. release ๋นŒ๋“œ ์ƒ์„ฑ
4. Google Play Console ์—…๋กœ๋“œ
5. ์Šคํ† ์–ด ๋“ฑ๋ก ์ •๋ณด ์ž‘์„ฑ
6. ์‹ฌ์‚ฌ ์ œ์ถœ

## ์ถ”์ฒœ ํ•™์Šต ์ˆœ์„œ
1. Kotlin ๊ธฐ๋ณธ ๋ฌธ๋ฒ•
2. Compose UI ๊ธฐ์ดˆ
3. ์ƒํƒœ ๊ด€๋ฆฌ
4. ๋„ค๋น„๊ฒŒ์ด์…˜
5. API ์—ฐ๋™ ๋ฐ ๋ฐฐํฌ