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/week02 xml #3

Open
wants to merge 13 commits into
base: develop-xml
Choose a base branch
from
7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ android {
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildFeatures {
viewBinding = true
}
Copy link
Member

Choose a reason for hiding this comment

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

ํ˜น์‹œ ์ด ๋ถ€๋ถ„์€ ์ž˜ ๋ชป ๋“ค์–ด๊ฐ„ ๊ฑด๊ฐ€์š”??

}

buildTypes {
Expand All @@ -30,6 +33,9 @@ android {
kotlinOptions {
jvmTarget = '17'
}
buildFeatures {
viewBinding true
}
}

dependencies {
Expand All @@ -38,6 +44,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
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
21 changes: 20 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,33 @@
android:theme="@style/Theme.NOWSOPTAndroid"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".Activity.HomeActivity"
android:exported="false" />
<activity
android:name=".Activity.SignUpActivity"
android:exported="false" />
<activity
android:name=".Activity.LoginActivity"
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=".Activity.MainActivity"
android:exported="false" />

<activity
android:name=".Fragment.HomeFragment"
android:exported="false">

</activity>
Copy link
Member

Choose a reason for hiding this comment

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

fragment๋ผ์„œ activity ํƒœ๊ทธ๋กœ ๋”ฐ๋กœ ์ •์˜ ์•ˆํ•ด์ฃผ์…”๋„ ๋  ๊ฑฐ ๊ฐ™์•„์š”!


</application>

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

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.sopt.now.Fragment.HomeFragment
import com.sopt.now.Fragment.MyPageFragment
import com.sopt.now.Fragment.SearchFragment
import com.sopt.now.R
import com.sopt.now.databinding.ActivityHomeBinding
class HomeActivity : AppCompatActivity() {
private lateinit var binding: ActivityHomeBinding
private val nameId="ID"
private val namePassword = "PASSWORD"
private val nameNickname = "NICKNAME"
private val nameMbti = "MBTI"

private lateinit var userId: String
private lateinit var userPassword: String
private lateinit var userNickname: String
private lateinit var userMbti: String

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityHomeBinding.inflate(layoutInflater)
setContentView(binding.root)

Log.d("HomeActivity","HomeActivity onCreate")


userId = intent.getStringExtra(nameId).toString()
userPassword = intent.getStringExtra(namePassword).toString()
userNickname = intent.getStringExtra(nameNickname).toString()
userMbti = intent.getStringExtra(nameMbti).toString()

clickBottomNavigation()

val currentFragment = supportFragmentManager.findFragmentById(binding.fcvHome.id)
if (currentFragment == null) {
supportFragmentManager.beginTransaction()
.add(binding.fcvHome.id, HomeFragment(userNickname))
.commit()
}
}

private fun clickBottomNavigation() {
binding.bnvHome.setOnItemSelectedListener {
when (it.itemId) {
R.id.menu_home -> {
replaceFragment(HomeFragment(userNickname))
true
}

R.id.menu_search -> {
replaceFragment(SearchFragment())
true
}

R.id.menu_mypage -> {
replaceFragment(MyPageFragment(userId,userPassword,userNickname,userMbti))
true
}

else -> false
}
}
}

private fun replaceFragment(fragment: Fragment) {
supportFragmentManager.beginTransaction()
.replace(binding.fcvHome.id, fragment)
.commit()
}
}
73 changes: 73 additions & 0 deletions app/src/main/java/com/sopt/now/Activity/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.sopt.now.Activity


import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.Snackbar
import com.sopt.now.databinding.ActivityLoginBinding

class LoginActivity : AppCompatActivity() {
private lateinit var binding: ActivityLoginBinding
private val nameId="ID"
private val namePassword = "PASSWORD"
private val nameNickname = "NICKNAME"
private val nameMbti = "MBTI"

Choose a reason for hiding this comment

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

์ƒ์ˆ˜๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋” ์ข‹์€ ๋ฐฉ์‹์ด ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค !


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityLoginBinding.inflate(layoutInflater)
setContentView(binding.root)

val id = intent.getStringExtra(nameId)
val password = intent.getStringExtra(namePassword)
val nickname = intent.getStringExtra(nameNickname)
val mbti = intent.getStringExtra(nameMbti)


binding.loginBtn.setOnClickListener {
val enteredId = binding.editTextId.text.toString()
val enteredPassword = binding.editTextPw.text.toString()

when {
enteredId != id -> {
Snackbar.make(
binding.root,
"์•„์ด๋””๋ฅผ ํ™•์ธํ•˜์„ธ์š”.",
Snackbar.LENGTH_SHORT
).show()
}
enteredPassword != password -> {
Snackbar.make(
binding.root,
"๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ™•์ธํ•˜์„ธ์š”.",
Snackbar.LENGTH_SHORT
).show()
}
else -> {
Log.d("Login Success","Login Success")
val intentHome = Intent(this, HomeActivity::class.java).apply {
putExtra(nameId, id)
putExtra(namePassword, password)
putExtra(nameNickname, nickname)
putExtra(nameMbti, mbti)
}
Snackbar.make(
binding.root,
"๋กœ๊ทธ์ธ ์„ฑ๊ณต!",
Snackbar.LENGTH_SHORT
).show()
startActivity(intentHome)

}
}

}
binding.goSignupBtn.setOnClickListener {
val intentSignup = Intent(this, SignUpActivity::class.java)
startActivity(intentSignup)
}

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

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.Snackbar
import com.sopt.now.R
import com.sopt.now.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
private val nameId="ID"
private val namePassword = "PASSWORD"
private val nameNickname = "NICKNAME"
private val nameMbti = "MBTI"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater) //TODO: inflate ๋‘ ๋ฒˆ ํ•˜๋ฉด ์˜ค๋ฅ˜ ๊ณต๋ถ€
setContentView(binding.root)



val id = intent.getStringExtra(nameId)
val password = intent.getStringExtra(namePassword)
val nickname = intent.getStringExtra(nameNickname)
val mbti = intent.getStringExtra(nameMbti)

Snackbar.make(
binding.root,
"๋กœ๊ทธ์ธ ์„ฑ๊ณต!",
Snackbar.LENGTH_SHORT
).show()


binding.textNickname.text = getString(R.string.nickname,nickname)
binding.textMbti.text = getString(R.string.mbti,mbti)
binding.textId.text="$id"
binding.textPw.text="$password"



val mbtiImageName = mbti?.lowercase() + ".png"
val mbtiImageId = mbtiImageName.let { resources.getIdentifier(it, "drawable", packageName) }
// TODO: getIdentifier ๋ง๊ณ  ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ ํŒŒ์ผ ์ฐพ์•„๋ณด๊ธฐ
if (mbtiImageId != 0) {
binding.imageMbti.setImageResource(mbtiImageId)

}

val mbtiDescriptionMap = mapOf(
"ISFP" to R.string.isfp,
"ISFJ" to R.string.isfj,
"ISTP" to R.string.istp,
"ISTJ" to R.string.istj,
"INFP" to R.string.infp,
"INFJ" to R.string.infj,
"INTP" to R.string.intp,
"INTJ" to R.string.intj,
"ESFP" to R.string.esfp,
"ESFJ" to R.string.esfj,
"ESTP" to R.string.estp,
"ESTJ" to R.string.estj,
"ENFP" to R.string.enfp,
"ENFJ" to R.string.enfj,
"ENTP" to R.string.entp,
"ENTJ" to R.string.entj

)

val mbtiDescriptionResId = mbti?.let { mbtiDescriptionMap[it] }


val mbtiDescription = mbtiDescriptionResId?.let { getString(it) } ?: getString(R.string.default_description)

binding.textMbtiDes.text = mbtiDescription

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

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.Snackbar
import com.sopt.now.databinding.ActivitySignUpBinding

class SignUpActivity : AppCompatActivity() {
private lateinit var binding: ActivitySignUpBinding
private val nameId="ID"
private val namePassword = "PASSWORD"
private val nameNickname = "NICKNAME"
private val nameMbti = "MBTI"

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySignUpBinding.inflate(layoutInflater)
setContentView(binding.root)


binding.signupBtn.setOnClickListener {
val mbtiInput = binding.editTextMbti.text.toString().uppercase()

val id = binding.editTextId.text.toString()
val password = binding.editTextPw.text.toString()
val nickname = binding.editTextNn.text.toString()
val mbti = binding.editTextMbti.text.toString().uppercase()

when {
id.length !in 6..10 -> {
Snackbar.make(
binding.root,
"ID๋Š” 6~10๊ธ€์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.",
Snackbar.LENGTH_SHORT
).show()
}
password.length !in 8..12 -> {
Snackbar.make(
binding.root,
"Password๋Š” 8~12๊ธ€์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.",
Snackbar.LENGTH_SHORT
).show()
}
nickname.isEmpty() -> {
Snackbar.make(
binding.root,
"๋‹‰๋„ค์ž„์€ ํ•œ ๊ธ€์ž ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.",
Snackbar.LENGTH_SHORT
).show()
}
mbtiInput.length != 4 || !validMBTI(mbtiInput) -> {
Snackbar.make(
binding.root,
"MBTI ํ˜•์‹์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. (E/I, S/N, F/T, P/J)",
Snackbar.LENGTH_SHORT
).show()
}
else -> {
val intent = Intent(this, LoginActivity::class.java).apply {
putExtra(nameId, id)
putExtra(namePassword, password)
putExtra(nameNickname, nickname)
putExtra(nameMbti, mbti)
}
Snackbar.make(
binding.root,
"ํšŒ์›๊ฐ€์ž… ์„ฑ๊ณต",
Snackbar.LENGTH_SHORT
).show()
startActivity(intent)

Choose a reason for hiding this comment

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

์ด๋ ‡๊ฒŒ ๋กœ๊ทธ์ธ ์•กํ‹ฐ๋น„ํ‹ฐ๋กœ ์ด๋™ํ•œ๋’ค, ๋กœ๊ทธ์ธ ์•กํ‹ฐ๋น„ํ‹ฐ์—์„œ ๋’ค๋กœ๊ฐ€๊ธฐ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”?

}
}
}
}
}

fun validMBTI(mbti:String):Boolean{
val validMBTIPattern = Regex("[EI][SN][TF][JP]")
return validMBTIPattern.matches(mbti)
}
Loading