fix FragmentAdapter returning null fragments when activity was recreated (#1647)

* fix FragmentAdapter returning null fragments when activity was recreated

* remove unused import

* make activity in CustomFragmentStateAdapter private
This commit is contained in:
Konrad Pozniak 2020-01-29 19:17:11 +01:00 committed by GitHub
commit 45828fbb5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 21 deletions

View file

@ -0,0 +1,28 @@
/* Copyright 2019 Tusky Contributors
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.util
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
abstract class CustomFragmentStateAdapter(
private val activity: FragmentActivity
): FragmentStateAdapter(activity) {
fun getFragment(position: Int): Fragment?
= activity.supportFragmentManager.findFragmentByTag("f" + getItemId(position))
}