Skip to content

Commit

Permalink
[simba/#13] feat 3주차 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
BAEK0111 committed Apr 20, 2024
1 parent 62e0064 commit b717775
Show file tree
Hide file tree
Showing 26 changed files with 1,173 additions and 641 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()
}
}
}
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
}
}
37 changes: 37 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,6 +1,8 @@
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
Expand All @@ -9,11 +11,16 @@ 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 @@ -30,12 +37,42 @@ class HomeFragment : Fragment() {
(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)
}
}
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.FragmentLockerSavedalbumBinding

class SavedAlbumFragment : Fragment() {

lateinit var binding: FragmentLockerSavedalbumBinding

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

}
22 changes: 22 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/SavedSongFragment.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.FragmentLockerSavedsongBinding

class SavedSongFragment : Fragment() {
lateinit var binding : FragmentLockerSavedsongBinding

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

return binding.root
}
}
Loading

0 comments on commit b717775

Please sign in to comment.