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/#4] week2 - compose / essential(필수) #7

Merged
merged 2 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ dependencies {
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3'
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:theme="@style/Theme.NOWSOPTAndroid"
tools:targetApi="31">
<activity
android:name=".LoginActivity"
android:name=".activity.LoginActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.NOWSOPTAndroid">
Expand All @@ -24,12 +24,12 @@
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:name=".activity.MainActivity"
android:exported="false"
android:label="@string/app_name"
android:theme="@style/Theme.NOWSOPTAndroid" />
<activity
android:name=".SignupActivity"
android:name=".activity.SignupActivity"
android:exported="false"
android:label="@string/app_name"
android:theme="@style/Theme.NOWSOPTAndroid" />
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/sopt/now/compose/BottomNaviItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sopt.now.compose

import androidx.compose.ui.graphics.vector.ImageVector

data class BottomNaviItem (
val icon: ImageVector,
val label: String
)
92 changes: 92 additions & 0 deletions app/src/main/java/com/sopt/now/compose/HomeView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.sopt.now.compose
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.sopt.now.compose.friend.Friend
import com.sopt.now.compose.friend.FriendItem
import com.sopt.now.compose.user.UserInfo
import com.sopt.now.compose.user.UserItem


val userList = listOf<UserInfo>(

Choose a reason for hiding this comment

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

내 정보는 리스트로 안해도 되지 않을까용

UserInfo(
id = "nagaeng",
password = "qazwsx!@#",
nickname = "이나경",
mbti = "ENTJ"
)
)

val friendList = listOf<Friend>(
Friend(
profileImage = R.drawable.baeinhyeok,
name = "배인혁",
selfDescription = "아 제 이상형입니다",
),
Friend(
profileImage = R.drawable.leejungha,
name = "이정하",
selfDescription = "귀여운 사람이 좋습니다",
),
Friend(
profileImage = R.drawable.leedohyun,
name = "이도현",
selfDescription = "청순한 상도 좋아합니다",
),
Friend(
profileImage = R.drawable.jangyeongdo,
name = "장영도",
selfDescription = "좋아했는데 이제는 좋아하지 않는..",
),
Friend(
profileImage = R.drawable.hahyunsang,
name = "하현상",
selfDescription = "말랑뽀짝 현상이",
),
Friend(
profileImage = R.drawable.seohocheol,
name = "서호철",
selfDescription = "이적한다면 따라갈지도..",
),
Friend(
profileImage = R.drawable.kimwonpil,
name = "김원필",
selfDescription = "김원필 직캠 보며 잠들기",
),
Friend(
profileImage = R.drawable.kimseokjin,
name = "김석진",
selfDescription = "인생 처음이자 마지막 최애입니다",
),
Friend(
profileImage = R.drawable.minhyeok,
name = "이민혁",
selfDescription = "수많은 민혁 중 몬스타엑스 이민혁",
),
Friend(
profileImage = R.drawable.last,
name = "이현우",
selfDescription = "이 분은 나이를 안 먹으시더라구요..",
),
)
@Composable
fun HomeView() {
Column(
modifier = Modifier
.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
) {
LazyColumn {
items(userList) {
UserItem(it)
}
items(friendList) {
FriendItem(it)
Copy link
Member

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
@@ -1,66 +1,63 @@
package com.sopt.now.compose

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
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 com.sopt.now.compose.ui.theme.NOWSOPTAndroidTheme
import com.sopt.now.compose.ui.theme.PurpleGrey40

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val id = intent.getStringExtra("id")
val password = intent.getStringExtra("password")
val nickname = intent.getStringExtra("nickname")

setContent {
MainActivityContent(id = id ?: "", password = password ?: "", nickname = nickname?: "")
}
}
}

import com.sopt.now.compose.user.UserInfo
@Composable
fun MainActivityContent(id: String, password: String, nickname: String) {
fun MypageView(userInfo: UserInfo) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
.fillMaxSize()
.padding(30.dp),
verticalArrangement = Arrangement.spacedBy(40.dp),
) {
Image (
painter = painterResource(id = R.drawable.apple), // 이미지 리소스 추가
contentDescription = null,
modifier = Modifier
.aspectRatio(1.5f) // aspectRatio 설정
.padding(top = 30.dp)
.padding(bottom = 10.dp)
)
UserInfoComposable(id, password, nickname)
if (userInfo != null) {
Image(
painter = painterResource(id = R.drawable.apple),
contentDescription = null,
modifier = Modifier
.size(110.dp)
.aspectRatio(1f)
)
Text(text = "안녕하세요, ${userInfo.nickname}님",
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
)
Spacer(modifier = Modifier.height(15.dp))
Text(text = userInfo.id)
Spacer(modifier = Modifier.height(15.dp))
Text(text = userInfo.password)
} else {
Text(
text = "사용자 정보를 불러올 수 없습니다.",
fontSize = 20.sp,
Comment on lines +46 to +48
Copy link
Member

Choose a reason for hiding this comment

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

string,,,추출,,,해조요,,,,

fontWeight = FontWeight.Bold,
modifier = Modifier.fillMaxWidth()
)
}
}
}

@Composable
}@Composable
fun UserInfoComposable(id: String, password: String, nickname: String) {
Column(
modifier = Modifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(text = "안녕하세요, $id 님!\n",
Text(text = "안녕하세요, $nickname 님!\n",
fontSize = 24.sp,
fontWeight = FontWeight.ExtraBold)

Expand All @@ -77,7 +74,7 @@ fun UserInfoComposable(id: String, password: String, nickname: String) {

Button(
onClick = { },

contentPadding = PaddingValues(start = 90.dp, end = 90.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Color.LightGray,
Expand All @@ -89,18 +86,5 @@ fun UserInfoComposable(id: String, password: String, nickname: String) {
)
}
}

}


@Preview(showBackground = true)
@Composable
fun MainPreview() {
NOWSOPTAndroidTheme {
UserInfoComposable(
id = "exampleId",
password = "examplePassword",
nickname = "exampleNickname"
)
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package com.sopt.now.compose
package com.sopt.now.compose.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Person
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
Expand All @@ -28,11 +21,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.content.ContextCompat.startActivity
import com.sopt.now.compose.ui.theme.NOWSOPTAndroidTheme

class LoginActivity : ComponentActivity() {
Expand Down Expand Up @@ -152,7 +143,7 @@ fun SoptComposable(
onClick = { if (isValid(userId, userPassword, getId ?: "", getPassword ?: "")) {
Success(context, userId, userPassword, userNickname, userMbti)
}
else Toast.makeText(context, "아이디 또는 비밀번호가 일치하지 않습니다", Toast.LENGTH_SHORT).show()
else Toast.makeText(context, "아이디 또는 비밀번호가 일치하지 않습니다", Toast.LENGTH_SHORT).show()
},
contentPadding = PaddingValues(start = 90.dp, end = 90.dp),
colors = ButtonDefaults.buttonColors(
Expand Down Expand Up @@ -191,6 +182,6 @@ fun SoptComposable(
@Composable
fun LoginPreview() {
NOWSOPTAndroidTheme {
SoptComposable(getId ="", getPassword ="", getNickname = "", getMbti = "")
SoptComposable(getId = "", getPassword = "", getNickname = "", getMbti = "")
}
}
}
Loading