Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit f023049

Browse files
jainkuniyatimabbott
authored andcommitted
Prevent toggling when messages are less.
Don't toggle toolbar and floating button if messages doesn't occupy full screen.
1 parent 3ac6526 commit f023049

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

app/src/main/java/com/zulip/android/activities/MessageListFragment.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
164164
}
165165
}
166166
});
167+
mListener.setLayoutBehaviour(linearLayoutManager,adapter);
167168
return view;
168169
}
169170

@@ -701,6 +702,8 @@ public interface Listener {
701702
void recyclerViewScrolled();
702703

703704
void clearChatBox();
705+
706+
void setLayoutBehaviour(LinearLayoutManager linearLayoutManager , RecyclerMessageAdapter adapter);
704707
}
705708

706709
public void showLatestMessages() {

app/src/main/java/com/zulip/android/activities/ZulipActivity.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import android.support.v4.widget.DrawerLayout;
4646
import android.support.v4.widget.SimpleCursorAdapter;
4747
import android.support.v7.app.AppCompatDelegate;
48+
import android.support.v7.widget.LinearLayoutManager;
4849
import android.support.v7.widget.Toolbar;
4950
import android.text.Editable;
5051
import android.text.TextUtils;
@@ -102,6 +103,7 @@
102103
import com.zulip.android.util.AnimationHelper;
103104
import com.zulip.android.util.FilePathHelper;
104105
import com.zulip.android.util.MutedTopics;
106+
import com.zulip.android.util.RemoveViewsOnScroll;
105107
import com.zulip.android.util.SwipeRemoveLinearLayout;
106108
import com.zulip.android.util.UrlHelper;
107109
import com.zulip.android.util.ZLog;
@@ -254,6 +256,10 @@ public void removeChatBox(boolean animToRight) {
254256
hideSoftKeyBoard();
255257
}
256258
AnimationHelper.hideViewX(chatBox, animToRight);
259+
//show fab button
260+
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
261+
RemoveViewsOnScroll removeViewsOnScroll = (RemoveViewsOnScroll) layoutParams.getBehavior();
262+
removeViewsOnScroll.showView(fab);
257263
}
258264

259265
public HashMap<String, Bitmap> getGravatars() {
@@ -1648,6 +1654,17 @@ public void clearChatBox() {
16481654
}
16491655
}
16501656

1657+
@Override
1658+
public void setLayoutBehaviour(LinearLayoutManager linearLayoutManager, RecyclerMessageAdapter adapter) {
1659+
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
1660+
layoutParams.setBehavior(new RemoveViewsOnScroll(linearLayoutManager, adapter));
1661+
appBarLayout.requestLayout();
1662+
1663+
layoutParams = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
1664+
layoutParams.setBehavior(new RemoveViewsOnScroll(linearLayoutManager, adapter));
1665+
fab.setLayoutParams(layoutParams);
1666+
}
1667+
16511668
@Override
16521669
public void onBackPressed() {
16531670
//check for drawer

app/src/main/java/com/zulip/android/util/RemoveViewsOnScroll.java

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
import android.support.design.widget.FloatingActionButton;
99
import android.support.v4.view.ViewCompat;
1010
import android.support.v4.view.animation.FastOutSlowInInterpolator;
11+
import android.support.v7.widget.LinearLayoutManager;
1112
import android.util.AttributeSet;
1213
import android.util.TypedValue;
1314
import android.view.View;
1415
import android.view.ViewPropertyAnimator;
1516
import android.view.animation.Interpolator;
1617

1718
import com.zulip.android.R;
19+
import com.zulip.android.activities.RecyclerMessageAdapter;
1820

1921
/**
2022
* This hides the {@link AppBarLayout} and {@link android.support.design.widget.FloatingActionButton} when the
@@ -27,6 +29,8 @@ public class RemoveViewsOnScroll extends CoordinatorLayout.Behavior<View> {
2729
private boolean mIsShowing;
2830
private boolean isViewHidden;
2931
private View chatBox;
32+
private LinearLayoutManager linearLayoutManager;
33+
private RecyclerMessageAdapter adapter;
3034

3135
public RemoveViewsOnScroll(Context context, AttributeSet attrs) {
3236
super(context, attrs);
@@ -35,33 +39,42 @@ public RemoveViewsOnScroll(Context context, AttributeSet attrs) {
3539
toolbarHeight = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
3640
}
3741

42+
public RemoveViewsOnScroll(LinearLayoutManager linearLayoutManager, RecyclerMessageAdapter adapter) {
43+
this.linearLayoutManager = linearLayoutManager;
44+
this.adapter = adapter;
45+
}
46+
3847
@Override
3948
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) {
4049
return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
4150
}
4251

4352
@SuppressLint("NewApi")
4453
@Override
45-
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) {
46-
if (dy > 0 && changeInYDir < 0 || dy < 0 && changeInYDir > 0) {
47-
child.animate().cancel();
48-
changeInYDir = 0;
49-
}
54+
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) throws NullPointerException {
55+
//count index starts from 1 where as position starts from 0, thus difference 1
56+
//we have 2 loading layouts one at top and another at bottom of the messages which should be ignored
57+
//resulting in a overall difference of 3
58+
if (linearLayoutManager.findLastCompletelyVisibleItemPosition() < adapter.getItemCount() - 3) {
59+
if (dy > 0 && changeInYDir < 0 || dy < 0 && changeInYDir > 0) {
60+
child.animate().cancel();
61+
changeInYDir = 0;
62+
}
5063

51-
changeInYDir += dy;
52-
if (changeInYDir > toolbarHeight && child.getVisibility() == View.VISIBLE && !isViewHidden)
53-
hideView(child);
54-
else if (changeInYDir < 0 && child.getVisibility() == View.GONE && !mIsShowing) {
55-
if (child instanceof FloatingActionButton) {
56-
if (chatBox == null)
57-
chatBox = coordinatorLayout.findViewById(R.id.messageBoxContainer);
58-
if (chatBox.getVisibility() == View.VISIBLE) {
59-
return;
64+
changeInYDir += dy;
65+
if (changeInYDir > toolbarHeight && child.getVisibility() == View.VISIBLE && !isViewHidden)
66+
hideView(child);
67+
else if (changeInYDir < 0 && child.getVisibility() == View.GONE && !mIsShowing) {
68+
if (child instanceof FloatingActionButton) {
69+
if (chatBox == null)
70+
chatBox = coordinatorLayout.findViewById(R.id.messageBoxContainer);
71+
if (chatBox.getVisibility() == View.VISIBLE) {
72+
return;
73+
}
6074
}
75+
showView(child);
6176
}
62-
showView(child);
6377
}
64-
6578
}
6679

6780
@SuppressLint("NewApi")
@@ -98,7 +111,7 @@ public void onAnimationRepeat(Animator animator) {
98111
}
99112

100113
@SuppressLint("NewApi")
101-
private void showView(final View view) {
114+
public void showView(final View view) {
102115
mIsShowing = true;
103116
ViewPropertyAnimator animator = view.animate()
104117
.translationY(0)

0 commit comments

Comments
 (0)