Skip to content

Commit c9e2348

Browse files
sparrow007mariobehling
authored andcommitted
Fix #2510 scroll issue in favourite section (#2720)
1 parent faccc00 commit c9e2348

File tree

4 files changed

+77
-13
lines changed

4 files changed

+77
-13
lines changed

app/src/main/java/org/fossasia/phimpme/gallery/activities/LFMainActivity.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
import org.fossasia.phimpme.gallery.data.providers.StorageProvider;
9898
import org.fossasia.phimpme.gallery.util.Affix;
9999
import org.fossasia.phimpme.gallery.util.AlertDialogsHelper;
100+
import org.fossasia.phimpme.gallery.util.CustomNestedView;
100101
import org.fossasia.phimpme.gallery.util.ContentHelper;
101102
import org.fossasia.phimpme.gallery.util.Measure;
102103
import org.fossasia.phimpme.gallery.util.PreferenceUtil;
@@ -201,6 +202,8 @@ public class LFMainActivity extends SharedMediaActivity {
201202

202203
private SearchView searchView;
203204

205+
@BindView(R.id.nestedView)
206+
protected CustomNestedView nestedView;
204207
@BindView(R.id.toolbar)
205208
protected Toolbar toolbar;
206209
@BindView(R.id.swipeRefreshLayout)
@@ -1713,21 +1716,23 @@ private void checkNothing() {
17131716
private void checkNothingFavourites() {
17141717
nothingToShow.setTextColor(getTextColor());
17151718
nothingToShow.setText(R.string.no_favourites_text);
1716-
nothingToShow.setVisibility((albumsMode && getAlbums().dispAlbums.size() == 0 && !fav_photos) || (!albumsMode && getAlbum
1719+
int shouldShow = (albumsMode && getAlbums().dispAlbums.size() == 0 && !fav_photos) || (!albumsMode && getAlbum
17171720
().getMedia().size() == 0 && !fav_photos) || (fav_photos && favouriteslist.size() == 0) ? View
17181721
.VISIBLE : View
1719-
.GONE);
1720-
noFavMsg.setVisibility((albumsMode && getAlbums().dispAlbums.size() == 0 && !fav_photos) || (!albumsMode && getAlbum
1721-
().getMedia().size() == 0 && !fav_photos) || (fav_photos && favouriteslist.size() == 0) ? View
1722-
.VISIBLE : View
1723-
.GONE);
1722+
.GONE;
1723+
nothingToShow.setVisibility(shouldShow);
1724+
noFavMsg.setVisibility(shouldShow);
17241725
noFavMsg.setText(R.string.no_favourites_message);
17251726
noFavMsg.setTextColor(getTextColor());
1726-
starImageView.setVisibility((albumsMode && getAlbums().dispAlbums.size() == 0 && !fav_photos) || (!albumsMode && getAlbum
1727-
().getMedia().size() == 0 && !fav_photos) || (fav_photos && favouriteslist.size() == 0) ? View
1728-
.VISIBLE : View
1729-
.GONE);
1727+
starImageView.setVisibility(shouldShow);
17301728
starImageView.setColorFilter(getPrimaryColor());
1729+
if (shouldShow == View.VISIBLE) {
1730+
showAppBar();
1731+
nestedView.setScrolling(false);
1732+
rvMedia.setNestedScrollingEnabled(false);
1733+
1734+
}
1735+
17311736
}
17321737

17331738

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.fossasia.phimpme.gallery.util;
2+
3+
import android.content.Context;
4+
import android.support.v4.widget.NestedScrollView;
5+
import android.util.AttributeSet;
6+
import android.view.MotionEvent;
7+
8+
9+
public class CustomNestedView extends NestedScrollView
10+
{
11+
private boolean enableScrolling = true;
12+
13+
public CustomNestedView(Context context, AttributeSet attrs)
14+
{
15+
super(context, attrs);
16+
}
17+
18+
19+
public CustomNestedView(Context context, AttributeSet attrs, int defStyleAttr) {
20+
super(context, attrs, defStyleAttr);
21+
}
22+
23+
24+
@Override
25+
public boolean onInterceptTouchEvent(MotionEvent ev) {
26+
if (scrollingEnabled()) {
27+
return super.onInterceptTouchEvent(ev);
28+
} else {
29+
return false;
30+
}
31+
}
32+
@Override
33+
public boolean onTouchEvent(MotionEvent ev) {
34+
if (scrollingEnabled()) {
35+
return super.onTouchEvent(ev);
36+
} else {
37+
return false;
38+
}
39+
}
40+
41+
42+
private boolean scrollingEnabled(){
43+
return enableScrolling;
44+
}
45+
public void setScrolling(boolean enableScrolling) {
46+
this.enableScrolling = enableScrolling;
47+
}
48+
}

app/src/main/java/org/fossasia/phimpme/gallery/views/CustomScrollBarRecyclerView.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
public class CustomScrollBarRecyclerView extends RecyclerView {
1717
private int scrollBarColor = Color.RED;
18-
1918
public CustomScrollBarRecyclerView(Context context) {
2019
super(context);
2120
}
@@ -49,4 +48,15 @@ protected void onDrawVerticalScrollBar(Canvas canvas, Drawable scrollBar, int l,
4948
scrollBar.setBounds(l, t, r, b);
5049
scrollBar.draw(canvas);
5150
}
51+
52+
@Override
53+
public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow) {
54+
boolean returnValue;
55+
returnValue = super.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow);
56+
if (offsetInWindow[1] != 0) {
57+
offsetInWindow[1] = 0;
58+
}
59+
return returnValue;
60+
}
61+
5262
}

app/src/main/res/layout/activity_leafpic.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
layout="@layout/toolbar" />
2323
</android.support.design.widget.AppBarLayout>
2424

25-
<android.support.v4.widget.NestedScrollView
25+
<org.fossasia.phimpme.gallery.util.CustomNestedView
2626
android:layout_width="match_parent"
2727
android:layout_height="match_parent"
28+
android:id="@+id/nestedView"
2829
android:fillViewport="true"
2930
app:layout_behavior="@string/appbar_scrolling_view_behavior">
3031

@@ -113,7 +114,7 @@
113114
</RelativeLayout>
114115
</android.support.v4.widget.SwipeRefreshLayout>
115116
</FrameLayout>
116-
</android.support.v4.widget.NestedScrollView>
117+
</org.fossasia.phimpme.gallery.util.CustomNestedView>
117118

118119
<include
119120
android:id="@+id/bottombar"

0 commit comments

Comments
 (0)