Merge pull request #869 from TheAndroidMaster/master

fixed #833
This commit is contained in:
yakov116 2017-08-16 16:45:08 -04:00 committed by GitHub
commit 0ad0b23b68

View File

@ -8,6 +8,7 @@ import android.support.design.widget.AppBarLayout;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ProgressBar;
@ -17,7 +18,6 @@ import com.fastaccess.helper.ActivityHelper;
import com.fastaccess.helper.BundleConstant;
import com.fastaccess.helper.Bundler;
import com.fastaccess.helper.InputHelper;
import com.fastaccess.helper.Logger;
import com.fastaccess.helper.PrefGetter;
import com.fastaccess.ui.base.BaseFragment;
import com.fastaccess.ui.widgets.StateLayout;
@ -30,7 +30,7 @@ import it.sephiroth.android.library.bottomnavigation.BottomNavigation;
* Created by Kosh on 28 Nov 2016, 9:27 PM
*/
public class ViewerFragment extends BaseFragment<ViewerMvp.View, ViewerPresenter> implements ViewerMvp.View {
public class ViewerFragment extends BaseFragment<ViewerMvp.View, ViewerPresenter> implements ViewerMvp.View, AppBarLayout.OnOffsetChangedListener {
public static final String TAG = ViewerFragment.class.getSimpleName();
@ -39,7 +39,9 @@ public class ViewerFragment extends BaseFragment<ViewerMvp.View, ViewerPresenter
@BindView(R.id.stateLayout) StateLayout stateLayout;
private AppBarLayout appBarLayout;
private BottomNavigation bottomNavigation;
private boolean scrolledTop = true;
private boolean isAppBarMoving;
private boolean isAppBarExpanded = true;
private boolean isAppBarListener;
@State boolean isWrap = PrefGetter.isWrapCode();
public static ViewerFragment newInstance(@NonNull String url, @Nullable String htmlUrl) {
@ -153,18 +155,16 @@ public class ViewerFragment extends BaseFragment<ViewerMvp.View, ViewerPresenter
}
@Override public void onScrollChanged(boolean reachedTop, int scroll) {
if (getPresenter().isRepo()) {
if (appBarLayout != null && bottomNavigation != null) {
if (scroll <= (appBarLayout.getTotalScrollRange() / 2)) {
scrolledTop = true;
bottomNavigation.setExpanded(true, true);
appBarLayout.setExpanded(true, true);
} else if (scroll >= appBarLayout.getTotalScrollRange() && scrolledTop) {
bottomNavigation.setExpanded(false, true);
appBarLayout.setExpanded(false, true);
scrolledTop = false;
}
webView.setNestedScrollingEnabled(scroll <= (appBarLayout.getTotalScrollRange() * 2));
if (getPresenter().isRepo() && appBarLayout != null && bottomNavigation != null && webView != null) {
boolean shouldExpand = webView.getScrollY() == 0;
if (!isAppBarMoving && shouldExpand != isAppBarExpanded) {
isAppBarMoving = true;
isAppBarExpanded = shouldExpand;
bottomNavigation.setExpanded(shouldExpand, true);
appBarLayout.setExpanded(shouldExpand, true);
webView.setNestedScrollingEnabled(shouldExpand);
if (shouldExpand)
webView.onTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0));
}
}
}
@ -193,9 +193,32 @@ public class ViewerFragment extends BaseFragment<ViewerMvp.View, ViewerPresenter
if (getPresenter().isRepo()) {
appBarLayout = getActivity().findViewById(R.id.appbar);
bottomNavigation = getActivity().findViewById(R.id.bottomNavigation);
if (appBarLayout != null && !isAppBarListener) {
appBarLayout.addOnOffsetChangedListener(this);
isAppBarListener = true;
}
}
}
@Override
public void onStart() {
super.onStart();
if (appBarLayout != null && !isAppBarListener) {
appBarLayout.addOnOffsetChangedListener(this);
isAppBarListener = true;
}
}
@Override
public void onStop() {
if (appBarLayout != null && isAppBarListener) {
appBarLayout.removeOnOffsetChangedListener(this);
isAppBarListener = false;
}
super.onStop();
}
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.wrap_menu_option, menu);
@ -235,4 +258,11 @@ public class ViewerFragment extends BaseFragment<ViewerMvp.View, ViewerPresenter
appBarLayout.setVisibility(View.VISIBLE);
}
}
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
verticalOffset = Math.abs(verticalOffset);
if (verticalOffset == 0 || verticalOffset == appBarLayout.getTotalScrollRange())
isAppBarMoving = false;
}
}