migrate ReportPagerAdapter to ViewPager2 (#1635)

This commit is contained in:
Konrad Pozniak 2020-01-13 21:15:22 +01:00 committed by GitHub
parent 31b29047c7
commit 39915442aa
4 changed files with 8 additions and 40 deletions

View File

@ -78,7 +78,8 @@ class ReportActivity : BottomSheetActivity(), HasAndroidInjector {
}
private fun initViewPager() {
wizard.adapter = ReportPagerAdapter(supportFragmentManager)
wizard.isUserInputEnabled = false
wizard.adapter = ReportPagerAdapter(this)
}
private fun subscribeObservables() {

View File

@ -16,14 +16,14 @@
package com.keylesspalace.tusky.components.report.adapter
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.keylesspalace.tusky.components.report.fragments.ReportDoneFragment
import com.keylesspalace.tusky.components.report.fragments.ReportNoteFragment
import com.keylesspalace.tusky.components.report.fragments.ReportStatusesFragment
class ReportPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manager) {
override fun getItem(position: Int): Fragment {
class ReportPagerAdapter(activity: FragmentActivity) : FragmentStateAdapter(activity) {
override fun createFragment(position: Int): Fragment {
return when (position) {
0 -> ReportStatusesFragment.newInstance()
1 -> ReportNoteFragment.newInstance()
@ -32,5 +32,5 @@ class ReportPagerAdapter(manager: FragmentManager) : FragmentPagerAdapter(manage
}
}
override fun getCount(): Int = 3
override fun getItemCount() = 3
}

View File

@ -1,33 +0,0 @@
/* Copyright 2019 Joel Pyska
*
* 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.view
import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager
class NoSwipeViewPager @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ViewPager(context, attrs) {
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
return false
}
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
return false
}
}

View File

@ -9,7 +9,7 @@
<include layout="@layout/toolbar_basic" />
<com.keylesspalace.tusky.view.NoSwipeViewPager
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/wizard"
android:layout_width="match_parent"
android:layout_height="match_parent"