Skip to content

Commit

Permalink
[simba/#38] feat:: 회원가입, 로그인 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
BAEK0111 committed Jun 5, 2024
1 parent d3434ad commit 3a66370
Show file tree
Hide file tree
Showing 12 changed files with 671 additions and 15 deletions.
3 changes: 3 additions & 0 deletions UMC_6th/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
android:enabled="true"
android:exported="true"></service>

<activity android:name=".SignUpActivity"/>
<activity android:name=".LoginActivity"/>

<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class LockerAlbumRVAdapter () : RecyclerView.Adapter<LockerAlbumRVAdapter.ViewHo

private val switchStatus = SparseBooleanArray()
private val songs = ArrayList<Song>()
private var isGrayOverlayEnabled = false

override fun onCreateViewHolder(
parent: ViewGroup,
Expand All @@ -31,6 +32,14 @@ class LockerAlbumRVAdapter () : RecyclerView.Adapter<LockerAlbumRVAdapter.ViewHo
removeSong(position) // 화면에서 아이템 제거
}

// 항목 배경색 변경
// if (isGrayOverlayEnabled) {
// holder.binding.root.setBackgroundColor(holder.binding.root.context.getColor(R.color.gray_transparent))
// } else {
// holder.binding.root.setBackgroundColor(holder.binding.root.context.getColor(R.color.transparent))
// }


val switch = holder.binding.switchRV
switch.isChecked = switchStatus[position]
switch.setOnClickListener {
Expand Down Expand Up @@ -78,5 +87,4 @@ class LockerAlbumRVAdapter () : RecyclerView.Adapter<LockerAlbumRVAdapter.ViewHo
songs.removeAt(position)
notifyDataSetChanged()
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.umc_6th

import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
Expand Down Expand Up @@ -37,6 +38,10 @@ class LockerFragment : Fragment() {
bottomSheetFragment.show(requireFragmentManager(),"BottomSheetDialog")
}

binding.lockerLoginTv.setOnClickListener {
startActivity(Intent(activity, LoginActivity::class.java))
}

return binding.root
}
}
21 changes: 21 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.umc_6th

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.umc_6th.databinding.ActivityLoginBinding

class LoginActivity:AppCompatActivity() {

lateinit var binding : ActivityLoginBinding

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

binding.loginSignUpTv.setOnClickListener {
startActivity(Intent(this, SignUpActivity::class.java))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ class MainActivity : AppCompatActivity() {
}

binding.mainPlayerCl.setOnClickListener {
// val intent = Intent(this, SongActivity::class.java)
// intent.putExtra("title", song.title)
// intent.putExtra("singer", song.singer)
// intent.putExtra("second", song.second)
// intent.putExtra("playTime", song.playTime)
// intent.putExtra("isPlaying", song.isPlaying)
// intent.putExtra("music",song.music)
val editor = getSharedPreferences("song", MODE_PRIVATE).edit()
editor.putInt("songId", song.id)
editor.apply()
Expand Down Expand Up @@ -235,7 +228,7 @@ class MainActivity : AppCompatActivity() {
0,
240,
false,
"music_bbom",
"music_bboom",
R.drawable.img_album_exp5,
false,
4
Expand Down
49 changes: 49 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/SignUpActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.example.umc_6th

import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.umc_6th.databinding.ActivitySignupBinding

class SignUpActivity : AppCompatActivity(){

lateinit var binding : ActivitySignupBinding

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

binding.signUpSignUpBtn.setOnClickListener{
signUp()
}
}

private fun getUser() : User{
val email : String = binding.signUpIdEt.text.toString() + "@" + binding.signUpDirectInputEt.text.toString()
val pwd : String = binding.signUpPasswordEt.text.toString()

return User(email, pwd)
}

private fun signUp() {
if (binding.signUpIdEt.text.toString().isEmpty() || binding.signUpDirectInputEt.text.toString().isEmpty()){
Toast.makeText(this,"이메일 형식이 잘못되었습니다.",Toast.LENGTH_SHORT).show()
return
}
if (binding.signUpPasswordEt.text.toString() != binding.signUpPasswordCheckEt.text.toString()){
Toast.makeText(this,"비밀번호가 일치하지 않습니다",Toast.LENGTH_SHORT).show()
return
}

val userDB = SongDatabase.getInstance(this)!!
userDB.userDao().insert(getUser())

val user = userDB.userDao().getUsers()
Log.d("Sign-up",user.toString())

Toast.makeText(this,"회원가입이 완료되었습니다.",Toast.LENGTH_SHORT).show()
return
}
}
14 changes: 10 additions & 4 deletions UMC_6th/app/src/main/java/com/example/umc_6th/SongActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.umc_6th

import android.annotation.SuppressLint
import android.app.ActivityManager
import android.content.Context
import android.content.Intent
Expand Down Expand Up @@ -47,9 +48,6 @@ class SongActivity : AppCompatActivity() {
// setPlayer(song)
initClickListener()

var title : String? = null
var singer : String? = null

// if(intent.hasExtra("title") && intent.hasExtra("singer")){
// title = intent.getStringExtra("title")
// singer = intent.getStringExtra("singer")
Expand Down Expand Up @@ -176,6 +174,8 @@ class SongActivity : AppCompatActivity() {
}

private fun moveSong(direct: Int){
Log.d("moveSong", "현재 위치: $nowPos, 이동 방향: $direct, 총 곡 수: ${songs.size}")

if(nowPos + direct < 0){
// nowPos = songs.size -1
CustomSnackbar.make(binding.root, "처음 곡입니다.").show()
Expand Down Expand Up @@ -215,14 +215,20 @@ class SongActivity : AppCompatActivity() {
binding.songProgressSb.progress = (song.second * 1000 / song.playTime)

val music = resources.getIdentifier(song.music,"raw",this.packageName)

Log.d("setPlayer", "음악 리소스 ID: $music")
if (music == 0) {
Log.e("setPlayer", "음악 리소스 ID를 찾을 수 없습니다: ${song.music}")
return
}

mediaPlayer = MediaPlayer.create(this,music)

if(song.isLike){
binding.songLikeIv.setImageResource(R.drawable.ic_my_like_on)
} else{
binding.songLikeIv.setImageResource(R.drawable.ic_my_like_off)
}

setPlayerStatus(song.isPlaying)
}

Expand Down
4 changes: 2 additions & 2 deletions UMC_6th/app/src/main/java/com/example/umc_6th/SongDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

@Database(entities = [Song::class, Album::class], version = 1)
@Database(entities = [Song::class, Album::class, User::class], version = 1)
abstract class SongDatabase: RoomDatabase() {
abstract fun songDao(): SongDao
abstract fun albumDao() : AlbumDao

abstract fun userDao() : UserDao
companion object{
private var instance: SongDatabase? = null

Expand Down
12 changes: 12 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/User.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.umc_6th

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "UserTable")
data class User(
var email : String,
var password : String
){
@PrimaryKey(autoGenerate = true) var id : Int = 0
}
17 changes: 17 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/UserDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.umc_6th

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query

@Dao
interface UserDao {
@Insert
fun insert(user : User)

@Query("SELECT * FROM UserTable")
fun getUsers() : List<User>

@Query("SELECT * FROM usertable WHERE email = :email AND password = :password")
fun getUser(email : String ,password : String) : User?
}
Loading

0 comments on commit 3a66370

Please sign in to comment.