Skip to content

Commit

Permalink
[simba/#13] feat : Viewpager 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
BAEK0111 committed Apr 20, 2024
2 parents 9b0e4df + 9f10a73 commit ba3b3f1
Show file tree
Hide file tree
Showing 133 changed files with 2,619 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/Android_A.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions UMC_6th/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion UMC_6th/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion UMC_6th/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ android {
namespace = "com.example.umc_6th"
compileSdk = 34


buildFeatures{
viewBinding = true
}
defaultConfig {
applicationId = "com.example.umc_6th"
minSdk = 24
Expand Down Expand Up @@ -36,7 +40,8 @@ android {
}

dependencies {

implementation ("androidx.viewpager2:viewpager2:1.0.0")
implementation("androidx.fragment:fragment-ktx:1.3.0")
implementation("androidx.core:core-ktx:1.10.1")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
Expand Down
3 changes: 3 additions & 0 deletions UMC_6th/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SongActivity"
android:exported="true"/>
</application>

</manifest>
58 changes: 58 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/AlbumFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.example.umc_6th

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
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

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

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

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

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
}
}
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)
}
}
41 changes: 41 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
@@ -0,0 +1,41 @@
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 androidx.core.os.bundleOf
import androidx.fragment.app.setFragmentResult
import androidx.viewpager2.widget.ViewPager2
import com.example.umc_6th.databinding.FragmentHomeBinding

class HomeFragment : Fragment() {

lateinit var binding: FragmentHomeBinding

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

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

binding.homeAlbumImg01Iv1.setOnClickListener{
setFragmentResult("TitleInfo", bundleOf("title" to binding.titleLilac.text.toString()))
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

return binding.root
}
}
22 changes: 22 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/LockerFragment.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 androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

class LockerFragment : Fragment() {

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

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)
}
}
22 changes: 22 additions & 0 deletions UMC_6th/app/src/main/java/com/example/umc_6th/LookFragment.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 androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

class LookFragment : Fragment() {

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

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_look, container, false)
}
}
86 changes: 85 additions & 1 deletion UMC_6th/app/src/main/java/com/example/umc_6th/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,95 @@
package com.example.umc_6th

import androidx.appcompat.app.AppCompatActivity
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import com.example.umc_6th.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

lateinit var binding: ActivityMainBinding
lateinit var activityResultLauncher: ActivityResultLauncher<Intent>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setTheme(R.style.Theme_UMC_6th)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

val song = Song(binding.mainMiniplayerTitleTv.text.toString(),binding.mainMiniplayerSingerTv.text.toString())

binding.mainPlayerCl.setOnClickListener{
//startActivity(Intent(this,SongActivity::class.java))
val intent = Intent(this,SongActivity::class.java)
intent.putExtra("title",song.title)
intent.putExtra("singer",song.singer)
startActivity(intent)
}

initBottomNavigation()

Log.d("Song",song.title+song.singer)

// activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
// if (result.resultCode == RESULT_OK) {
// val data = result.data
// if (data != null) {
// val message = data.getStringExtra("message")
// Log.d("message", message!!)
// Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
// }
// }
// }

binding.mainPlayerCl.setOnClickListener{
val intent = Intent(this,SongActivity::class.java)
// intent.putExtra("title",song.title)
// intent.putExtra("singer",song.singer)
startActivity(intent)
}
}

private fun initBottomNavigation() {

supportFragmentManager.beginTransaction()
.replace(R.id.main_frm, HomeFragment())
.commitNowAllowingStateLoss()

binding.mainBnv.setOnItemSelectedListener { item ->
when (item.itemId) {

R.id.homeFragment -> {
supportFragmentManager.beginTransaction()
.replace(R.id.main_frm, HomeFragment())
.commitAllowingStateLoss()
return@setOnItemSelectedListener true
}

R.id.lookFragment -> {
supportFragmentManager.beginTransaction()
.replace(R.id.main_frm, LookFragment())
.commitAllowingStateLoss()
return@setOnItemSelectedListener true
}

R.id.searchFragment -> {
supportFragmentManager.beginTransaction()
.replace(R.id.main_frm, SearchFragment())
.commitAllowingStateLoss()
return@setOnItemSelectedListener true
}

R.id.lockerFragment -> {
supportFragmentManager.beginTransaction()
.replace(R.id.main_frm, LockerFragment())
.commitAllowingStateLoss()
return@setOnItemSelectedListener true
}
}
false
}
}
}
Loading

0 comments on commit ba3b3f1

Please sign in to comment.