-
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.
Showing
19 changed files
with
418 additions
and
53 deletions.
There are no files selected for viewing
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 | ||
) |
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 생명주기 메소드를 오버라이드합니다. | ||
} |
65 changes: 65 additions & 0 deletions
65
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,65 @@ | ||
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)) | ||
} | ||
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
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, | ||
) |
57 changes: 57 additions & 0 deletions
57
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,57 @@ | ||
package com.example.umc_6th.adapter | ||
|
||
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>() { | ||
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) | ||
} | ||
} | ||
|
||
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.
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
Oops, something went wrong.