Skip to content

Commit

Permalink
[simba/#28] feat::리사이클러뷰 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
BAEK0111 committed May 19, 2024
1 parent e693a85 commit ca3ed59
Show file tree
Hide file tree
Showing 9 changed files with 530 additions and 183 deletions.

Large diffs are not rendered by default.

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

This file was deleted.

This file was deleted.

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

import java.util.ArrayList

data class Album(
var title: String? = "",
var singer: String? = "",
var coverImg: Int? = null,
var songs: ArrayList<Song>? = null
)
32 changes: 32 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/AlbumRVAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.umc_6th

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.umc_6th.databinding.ItemAlbumBinding

class AlbumRVAdapter(private val albumlist:ArrayList<Album>) : RecyclerView.Adapter<AlbumRVAdapter.ViewHolder>() {

override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): AlbumRVAdapter.ViewHolder {
val binding: ItemAlbumBinding = ItemAlbumBinding.inflate(LayoutInflater.from(viewGroup.context),viewGroup,false)

return ViewHolder(binding)
}

override fun onBindViewHolder(holder: AlbumRVAdapter.ViewHolder, position: Int) {
holder.bind(albumlist[position])
}

override fun getItemCount(): Int = albumlist.size

inner class ViewHolder(val binding:ItemAlbumBinding): RecyclerView.ViewHolder(binding.root){
fun bind(album: Album){
binding.itemAlbumTitleTv.text = album.title
binding.itemAlbumSingerTv.text = album.singer
binding.itemAlbumCoverImgIv.setImageResource(album.coverImg!!)
}
}



}
24 changes: 20 additions & 4 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 @@ -9,8 +9,10 @@ import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.fragment.app.setFragmentResult
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.viewpager2.widget.ViewPager2
import com.example.umc_6th.databinding.FragmentHomeBinding
import java.util.ArrayList
import java.util.Timer
import java.util.TimerTask

Expand All @@ -20,6 +22,7 @@ class HomeFragment : Fragment() {

private val timer = Timer()
private val handler = Handler(Looper.getMainLooper())
private var albumDatas = ArrayList<Album>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -31,12 +34,25 @@ class HomeFragment : Fragment() {
): View? {
binding = FragmentHomeBinding.inflate(inflater,container,false)

binding.homeAlbumImg01Iv1.setOnClickListener{
setFragmentResult("TitleInfo", bundleOf("title" to binding.titleLilac.text.toString()))
setFragmentResult("SingerInfo", bundleOf("singer" to binding.singerIu.text.toString()))
(context as MainActivity).supportFragmentManager.beginTransaction().replace(R.id.main_frm,AlbumFragment()).commitAllowingStateLoss()
// binding.homeAlbumImg01Iv1.setOnClickListener{
// setFragmentResult("TitleInfo", bundleOf("title" to binding.titleLilac.text.toString()))
// setFragmentResult("SingerInfo", bundleOf("singer" to binding.singerIu.text.toString()))
// (context as MainActivity).supportFragmentManager.beginTransaction().replace(R.id.main_frm,AlbumFragment()).commitAllowingStateLoss()
// }

albumDatas.apply{
add(Album("Butter","방탄소년단(BTS)",R.drawable.img_album_exp))
add(Album("Lilac","아이유(IU)",R.drawable.img_album_exp2))
add(Album("Next Level","에스파(AESPA)",R.drawable.img_album_exp3))
add(Album("Boy with Luv","방탄소년단(BTS)",R.drawable.img_album_exp4))
add(Album("BBoom BBoom","모모랜드(MOMOLAND)",R.drawable.img_album_exp5))
add(Album("Weekend","태연(Tae Yeon)",R.drawable.img_album_exp6))
}

val albumRVAdapter = AlbumRVAdapter(albumDatas)
binding.homeTodayMusicAlbumRv.adapter = albumRVAdapter
binding.homeTodayMusicAlbumRv.layoutManager = LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false)


val bannerAdapter = BannerVPAdapter(this)
bannerAdapter.addFragment(BannerFragment(R.drawable.img_home_viewpager_exp))
Expand Down
Loading

0 comments on commit ca3ed59

Please sign in to comment.