-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [nunu/#28] feat: 6주차 구현1 - item_album.xml 구현 * [nunu/#28] feat: 6주차 구현2 - 리사이클러뷰를 사용해서 화면 만들기 - 리사이클러뷰 클릭 이벤트 * [nunu/#28] feat: 6주차 구현3 - Play 버튼 클릭시 MiniPlayer에 동기화 - SongActivity intent 관련 문제 해결 * [nunu/#28] 6주차 구현4 - RecyclerView 문제점 해결 (SparseBooleanArray 사용)
1 parent
16d995a
commit a4cb646
Showing
26 changed files
with
626 additions
and
215 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.example.umc_6th | ||
|
||
data class Album( | ||
var title : String? = "", | ||
var artist : String? = "", | ||
var coverImage : Int? = null, | ||
var songs: ArrayList<Song>? = null | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 23 additions & 5 deletions
28
UMC_6th/app/src/main/java/com/example/umc_6th/LockerFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,39 @@ | ||
package com.example.umc_6th | ||
|
||
import android.os.Bundle | ||
import android.os.Handler | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import com.example.umc_6th.adapter.LockerPagerAdapter | ||
import com.example.umc_6th.databinding.FragmentHomeBinding | ||
import com.example.umc_6th.databinding.FragmentLockerBinding | ||
import com.google.android.material.tabs.TabLayoutMediator | ||
|
||
class LockerFragment : Fragment() { | ||
// 여기에 Fragment의 구현 내용을 작성합니다. | ||
private var _binding: FragmentLockerBinding? = null | ||
private val binding get() = _binding!! | ||
private val information = arrayListOf("저장한곡", "음악파일") | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// 여기에서 Fragment의 레이아웃을 인플레이트합니다. | ||
return inflater.inflate(R.layout.fragment_locker, container, false) | ||
): View { | ||
_binding = FragmentLockerBinding.inflate(inflater, container, false) | ||
|
||
val lockerAdapter = LockerPagerAdapter(this) | ||
binding.vpLocker.adapter = lockerAdapter | ||
TabLayoutMediator(binding.tbLocker, binding.vpLocker) { tab, position -> | ||
tab.text = information[position] | ||
}.attach() | ||
|
||
return binding.root | ||
} | ||
|
||
// 필요한 경우 다른 Fragment 생명주기 메소드를 오버라이드합니다. | ||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
UMC_6th/app/src/main/java/com/example/umc_6th/LockerMusicFileFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.umc_6th | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
|
||
class LockerMusicFileFragment : Fragment() { | ||
// 여기에 Fragment의 구현 내용을 작성합니다. | ||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
// 여기에서 Fragment의 레이아웃을 인플레이트합니다. | ||
return inflater.inflate(R.layout.fragment_locker_music_file, container, false) | ||
} | ||
|
||
// 필요한 경우 다른 Fragment 생명주기 메소드를 오버라이드합니다. | ||
} |
77 changes: 77 additions & 0 deletions
77
UMC_6th/app/src/main/java/com/example/umc_6th/LockerSavedSongFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.example.umc_6th | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.example.umc_6th.adapter.LockerAlbumRecyclerAdapter | ||
import com.example.umc_6th.databinding.FragmentLockerSavedSongBinding | ||
import com.google.gson.Gson | ||
|
||
class LockerSavedSongFragment : Fragment() { | ||
private var albumDatas = ArrayList<Album>() | ||
lateinit var binding : FragmentLockerSavedSongBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
binding = FragmentLockerSavedSongBinding.inflate(inflater, container, false) | ||
|
||
albumDatas.apply { | ||
add(Album("Love wins all", "아이유 (IU)", R.drawable.img_album_lovewinsall)) | ||
add(Album("해야 (HEYA)", "IVE", R.drawable.img_album_heya)) | ||
add(Album("Supernova", "에스파 (aespa)", R.drawable.img_album_supernova)) | ||
add(Album("Lilac", "아이유 (IU)", R.drawable.img_album_exp2)) | ||
add(Album("Drama", "에스파 (aespa)", R.drawable.img_album_drama)) | ||
add(Album("Weekend", "태연 (Tae Yeon)", R.drawable.img_album_exp6)) | ||
add(Album("Love wins all", "아이유 (IU)", R.drawable.img_album_lovewinsall)) | ||
add(Album("해야 (HEYA)", "IVE", R.drawable.img_album_heya)) | ||
add(Album("Supernova", "에스파 (aespa)", R.drawable.img_album_supernova)) | ||
add(Album("Lilac", "아이유 (IU)", R.drawable.img_album_exp2)) | ||
add(Album("Drama", "에스파 (aespa)", R.drawable.img_album_drama)) | ||
add(Album("Weekend", "태연 (Tae Yeon)", R.drawable.img_album_exp6)) | ||
add(Album("Love wins all", "아이유 (IU)", R.drawable.img_album_lovewinsall)) | ||
add(Album("해야 (HEYA)", "IVE", R.drawable.img_album_heya)) | ||
add(Album("Supernova", "에스파 (aespa)", R.drawable.img_album_supernova)) | ||
add(Album("Lilac", "아이유 (IU)", R.drawable.img_album_exp2)) | ||
add(Album("Drama", "에스파 (aespa)", R.drawable.img_album_drama)) | ||
add(Album("Weekend", "태연 (Tae Yeon)", R.drawable.img_album_exp6)) | ||
} | ||
val lockerAlbumRecyclerAdapter = LockerAlbumRecyclerAdapter(albumDatas) | ||
binding.rvLockerSavedSong.adapter = lockerAlbumRecyclerAdapter | ||
binding.rvLockerSavedSong.layoutManager = LinearLayoutManager(requireActivity()) | ||
|
||
lockerAlbumRecyclerAdapter.setItemClickListener(object : LockerAlbumRecyclerAdapter.OnItemClickListener { | ||
override fun onRemoveAlbum(position: Int) { | ||
lockerAlbumRecyclerAdapter.removeItem(position) | ||
} | ||
|
||
override fun onItemClick(album: Album) { | ||
changeAlbumFragment(album) | ||
} | ||
}) | ||
|
||
return binding.root | ||
} | ||
|
||
private fun changeAlbumFragment(album: Album) { | ||
(context as MainActivity).supportFragmentManager.beginTransaction() | ||
.replace(R.id.main_container, AlbumFragment().apply { | ||
arguments = Bundle().apply { | ||
val gson = Gson() | ||
val albumToJson = gson.toJson(album) | ||
putString("album", albumToJson) | ||
} | ||
}) | ||
.commitAllowingStateLoss() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.umc_6th | ||
|
||
data class Song( | ||
var title : String? = "", | ||
var artist : String? = "", | ||
var coverImage : Int? = null, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
UMC_6th/app/src/main/java/com/example/umc_6th/adapter/AlbumRecyclerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.example.umc_6th.adapter | ||
|
||
class AlbumRecyclerAdapter { | ||
} |
73 changes: 73 additions & 0 deletions
73
UMC_6th/app/src/main/java/com/example/umc_6th/adapter/LockerAlbumRecyclerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.example.umc_6th.adapter | ||
|
||
import android.util.SparseBooleanArray | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.example.umc_6th.Album | ||
import com.example.umc_6th.databinding.ItemLockerAlbumBinding | ||
|
||
class LockerAlbumRecyclerAdapter(private val albumList: ArrayList<Album>) : RecyclerView.Adapter<LockerAlbumRecyclerAdapter.ViewHolder>() { | ||
|
||
private val switchStatus = SparseBooleanArray() | ||
override fun onCreateViewHolder( | ||
parent: ViewGroup, | ||
viewType: Int | ||
): LockerAlbumRecyclerAdapter.ViewHolder { | ||
val binding: ItemLockerAlbumBinding = ItemLockerAlbumBinding | ||
.inflate(LayoutInflater.from(parent.context), parent, false) | ||
|
||
return ViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: LockerAlbumRecyclerAdapter.ViewHolder, position: Int) { | ||
holder.bind(albumList[position]) | ||
holder.itemView.setOnClickListener { | ||
itemClickListener.onItemClick(albumList[position]) | ||
} | ||
|
||
holder.binding.imgItemLockerAlbumMore.setOnClickListener { | ||
itemClickListener.onRemoveAlbum(position) | ||
} | ||
|
||
val switch = holder.binding.switchRV | ||
switch.isChecked = switchStatus[position] | ||
switch.setOnClickListener { | ||
if (switch.isChecked) { | ||
switchStatus.put(position, true) | ||
} | ||
else { | ||
switchStatus.put(position, false) | ||
} | ||
|
||
notifyItemChanged(position) | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int = albumList.size | ||
|
||
inner class ViewHolder(val binding: ItemLockerAlbumBinding): RecyclerView.ViewHolder(binding.root){ | ||
|
||
fun bind(album: Album){ | ||
binding.txItemLockerAlbumTitle.text = album.title | ||
binding.txItemLockerAlbumArtist.text = album.artist | ||
binding.imgItemLockerAlbumCover.setImageResource(album.coverImage!!) | ||
} | ||
} | ||
|
||
interface OnItemClickListener { | ||
fun onItemClick(album : Album) | ||
abstract fun onRemoveAlbum(position: Int) | ||
} | ||
|
||
private lateinit var itemClickListener : OnItemClickListener | ||
|
||
fun setItemClickListener(onItemClickListener: OnItemClickListener) { | ||
this.itemClickListener = onItemClickListener | ||
} | ||
|
||
fun removeItem(position: Int){ | ||
albumList.removeAt(position) | ||
notifyDataSetChanged() | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
UMC_6th/app/src/main/java/com/example/umc_6th/adapter/LockerPagerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.example.umc_6th.adapter | ||
|
||
import androidx.fragment.app.Fragment | ||
import androidx.viewpager2.adapter.FragmentStateAdapter | ||
import com.example.umc_6th.LockerMusicFileFragment | ||
import com.example.umc_6th.LockerSavedSongFragment | ||
|
||
class LockerPagerAdapter (fragment : Fragment) : FragmentStateAdapter(fragment) { | ||
override fun getItemCount(): Int = 2 | ||
|
||
override fun createFragment(position: Int): Fragment { | ||
return when(position){ | ||
0 -> LockerSavedSongFragment() | ||
else -> LockerMusicFileFragment() | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.