Skip to content

Commit

Permalink
[maro/#28] feat && fix :: 앨범 상세 정보 개발 && 앱 꺼짐 에러 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
leesumin0526 committed May 20, 2024
1 parent 6559808 commit c6ad832
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 138 deletions.
21 changes: 15 additions & 6 deletions .idea/workspace.xml

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

22 changes: 18 additions & 4 deletions UMC_6th/app/src/main/java/com/example/umc_6th/AlbumFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ import com.example.umc_6th.databinding.FragmentAlbumBinding
import com.example.umc_6th.databinding.FragmentAlbumBinding.inflate
import com.example.umc_6th.databinding.FragmentSongBinding
import com.google.android.material.tabs.TabLayoutMediator
import com.google.gson.Gson

class AlbumFragment : Fragment() {
lateinit var binding: FragmentAlbumBinding
private var gson : Gson = Gson()

private val information = arrayListOf("수록곡","상세정보","영상")
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = inflate(inflater,container,false)
binding = FragmentAlbumBinding.inflate(inflater,container,false)

val albumToJson = arguments?.getString("album")
val album = gson.fromJson(albumToJson, Album::class.java)
setInit(album)

binding.albumBackIv.setOnClickListener{
(context as MainActivity).supportFragmentManager.beginTransaction().
replace(R.id.main_frm,HomeFragment()).
Expand All @@ -33,10 +40,10 @@ class AlbumFragment : Fragment() {


setFragmentResultListener("TitleInfo") { requestKey, bundle ->
binding.albumTitleTv.text = bundle.getString("title")
binding.albumMusicTitleTv.text = bundle.getString("title")
}
setFragmentResultListener("SingerInfo") { requestKey, bundle ->
binding.albumSingerTv.text = bundle.getString("singer")
binding.albumSingerNameTv.text = bundle.getString("singer")
}

TabLayoutMediator(binding.albumContentTb,binding.albumContentVp){
Expand All @@ -46,4 +53,11 @@ class AlbumFragment : Fragment() {

return binding.root
}
}

private fun setInit(album : Album) {
binding.albumAlbumIv.setImageResource(album.coverImage!!)
binding.albumMusicTitleTv.text = album.title.toString()
binding.albumSingerNameTv.text = album.singer.toString()
}

}
25 changes: 22 additions & 3 deletions UMC_6th/app/src/main/java/com/example/umc_6th/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import android.widget.Button
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.gson.Gson

class HomeFragment : Fragment() {

Expand All @@ -36,6 +37,8 @@ class HomeFragment : Fragment() {
savedInstanceState: Bundle?

): View? {
binding = FragmentHomeBinding.inflate(inflater, container, false)

albumDatas.apply {
add(Album("Butter", "방탄소년단 (BTS)", R.drawable.img_album_exp))
add(Album("Lilac", "아이유 (IU)", R.drawable.img_album_exp2))
Expand All @@ -49,8 +52,6 @@ class HomeFragment : Fragment() {
binding.homeTodayMusicAlbumRv.adapter = albumRVAdapter
binding.homeTodayMusicAlbumRv.layoutManager = LinearLayoutManager(requireActivity(), LinearLayoutManager.HORIZONTAL, false)

binding = FragmentHomeBinding.inflate(inflater, container, false)

val bannerAdapter = BannerVPAdapter(this)
bannerAdapter.addFragment(BannerFragment(R.drawable.img_home_viewpager_exp))
bannerAdapter.addFragment(BannerFragment(R.drawable.img_home_viewpager_exp2))
Expand All @@ -71,9 +72,27 @@ class HomeFragment : Fragment() {

binding.homePannelIndicator.setViewPager(binding.homePannelBackgroundVp)

albumRVAdapter.setItemClickListener(object : AlbumRVAdapter.OnItemClickListener {
override fun onItemClick(album : Album) {
changeToAlbumFragment(album)
}
})

return binding.root
}

private fun changeToAlbumFragment(album: Album) {
(context as MainActivity).supportFragmentManager.beginTransaction()
.replace(R.id.main_frm, AlbumFragment().apply {
arguments = Bundle().apply {
val gson = Gson()
val albumToJson = gson.toJson(album)
putString("album", albumToJson)
}
})
.commitAllowingStateLoss()
}

private fun autoSlide(adapter: BannerVPAdapter) {
timer.scheduleAtFixedRate(object : TimerTask() {
override fun run() {
Expand All @@ -88,4 +107,4 @@ class HomeFragment : Fragment() {
}
}, 3000, 3000)
}
}
}
Loading

0 comments on commit c6ad832

Please sign in to comment.