Skip to content

Commit

Permalink
[FEAT/#1] 1주차 xml (로그인 및 회원가입 화면 구현)
Browse files Browse the repository at this point in the history
  • Loading branch information
nagaeng committed Apr 4, 2024
1 parent 2a55c2d commit 401b208
Show file tree
Hide file tree
Showing 8 changed files with 418 additions and 8 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ android {
kotlinOptions {
jvmTarget = '17'
}
buildFeatures {
viewBinding true
}
}

dependencies {
Expand All @@ -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'
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
android:theme="@style/Theme.NOWSOPTAndroid"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".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=".MainActivity"
android:exported="false"></activity>
<activity
android:name=".SignupActivity"
android:exported="false"></activity>
</application>

</manifest>
69 changes: 69 additions & 0 deletions app/src/main/java/com/sopt/now/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
13 changes: 12 additions & 1 deletion app/src/main/java/com/sopt/now/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
64 changes: 64 additions & 0 deletions app/src/main/java/com/sopt/now/SignupActivity.kt
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
}
90 changes: 90 additions & 0 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LoginActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="WELCOME TO NOW SOPT"
android:textSize="24dp"
android:textStyle="bold"
android:layout_marginTop="70dp"
android:textColor="#ab9bbf"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ID"
android:textSize="20dp"
android:layout_marginTop="200dp"
android:layout_marginStart="70dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="230dp"
android:layout_marginStart="70dp"
android:layout_marginEnd="70dp"
android:hint="ID를 입력하세요"
android:id="@+id/txtfield_id"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PASSWORD"
android:textSize="20dp"
android:layout_marginTop="320dp"
android:layout_marginStart="70dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="350dp"
android:layout_marginStart="70dp"
android:layout_marginEnd="70dp"
android:hint="PASSWORD를 입력하세요"
android:inputType="textPassword"
android:id="@+id/txtfield_pw"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<Button
android:id="@+id/btn_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="130dp"
android:paddingStart="40dp"
android:paddingEnd="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:text="로그인"
/>
<Button
android:id="@+id/btn_signup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="70dp"
android:paddingStart="40dp"
android:paddingEnd="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:text="회원가입"
/>

</androidx.constraintlayout.widget.ConstraintLayout>
58 changes: 52 additions & 6 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
android:text="MY PAGE"
android:textSize="24dp"
android:textStyle="bold"
android:layout_marginTop="70dp"
android:textColor="#ab9bbf"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="@+id/txtfield_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="190dp"
android:layout_marginStart="50dp"/>
<TextView
android:id="@+id/txtfield_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="380dp"
android:layout_marginStart="50dp"/>
<TextView
android:id="@+id/txtfield_pw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
app:layout_constraintTop_toBottomOf="@id/txtfield_id"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="16dp"
android:layout_marginStart="50dp"/>

<Button
android:id="@+id/btn_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="130dp"
android:paddingStart="40dp"
android:paddingEnd="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:text="수정하기"
/>


</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit 401b208

Please sign in to comment.