Skip to content

Commit

Permalink
[simba/#13] feat 3주차 구현 (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
BAEK0111 authored Apr 24, 2024
1 parent fdd7b9a commit a4a13da
Show file tree
Hide file tree
Showing 29 changed files with 1,257 additions and 645 deletions.
1 change: 1 addition & 0 deletions UMC_6th/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ android {

dependencies {
implementation ("androidx.viewpager2:viewpager2:1.0.0")
implementation ("me.relex:circleindicator:2.1.6")
implementation("androidx.fragment:fragment-ktx:1.3.0")
implementation("androidx.core:core-ktx:1.10.1")
implementation("androidx.appcompat:appcompat:1.6.1")
Expand Down
67 changes: 42 additions & 25 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 @@ -9,50 +9,67 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.setFragmentResultListener
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

class AlbumFragment : Fragment() {
lateinit var binding: FragmentAlbumBinding

lateinit var binding : FragmentAlbumBinding

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

binding.albumBackIv.setOnClickListener{
(context as MainActivity).supportFragmentManager.beginTransaction().
replace(R.id.main_frm,HomeFragment()).
commitAllowingStateLoss()
}

val albumAdapter = AlbumVPAdapter(this)
binding.albumContentVp.adapter = albumAdapter


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

binding.albumBackIv.setOnClickListener{
(context as MainActivity).supportFragmentManager.beginTransaction().replace(R.id.main_frm,HomeFragment()).commitAllowingStateLoss()
}
TabLayoutMediator(binding.albumContentTb,binding.albumContentVp){
tab, position ->
tab.text = information[position]
}.attach()

binding.songLalacLayout.setOnClickListener{
Toast.makeText(activity,"LILAC",Toast.LENGTH_SHORT).show()
}
binding.songFluLayout.setOnClickListener {
Toast.makeText(activity,"FLU", Toast.LENGTH_SHORT).show()
}

binding.songCoinLayout.setOnClickListener {
Toast.makeText(activity,"Coin", Toast.LENGTH_SHORT).show()
}

binding.songSpringLayout.setOnClickListener {
Toast.makeText(activity,"봄 안녕 봄", Toast.LENGTH_SHORT).show()
}

binding.songCelebrityLayout.setOnClickListener {
Toast.makeText(activity,"Celebrity", Toast.LENGTH_SHORT).show()
}

binding.songSingLayout.setOnClickListener {
Toast.makeText(activity,"돌림노래 (Feat. DEAN)", Toast.LENGTH_SHORT).show()
}
// binding.songLalacLayout.setOnClickListener{
// Toast.makeText(activity,"LILAC",Toast.LENGTH_SHORT).show()
// }
//
// binding.songFluLayout.setOnClickListener {
// Toast.makeText(activity,"FLU", Toast.LENGTH_SHORT).show()
// }
//
// binding.songCoinLayout.setOnClickListener {
// Toast.makeText(activity,"Coin", Toast.LENGTH_SHORT).show()
// }
//
// binding.songSpringLayout.setOnClickListener {
// Toast.makeText(activity,"봄 안녕 봄", Toast.LENGTH_SHORT).show()
// }
//
// binding.songCelebrityLayout.setOnClickListener {
// Toast.makeText(activity,"Celebrity", Toast.LENGTH_SHORT).show()
// }
//
// binding.songSingLayout.setOnClickListener {
// Toast.makeText(activity,"돌림노래 (Feat. DEAN)", Toast.LENGTH_SHORT).show()
// }
return binding.root
}
}
16 changes: 16 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/AlbumVPAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.umc_6th

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter

class AlbumVPAdapter(fragment:Fragment) : FragmentStateAdapter(fragment){
override fun getItemCount(): Int = 3

override fun createFragment(position: Int): Fragment {
return when(position){
0 -> SongFragment()
1 -> DetailFragment()
else -> VideoFragment()
}
}
}
25 changes: 25 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/BannerFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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 com.example.umc_6th.databinding.FragmentBannerBinding


class BannerFragment(val imgRes : Int):Fragment() {

lateinit var binding: FragmentBannerBinding

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentBannerBinding.inflate(inflater,container,false)

binding.bannerImageIv.setImageResource(imgRes)
return binding.root
}
}
17 changes: 17 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/BannerVPAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.umc_6th

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter

class BannerVPAdapter (fragment: Fragment) :FragmentStateAdapter(fragment){

private val fragmentlist : ArrayList<Fragment> = ArrayList()
override fun getItemCount(): Int = fragmentlist.size

override fun createFragment(position: Int): Fragment = fragmentlist[position]

fun addFragment(fragment: Fragment){
fragmentlist.add(fragment)
notifyItemInserted(fragmentlist.size-1)
}
}
23 changes: 23 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/DetailFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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 com.example.umc_6th.databinding.FragmentDetailBinding

class DetailFragment : Fragment(){

lateinit var binding : FragmentDetailBinding

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentDetailBinding.inflate(inflater,container,false)

return binding.root
}
}
45 changes: 45 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package com.example.umc_6th

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.fragment.app.setFragmentResult
import androidx.viewpager2.widget.ViewPager2
import com.example.umc_6th.databinding.FragmentHomeBinding
import java.util.Timer
import java.util.TimerTask

class HomeFragment : Fragment() {

lateinit var binding: FragmentHomeBinding

private val timer = Timer()
private val handler = Handler(Looper.getMainLooper())

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
Expand All @@ -28,6 +36,43 @@ class HomeFragment : Fragment() {
setFragmentResult("SingerInfo", bundleOf("singer" to binding.singerIu.text.toString()))
(context as MainActivity).supportFragmentManager.beginTransaction().replace(R.id.main_frm,AlbumFragment()).commitAllowingStateLoss()
}


val bannerAdapter = BannerVPAdapter(this)
bannerAdapter.addFragment(BannerFragment(R.drawable.img_home_viewpager_exp))
bannerAdapter.addFragment(BannerFragment(R.drawable.img_home_viewpager_exp2))

binding.homeBannerVp.adapter = bannerAdapter
binding.homeBannerVp.orientation = ViewPager2.ORIENTATION_HORIZONTAL

binding.homeBannerIndicator.setViewPager(binding.homeBannerVp)

autoSlide(bannerAdapter)

val pannelVPAdapter = PannelVPAdapter(this)
pannelVPAdapter.addFragment(PannelFragment(R.drawable.img_first_album_default))
pannelVPAdapter.addFragment(PannelFragment(R.drawable.img_first_album_default))

binding.homePannelBackgroundVp.adapter = pannelVPAdapter
binding.homeBannerVp.orientation = ViewPager2.ORIENTATION_HORIZONTAL

binding.homePannelIndicator.setViewPager(binding.homePannelBackgroundVp)

return binding.root
}
private fun autoSlide(adapter: BannerVPAdapter) {
timer.scheduleAtFixedRate(object : TimerTask() {
override fun run() {
handler.post {
val nextItem = binding.homeBannerVp.currentItem + 1
if (nextItem < adapter.itemCount) {
binding.homeBannerVp.currentItem = nextItem
} else {
binding.homeBannerVp.currentItem = 0 // 순환
}
}
}
}, 3000, 3000)
}

}
19 changes: 13 additions & 6 deletions UMC_6th/app/src/main/java/com/example/umc_6th/LockerFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.umc_6th.databinding.FragmentLockerBinding
import com.google.android.material.tabs.TabLayoutMediator

class LockerFragment : Fragment() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}

lateinit var binding: FragmentLockerBinding
private var information = arrayListOf("저장한 곡", "음악파일", "저장앨범")
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_locker, container, false)
binding = FragmentLockerBinding.inflate(inflater, container, false)
val lockerAdapter = LockerVPAdapter(this)
binding.lockerContentVp.adapter = lockerAdapter
TabLayoutMediator(binding.lockerContentTb,binding.lockerContentVp){
tab,position ->
tab.text = information[position]
}.attach()
return binding.root
}

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

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter

class LockerVPAdapter(fragment: Fragment) :FragmentStateAdapter(fragment) {
override fun getItemCount(): Int = 3

override fun createFragment(position: Int): Fragment {
return when(position){
0 -> SavedSongFragment()
1 -> MusicFileFragment()
else -> SavedAlbumFragment()
}
}
}
22 changes: 22 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/MusicFileFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 com.example.umc_6th.databinding.FragmentLockerMusicfileBinding

class MusicFileFragment : Fragment() {
lateinit var binding:FragmentLockerMusicfileBinding

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentLockerMusicfileBinding.inflate(inflater,container,false)

return binding.root
}
}
28 changes: 28 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/PannelFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.umc_6th

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.umc_6th.databinding.FragmentPannelBinding

class PannelFragment(val imgRes : Int):Fragment() {

lateinit var binding : FragmentPannelBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentPannelBinding.inflate(inflater,container,false)
binding.pannelImageIv.setImageResource(imgRes)
return binding.root
}

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

import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter

class PannelVPAdapter(fragment:Fragment) : FragmentStateAdapter(fragment) {

private val fragmentList : ArrayList<Fragment> = ArrayList()

override fun getItemCount(): Int {
return fragmentList.size
}

override fun createFragment(position: Int): Fragment {
return fragmentList[position]
}

fun addFragment(fragment: Fragment){
fragmentList.add(fragment)
notifyItemInserted(fragmentList.size-1)
}
}
Loading

0 comments on commit a4a13da

Please sign in to comment.