Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix binance buy section close related issue #8527

Merged
merged 1 commit into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
Expand Down Expand Up @@ -118,9 +118,13 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TreeMap;

public class BraveNewTabPageLayout extends NewTabPageLayout {
public class BraveNewTabPageLayout
extends NewTabPageLayout implements CryptoWidgetBottomSheetDialogFragment
.CryptoWidgetBottomSheetDialogDismissListener {
private static final String TAG = "BraveNewTabPageView";
private static final String BRAVE_BINANCE = "https://brave.com/binance/";
private static final String BRAVE_REF_URL = "https://brave.com/r/";
Expand Down Expand Up @@ -157,7 +161,7 @@ public class BraveNewTabPageLayout extends NewTabPageLayout {

private BinanceNativeWorker mBinanceNativeWorker;
private CryptoWidgetBottomSheetDialogFragment cryptoWidgetBottomSheetDialogFragment;
private CountDownTimer countDownTimer;
private Timer countDownTimer;
private List<NTPWidgetItem> widgetList = new ArrayList<NTPWidgetItem>();
public static final int NTP_WIDGET_STACK_CODE = 3333;

Expand Down Expand Up @@ -324,6 +328,9 @@ public void onClick(View view) {
cancelTimer();
cryptoWidgetBottomSheetDialogFragment =
new CryptoWidgetBottomSheetDialogFragment();
cryptoWidgetBottomSheetDialogFragment
.setCryptoWidgetBottomSheetDialogDismissListener(
BraveNewTabPageLayout.this);
cryptoWidgetBottomSheetDialogFragment.show(
((BraveActivity) mActivity).getSupportFragmentManager(),
CryptoWidgetBottomSheetDialogFragment.TAG_FRAGMENT);
Expand Down Expand Up @@ -879,7 +886,6 @@ public void onMenuDisconnect() {
private BinanceObserver mBinanaceObserver = new BinanceObserver() {
@Override
public void OnGetAccessToken(boolean isSuccess) {
Log.e("NTP", "OnGetAccessToken : " + isSuccess);
BinanceWidgetManager.getInstance().setUserAuthenticationForBinance(isSuccess);
if (isSuccess) {
mBinanceNativeWorker.getAccountBalances();
Expand Down Expand Up @@ -919,23 +925,31 @@ public void OnGetAccountBalances(String jsonBalances, boolean isSuccess) {

// start timer function
public void startTimer() {
countDownTimer = new CountDownTimer(30000, 1000) {
@Override
public void onTick(long millisUntilFinished) {}
@Override
public void onFinish() {
if (BinanceWidgetManager.getInstance().isUserAuthenticatedForBinance()) {
mBinanceNativeWorker.getAccountBalances();
if (countDownTimer == null) {
countDownTimer = new Timer();
final Handler handler = new Handler();
countDownTimer.scheduleAtFixedRate(new TimerTask() {
public void run() {
handler.post(new Runnable() {
public void run() {
if (BinanceWidgetManager.getInstance()
.isUserAuthenticatedForBinance()) {
mBinanceNativeWorker.getAccountBalances();
}
}
});
}
if ((BraveActivity) mActivity != null) startTimer();
}
};
countDownTimer.start();
}, 0, 30000);
}
}

// cancel timer
public void cancelTimer() {
if (countDownTimer != null) countDownTimer.cancel();
if (countDownTimer != null) {
countDownTimer.cancel();
countDownTimer.purge();
countDownTimer = null;
}
}

public void openWidgetStack() {
Expand All @@ -946,7 +960,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
fm.beginTransaction().remove(this).commit();
if (requestCode == NTP_WIDGET_STACK_CODE) {
Log.e("NTP", "Inside result");
showWidgets();
}
}
Expand Down Expand Up @@ -978,4 +991,9 @@ public void onTileCountChanged() {
mTopsiteErrorMessage.setVisibility(View.VISIBLE);
}
}

@Override
public void onCryptoWidgetBottomSheetDialogDismiss() {
startTimer();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,19 @@ public class BinanceBuyFragment extends Fragment {
private static final String US = ".us";
private static final String COM = ".com";

private CryptoWidgetBottomSheetDialogFragment
.BinanceBottomSheetListener mBinanceBottomSheetListener;

public BinanceBuyFragment() {
// Required empty public constructor
}

public void setBinanceBottomSheetListener(
CryptoWidgetBottomSheetDialogFragment
.BinanceBottomSheetListener binanceBottomSheetListener) {
mBinanceBottomSheetListener = binanceBottomSheetListener;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -194,15 +203,7 @@ private void setFiatSpinner(List<String> fiatSpinnerList) {
}

private void dismissBinanceBottomSheet() {
FragmentManager fm = getParentFragmentManager();
CryptoWidgetBottomSheetDialogFragment fragment =
(CryptoWidgetBottomSheetDialogFragment) fm.findFragmentByTag(
CryptoWidgetBottomSheetDialogFragment.TAG_FRAGMENT);
FragmentTransaction transaction = fm.beginTransaction();

if (fragment != null) {
fragment.dismiss();
}
mBinanceBottomSheetListener.dismissBottomSheetDialog();
}

private BinanceObserver mBinanaceObserver = new BinanceObserver() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,6 @@ public void onNothingSelected(AdapterView<?> parentView) {}
}
}

private void dismissBinanceBottomSheet() {
FragmentManager fm = getParentFragmentManager();
CryptoWidgetBottomSheetDialogFragment fragment =
(CryptoWidgetBottomSheetDialogFragment) fm.findFragmentByTag(
CryptoWidgetBottomSheetDialogFragment.TAG_FRAGMENT);
FragmentTransaction transaction = fm.beginTransaction();

if (fragment != null) {
fragment.dismiss();
}
}

private BinanceObserver mBinanaceObserver = new BinanceObserver() {
@Override
public void OnGetConvertQuote(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.chromium.chrome.browser.widget.crypto.binance;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -35,9 +36,23 @@ public class CryptoWidgetBottomSheetDialogFragment extends BottomSheetDialogFrag
final public static String TAG_FRAGMENT = "CRYPTO_WIDGET_FRAG";
private ViewPager viewPager;
private CryptoWidgetTabAdapter adapter;
private CryptoWidgetBottomSheetDialogDismissListener
mCryptoWidgetBottomSheetDialogDismissListener;

public interface BinanceBottomSheetListener {
void onContinue();
void dismissBottomSheetDialog();
}

public interface CryptoWidgetBottomSheetDialogDismissListener {
void onCryptoWidgetBottomSheetDialogDismiss();
}

public void setCryptoWidgetBottomSheetDialogDismissListener(
CryptoWidgetBottomSheetDialogDismissListener
cryptoWidgetBottomSheetDialogDismissListener) {
this.mCryptoWidgetBottomSheetDialogDismissListener =
cryptoWidgetBottomSheetDialogDismissListener;
}

@Nullable
Expand All @@ -64,11 +79,22 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
tabLayout.setupWithViewPager(viewPager);
}

@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
mCryptoWidgetBottomSheetDialogDismissListener.onCryptoWidgetBottomSheetDialogDismiss();
}

private BinanceBottomSheetListener binanceBottomSheetListener =
new BinanceBottomSheetListener() {
@Override
public void onContinue() {
if (viewPager != null && adapter != null) viewPager.setAdapter(adapter);
}

@Override
public void dismissBottomSheetDialog() {
dismiss();
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public Fragment getItem(int position) {
((BinanceConvertFragment)fragment).setBinanceBottomSheetListener(mBinanceBottomSheetListener);
} else if (position == 3) {
fragment = new BinanceBuyFragment();
((BinanceBuyFragment) fragment)
.setBinanceBottomSheetListener(mBinanceBottomSheetListener);
}
return fragment;
}
Expand Down