Skip to content

Commit

Permalink
[maro/#38] feat :: 저장 앨범 탭, 둘러보기 페이지 제작
Browse files Browse the repository at this point in the history
  • Loading branch information
leesumin0526 committed Jun 5, 2024
1 parent 5b5844c commit b4c3820
Show file tree
Hide file tree
Showing 5 changed files with 404 additions and 18 deletions.
26 changes: 15 additions & 11 deletions .idea/workspace.xml

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

94 changes: 92 additions & 2 deletions UMC_6th/app/src/main/java/com/example/umc_6th/LookFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,37 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ScrollView
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.umc_6th.databinding.FragmentLookBinding

class LookFragment : Fragment() {

lateinit var binding: FragmentLookBinding
private lateinit var songDB: SongDatabase

private lateinit var chartBtn : Button
private lateinit var videoBtn : Button
private lateinit var genreBtn : Button
private lateinit var situationBtn : Button
private lateinit var audioBtn : Button
private lateinit var atmosphereBtn : Button

private lateinit var buttonList: List<Button>

private lateinit var chartTv : TextView
private lateinit var videoTv : TextView
private lateinit var genreTv : TextView
private lateinit var situationTv : TextView
private lateinit var audioTv : TextView
private lateinit var atmosphereTv : TextView

private lateinit var textList: List<TextView>

lateinit var scrollView : ScrollView

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
Expand All @@ -16,7 +44,69 @@ class LookFragment : Fragment() {
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_look, container, false)
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()
}

private fun initRecyclerview(){
val recyclerView = binding.lookChartSongRv
recyclerView.layoutManager = LinearLayoutManager(requireActivity())
val lookAlbumRVAdapter = LockerAlbumRVAdapter()

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

private fun setButtonClickListeners() {
for (i in buttonList.indices) {
val button = buttonList[i]

button.setOnClickListener {
initButton(i)
}
}
}

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)
}
}
6 changes: 6 additions & 0 deletions UMC_6th/app/src/main/res/drawable/not_selected_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="40dp" />
<solid android:color="@color/song_player_bg" />
</shape>
6 changes: 6 additions & 0 deletions UMC_6th/app/src/main/res/drawable/selected_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="40dp" />
<solid android:color="@color/select_color" />
</shape>
Loading

0 comments on commit b4c3820

Please sign in to comment.