mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Fixes #4215 "Swiping on the last item in explore featured tab takes you to uploaded via mobile" (#4227)
* scrolling disabled on media details * javadoc added * javadoc modified
This commit is contained in:
parent
7d5773f235
commit
1a31265770
7 changed files with 87 additions and 12 deletions
|
|
@ -4,35 +4,30 @@ import android.os.Bundle;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
|
||||
import android.widget.FrameLayout;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
||||
import fr.free.nrw.commons.contributions.MainActivity;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.explore.ParentViewPager;
|
||||
import fr.free.nrw.commons.theme.BaseActivity;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.category.CategoryImagesCallback;
|
||||
import fr.free.nrw.commons.contributions.ContributionController;
|
||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
||||
|
||||
public class BookmarkFragment extends CommonsDaggerSupportFragment {
|
||||
|
||||
private FragmentManager supportFragmentManager;
|
||||
private BookmarksPagerAdapter adapter;
|
||||
@BindView(R.id.viewPagerBookmarks)
|
||||
ViewPager viewPager;
|
||||
ParentViewPager viewPager;
|
||||
@BindView(R.id.tab_layout)
|
||||
TabLayout tabLayout;
|
||||
@BindView(R.id.fragmentContainer)
|
||||
|
|
@ -48,6 +43,10 @@ public class BookmarkFragment extends CommonsDaggerSupportFragment {
|
|||
return fragment;
|
||||
}
|
||||
|
||||
public void setScroll(boolean canScroll){
|
||||
viewPager.setCanScroll(canScroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
|
|||
|
|
@ -181,13 +181,14 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
|
|||
}
|
||||
|
||||
public void backPressed() {
|
||||
//check medaiDetailPage fragment is not null then we check medaiDetail.is Visible or not to avoid NullPointerException
|
||||
//check mediaDetailPage fragment is not null then we check mediaDetail.is Visible or not to avoid NullPointerException
|
||||
if(mediaDetails!=null) {
|
||||
if (mediaDetails.isVisible()) {
|
||||
// todo add get list fragment
|
||||
((BookmarkFragment) getParentFragment()).tabLayout.setVisibility(View.VISIBLE);
|
||||
ArrayList<Integer> removed=mediaDetails.getRemovedItems();
|
||||
removeFragment(mediaDetails);
|
||||
((BookmarkFragment) getParentFragment()).setScroll(true);
|
||||
setFragment(listFragment, mediaDetails);
|
||||
((MainActivity) getActivity()).showTabs();
|
||||
if(listFragment instanceof BookmarkPicturesFragment){
|
||||
|
|
@ -217,6 +218,7 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
|
|||
container.setVisibility(View.VISIBLE);
|
||||
((BookmarkFragment)getParentFragment()).tabLayout.setVisibility(View.GONE);
|
||||
mediaDetails = new MediaDetailPagerFragment(false, true);
|
||||
((BookmarkFragment) getParentFragment()).setScroll(false);
|
||||
setFragment(mediaDetails, listFragment);
|
||||
mediaDetails.showImage(position);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import android.view.ViewGroup;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
|
|
@ -30,11 +29,15 @@ public class ExploreFragment extends CommonsDaggerSupportFragment {
|
|||
@BindView(R.id.tab_layout)
|
||||
TabLayout tabLayout;
|
||||
@BindView(R.id.viewPager)
|
||||
ViewPager viewPager;
|
||||
ParentViewPager viewPager;
|
||||
ViewPagerAdapter viewPagerAdapter;
|
||||
private ExploreListRootFragment featuredRootFragment;
|
||||
private ExploreListRootFragment mobileRootFragment;
|
||||
|
||||
public void setScroll(boolean canScroll){
|
||||
viewPager.setCanScroll(canScroll);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static ExploreFragment newInstance() {
|
||||
ExploreFragment fragment = new ExploreFragment();
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
|
|||
((ExploreFragment)getParentFragment()).tabLayout.setVisibility(View.GONE);
|
||||
mediaDetails = new MediaDetailPagerFragment(false, true);
|
||||
mediaDetails.showImage(position);
|
||||
((ExploreFragment) getParentFragment()).setScroll(false);
|
||||
setFragment(mediaDetails, listFragment);
|
||||
}
|
||||
|
||||
|
|
@ -173,6 +174,7 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
|
|||
// todo add get list fragment
|
||||
((ExploreFragment)getParentFragment()).tabLayout.setVisibility(View.VISIBLE);
|
||||
removeFragment(mediaDetails);
|
||||
((ExploreFragment) getParentFragment()).setScroll(true);
|
||||
setFragment(listFragment, mediaDetails);
|
||||
} else {
|
||||
((MainActivity) getActivity()).setSelectedItemId(NavTab.CONTRIBUTIONS.code());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
android:orientation="horizontal"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
<fr.free.nrw.commons.explore.ParentViewPager
|
||||
android:id="@+id/viewPagerBookmarks"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
android:orientation="horizontal"
|
||||
android:visibility="gone" />
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
<fr.free.nrw.commons.explore.ParentViewPager
|
||||
android:id="@+id/viewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue