Commit f4a588f4 authored by Andreas Schildbach's avatar Andreas Schildbach

WalletActivity: Make balance (plus usually the current address) scroll away...

WalletActivity: Make balance (plus usually the current address) scroll away with scrolling the transactions list.
parent 52c77116
...@@ -14,6 +14,7 @@ dependencies { ...@@ -14,6 +14,7 @@ dependencies {
compile 'androidx.fragment:fragment:1.0.0' compile 'androidx.fragment:fragment:1.0.0'
compile 'androidx.recyclerview:recyclerview:1.0.0' compile 'androidx.recyclerview:recyclerview:1.0.0'
compile 'androidx.cardview:cardview:1.0.0' compile 'androidx.cardview:cardview:1.0.0'
compile 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
compile 'androidx.viewpager:viewpager:1.0.0' compile 'androidx.viewpager:viewpager:1.0.0'
compile 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' compile 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
compile 'androidx.lifecycle:lifecycle-extensions:2.0.0' compile 'androidx.lifecycle:lifecycle-extensions:2.0.0'
......
...@@ -30,15 +30,15 @@ ...@@ -30,15 +30,15 @@
android:tag="slide_in_left" /> android:tag="slide_in_left" />
</FrameLayout> </FrameLayout>
<LinearLayout <androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="0px" android:layout_width="0px"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1" >
android:orientation="vertical" >
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="@color/bg_panel" android:background="@color/bg_panel"
android:elevation="3dp" android:elevation="3dp"
android:tag="levitate" > android:tag="levitate" >
...@@ -56,11 +56,9 @@ ...@@ -56,11 +56,9 @@
android:id="@+id/wallet_transactions_fragment" android:id="@+id/wallet_transactions_fragment"
android:name="de.schildbach.wallet.ui.WalletTransactionsFragment" android:name="de.schildbach.wallet.ui.WalletTransactionsFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0px" android:layout_height="match_parent"
android:layout_gravity="bottom|center_horizontal"
android:layout_weight="1"
android:tag="slide_in_bottom" /> android:tag="slide_in_bottom" />
</LinearLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
</LinearLayout> </LinearLayout>
<include layout="@layout/wallet_activity_bottom_include" /> <include layout="@layout/wallet_activity_bottom_include" />
......
...@@ -4,15 +4,15 @@ ...@@ -4,15 +4,15 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" > android:orientation="vertical" >
<LinearLayout <androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0px" android:layout_height="0px"
android:layout_weight="1" android:layout_weight="1" >
android:orientation="vertical" >
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="@color/bg_panel" android:background="@color/bg_panel"
android:baselineAligned="false" android:baselineAligned="false"
android:elevation="3dp" android:elevation="3dp"
...@@ -44,11 +44,9 @@ ...@@ -44,11 +44,9 @@
android:id="@+id/wallet_transactions_fragment" android:id="@+id/wallet_transactions_fragment"
android:name="de.schildbach.wallet.ui.WalletTransactionsFragment" android:name="de.schildbach.wallet.ui.WalletTransactionsFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0px" android:layout_height="match_parent"
android:layout_gravity="bottom|center_horizontal"
android:layout_weight="1"
android:tag="slide_in_bottom" /> android:tag="slide_in_bottom" />
</LinearLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
<include layout="@layout/wallet_activity_bottom_include" /> <include layout="@layout/wallet_activity_bottom_include" />
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
android:id="@+id/wallet_transactions_list" android:id="@+id/wallet_transactions_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical" /> android:scrollbars="vertical" />
</ViewAnimator> </ViewAnimator>
...@@ -22,6 +22,8 @@ import org.bitcoinj.core.Transaction; ...@@ -22,6 +22,8 @@ import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.VerificationException; import org.bitcoinj.core.VerificationException;
import org.bitcoinj.script.Script; import org.bitcoinj.script.Script;
import com.google.common.primitives.Floats;
import de.schildbach.wallet.Configuration; import de.schildbach.wallet.Configuration;
import de.schildbach.wallet.Constants; import de.schildbach.wallet.Constants;
import de.schildbach.wallet.R; import de.schildbach.wallet.R;
...@@ -62,6 +64,8 @@ import android.view.Menu; ...@@ -62,6 +64,8 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.animation.DecelerateInterpolator; import android.view.animation.DecelerateInterpolator;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.ViewCompat;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders; import androidx.lifecycle.ViewModelProviders;
...@@ -76,6 +80,7 @@ public final class WalletActivity extends AbstractWalletActivity { ...@@ -76,6 +80,7 @@ public final class WalletActivity extends AbstractWalletActivity {
private WalletActivityViewModel viewModel; private WalletActivityViewModel viewModel;
private AnimatorSet enterAnimation; private AnimatorSet enterAnimation;
private View contentView; private View contentView;
private View levitateView;
private static final int REQUEST_CODE_SCAN = 0; private static final int REQUEST_CODE_SCAN = 0;
...@@ -89,6 +94,30 @@ public final class WalletActivity extends AbstractWalletActivity { ...@@ -89,6 +94,30 @@ public final class WalletActivity extends AbstractWalletActivity {
setContentView(R.layout.wallet_content); setContentView(R.layout.wallet_content);
contentView = findViewById(android.R.id.content); contentView = findViewById(android.R.id.content);
levitateView = contentView.findViewWithTag("levitate");
// Make view tagged with 'levitate' scroll away and quickly return.
final View targetList = findViewById(R.id.wallet_transactions_list);
final View targetEmpty = findViewById(R.id.wallet_transactions_empty);
if (levitateView != null && targetList != null && targetEmpty != null) {
final CoordinatorLayout.LayoutParams layoutParams = new CoordinatorLayout.LayoutParams(
levitateView.getLayoutParams().width, levitateView.getLayoutParams().height);
layoutParams.setBehavior(new QuickReturnBehavior());
levitateView.setLayoutParams(layoutParams);
levitateView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(final View v, final int left, final int top, final int right,
final int bottom, final int oldLeft, final int oldTop, final int oldRight,
final int oldBottom) {
final int height = bottom - top;
targetList.setPadding(targetList.getPaddingLeft(), height, targetList.getPaddingRight(),
targetList.getPaddingBottom());
targetEmpty.setPadding(targetEmpty.getPaddingLeft(), height, targetEmpty.getPaddingRight(),
targetEmpty.getPaddingBottom());
}
});
}
OnFirstPreDraw.listen(contentView, viewModel); OnFirstPreDraw.listen(contentView, viewModel);
enterAnimation = buildEnterAnimation(contentView); enterAnimation = buildEnterAnimation(contentView);
...@@ -291,12 +320,12 @@ public final class WalletActivity extends AbstractWalletActivity { ...@@ -291,12 +320,12 @@ public final class WalletActivity extends AbstractWalletActivity {
fragmentEnterAnimationBuilder.before(slide).before(fadeIn); fragmentEnterAnimationBuilder.before(slide).before(fadeIn);
} }
final View levitate = contentView.findViewWithTag("levitate"); if (levitateView != null) {
if (levitate != null) { final ObjectAnimator elevate = ObjectAnimator.ofFloat(levitateView, "elevation", 0.0f,
final ObjectAnimator elevate = ObjectAnimator.ofFloat(levitate, "elevation", 0.0f, levitate.getElevation()); levitateView.getElevation());
elevate.setDuration(duration); elevate.setDuration(duration);
fragmentEnterAnimationBuilder.before(elevate); fragmentEnterAnimationBuilder.before(elevate);
final Drawable levitateBackground = levitate.getBackground(); final Drawable levitateBackground = levitateView.getBackground();
final Animator fadeIn = AnimatorInflater.loadAnimator(WalletActivity.this, R.animator.fade_in_drawable); final Animator fadeIn = AnimatorInflater.loadAnimator(WalletActivity.this, R.animator.fade_in_drawable);
fadeIn.setTarget(levitateBackground); fadeIn.setTarget(levitateBackground);
fragmentEnterAnimationBuilder.before(fadeIn); fragmentEnterAnimationBuilder.before(fadeIn);
...@@ -493,4 +522,19 @@ public final class WalletActivity extends AbstractWalletActivity { ...@@ -493,4 +522,19 @@ public final class WalletActivity extends AbstractWalletActivity {
enterAnimation.end(); enterAnimation.end();
ScanActivity.startForResult(this, clickView, WalletActivity.REQUEST_CODE_SCAN); ScanActivity.startForResult(this, clickView, WalletActivity.REQUEST_CODE_SCAN);
} }
private static final class QuickReturnBehavior extends CoordinatorLayout.Behavior<View> {
@Override
public boolean onStartNestedScroll(final CoordinatorLayout coordinatorLayout, final View child,
final View directTargetChild, final View target, final int nestedScrollAxes, final int type) {
return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
}
@Override
public void onNestedScroll(final CoordinatorLayout coordinatorLayout, final View child, final View target,
final int dxConsumed, final int dyConsumed, final int dxUnconsumed, final int dyUnconsumed,
final int type) {
child.setTranslationY(Floats.constrainToRange(child.getTranslationY() - dyConsumed, -child.getHeight(), 0));
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment