adding a player fragment

This commit is contained in:
tibbi 2020-03-31 20:22:04 +02:00
parent d8dea46228
commit 81da9ea456
4 changed files with 43 additions and 18 deletions

View File

@ -34,13 +34,12 @@ class MainActivity : SimpleActivity() {
finish() finish()
} }
} }
setupTabColors(config.lastUsedViewPagerPage)
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
getPagerAdapter()?.onResume() getPagerAdapter()?.onResume()
setupTabColors()
} }
override fun onDestroy() { override fun onDestroy() {
@ -84,19 +83,10 @@ class MainActivity : SimpleActivity() {
private fun setupViewPager() { private fun setupViewPager() {
view_pager.adapter = ViewPagerAdapter(this) view_pager.adapter = ViewPagerAdapter(this)
} view_pager.onPageChangeListener {
main_tabs_holder.getTabAt(it)?.select()
private fun getPagerAdapter() = (view_pager.adapter as? ViewPagerAdapter)
private fun setupTabColors(lastUsedTab: Int) {
main_tabs_holder.apply {
background = ColorDrawable(config.backgroundColor)
setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
getTabAt(lastUsedTab)?.apply {
select()
icon?.applyColorFilter(getAdjustedPrimaryColor())
}
} }
view_pager.currentItem = config.lastUsedViewPagerPage
main_tabs_holder.onTabSelectionChanged( main_tabs_holder.onTabSelectionChanged(
tabUnselectedAction = { tabUnselectedAction = {
@ -109,6 +99,19 @@ class MainActivity : SimpleActivity() {
) )
} }
private fun getPagerAdapter() = (view_pager.adapter as? ViewPagerAdapter)
private fun setupTabColors() {
main_tabs_holder.apply {
background = ColorDrawable(config.backgroundColor)
setSelectedTabIndicatorColor(getAdjustedPrimaryColor())
getTabAt(view_pager.currentItem)?.icon?.applyColorFilter(getAdjustedPrimaryColor())
getTabAt(getInactiveTabIndex())?.icon?.applyColorFilter(config.textColor)
}
}
private fun getInactiveTabIndex() = if (view_pager.currentItem == 0) 1 else 0
private fun launchSettings() { private fun launchSettings() {
startActivity(Intent(applicationContext, SettingsActivity::class.java)) startActivity(Intent(applicationContext, SettingsActivity::class.java))
} }

View File

@ -12,7 +12,7 @@ class ViewPagerAdapter(private val activity: SimpleActivity) : PagerAdapter() {
private val mFragments = SparseArray<MyViewPagerFragment>() private val mFragments = SparseArray<MyViewPagerFragment>()
override fun instantiateItem(container: ViewGroup, position: Int): Any { override fun instantiateItem(container: ViewGroup, position: Int): Any {
val layout = R.layout.fragment_recorder val layout = if (position == 0) R.layout.fragment_recorder else R.layout.fragment_player
val view = activity.layoutInflater.inflate(layout, container, false) val view = activity.layoutInflater.inflate(layout, container, false)
container.addView(view) container.addView(view)
@ -25,15 +25,19 @@ class ViewPagerAdapter(private val activity: SimpleActivity) : PagerAdapter() {
container.removeView(item as View) container.removeView(item as View)
} }
override fun getCount() = 1 override fun getCount() = 2
override fun isViewFromObject(view: View, item: Any) = view == item override fun isViewFromObject(view: View, item: Any) = view == item
fun onResume() { fun onResume() {
mFragments.get(0)?.onResume() for (i in 0 until mFragments.size()) {
mFragments[i].onResume()
}
} }
fun onDestroy() { fun onDestroy() {
mFragments.get(0)?.onDestroy() for (i in 0 until mFragments.size()) {
mFragments[i].onDestroy()
}
} }
} }

View File

@ -0,0 +1,11 @@
package com.simplemobiletools.voicerecorder.fragments
import android.content.Context
import android.util.AttributeSet
class PlayerFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerFragment(context, attributeSet) {
override fun onResume() {}
override fun onDestroy() {}
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.voicerecorder.fragments.PlayerFragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/player_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.simplemobiletools.voicerecorder.fragments.PlayerFragment>