Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kara/#13] feat: 3주차 구현 완료 #14

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UMC_6th/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies {
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
implementation ("androidx.fragment:fragment-ktx:1.6.2")
implementation ("me.relex:circleindicator:2.1.6")
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
Expand Down
28 changes: 10 additions & 18 deletions UMC_6th/app/src/main/java/com/example/myfirstapp/AlbumFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.example.myfirstapp.databinding.FragmentAlbumBinding
import com.google.android.material.tabs.TabLayoutMediator

class AlbumFragment : Fragment() {

lateinit var binding : FragmentAlbumBinding

private val information = arrayListOf("수록곡","상세정보","영상")

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -26,24 +29,13 @@ class AlbumFragment : Fragment() {
binding.albumBackIv.setOnClickListener{
(context as MainActivity).supportFragmentManager.beginTransaction().replace(R.id.main_container,HomeFragment()).commitAllowingStateLoss()
}
binding.albumSongLalacCl.setOnClickListener{
Toast.makeText(activity,"LILAC",Toast.LENGTH_SHORT).show()
}
binding.albumSongFluCl.setOnClickListener{
Toast.makeText(activity,"FLU",Toast.LENGTH_SHORT).show()
}
binding.albumSongCoinCl.setOnClickListener{
Toast.makeText(activity,"Coin",Toast.LENGTH_SHORT).show()
}
binding.albumSongSpringhelloCl.setOnClickListener{
Toast.makeText(activity,"봄 안녕 봄",Toast.LENGTH_SHORT).show()
}
binding.albumSongCelebrityCl.setOnClickListener{
Toast.makeText(activity,"Celebrity",Toast.LENGTH_SHORT).show()
}
binding.albumSongSingCl.setOnClickListener{
Toast.makeText(activity,"돌림노래 (Feat.DEAN)",Toast.LENGTH_SHORT).show()
}

val albumVpAdapter = AlbumVpAdapter(this)
binding.albumContentVp.adapter = albumVpAdapter
TabLayoutMediator(binding.albumContentTb,binding.albumContentVp){
tab ,position ->
tab.text =information[position]
}.attach()

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

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()
}
}

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

import android.content.res.Configuration
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.myfirstapp.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.bannerImgIv.setImageResource(imgRes)
return binding.root
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.myfirstapp

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 {
return fragmentList.size
}

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

fun addFragment(fragment: Fragment){
fragmentList.add(fragment)
notifyItemInserted(fragmentList.size-1)
}
}
22 changes: 22 additions & 0 deletions UMC_6th/app/src/main/java/com/example/myfirstapp/DetailFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.myfirstapp

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.myfirstapp.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
}
}
46 changes: 46 additions & 0 deletions UMC_6th/app/src/main/java/com/example/myfirstapp/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package com.example.myfirstapp

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2
import com.example.myfirstapp.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 onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand All @@ -29,6 +38,43 @@ class HomeFragment : Fragment() {
(context as MainActivity).supportFragmentManager.beginTransaction()
.replace(R.id.main_container, albumFragment).commitAllowingStateLoss()
}
val bannerAdapter = BannerVPAdapter(this)
bannerAdapter.addFragment(BannerFragment(R.drawable.img_home_viewpager_exp))
bannerAdapter.addFragment(BannerFragment(R.drawable.img_home_viewpager_exp2))
bannerAdapter.addFragment(BannerFragment(R.drawable.img_home_viewpager_exp))
bannerAdapter.addFragment(BannerFragment(R.drawable.img_home_viewpager_exp2))
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 pannelAdpater = PannelVPAdapter(this)
pannelAdpater.addFragment(PannelFragment(R.drawable.img_first_album_default))
pannelAdpater.addFragment(PannelFragment(R.drawable.img_first_album_default))
binding.homePannelBackgroundVp.adapter = pannelAdpater
binding.homePannelBackgroundVp.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)
}
}
18 changes: 15 additions & 3 deletions UMC_6th/app/src/main/java/com/example/myfirstapp/LockerFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,27 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.myfirstapp.databinding.FragmentLockerBinding
import com.google.android.material.tabs.TabLayoutMediator

class LockerFragment : Fragment() {
// 여기에 Fragment의 구현 내용을 작성합니다.
lateinit var binding: FragmentLockerBinding
private val information = arrayListOf("저장한 곡", "음악파일", "저장앨범")
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// 여기에서 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

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.myfirstapp

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()
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.myfirstapp

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.myfirstapp.databinding.FragmentDetailBinding
import com.example.myfirstapp.databinding.FragmentMusicfileBinding

class MusicFileFragment : Fragment(){

lateinit var binding: FragmentMusicfileBinding

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentMusicfileBinding.inflate(inflater,container,false)
return binding.root
}
}
27 changes: 27 additions & 0 deletions UMC_6th/app/src/main/java/com/example/myfirstapp/PannelFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.myfirstapp

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.myfirstapp.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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.myfirstapp

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,24 @@
package com.example.myfirstapp

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.myfirstapp.databinding.FragmentDetailBinding
import com.example.myfirstapp.databinding.FragmentMusicfileBinding
import com.example.myfirstapp.databinding.FragmentSavedalbumBinding

class SavedAlbumFragment : Fragment(){

lateinit var binding: FragmentSavedalbumBinding

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = FragmentSavedalbumBinding.inflate(inflater,container,false)
return binding.root
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.myfirstapp

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.myfirstapp.databinding.FragmentDetailBinding
import com.example.myfirstapp.databinding.FragmentMusicfileBinding
import com.example.myfirstapp.databinding.FragmentSavedsongBinding

class SavedSongFragment : Fragment(){

lateinit var binding: FragmentSavedsongBinding

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