Move the wallet floating button away when scroll gets to the bottom at FileViewFragment (#1155)
This commit is contained in:
parent
67b883660f
commit
a8cdc4a771
2 changed files with 39 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
package io.lbry.browser;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
|
@ -824,6 +825,20 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
walletBalanceListeners.remove(listener);
|
||||
}
|
||||
|
||||
public void restoreWalletContainerPosition() {
|
||||
View floatingBalance = findViewById(R.id.floating_balance_main_container);
|
||||
|
||||
ObjectAnimator animation = ObjectAnimator.ofFloat(floatingBalance, "translationY", 0f);
|
||||
animation.setDuration(250).start();
|
||||
}
|
||||
|
||||
public void translateFloatingWallet(float initialY) {
|
||||
if (findViewById(R.id.floating_balance_main_container).getY() == initialY) {
|
||||
ObjectAnimator animation = ObjectAnimator.ofFloat(findViewById(R.id.floating_balance_main_container), "translationY", 2 * findViewById(R.id.floating_balance_main_container).getHeight());
|
||||
animation.setDuration(300).start();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeNavFragment(Class fragmentClass, int navItemId) {
|
||||
String key = buildNavFragmentKey(fragmentClass, navItemId, null);
|
||||
if (openNavFragments.containsKey(key)) {
|
||||
|
|
|
@ -247,6 +247,8 @@ public class FileViewFragment extends BaseFragment implements
|
|||
// if this is set, scroll to the specific comment on load
|
||||
private String commentHash;
|
||||
|
||||
private float floatingWalletPositionY;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
View root = inflater.inflate(R.layout.fragment_file_view, container, false);
|
||||
|
@ -802,6 +804,7 @@ public class FileViewFragment extends BaseFragment implements
|
|||
activity.removeSdkStatusListener(this);
|
||||
activity.removeStoragePermissionListener(this);
|
||||
activity.removeWalletBalanceListener(this);
|
||||
activity.restoreWalletContainerPosition();
|
||||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
||||
}
|
||||
|
||||
|
@ -1282,6 +1285,27 @@ public class FileViewFragment extends BaseFragment implements
|
|||
buttonUnfollow.setOnClickListener(followUnfollowListener);
|
||||
buttonBell.setOnClickListener(bellIconListener);
|
||||
|
||||
NestedScrollView scrollView = root.findViewById(R.id.file_view_scroll_view);
|
||||
|
||||
// Store floating wallet balance vertical position when fragment was created
|
||||
// This is used for animate it when user scrolls to the bottom of the screen
|
||||
View floatingBalance = getActivity().findViewById(R.id.floating_balance_main_container);
|
||||
floatingWalletPositionY = floatingBalance.getY();
|
||||
|
||||
scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
|
||||
@Override
|
||||
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
||||
Context ctx = getContext();
|
||||
if (scrollY < oldScrollY && ctx instanceof MainActivity) {
|
||||
// User has scrolled upwards
|
||||
((MainActivity) ctx).restoreWalletContainerPosition();
|
||||
} else if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight()) && ctx instanceof MainActivity) {
|
||||
// User is at the bottom of the screen
|
||||
((MainActivity) ctx).translateFloatingWallet(floatingWalletPositionY);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
commentChannelSpinnerAdapter = new InlineChannelSpinnerAdapter(getContext(), R.layout.spinner_item_channel, new ArrayList<>());
|
||||
commentChannelSpinnerAdapter.addPlaceholder(false);
|
||||
|
||||
|
|
Loading…
Reference in a new issue