Skip to content

Commit

Permalink
- remove animation logic from fragment#onStop()
Browse files Browse the repository at this point in the history
 - remove fragment close logic from SlideDetector
 - clean up duplicate fragmentmanager stack pop
 - other small fixes
  • Loading branch information
vsima committed Feb 3, 2023
1 parent e3c8933 commit bd20478
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,8 @@ public void onGlobalLayout() {
@Override
public void onStop() {
super.onStop();

animateBackgroundDim(true);
animateSignalSlide(true);
// animateBackgroundDim(true);
// animateSignalSlide(true);
if (!authSucceeded)
completion.onCancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public View onCreateView(LayoutInflater inflater,
background.setOnClickListener(v -> {
if (!BRAnimator.isClickAllowed()) return;
closeMenu();
getActivity().onBackPressed();
});

itemList = new ArrayList<>();
Expand Down Expand Up @@ -82,21 +81,18 @@ public View onCreateView(LayoutInflater inflater,
itemList.add(new BRMenuItem(getString(R.string.MenuButton_lock), R.drawable.ic_lock, v -> {
closeMenu();
final Activity from = getActivity();
from.getFragmentManager().popBackStack();
BRAnimator.startBreadActivity(from, true);
}));

/* Close button*/
rootView.findViewById(R.id.close_button).setOnClickListener(v -> {
closeMenu();
Activity app = getActivity();
app.getFragmentManager().popBackStack();
});

mTitle = rootView.findViewById(R.id.title);
mListView = rootView.findViewById(R.id.menu_listview);
mListView.setAdapter(new MenuListAdapter(getContext(), R.layout.menu_list_item, itemList));
signalLayout.setOnTouchListener(new SlideDetector(getContext(), signalLayout));
signalLayout.setOnTouchListener(new SlideDetector(signalLayout, this::closeMenu));

return rootView;
}
Expand Down Expand Up @@ -154,7 +150,7 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
private void closeMenu() {
BRAnimator.animateBackgroundDim(background, true);
BRAnimator.animateSignalSlide(signalLayout, true, () -> {
if (getActivity() != null) {
if (getActivity() != null && !getActivity().isDestroyed() && !getActivity().isFinishing()) {
getActivity().getFragmentManager().popBackStack();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,22 @@ public void run() {
@Override
public void onStop() {
super.onStop();
keyboard.animate()
.translationY(1000)
.withLayer();
dialogLayout.animate()
.scaleY(0)
.scaleX(0).alpha(0);
mainLayout.animate().alpha(0);
if (!authSucceeded)
completion.onCancel();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (getActivity() != null)
getActivity().getFragmentManager().beginTransaction().remove(FragmentPin.this).commit();
}
}, 1000);
// keyboard.animate()
// .translationY(1000)
// .withLayer();
// dialogLayout.animate()
// .scaleY(0)
// .scaleX(0).alpha(0);
// mainLayout.animate().alpha(0);
// if (!authSucceeded)
// completion.onCancel();
// new Handler().postDelayed(new Runnable() {
// @Override
// public void run() {
// if (getActivity() != null)
// getActivity().getFragmentManager().beginTransaction().remove(FragmentPin.this).commit();
// }
// }, 1000);
}

public void setCompletion(BRAuthCompletion completion) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.breadwallet.presenter.fragments;

import static com.breadwallet.tools.animation.BRAnimator.animateBackgroundDim;
import static com.breadwallet.tools.animation.BRAnimator.animateSignalSlide;

import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import androidx.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -16,6 +18,8 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.breadwallet.BreadApp;
import com.breadwallet.R;
import com.breadwallet.presenter.customviews.BRButton;
Expand All @@ -32,9 +36,6 @@
import com.breadwallet.tools.util.Utils;
import com.breadwallet.wallet.BRWalletManager;

import static com.breadwallet.tools.animation.BRAnimator.animateBackgroundDim;
import static com.breadwallet.tools.animation.BRAnimator.animateSignalSlide;

public class FragmentReceive extends Fragment {
private static final String TAG = FragmentReceive.class.getName();

Expand All @@ -47,7 +48,7 @@ public class FragmentReceive extends Fragment {
private View separator;
private BRButton shareButton;
private Button shareEmail;
// private Button shareTextMessage;
// private Button shareTextMessage;
private Button requestButton;
private BRLinearLayoutWithCaret shareButtonsLayout;
private BRLinearLayoutWithCaret copiedLayout;
Expand Down Expand Up @@ -84,39 +85,25 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
separator2.setVisibility(View.GONE);

setListeners();
BRWalletManager.getInstance().addBalanceChangedListener(new BRWalletManager.OnBalanceChanged() {
@Override
public void onBalanceChanged(long balance) {
updateQr();
}
});
BRWalletManager.getInstance().addBalanceChangedListener(balance -> updateQr());

ImageButton faq = (ImageButton) rootView.findViewById(R.id.faq_button);
//TODO: all views are using the layout of this button. Views should be refactored without it
// Hiding until layouts are built.

signalLayout.removeView(shareButtonsLayout);
signalLayout.removeView(copiedLayout);

signalLayout.setLayoutTransition(BRAnimator.getDefaultTransition());

signalLayout.setOnTouchListener(new SlideDetector(getContext(), signalLayout));

signalLayout.setOnTouchListener(new SlideDetector(signalLayout, this::animateClose));
AnalyticsManager.logCustomEvent(BRConstants._20202116_VRC);

return rootView;
}


private void setListeners() {
shareEmail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!BRAnimator.isClickAllowed()) return;
String bitcoinUri = Utils.createBitcoinUrl(receiveAddress, 0, null, null, null);
QRUtils.share("mailto:", getActivity(), bitcoinUri);

}
shareEmail.setOnClickListener(v -> {
if (!BRAnimator.isClickAllowed()) return;
String bitcoinUri = Utils.createBitcoinUrl(receiveAddress, 0, null, null, null);
QRUtils.share("mailto:", getActivity(), bitcoinUri);
});
// shareTextMessage.setOnClickListener(new View.OnClickListener() {
// @Override
Expand All @@ -126,55 +113,28 @@ public void onClick(View v) {
// QRUtils.share("sms:", getActivity(), bitcoinUri);
// }
// });
shareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!BRAnimator.isClickAllowed()) return;
shareButtonsShown = !shareButtonsShown;
showShareButtons(shareButtonsShown);
}
});
mAddress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!BRAnimator.isClickAllowed()) return;
copyText();
}
shareButton.setOnClickListener(v -> {
if (!BRAnimator.isClickAllowed()) return;
shareButtonsShown = !shareButtonsShown;
showShareButtons(shareButtonsShown);
});
requestButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!BRAnimator.isClickAllowed()) return;
Activity app = getActivity();
app.onBackPressed();
BRAnimator.showRequestFragment(app, receiveAddress);

}
mAddress.setOnClickListener(v -> {
if (!BRAnimator.isClickAllowed()) return;
copyText();
});

backgroundLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!BRAnimator.isClickAllowed()) return;
getActivity().onBackPressed();
}
requestButton.setOnClickListener(v -> {
if (!BRAnimator.isClickAllowed()) return;
closeAndOpenShowRequest();
});
mQrImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!BRAnimator.isClickAllowed()) return;
copyText();
}
backgroundLayout.setOnClickListener(v -> {
if (!BRAnimator.isClickAllowed()) return;
animateClose();
});

close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Activity app = getActivity();
if (app != null)
app.getFragmentManager().popBackStack();
}
mQrImage.setOnClickListener(v -> {
if (!BRAnimator.isClickAllowed()) return;
copyText();
});
close.setOnClickListener(v -> animateClose());
}

private void showShareButtons(boolean b) {
Expand Down Expand Up @@ -218,7 +178,7 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if(observer.isAlive()) {
if (observer.isAlive()) {
observer.removeOnGlobalLayoutListener(this);
}
animateBackgroundDim(backgroundLayout, false);
Expand All @@ -240,7 +200,6 @@ public void run() {
updateQr();
}
});

}

private void updateQr() {
Expand All @@ -254,7 +213,7 @@ public void run() {
BRExecutor.getInstance().forMainThreadTasks().execute(new Runnable() {
@Override
public void run() {
((Activity) ctx).onBackPressed();
close();
}
});

Expand All @@ -273,35 +232,30 @@ public void run() {
});
}
});

}

private void copyText() {
BRClipboardManager.putClipboard(getContext(), mAddress.getText().toString());
showCopiedLayout(true);
}

@Override
public void onStop() {
super.onStop();
private void animateClose() {
animateBackgroundDim(backgroundLayout, true);
animateSignalSlide(signalLayout, true, new BRAnimator.OnSlideAnimationEnd() {
@Override
public void onAnimationEnd() {
if (getActivity() != null)
getActivity().getFragmentManager().popBackStack();
}
});
animateSignalSlide(signalLayout, true, this::close);
}

@Override
public void onResume() {
super.onResume();
private void close() {
if (getActivity() != null && !getActivity().isFinishing()) {
getActivity().onBackPressed();
}
}

@Override
public void onPause() {
super.onPause();
}
private void closeAndOpenShowRequest() {
animateBackgroundDim(backgroundLayout, true);
animateSignalSlide(signalLayout, true, () -> {
close();
BRAnimator.showRequestFragment(getActivity(), receiveAddress);
});

}
}
Loading

0 comments on commit bd20478

Please sign in to comment.