mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Convert the ParentViewPager to kotlin
This commit is contained in:
parent
f71418a4f6
commit
7042a5cd56
6 changed files with 30 additions and 75 deletions
|
|
@ -33,7 +33,7 @@ class BookmarkFragment : CommonsDaggerSupportFragment() {
|
|||
|
||||
fun setScroll(canScroll: Boolean) {
|
||||
binding?.let {
|
||||
it.viewPagerBookmarks.isCanScroll = canScroll
|
||||
it.viewPagerBookmarks.canScroll = canScroll
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
package fr.free.nrw.commons.explore;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
/**
|
||||
* ParentViewPager A custom viewPager whose scrolling can be enabled and disabled.
|
||||
*/
|
||||
public class ParentViewPager extends ViewPager {
|
||||
|
||||
/**
|
||||
* Boolean variable that stores the current state of pager scroll i.e(enabled or disabled)
|
||||
*/
|
||||
private boolean canScroll = true;
|
||||
|
||||
|
||||
/**
|
||||
* Default constructors
|
||||
*/
|
||||
public ParentViewPager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ParentViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setter method for canScroll.
|
||||
*/
|
||||
public void setCanScroll(boolean canScroll) {
|
||||
this.canScroll = canScroll;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Getter method for canScroll.
|
||||
*/
|
||||
public boolean isCanScroll() {
|
||||
return canScroll;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method that prevents scrolling if canScroll is set to false.
|
||||
*/
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
return canScroll && super.onTouchEvent(ev);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A facilitator method that allows parent to intercept touch events before its children. thus
|
||||
* making it possible to prevent swiping parent on child end.
|
||||
*/
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
return canScroll && super.onInterceptTouchEvent(ev);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package fr.free.nrw.commons.explore
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
|
||||
/**
|
||||
* ParentViewPager A custom viewPager whose scrolling can be enabled and disabled.
|
||||
*/
|
||||
class ParentViewPager : ViewPager {
|
||||
var canScroll: Boolean = true
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
|
||||
override fun onTouchEvent(ev: MotionEvent): Boolean {
|
||||
return canScroll && super.onTouchEvent(ev)
|
||||
}
|
||||
|
||||
override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
|
||||
return canScroll && super.onInterceptTouchEvent(ev)
|
||||
}
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ class ProfileActivity : BaseActivity() {
|
|||
private var contributionsFragment: ContributionsFragment? = null
|
||||
|
||||
fun setScroll(canScroll: Boolean) {
|
||||
binding.viewPager.setCanScroll(canScroll)
|
||||
binding.viewPager.canScroll = canScroll
|
||||
}
|
||||
|
||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||
|
|
|
|||
|
|
@ -56,11 +56,7 @@ class UploadProgressActivity : BaseActivity() {
|
|||
|
||||
override fun onPageSelected(position: Int) {
|
||||
updateMenuItems(position)
|
||||
if (position == 2) {
|
||||
binding.uploadProgressViewPager.setCanScroll(false)
|
||||
} else {
|
||||
binding.uploadProgressViewPager.setCanScroll(true)
|
||||
}
|
||||
binding.uploadProgressViewPager.canScroll = (position != 2)
|
||||
}
|
||||
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
|
|
|
|||
|
|
@ -88,14 +88,14 @@ class ExploreFragmentUnitTest {
|
|||
@Throws(Exception::class)
|
||||
fun testSetScrollCaseTrue() {
|
||||
fragment.setScroll(true)
|
||||
Assert.assertEquals(viewPager.isCanScroll, true)
|
||||
Assert.assertEquals(viewPager.canScroll, true)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetScrollCaseFalse() {
|
||||
fragment.setScroll(false)
|
||||
Assert.assertEquals(viewPager.isCanScroll, false)
|
||||
Assert.assertEquals(viewPager.canScroll, false)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue