Skip to content

Commit

Permalink
[maro/#43] feat :: 9주차 구현 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
leesumin0526 committed Jun 18, 2024
1 parent 0bbe085 commit 3d3fcde
Show file tree
Hide file tree
Showing 9 changed files with 633 additions and 348 deletions.
45 changes: 35 additions & 10 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions UMC_6th/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,15 @@ dependencies {
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
// Retrofit
implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2")
implementation("com.squareup.retrofit2:adapter-rxjava2:2.9.0")
// okHttp
implementation("com.squareup.okhttp3:okhttp:4.9.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.9.0")
// Glide
implementation("com.github.bumptech.glide:glide:4.12.0")
annotationProcessor("com.github.bumptech.glide:compiler:4.12.0")
}
2 changes: 1 addition & 1 deletion UMC_6th/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
Expand Down
53 changes: 40 additions & 13 deletions UMC_6th/app/src/main/java/com/example/umc_6th/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.example.umc_6th
package com.chrome.umcflo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.umc_6th.LoginView
import com.example.umc_6th.MainActivity
import com.example.umc_6th.User
import com.example.umc_6th.databinding.ActivityLoginBinding

class LoginActivity : AppCompatActivity() {

class LoginActivity : AppCompatActivity(), LoginView {

lateinit var binding : ActivityLoginBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityLoginBinding.inflate(layoutInflater)
Expand All @@ -24,6 +28,7 @@ class LoginActivity : AppCompatActivity() {
login()
}
}

private fun login() {
if (binding.loginIdEt.text.toString().isEmpty() || binding.loginDirectInputEt.text.toString().isEmpty()) {
Toast.makeText(this, "이메일을 입력해주세요", Toast.LENGTH_SHORT).show()
Expand All @@ -38,16 +43,21 @@ class LoginActivity : AppCompatActivity() {
val email : String = binding.loginIdEt.text.toString() + "@" + binding.loginDirectInputEt.text.toString()
val pwd : String = binding.loginPasswordEt.text.toString()

val songDB = SongDatabase.getInstance(this)!!
val user = songDB.userDao().getUser(email, pwd)
// val songDB = SongDatabase.getInstance(this)!!
// val user = songDB.userDao().getUser(email, pwd)
//
// if (user != null) {
// Log.d("LoginActivity", user.id.toString())
// saveJwt(user.id)
// startMainActivity()
// } else {
// Toast.makeText(this, "회원 정보가 존재하지 않습니다", Toast.LENGTH_SHORT).show()
// }

if (user != null) {
Log.d("LoginActivity", user.id.toString())
saveJwt(user.id)
startMainActivity()
} else {
Toast.makeText(this, "회원 정보가 존재하지 않습니다", Toast.LENGTH_SHORT).show()
}
val authService = AuthService()
authService.setLoginView(this)

authService.login(User(email, pwd, ""))
}

private fun saveJwt(jwt : Int) {
Expand All @@ -58,8 +68,25 @@ class LoginActivity : AppCompatActivity() {
editor.apply()
}

private fun saveJwtFromServer(jwt : String) {
val spf = getSharedPreferences("auth2", MODE_PRIVATE)
val editor = spf.edit()

editor.putString("jwt", jwt)
editor.apply()
}

private fun startMainActivity() {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}

override fun onLoginSuccess(code : Int, result: Result) {
saveJwtFromServer(result.jwt)
startMainActivity()
}

override fun onLoginFailure(message : String) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}
}
72 changes: 23 additions & 49 deletions UMC_6th/app/src/main/java/com/example/umc_6th/LookFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.umc_6th

import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
Expand All @@ -11,7 +12,7 @@ import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.umc_6th.databinding.FragmentLookBinding

class LookFragment : Fragment() {
class LookFragment : Fragment(), LookView {

lateinit var binding: FragmentLookBinding
private lateinit var songDB: SongDatabase
Expand Down Expand Up @@ -47,66 +48,39 @@ class LookFragment : Fragment() {
binding = FragmentLookBinding.inflate(inflater, container, false)
songDB = SongDatabase.getInstance(requireContext())!!

// 스크롤 뷰 초기화
scrollView = binding.lookSv

// 버튼 초기화
chartBtn = binding.lookChartBtn
videoBtn = binding.lookVideoBtn
genreBtn = binding.lookGenreBtn
situationBtn = binding.lookSituationBtn
audioBtn = binding.lookAudioBtn
atmosphereBtn = binding.lookAtmostphereBtn

buttonList = listOf(chartBtn, videoBtn, genreBtn, situationBtn, audioBtn, atmosphereBtn)

// 텍스트 초기화
chartTv = binding.lookChartTv
videoTv = binding.lookVideoTv
genreTv = binding.lookGenreTv
situationTv = binding.lookSituationTv
audioTv = binding.lookAudioTv
atmosphereTv = binding.lookAtmostphereTv

textList = listOf(chartTv, videoTv, genreTv, situationTv, audioTv, atmosphereTv)

setButtonClickListeners()

return binding.root
}

override fun onStart() {
super.onStart()
initRecyclerview()
getSongs()
}

private fun initRecyclerview(){
val recyclerView = binding.lookChartSongRv
recyclerView.layoutManager = LinearLayoutManager(requireActivity())
val lookAlbumRVAdapter = LockerAlbumRVAdapter()
private fun initRecyclerView(result: FloChartResult) {
floCharAdapter = SongRVAdapter(requireContext(), result)

binding.lookChartSongRv.adapter = lookAlbumRVAdapter
lookAlbumRVAdapter.addSongs(songDB.songDao().getSongs() as ArrayList<Song>)
binding.lookFloChartRv.adapter = floCharAdapter
}

private fun setButtonClickListeners() {
for (i in buttonList.indices) {
val button = buttonList[i]
private fun getSongs() {
val songService = SongService()
songService.setLookView(this)

songService.getSongs()

}

override fun onGetSongLoading() {
binding.lookLoadingPb.visibility = View.VISIBLE
}

button.setOnClickListener {
initButton(i)
}
}
override fun onGetSongSuccess(code: Int, result: FloChartResult) {
binding.lookLoadingPb.visibility = View.GONE
initRecyclerView(result)
}

private fun initButton(idx : Int) {
for(presentBtn : Button in buttonList) {
if(presentBtn == buttonList[idx]) {
presentBtn.setBackgroundResource(R.drawable.selected_button)
} else {
presentBtn.setBackgroundResource(R.drawable.not_selected_button)
}
}
scrollView.smoothScrollTo(0, textList[idx].top)
override fun onGetSongFailure(code: Int, message: String) {
binding.lookLoadingPb.visibility = View.GONE
Log.d("LOOK-FRAG/SONG-RESPONSE", message)
}
}
8 changes: 8 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,17 @@ class MainActivity : AppCompatActivity() {
val intent = Intent(this,SongActivity::class.java)
startActivity(intent)
activityResultLauncher.launch(intent)

Log.d("MainActivity", getJwt().toString())
}
}

private fun getJwt() : String? {
val spf = this.getSharedPreferences("auth2", MODE_PRIVATE)

return spf!!.getString("jwt", "")
}

override fun onResume() {
super.onResume()
// val sharedPreferences = getSharedPreferences("song", MODE_PRIVATE)
Expand Down
Loading

0 comments on commit 3d3fcde

Please sign in to comment.