diff --git a/app/build.gradle b/app/build.gradle index ef8934d..66432e6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,6 +30,9 @@ android { kotlinOptions { jvmTarget = '17' } + buildFeatures { + viewBinding true + } } dependencies { @@ -38,6 +41,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.activity:activity:1.8.0' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3b8f448..3f49b4d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ android:theme="@style/Theme.NOWSOPTAndroid" tools:targetApi="31"> @@ -21,6 +21,12 @@ + + \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/LoginActivity.kt b/app/src/main/java/com/sopt/now/LoginActivity.kt new file mode 100644 index 0000000..b9dfa25 --- /dev/null +++ b/app/src/main/java/com/sopt/now/LoginActivity.kt @@ -0,0 +1,69 @@ +package com.sopt.now + +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import com.google.android.material.snackbar.Snackbar +import com.sopt.now.databinding.ActivityLoginBinding + +class LoginActivity : AppCompatActivity() { + private lateinit var binding: ActivityLoginBinding + + // 회원가입 시 받은 id랑 pw를 저장할 (임시) 변수 + private var registeredId: String? = null + private var registeredPassword: String? = null + private var registeredNickname: String? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = ActivityLoginBinding.inflate(layoutInflater) + setContentView(binding.root) + + binding.btnLogin.setOnClickListener { + // 임시 변수에 받은 id랑 pw를 저장 + val inputId = binding.txtfieldId.text.toString() + val inputPassword = binding.txtfieldPw.text.toString() + + if (inputId == registeredId && inputPassword == registeredPassword) { + val intent = Intent(this, MainActivity::class.java) + intent.putExtra("id", inputId) + intent.putExtra("password", inputPassword) + intent.putExtra("nickname", registeredNickname) + startActivity(intent) + } + else if (inputId != registeredId){ + Snackbar.make( + binding.root, + "아이디가 일치하지 않습니다", + Snackbar.LENGTH_LONG + ).show() + } + else if (inputPassword != registeredPassword){ + Snackbar.make( + binding.root, + "비밀번호가 일치하지 않습니다", + Snackbar.LENGTH_LONG + ).show() + } + } + binding.btnSignup.setOnClickListener { + val intent = Intent(this, SignupActivity::class.java) + startActivityForResult(intent, REQUEST_SIGNUP) + } + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (requestCode == 123 && resultCode == Activity.RESULT_OK) { + registeredId = data?.getStringExtra("id") + registeredPassword = data?.getStringExtra("password") + registeredNickname = data?.getStringExtra("nickname") + } + } + companion object { + const val REQUEST_SIGNUP = 123 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/MainActivity.kt b/app/src/main/java/com/sopt/now/MainActivity.kt index 23e7302..b010bd8 100644 --- a/app/src/main/java/com/sopt/now/MainActivity.kt +++ b/app/src/main/java/com/sopt/now/MainActivity.kt @@ -5,11 +5,22 @@ import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat +import com.sopt.now.databinding.ActivityMainBinding class MainActivity : AppCompatActivity() { + private lateinit var binding: ActivityMainBinding + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) + binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) + + val id = intent.getStringExtra("id") + val password = intent.getStringExtra("password") + val nickname = intent.getStringExtra("nickname") + binding.txtfieldId.text = "아이디: $id" + binding.txtfieldPw.text = "비밀번호: $password" + binding.txtfieldName.text = "안녕하세요, $nickname 님" } } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/SignupActivity.kt b/app/src/main/java/com/sopt/now/SignupActivity.kt new file mode 100644 index 0000000..37fd6cb --- /dev/null +++ b/app/src/main/java/com/sopt/now/SignupActivity.kt @@ -0,0 +1,64 @@ +package com.sopt.now + +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import android.widget.Toast +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import com.google.android.material.snackbar.Snackbar +import com.sopt.now.databinding.ActivitySignupBinding + +class SignupActivity : AppCompatActivity() { + private lateinit var binding: ActivitySignupBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = ActivitySignupBinding.inflate(layoutInflater) + setContentView(binding.root) + + binding.btnSignup.setOnClickListener { + val id = binding.txtfieldId.text.toString() + val password = binding.txtfieldPw.text.toString() + val nickname = binding.txtfieldName.text.toString() + val mbti = binding.txtfieldMbti.text.toString() + + if (id.isEmpty() || password.isEmpty() || nickname.isEmpty() || mbti.isEmpty()) { + Snackbar.make( + binding.root, + "모든 정보를 입력하세요", + Snackbar.LENGTH_LONG + ).show() + } else if (binding.txtfieldId.length() < 6 || binding.txtfieldId.length() > 10) { + Snackbar.make( + binding.root, + "아이디를 6~10자로 설정해주세요", + Snackbar.LENGTH_LONG + ).show() + } else if (binding.txtfieldPw.length() < 8 || binding.txtfieldPw.length() > 12) { + Snackbar.make( + binding.root, + "비밀번호를 8~12자로 설정해주세요", + Snackbar.LENGTH_LONG + ).show() + } else if (binding.txtfieldName.length() <= 0) { + Snackbar.make( + binding.root, + "닉네임은 한 글자 이상으로 설정해주세요", + Snackbar.LENGTH_LONG + ).show() + } else { + val resultIntent = Intent() + resultIntent.putExtra("id", id) + resultIntent.putExtra("password", password) + resultIntent.putExtra("nickname", nickname) + resultIntent.putExtra("mbti", mbti) + setResult(Activity.RESULT_OK, resultIntent) + Toast.makeText(this, "회원가입 성공!", Toast.LENGTH_SHORT).show() + finish() + } + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml new file mode 100644 index 0000000..b6f598a --- /dev/null +++ b/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,90 @@ + + + + + + + + +