diff --git a/.idea/misc.xml b/.idea/misc.xml index 78b59de..7845ca7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,13 @@ diff --git a/.idea/misc.xml b/.idea/misc.xml index 78b59de..7845ca7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,13 @@ diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 83b5861..100fd06 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -2,32 +2,29 @@ import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.view.View -import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout import com.lukas.music.databinding.ActivityMainBinding +import com.lukas.music.ui.tab.TabAdapter +import com.lukas.music.ui.fragments.CreditsFragment +import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.tab.PageListener +import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { - private lateinit var binding: ActivityMainBinding - private var isOn = true; + private val tabFragments = listOf(PlayFragment(), CreditsFragment()) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - - binding.sampleText.text = "test" - startAudio() - } - - public fun toggleAudio(view: View) { - isOn = !isOn - if (isOn) { - unmuteAudio() - } else { - muteAudio() - } + binding.tabPager.adapter = TabAdapter(supportFragmentManager, lifecycle, tabFragments) + binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout)) + binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager)) + // startAudio() } private external fun startAudio() diff --git a/.idea/misc.xml b/.idea/misc.xml index 78b59de..7845ca7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,13 @@ diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 83b5861..100fd06 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -2,32 +2,29 @@ import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.view.View -import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout import com.lukas.music.databinding.ActivityMainBinding +import com.lukas.music.ui.tab.TabAdapter +import com.lukas.music.ui.fragments.CreditsFragment +import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.tab.PageListener +import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { - private lateinit var binding: ActivityMainBinding - private var isOn = true; + private val tabFragments = listOf(PlayFragment(), CreditsFragment()) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - - binding.sampleText.text = "test" - startAudio() - } - - public fun toggleAudio(view: View) { - isOn = !isOn - if (isOn) { - unmuteAudio() - } else { - muteAudio() - } + binding.tabPager.adapter = TabAdapter(supportFragmentManager, lifecycle, tabFragments) + binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout)) + binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager)) + // startAudio() } private external fun startAudio() diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt new file mode 100644 index 0000000..ddc76f2 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -0,0 +1,26 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class CreditsFragment : Fragment() { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_credits, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + CreditsFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 78b59de..7845ca7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,13 @@ diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 83b5861..100fd06 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -2,32 +2,29 @@ import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.view.View -import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout import com.lukas.music.databinding.ActivityMainBinding +import com.lukas.music.ui.tab.TabAdapter +import com.lukas.music.ui.fragments.CreditsFragment +import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.tab.PageListener +import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { - private lateinit var binding: ActivityMainBinding - private var isOn = true; + private val tabFragments = listOf(PlayFragment(), CreditsFragment()) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - - binding.sampleText.text = "test" - startAudio() - } - - public fun toggleAudio(view: View) { - isOn = !isOn - if (isOn) { - unmuteAudio() - } else { - muteAudio() - } + binding.tabPager.adapter = TabAdapter(supportFragmentManager, lifecycle, tabFragments) + binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout)) + binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager)) + // startAudio() } private external fun startAudio() diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt new file mode 100644 index 0000000..ddc76f2 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -0,0 +1,26 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class CreditsFragment : Fragment() { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_credits, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + CreditsFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt new file mode 100644 index 0000000..b6a755b --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt @@ -0,0 +1,32 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class PlayFragment : Fragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + arguments?.let { + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_play, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + PlayFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 78b59de..7845ca7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,13 @@ diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 83b5861..100fd06 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -2,32 +2,29 @@ import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.view.View -import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout import com.lukas.music.databinding.ActivityMainBinding +import com.lukas.music.ui.tab.TabAdapter +import com.lukas.music.ui.fragments.CreditsFragment +import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.tab.PageListener +import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { - private lateinit var binding: ActivityMainBinding - private var isOn = true; + private val tabFragments = listOf(PlayFragment(), CreditsFragment()) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - - binding.sampleText.text = "test" - startAudio() - } - - public fun toggleAudio(view: View) { - isOn = !isOn - if (isOn) { - unmuteAudio() - } else { - muteAudio() - } + binding.tabPager.adapter = TabAdapter(supportFragmentManager, lifecycle, tabFragments) + binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout)) + binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager)) + // startAudio() } private external fun startAudio() diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt new file mode 100644 index 0000000..ddc76f2 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -0,0 +1,26 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class CreditsFragment : Fragment() { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_credits, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + CreditsFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt new file mode 100644 index 0000000..b6a755b --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt @@ -0,0 +1,32 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class PlayFragment : Fragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + arguments?.let { + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_play, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + PlayFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt new file mode 100644 index 0000000..6fdf160 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt @@ -0,0 +1,11 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class PageListener(private val tabLayout: TabLayout): ViewPager2.OnPageChangeCallback() { + override fun onPageSelected(position: Int) { + super.onPageSelected(position) + tabLayout.selectTab(tabLayout.getTabAt(position)) + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 78b59de..7845ca7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,13 @@ diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 83b5861..100fd06 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -2,32 +2,29 @@ import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.view.View -import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout import com.lukas.music.databinding.ActivityMainBinding +import com.lukas.music.ui.tab.TabAdapter +import com.lukas.music.ui.fragments.CreditsFragment +import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.tab.PageListener +import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { - private lateinit var binding: ActivityMainBinding - private var isOn = true; + private val tabFragments = listOf(PlayFragment(), CreditsFragment()) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - - binding.sampleText.text = "test" - startAudio() - } - - public fun toggleAudio(view: View) { - isOn = !isOn - if (isOn) { - unmuteAudio() - } else { - muteAudio() - } + binding.tabPager.adapter = TabAdapter(supportFragmentManager, lifecycle, tabFragments) + binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout)) + binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager)) + // startAudio() } private external fun startAudio() diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt new file mode 100644 index 0000000..ddc76f2 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -0,0 +1,26 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class CreditsFragment : Fragment() { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_credits, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + CreditsFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt new file mode 100644 index 0000000..b6a755b --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt @@ -0,0 +1,32 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class PlayFragment : Fragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + arguments?.let { + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_play, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + PlayFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt new file mode 100644 index 0000000..6fdf160 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt @@ -0,0 +1,11 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class PageListener(private val tabLayout: TabLayout): ViewPager2.OnPageChangeCallback() { + override fun onPageSelected(position: Int) { + super.onPageSelected(position) + tabLayout.selectTab(tabLayout.getTabAt(position)) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt new file mode 100644 index 0000000..4bd5064 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt @@ -0,0 +1,20 @@ +package com.lukas.music.ui.tab + +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Lifecycle +import androidx.viewpager2.adapter.FragmentStateAdapter + +class TabAdapter( + fragmentManager: FragmentManager, + lifecycle: Lifecycle, + private val fragments: List +) : FragmentStateAdapter(fragmentManager, lifecycle) { + override fun getItemCount(): Int { + return fragments.size + } + + override fun createFragment(position: Int): Fragment { + return fragments[position] + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 78b59de..7845ca7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,13 @@ diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 83b5861..100fd06 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -2,32 +2,29 @@ import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.view.View -import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout import com.lukas.music.databinding.ActivityMainBinding +import com.lukas.music.ui.tab.TabAdapter +import com.lukas.music.ui.fragments.CreditsFragment +import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.tab.PageListener +import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { - private lateinit var binding: ActivityMainBinding - private var isOn = true; + private val tabFragments = listOf(PlayFragment(), CreditsFragment()) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - - binding.sampleText.text = "test" - startAudio() - } - - public fun toggleAudio(view: View) { - isOn = !isOn - if (isOn) { - unmuteAudio() - } else { - muteAudio() - } + binding.tabPager.adapter = TabAdapter(supportFragmentManager, lifecycle, tabFragments) + binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout)) + binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager)) + // startAudio() } private external fun startAudio() diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt new file mode 100644 index 0000000..ddc76f2 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -0,0 +1,26 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class CreditsFragment : Fragment() { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_credits, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + CreditsFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt new file mode 100644 index 0000000..b6a755b --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt @@ -0,0 +1,32 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class PlayFragment : Fragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + arguments?.let { + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_play, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + PlayFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt new file mode 100644 index 0000000..6fdf160 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt @@ -0,0 +1,11 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class PageListener(private val tabLayout: TabLayout): ViewPager2.OnPageChangeCallback() { + override fun onPageSelected(position: Int) { + super.onPageSelected(position) + tabLayout.selectTab(tabLayout.getTabAt(position)) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt new file mode 100644 index 0000000..4bd5064 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt @@ -0,0 +1,20 @@ +package com.lukas.music.ui.tab + +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Lifecycle +import androidx.viewpager2.adapter.FragmentStateAdapter + +class TabAdapter( + fragmentManager: FragmentManager, + lifecycle: Lifecycle, + private val fragments: List +) : FragmentStateAdapter(fragmentManager, lifecycle) { + override fun getItemCount(): Int { + return fragments.size + } + + override fun createFragment(position: Int): Fragment { + return fragments[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt b/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt new file mode 100644 index 0000000..176157d --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt @@ -0,0 +1,16 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class TabListener(private val pager: ViewPager2): TabLayout.OnTabSelectedListener { + override fun onTabSelected(tab: TabLayout.Tab?) { + tab?.let { pager.currentItem = it.position } + } + + override fun onTabUnselected(tab: TabLayout.Tab?) { + } + + override fun onTabReselected(tab: TabLayout.Tab?) { + } +} \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 78b59de..7845ca7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,13 @@ diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 83b5861..100fd06 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -2,32 +2,29 @@ import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.view.View -import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout import com.lukas.music.databinding.ActivityMainBinding +import com.lukas.music.ui.tab.TabAdapter +import com.lukas.music.ui.fragments.CreditsFragment +import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.tab.PageListener +import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { - private lateinit var binding: ActivityMainBinding - private var isOn = true; + private val tabFragments = listOf(PlayFragment(), CreditsFragment()) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - - binding.sampleText.text = "test" - startAudio() - } - - public fun toggleAudio(view: View) { - isOn = !isOn - if (isOn) { - unmuteAudio() - } else { - muteAudio() - } + binding.tabPager.adapter = TabAdapter(supportFragmentManager, lifecycle, tabFragments) + binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout)) + binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager)) + // startAudio() } private external fun startAudio() diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt new file mode 100644 index 0000000..ddc76f2 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -0,0 +1,26 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class CreditsFragment : Fragment() { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_credits, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + CreditsFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt new file mode 100644 index 0000000..b6a755b --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt @@ -0,0 +1,32 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class PlayFragment : Fragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + arguments?.let { + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_play, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + PlayFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt new file mode 100644 index 0000000..6fdf160 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt @@ -0,0 +1,11 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class PageListener(private val tabLayout: TabLayout): ViewPager2.OnPageChangeCallback() { + override fun onPageSelected(position: Int) { + super.onPageSelected(position) + tabLayout.selectTab(tabLayout.getTabAt(position)) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt new file mode 100644 index 0000000..4bd5064 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt @@ -0,0 +1,20 @@ +package com.lukas.music.ui.tab + +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Lifecycle +import androidx.viewpager2.adapter.FragmentStateAdapter + +class TabAdapter( + fragmentManager: FragmentManager, + lifecycle: Lifecycle, + private val fragments: List +) : FragmentStateAdapter(fragmentManager, lifecycle) { + override fun getItemCount(): Int { + return fragments.size + } + + override fun createFragment(position: Int): Fragment { + return fragments[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt b/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt new file mode 100644 index 0000000..176157d --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt @@ -0,0 +1,16 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class TabListener(private val pager: ViewPager2): TabLayout.OnTabSelectedListener { + override fun onTabSelected(tab: TabLayout.Tab?) { + tab?.let { pager.currentItem = it.position } + } + + override fun onTabUnselected(tab: TabLayout.Tab?) { + } + + override fun onTabReselected(tab: TabLayout.Tab?) { + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index b4de30a..12d00ae 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,26 +6,32 @@ android:layout_height="match_parent" tools:context=".MainActivity"> - + app:layout_constraintTop_toTopOf="parent"> - + + + + + + app:layout_constraintTop_toBottomOf="@+id/tabLayout" /> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 78b59de..7845ca7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,13 @@ diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 83b5861..100fd06 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -2,32 +2,29 @@ import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.view.View -import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout import com.lukas.music.databinding.ActivityMainBinding +import com.lukas.music.ui.tab.TabAdapter +import com.lukas.music.ui.fragments.CreditsFragment +import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.tab.PageListener +import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { - private lateinit var binding: ActivityMainBinding - private var isOn = true; + private val tabFragments = listOf(PlayFragment(), CreditsFragment()) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - - binding.sampleText.text = "test" - startAudio() - } - - public fun toggleAudio(view: View) { - isOn = !isOn - if (isOn) { - unmuteAudio() - } else { - muteAudio() - } + binding.tabPager.adapter = TabAdapter(supportFragmentManager, lifecycle, tabFragments) + binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout)) + binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager)) + // startAudio() } private external fun startAudio() diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt new file mode 100644 index 0000000..ddc76f2 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -0,0 +1,26 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class CreditsFragment : Fragment() { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_credits, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + CreditsFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt new file mode 100644 index 0000000..b6a755b --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt @@ -0,0 +1,32 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class PlayFragment : Fragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + arguments?.let { + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_play, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + PlayFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt new file mode 100644 index 0000000..6fdf160 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt @@ -0,0 +1,11 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class PageListener(private val tabLayout: TabLayout): ViewPager2.OnPageChangeCallback() { + override fun onPageSelected(position: Int) { + super.onPageSelected(position) + tabLayout.selectTab(tabLayout.getTabAt(position)) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt new file mode 100644 index 0000000..4bd5064 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt @@ -0,0 +1,20 @@ +package com.lukas.music.ui.tab + +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Lifecycle +import androidx.viewpager2.adapter.FragmentStateAdapter + +class TabAdapter( + fragmentManager: FragmentManager, + lifecycle: Lifecycle, + private val fragments: List +) : FragmentStateAdapter(fragmentManager, lifecycle) { + override fun getItemCount(): Int { + return fragments.size + } + + override fun createFragment(position: Int): Fragment { + return fragments[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt b/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt new file mode 100644 index 0000000..176157d --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt @@ -0,0 +1,16 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class TabListener(private val pager: ViewPager2): TabLayout.OnTabSelectedListener { + override fun onTabSelected(tab: TabLayout.Tab?) { + tab?.let { pager.currentItem = it.position } + } + + override fun onTabUnselected(tab: TabLayout.Tab?) { + } + + override fun onTabReselected(tab: TabLayout.Tab?) { + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index b4de30a..12d00ae 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,26 +6,32 @@ android:layout_height="match_parent" tools:context=".MainActivity"> - + app:layout_constraintTop_toTopOf="parent"> - + + + + + + app:layout_constraintTop_toBottomOf="@+id/tabLayout" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_credits.xml b/app/src/main/res/layout/fragment_credits.xml new file mode 100644 index 0000000..ffb1f59 --- /dev/null +++ b/app/src/main/res/layout/fragment_credits.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 78b59de..7845ca7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,13 @@ diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 83b5861..100fd06 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -2,32 +2,29 @@ import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.view.View -import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout import com.lukas.music.databinding.ActivityMainBinding +import com.lukas.music.ui.tab.TabAdapter +import com.lukas.music.ui.fragments.CreditsFragment +import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.tab.PageListener +import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { - private lateinit var binding: ActivityMainBinding - private var isOn = true; + private val tabFragments = listOf(PlayFragment(), CreditsFragment()) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - - binding.sampleText.text = "test" - startAudio() - } - - public fun toggleAudio(view: View) { - isOn = !isOn - if (isOn) { - unmuteAudio() - } else { - muteAudio() - } + binding.tabPager.adapter = TabAdapter(supportFragmentManager, lifecycle, tabFragments) + binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout)) + binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager)) + // startAudio() } private external fun startAudio() diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt new file mode 100644 index 0000000..ddc76f2 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -0,0 +1,26 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class CreditsFragment : Fragment() { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_credits, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + CreditsFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt new file mode 100644 index 0000000..b6a755b --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt @@ -0,0 +1,32 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class PlayFragment : Fragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + arguments?.let { + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_play, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + PlayFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt new file mode 100644 index 0000000..6fdf160 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt @@ -0,0 +1,11 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class PageListener(private val tabLayout: TabLayout): ViewPager2.OnPageChangeCallback() { + override fun onPageSelected(position: Int) { + super.onPageSelected(position) + tabLayout.selectTab(tabLayout.getTabAt(position)) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt new file mode 100644 index 0000000..4bd5064 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt @@ -0,0 +1,20 @@ +package com.lukas.music.ui.tab + +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Lifecycle +import androidx.viewpager2.adapter.FragmentStateAdapter + +class TabAdapter( + fragmentManager: FragmentManager, + lifecycle: Lifecycle, + private val fragments: List +) : FragmentStateAdapter(fragmentManager, lifecycle) { + override fun getItemCount(): Int { + return fragments.size + } + + override fun createFragment(position: Int): Fragment { + return fragments[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt b/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt new file mode 100644 index 0000000..176157d --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt @@ -0,0 +1,16 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class TabListener(private val pager: ViewPager2): TabLayout.OnTabSelectedListener { + override fun onTabSelected(tab: TabLayout.Tab?) { + tab?.let { pager.currentItem = it.position } + } + + override fun onTabUnselected(tab: TabLayout.Tab?) { + } + + override fun onTabReselected(tab: TabLayout.Tab?) { + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index b4de30a..12d00ae 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,26 +6,32 @@ android:layout_height="match_parent" tools:context=".MainActivity"> - + app:layout_constraintTop_toTopOf="parent"> - + + + + + + app:layout_constraintTop_toBottomOf="@+id/tabLayout" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_credits.xml b/app/src/main/res/layout/fragment_credits.xml new file mode 100644 index 0000000..ffb1f59 --- /dev/null +++ b/app/src/main/res/layout/fragment_credits.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_play.xml b/app/src/main/res/layout/fragment_play.xml new file mode 100644 index 0000000..0ef6fc8 --- /dev/null +++ b/app/src/main/res/layout/fragment_play.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 78b59de..7845ca7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,13 @@ diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 83b5861..100fd06 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -2,32 +2,29 @@ import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.view.View -import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout import com.lukas.music.databinding.ActivityMainBinding +import com.lukas.music.ui.tab.TabAdapter +import com.lukas.music.ui.fragments.CreditsFragment +import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.tab.PageListener +import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { - private lateinit var binding: ActivityMainBinding - private var isOn = true; + private val tabFragments = listOf(PlayFragment(), CreditsFragment()) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - - binding.sampleText.text = "test" - startAudio() - } - - public fun toggleAudio(view: View) { - isOn = !isOn - if (isOn) { - unmuteAudio() - } else { - muteAudio() - } + binding.tabPager.adapter = TabAdapter(supportFragmentManager, lifecycle, tabFragments) + binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout)) + binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager)) + // startAudio() } private external fun startAudio() diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt new file mode 100644 index 0000000..ddc76f2 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -0,0 +1,26 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class CreditsFragment : Fragment() { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_credits, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + CreditsFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt new file mode 100644 index 0000000..b6a755b --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt @@ -0,0 +1,32 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class PlayFragment : Fragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + arguments?.let { + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_play, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + PlayFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt new file mode 100644 index 0000000..6fdf160 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt @@ -0,0 +1,11 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class PageListener(private val tabLayout: TabLayout): ViewPager2.OnPageChangeCallback() { + override fun onPageSelected(position: Int) { + super.onPageSelected(position) + tabLayout.selectTab(tabLayout.getTabAt(position)) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt new file mode 100644 index 0000000..4bd5064 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt @@ -0,0 +1,20 @@ +package com.lukas.music.ui.tab + +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Lifecycle +import androidx.viewpager2.adapter.FragmentStateAdapter + +class TabAdapter( + fragmentManager: FragmentManager, + lifecycle: Lifecycle, + private val fragments: List +) : FragmentStateAdapter(fragmentManager, lifecycle) { + override fun getItemCount(): Int { + return fragments.size + } + + override fun createFragment(position: Int): Fragment { + return fragments[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt b/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt new file mode 100644 index 0000000..176157d --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt @@ -0,0 +1,16 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class TabListener(private val pager: ViewPager2): TabLayout.OnTabSelectedListener { + override fun onTabSelected(tab: TabLayout.Tab?) { + tab?.let { pager.currentItem = it.position } + } + + override fun onTabUnselected(tab: TabLayout.Tab?) { + } + + override fun onTabReselected(tab: TabLayout.Tab?) { + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index b4de30a..12d00ae 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,26 +6,32 @@ android:layout_height="match_parent" tools:context=".MainActivity"> - + app:layout_constraintTop_toTopOf="parent"> - + + + + + + app:layout_constraintTop_toBottomOf="@+id/tabLayout" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_credits.xml b/app/src/main/res/layout/fragment_credits.xml new file mode 100644 index 0000000..ffb1f59 --- /dev/null +++ b/app/src/main/res/layout/fragment_credits.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_play.xml b/app/src/main/res/layout/fragment_play.xml new file mode 100644 index 0000000..0ef6fc8 --- /dev/null +++ b/app/src/main/res/layout/fragment_play.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index f8c6127..66e3f6c 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,4 +7,8 @@ #FF018786 #FF000000 #FFFFFFFF + #FF29B6F6 + #FF039BE5 + #FFBDBDBD + #FF757575 \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 78b59de..7845ca7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,13 @@ diff --git a/app/src/main/java/com/lukas/music/MainActivity.kt b/app/src/main/java/com/lukas/music/MainActivity.kt index 83b5861..100fd06 100644 --- a/app/src/main/java/com/lukas/music/MainActivity.kt +++ b/app/src/main/java/com/lukas/music/MainActivity.kt @@ -2,32 +2,29 @@ import androidx.appcompat.app.AppCompatActivity import android.os.Bundle -import android.view.View -import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout import com.lukas.music.databinding.ActivityMainBinding +import com.lukas.music.ui.tab.TabAdapter +import com.lukas.music.ui.fragments.CreditsFragment +import com.lukas.music.ui.fragments.PlayFragment +import com.lukas.music.ui.tab.PageListener +import com.lukas.music.ui.tab.TabListener class MainActivity : AppCompatActivity() { - private lateinit var binding: ActivityMainBinding - private var isOn = true; + private val tabFragments = listOf(PlayFragment(), CreditsFragment()) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - - binding.sampleText.text = "test" - startAudio() - } - - public fun toggleAudio(view: View) { - isOn = !isOn - if (isOn) { - unmuteAudio() - } else { - muteAudio() - } + binding.tabPager.adapter = TabAdapter(supportFragmentManager, lifecycle, tabFragments) + binding.tabPager.registerOnPageChangeCallback(PageListener(binding.tabLayout)) + binding.tabLayout.addOnTabSelectedListener(TabListener(binding.tabPager)) + // startAudio() } private external fun startAudio() diff --git a/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt new file mode 100644 index 0000000..ddc76f2 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/CreditsFragment.kt @@ -0,0 +1,26 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class CreditsFragment : Fragment() { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_credits, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + CreditsFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt new file mode 100644 index 0000000..b6a755b --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/fragments/PlayFragment.kt @@ -0,0 +1,32 @@ +package com.lukas.music.ui.fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.lukas.music.R + +class PlayFragment : Fragment() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + arguments?.let { + } + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_play, container, false) + } + + companion object { + @JvmStatic + fun newInstance() = + PlayFragment().apply { + arguments = Bundle().apply { + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt new file mode 100644 index 0000000..6fdf160 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/PageListener.kt @@ -0,0 +1,11 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class PageListener(private val tabLayout: TabLayout): ViewPager2.OnPageChangeCallback() { + override fun onPageSelected(position: Int) { + super.onPageSelected(position) + tabLayout.selectTab(tabLayout.getTabAt(position)) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt new file mode 100644 index 0000000..4bd5064 --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/TabAdapter.kt @@ -0,0 +1,20 @@ +package com.lukas.music.ui.tab + +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Lifecycle +import androidx.viewpager2.adapter.FragmentStateAdapter + +class TabAdapter( + fragmentManager: FragmentManager, + lifecycle: Lifecycle, + private val fragments: List +) : FragmentStateAdapter(fragmentManager, lifecycle) { + override fun getItemCount(): Int { + return fragments.size + } + + override fun createFragment(position: Int): Fragment { + return fragments[position] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt b/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt new file mode 100644 index 0000000..176157d --- /dev/null +++ b/app/src/main/java/com/lukas/music/ui/tab/TabListener.kt @@ -0,0 +1,16 @@ +package com.lukas.music.ui.tab + +import androidx.viewpager2.widget.ViewPager2 +import com.google.android.material.tabs.TabLayout + +class TabListener(private val pager: ViewPager2): TabLayout.OnTabSelectedListener { + override fun onTabSelected(tab: TabLayout.Tab?) { + tab?.let { pager.currentItem = it.position } + } + + override fun onTabUnselected(tab: TabLayout.Tab?) { + } + + override fun onTabReselected(tab: TabLayout.Tab?) { + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index b4de30a..12d00ae 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,26 +6,32 @@ android:layout_height="match_parent" tools:context=".MainActivity"> - + app:layout_constraintTop_toTopOf="parent"> - + + + + + + app:layout_constraintTop_toBottomOf="@+id/tabLayout" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_credits.xml b/app/src/main/res/layout/fragment_credits.xml new file mode 100644 index 0000000..ffb1f59 --- /dev/null +++ b/app/src/main/res/layout/fragment_credits.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_play.xml b/app/src/main/res/layout/fragment_play.xml new file mode 100644 index 0000000..0ef6fc8 --- /dev/null +++ b/app/src/main/res/layout/fragment_play.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index f8c6127..66e3f6c 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,4 +7,8 @@ #FF018786 #FF000000 #FFFFFFFF + #FF29B6F6 + #FF039BE5 + #FFBDBDBD + #FF757575 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4813395..32c8b81 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,6 @@ Music + Credits + this app was created by Lukas Eisenhauer + Hello blank fragment \ No newline at end of file