diff options
Diffstat (limited to 'app/src')
4 files changed, 63 insertions, 1 deletions
diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java index d14dc9e5..448a4834 100644 --- a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java @@ -26,6 +26,8 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.animation.AccelerateInterpolator; +import android.view.animation.DecelerateInterpolator; import com.wireguard.android.Application; import com.wireguard.android.R; @@ -35,6 +37,7 @@ import com.wireguard.android.databinding.TunnelListFragmentBinding; import com.wireguard.android.databinding.TunnelListItemBinding; import com.wireguard.android.model.Tunnel; import com.wireguard.android.util.ExceptionLoggers; +import com.wireguard.android.widget.CustomRecyclerViewScrollListener; import com.wireguard.config.Config; import java.io.BufferedReader; @@ -189,6 +192,23 @@ public class TunnelListFragment extends BaseFragment { } return false; }); + binding.tunnelList.setOnScrollListener(new CustomRecyclerViewScrollListener() { + @Override + public void show() { + binding.createMenu.animate() + .translationY(0) + .setInterpolator(new DecelerateInterpolator(2)) + .start(); + } + + @Override + public void hide() { + binding.createMenu.animate() + .translationY(binding.createMenu.getHeight() + getResources().getDimension(R.dimen.fab_margin)) + .setInterpolator(new AccelerateInterpolator(2)) + .start(); + } + }); binding.executePendingBindings(); return binding.getRoot(); } diff --git a/app/src/main/java/com/wireguard/android/widget/CustomRecyclerViewScrollListener.java b/app/src/main/java/com/wireguard/android/widget/CustomRecyclerViewScrollListener.java new file mode 100644 index 00000000..2660179f --- /dev/null +++ b/app/src/main/java/com/wireguard/android/widget/CustomRecyclerViewScrollListener.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2018 Harsh Shandilya <msfjarvis@gmail.com> + * Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.wireguard.android.widget; + +import android.support.v7.widget.RecyclerView; + +public abstract class CustomRecyclerViewScrollListener extends RecyclerView.OnScrollListener { + + private int scrollDist; + private boolean isVisible = true; + private static final float FLING_THRESHOLD = 25; + + @Override + public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) { + super.onScrolled(recyclerView, dx, dy); + + if (isVisible && scrollDist > FLING_THRESHOLD) { + hide(); + scrollDist = 0; + isVisible = false; + } else if (!isVisible && scrollDist < -FLING_THRESHOLD) { + show(); + scrollDist = 0; + isVisible = true; + } + + if (isVisible ? dy > 0 : dy < 0) { + scrollDist += dy; + } + } + + public abstract void show(); + public abstract void hide(); +} diff --git a/app/src/main/res/layout/tunnel_list_fragment.xml b/app/src/main/res/layout/tunnel_list_fragment.xml index a8a33dcc..5dd091f8 100644 --- a/app/src/main/res/layout/tunnel_list_fragment.xml +++ b/app/src/main/res/layout/tunnel_list_fragment.xml @@ -40,7 +40,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" - android:layout_margin="16dp" + android:layout_margin="@dimen/fab_margin" app:fab_labelStyle="@style/fab_label" android:clipChildren="false" app:fab_labelsPosition="left" diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 00000000..92be463c --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <dimen name="fab_margin">16dp</dimen> +</resources>
\ No newline at end of file |