change: Move CustomFragmentStateAdapter to core.activity (#452)
This commit is contained in:
parent
96c7799539
commit
b3978c4af7
|
@ -20,9 +20,9 @@ import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import app.pachli.components.account.media.AccountMediaFragment
|
import app.pachli.components.account.media.AccountMediaFragment
|
||||||
import app.pachli.components.timeline.TimelineFragment
|
import app.pachli.components.timeline.TimelineFragment
|
||||||
|
import app.pachli.core.activity.CustomFragmentStateAdapter
|
||||||
import app.pachli.core.activity.RefreshableFragment
|
import app.pachli.core.activity.RefreshableFragment
|
||||||
import app.pachli.core.network.model.TimelineKind
|
import app.pachli.core.network.model.TimelineKind
|
||||||
import app.pachli.util.CustomFragmentStateAdapter
|
|
||||||
|
|
||||||
class AccountPagerAdapter(
|
class AccountPagerAdapter(
|
||||||
activity: FragmentActivity,
|
activity: FragmentActivity,
|
||||||
|
|
|
@ -19,7 +19,7 @@ package app.pachli.pager
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import app.pachli.TabViewData
|
import app.pachli.TabViewData
|
||||||
import app.pachli.util.CustomFragmentStateAdapter
|
import app.pachli.core.activity.CustomFragmentStateAdapter
|
||||||
|
|
||||||
class MainPagerAdapter(var tabs: List<TabViewData>, activity: FragmentActivity) : CustomFragmentStateAdapter(activity) {
|
class MainPagerAdapter(var tabs: List<TabViewData>, activity: FragmentActivity) : CustomFragmentStateAdapter(activity) {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/* Copyright 2019 Tusky Contributors
|
/*
|
||||||
|
* Copyright 2024 Pachli Association
|
||||||
*
|
*
|
||||||
* This file is a part of Pachli.
|
* This file is a part of Pachli.
|
||||||
*
|
*
|
||||||
|
@ -14,16 +15,30 @@
|
||||||
* see <http://www.gnu.org/licenses>.
|
* see <http://www.gnu.org/licenses>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package app.pachli.util
|
package app.pachli.core.activity
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
|
import androidx.fragment.app.FragmentManager
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A [FragmentStateAdapter] that provides [getFragment].
|
||||||
|
*
|
||||||
|
* Useful if the hosting activity or fragment needs to call methods on
|
||||||
|
* one or more of the child fragments (e.g., to trigger a refresh).
|
||||||
|
*/
|
||||||
abstract class CustomFragmentStateAdapter(
|
abstract class CustomFragmentStateAdapter(
|
||||||
private val activity: FragmentActivity,
|
open val fragmentManager: FragmentManager,
|
||||||
) : FragmentStateAdapter(activity) {
|
open val lifecycle: Lifecycle,
|
||||||
|
) : FragmentStateAdapter(fragmentManager, lifecycle) {
|
||||||
|
constructor(activity: FragmentActivity) :
|
||||||
|
this(activity.supportFragmentManager, activity.lifecycle)
|
||||||
|
|
||||||
|
constructor(fragment: Fragment) :
|
||||||
|
this(fragment.childFragmentManager, fragment.lifecycle)
|
||||||
|
|
||||||
fun getFragment(position: Int): Fragment? =
|
fun getFragment(position: Int): Fragment? =
|
||||||
activity.supportFragmentManager.findFragmentByTag("f" + getItemId(position))
|
fragmentManager.findFragmentByTag("f" + getItemId(position))
|
||||||
}
|
}
|
Loading…
Reference in New Issue