adding a player fragment
This commit is contained in:
parent
d8dea46228
commit
81da9ea456
|
@ -34,13 +34,12 @@ class MainActivity : SimpleActivity() {
|
|||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
setupTabColors(config.lastUsedViewPagerPage)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
getPagerAdapter()?.onResume()
|
||||
setupTabColors()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -84,19 +83,10 @@ class MainActivity : SimpleActivity() {
|
|||
|
||||
private fun setupViewPager() {
|
||||
view_pager.adapter = ViewPagerAdapter(this)
|
||||
}
|
||||
|
||||
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.onPageChangeListener {
|
||||
main_tabs_holder.getTabAt(it)?.select()
|
||||
}
|
||||
view_pager.currentItem = config.lastUsedViewPagerPage
|
||||
|
||||
main_tabs_holder.onTabSelectionChanged(
|
||||
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() {
|
||||
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class ViewPagerAdapter(private val activity: SimpleActivity) : PagerAdapter() {
|
|||
private val mFragments = SparseArray<MyViewPagerFragment>()
|
||||
|
||||
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)
|
||||
container.addView(view)
|
||||
|
||||
|
@ -25,15 +25,19 @@ class ViewPagerAdapter(private val activity: SimpleActivity) : PagerAdapter() {
|
|||
container.removeView(item as View)
|
||||
}
|
||||
|
||||
override fun getCount() = 1
|
||||
override fun getCount() = 2
|
||||
|
||||
override fun isViewFromObject(view: View, item: Any) = view == item
|
||||
|
||||
fun onResume() {
|
||||
mFragments.get(0)?.onResume()
|
||||
for (i in 0 until mFragments.size()) {
|
||||
mFragments[i].onResume()
|
||||
}
|
||||
}
|
||||
|
||||
fun onDestroy() {
|
||||
mFragments.get(0)?.onDestroy()
|
||||
for (i in 0 until mFragments.size()) {
|
||||
mFragments[i].onDestroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {}
|
||||
}
|
|
@ -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>
|
Loading…
Reference in New Issue