导航菜单

页面标题

页面副标题

bbinstant v6.24.0 - DiscoverActivity.java 源代码

正在查看: bbinstant v6.24.0 应用的 DiscoverActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.bigbasket.bbinstant.ui.discoverability;

import android.R;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.Html;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.c;
import androidx.fragment.app.DialogFragment;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.amazonaws.services.s3.model.InstructionFileId;
import com.bigbasket.bbinstant.App;
import com.bigbasket.bbinstant.analytics.snowplow.PlowUtils;
import com.bigbasket.bbinstant.core.Constants;
import com.bigbasket.bbinstant.core.io.socket.command.messages.BusyCommand;
import com.bigbasket.bbinstant.core.io.socket.command.messages.ClosedCommand;
import com.bigbasket.bbinstant.core.io.socket.command.messages.FreeCommand;
import com.bigbasket.bbinstant.core.io.socket.command.messages.MachineNotAvailable;
import com.bigbasket.bbinstant.core.io.socket.command.messages.MessageNotDelivered;
import com.bigbasket.bbinstant.core.io.socket.command.messages.OpenCommand;
import com.bigbasket.bbinstant.core.io.socket.command.messages.RequestRetry;
import com.bigbasket.bbinstant.core.io.socket.command.messages.TimeExpired;
import com.bigbasket.bbinstant.core.machine.entity.MachineEntity;
import com.bigbasket.bbinstant.core.machine.entity.Tray;
import com.bigbasket.bbinstant.core.payments.exceptions.CheckoutException;
import com.bigbasket.bbinstant.core.payments.newiml.PaymentManager;
import com.bigbasket.bbinstant.core.payments.repository.i1;
import com.bigbasket.bbinstant.core.persistance.LocationStore;
import com.bigbasket.bbinstant.core.rx.RxUtils;
import com.bigbasket.bbinstant.core.utils.StringUtils;
import com.bigbasket.bbinstant.labs.plower.events.d;
import com.bigbasket.bbinstant.ui.BaseActivity;
import com.bigbasket.bbinstant.ui.common.QRScanActivity;
import com.bigbasket.bbinstant.ui.discoverability.adapters.c;
import com.bigbasket.bbinstant.ui.discoverability.adapters.f;
import com.bigbasket.bbinstant.ui.discoverability.c;
import com.bigbasket.bbinstant.ui.discoverability.entity.CategoryModel;
import com.bigbasket.bbinstant.ui.discoverability.entity.MachineInfoList;
import com.bigbasket.bbinstant.ui.discoverability.entity.TrayInfoList;
import com.bigbasket.bbinstant.ui.dynamic_minimum_balance.DMBRepository;
import com.bigbasket.bbinstant.ui.dynamic_minimum_balance.MinBalanceOfferData;
import com.bigbasket.bbinstant.ui.machine.GifDialogFragment;
import com.bigbasket.bbinstant.ui.machine.MinBalanceOfferSheet;
import com.bigbasket.bbinstant.ui.payments.EmployerWalletBalanceExhausted;
import com.bigbasket.bbinstant.ui.payments.LowBalanceAlertSheet;
import com.bigbasket.bbinstant.ui.payments.UnSupportedPaymentLocation;
import com.facebook.shimmer.ShimmerFrameLayout;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class DiscoverActivity extends BaseActivity implements f.a, c.b {
    private static String TAG = "DiscoverActivity";
    private String TAG_GIF_DIALOG = "gif-dialog";
    private Map<String, List<CategoryModel>> categoryItems;
    private Dialog dialog;
    private c discovProdDialogView;
    private CompositeDisposable disposable;
    private ViewGroup errorScreen;
    private com.bigbasket.bbinstant.ui.discoverability.adapters.c itemAdapter;
    private Disposable mAnimationDisposable;
    private GifDialogFragment mGifDialogFragment;
    private Disposable mPredicateDisposable;
    private DiscoveryViewModel mViewModel;
    private MachineEntity machineEntity;
    private ShimmerFrameLayout prodLoadShimmer;
    private RecyclerView rclCategoryTab;
    private RecyclerView rclItemGrid;
    private MachineInfoList scannedMachInfo;
    private CategoryModel selectedItem;
    private Tray selectedTray;
    private Disposable socketConnectionObserver;
    private Disposable socketMessageObserver;

    class a implements i1 {
        a() {
        }

        @Override
        public void failed(Throwable th) {
            DiscoverActivity.this.onCheckoutFailed(th);
        }

        @Override
        public void success(Boolean bool) {
            DiscoverActivity.this.showGifAnim();
            String unused = DiscoverActivity.TAG;
            CompositeDisposable compositeDisposable = DiscoverActivity.this.disposable;
            Single compose = DiscoverActivity.this.mViewModel.getHookedMac().openDoor(DiscoverActivity.this.selectedTray).timeout(10L, TimeUnit.SECONDS).compose(RxUtils.applySingleSchedulers());
            final DiscoverActivity discoverActivity = DiscoverActivity.this;
            Consumer consumer = new Consumer() {
                public final void accept(Object obj) {
                    DiscoverActivity.access$600(DiscoverActivity.this, (Boolean) obj);
                }
            };
            final DiscoverActivity discoverActivity2 = DiscoverActivity.this;
            compositeDisposable.add(compose.subscribe(consumer, new Consumer() {
                public final void accept(Object obj) {
                    DiscoverActivity.access$500(DiscoverActivity.this, (Throwable) obj);
                }
            }));
        }
    }

    private void EmployerWalletBalanceExhausted() {
        EmployerWalletBalanceExhausted.INSTANCE.show(getSupportFragmentManager(), "EmployerWalletBalanceExhausted");
    }

    public static void access$500(DiscoverActivity discoverActivity, Throwable th) {
        discoverActivity.onTrayOpenFailed(th);
    }

    public static void access$600(DiscoverActivity discoverActivity, Boolean bool) {
        discoverActivity.onTrayOpenResult(bool);
    }

    private void attachTimer() {
        RxUtils.dispose(this.mAnimationDisposable);
        this.mAnimationDisposable = Completable.timer(15L, TimeUnit.SECONDS).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action() {
            public final void run() {
                DiscoverActivity.this.dismissAnimationForTimeout();
            }
        }, new com.bigbasket.bbinstant.core.io.wifi.q());
    }

    private void checkDMB(String str) {
        this.disposable.add(new DMBRepository().getData(str).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer() {
            public final void accept(Object obj) {
                DiscoverActivity.this.lambda$checkDMB$0((MinBalanceOfferData) obj);
            }
        }, new Consumer() {
            public final void accept(Object obj) {
                DiscoverActivity.lambda$checkDMB$1((Throwable) obj);
            }
        }));
    }

    private void createBottomSheet(MinBalanceOfferData minBalanceOfferData) {
        final LinearLayout linearLayout = (LinearLayout) findViewById(2131362267);
        linearLayout.setVisibility(0);
        TextView textView = (TextView) findViewById(2131362739);
        TextView textView2 = (TextView) findViewById(2131362738);
        textView.setText(minBalanceOfferData.getDmbDays().intValue() - minBalanceOfferData.getUserTransactionDays().intValue() == 1 ? com.bigbasket.bbinstant.core.persistance.d.get().getSettings().getDmbToastMessageSingular() : String.format(minBalanceOfferData.getDmbToastMessage(), ""));
        textView2.setText(String.valueOf(minBalanceOfferData.getDmbDays().intValue() - minBalanceOfferData.getUserTransactionDays().intValue()));
        final Bundle bundle = new Bundle();
        bundle.putSerializable("dmb_data", minBalanceOfferData);
        if (minBalanceOfferData.getDmbDays() == minBalanceOfferData.getUserTransactionDays()) {
            if (shouldWeCelebrate()) {
                opnenOfferBottomSheet(bundle, linearLayout);
            }
            linearLayout.setVisibility(8);
        }
        linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                DiscoverActivity.this.lambda$createBottomSheet$16(bundle, linearLayout, view);
            }
        });
    }

    private void dismissAnimation() {
        GifDialogFragment gifDialogFragment = this.mGifDialogFragment;
        if (gifDialogFragment != null) {
            gifDialogFragment.dismissAllowingStateLoss();
        }
    }

    public void dismissAnimationForTimeout() {
        GifDialogFragment gifDialogFragment = this.mGifDialogFragment;
        if (gifDialogFragment == null || gifDialogFragment.getDialog() == null || !this.mGifDialogFragment.getDialog().isShowing()) {
            return;
        }
        dismissAnimation();
        showTimeoutSnackbar();
    }

    private void dismissDialog() {
        Dialog dialog = this.dialog;
        if (dialog != null) {
            dialog.dismiss();
        }
    }

    private String getMachineIdFromQR(Intent intent) {
        String contents = com.google.zxing.integration.android.a.parseActivityResult(-1, intent).getContents();
        if (contents != null && contents.contains("mid=")) {
            String[] split = contents.split("mid=");
            if (split.length > 1) {
                return split[1];
            }
        }
        return null;
    }

    private void initSocketObserver() {
        this.disposable = new CompositeDisposable();
        this.socketConnectionObserver = com.bigbasket.bbinstant.core.io.socket.b.get().getBus().compose(RxUtils.applySchedulers()).subscribe(new Consumer() {
            public final void accept(Object obj) {
                DiscoverActivity.lambda$initSocketObserver$11((com.bigbasket.bbinstant.core.io.events.a) obj);
            }
        }, new com.bigbasket.bbinstant.core.io.wifi.q());
        this.socketMessageObserver = com.bigbasket.bbinstant.core.io.socket.c.get().getBus().compose(RxUtils.applySchedulers()).subscribe(new Consumer() {
            public final void accept(Object obj) {
                DiscoverActivity.this.onCommandReceived((com.bigbasket.bbinstant.core.io.socket.command.a) obj);
            }
        }, new com.bigbasket.bbinstant.core.io.wifi.q());
        this.disposable.add(this.socketConnectionObserver);
        this.disposable.add(this.socketMessageObserver);
    }

    private void initView() {
        this.rclCategoryTab = (RecyclerView) findViewById(2131362443);
        this.rclItemGrid = (RecyclerView) findViewById(2131362444);
        ImageView imageView = (ImageView) findViewById(2131362187);
        this.prodLoadShimmer = (ShimmerFrameLayout) findViewById(2131362525);
        this.errorScreen = (ViewGroup) findViewById(2131362082);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                DiscoverActivity.this.lambda$initView$5(view);
            }
        });
    }

    private int isOfflineConditionsMet() {
        if (!com.bigbasket.bbinstant.core.persistance.b.get().lastMinBalanceAvailable()) {
            return 1;
        }
        if (com.bigbasket.bbinstant.core.payments.newiml.q.ZETASODEXO == com.bigbasket.bbinstant.core.persistance.b.get().lastDefaultPayment()) {
            return (!com.bigbasket.bbinstant.core.persistance.b.get().isWalletEnabled() || com.bigbasket.bbinstant.core.persistance.b.get().lastKwik24Balance() <= com.bigbasket.bbinstant.core.persistance.b.get().minBalanceToMakeTransaction()) ? 2 : 0;
        }
        return 0;
    }

    public void lambda$checkDMB$0(MinBalanceOfferData minBalanceOfferData) throws Exception {
        if (minBalanceOfferData == null || !shoulshowDMB(minBalanceOfferData)) {
            return;
        }
        createBottomSheet(minBalanceOfferData);
    }

    public static void lambda$checkDMB$1(Throwable th) throws Exception {
    }

    public void lambda$createBottomSheet$16(Bundle bundle, LinearLayout linearLayout, View view) {
        opnenOfferBottomSheet(bundle, linearLayout);
    }

    public static void lambda$initSocketObserver$11(com.bigbasket.bbinstant.core.io.events.a aVar) throws Exception {
    }

    public void lambda$initView$5(View view) {
        onBackPressed();
    }

    public void lambda$observeConectionMac$2(Object obj) {
        if (obj instanceof Boolean) {
            Boolean bool = (Boolean) obj;
            if (bool.booleanValue()) {
                this.discovProdDialogView.updateProgressBar(8);
                this.discovProdDialogView.updateBuyBtn(c.b.BUY);
            } else {
                this.discovProdDialogView.updateProgressBar(0);
                this.discovProdDialogView.updateBuyBtn(c.b.CONNECTING);
            }
            PlowUtils.MachineInteractionHelper.trackBrowseBuyNowEnabled(bool.booleanValue());
        }
        if (obj instanceof Throwable) {
            this.discovProdDialogView.updateProgressBar(8);
            this.discovProdDialogView.updateBuyBtn(c.b.SCAN);
            this.discovProdDialogView.showAllMachineList();
            Toast.makeText(this, "Connection Failed. Please try again.", 0).show();
        }
    }

    public void lambda$observerCategoryData$3(View view) {
        observerCategoryData();
    }

    public void lambda$observerCategoryData$4(Map map) {
        if (map == null) {
            this.errorScreen.setVisibility(0);
            this.prodLoadShimmer.setVisibility(8);
            this.errorScreen.findViewById(2131361930).setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    DiscoverActivity.this.lambda$observerCategoryData$3(view);
                }
            });
            PlowUtils.ScreenViewHelper.trackBrowseErrorScreen();
            return;
        }
        this.errorScreen.setVisibility(8);
        this.prodLoadShimmer.setVisibility(8);
        this.mViewModel.addAllToCategoryItem(map);
        this.categoryItems = map;
        setCategoryTab(map);
        onTabSelected("All");
    }

    public static void lambda$onAuthenticationFailed$13(com.bigbasket.bbinstant.core.payments.newiml.r rVar, com.google.android.material.bottomsheet.a aVar, View view) {
        Bundle bundle = new Bundle();
        bundle.putString("deeplink", "link");
        bundle.putString("paymentType", rVar.model().type().value());
        aVar.dismiss();
    }

    public void lambda$onCommandReceived$10(Long l) throws Exception {
        checkDMB(LocationStore.get().getRecentLocations().get(0).getId());
    }

    public static void lambda$onPaymentSyncFailed$12(com.google.android.material.bottomsheet.a aVar, View view) {
        aVar.dismiss();
        PaymentManager.get().refreshSilent(LocationStore.get().getRecentLocations().get(0).getId());
    }

    public void lambda$showConfDialog$8(DialogInterface dialogInterface, int i) {
        openTray();
    }

    public void lambda$showProductDetail$6(CategoryModel categoryModel, View view) {
        if (view.getTag() == c.b.SCAN) {
            requestQRScan();
            PlowUtils.ProductInteractionHelper.trackBrowseScanNConnectClick(categoryModel);
        } else if (view.getTag() == c.b.BUY) {
            showConfDialog();
            PlowUtils.ProductInteractionHelper.trackBrowseBuyNowClick(this.scannedMachInfo, this.selectedItem);
        }
    }

    public void lambda$showProductDetail$7(View view) {
        this.dialog.dismiss();
    }

    private void observeConectionMac() {
        this.mViewModel.getConnection().observe(this, new androidx.lifecycle.s() {
            @Override
            public final void onChanged(Object obj) {
                DiscoverActivity.this.lambda$observeConectionMac$2(obj);
            }
        });
    }

    private void observerCategoryData() {
        this.mViewModel.init(this.machineEntity);
        this.prodLoadShimmer.setVisibility(0);
        this.errorScreen.setVisibility(8);
        this.mViewModel.getListCat().observe(this, new androidx.lifecycle.s() {
            @Override
            public final void onChanged(Object obj) {
                DiscoverActivity.this.lambda$observerCategoryData$4((Map) obj);
            }
        });
    }

    private void onAuthenticationFailed() {
        final com.bigbasket.bbinstant.core.payments.newiml.r wallet = PaymentManager.get().getWallet(PaymentManager.get().getDefaultPayment());
        if (wallet == null) {
            return;
        }
        com.bigbasket.bbinstant.ui.payments.errors.a aVar = new com.bigbasket.bbinstant.ui.payments.errors.a(this);
        aVar.setTitle("Relink " + wallet.name() + InstructionFileId.DOT);
        StringBuilder sb = new StringBuilder();
        sb.append(wallet.model().type().displayName());
        sb.append(" session timeout. Kindly relink.");
        aVar.setDescription(sb.toString());
        final com.google.android.material.bottomsheet.a aVar2 = new com.google.android.material.bottomsheet.a(this);
        aVar2.setContentView(aVar.getView());
        aVar.positiveBtn().setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                DiscoverActivity.lambda$onAuthenticationFailed$13(com.bigbasket.bbinstant.core.payments.newiml.r.this, aVar2, view);
            }
        });
        aVar.cancelBtn().setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                aVar2.dismiss();
            }
        });
        aVar2.show();
    }

    public void onCommandReceived(com.bigbasket.bbinstant.core.io.socket.command.a aVar) {
        GifDialogFragment gifDialogFragment;
        if (aVar instanceof TimeExpired) {
            Toast.makeText(this, "Time Expired", 0).show();
            dismissAnimation();
        }
        if ((aVar instanceof RequestRetry) && (gifDialogFragment = this.mGifDialogFragment) != null) {
            gifDialogFragment.update(1);
            attachTimer();
        }
        if (aVar instanceof OpenCommand) {
            GifDialogFragment gifDialogFragment2 = this.mGifDialogFragment;
            if (gifDialogFragment2 != null) {
                gifDialogFragment2.update(1);
                attachTimer();
            }
            PlowUtils.MachineInteractionHelper.trackBrwoseDoorEvent(this.mViewModel.getHookedMac(), d.g.OPENED);
        }
        if (aVar instanceof BusyCommand) {
            Toast.makeText(App.get(), "Please wait for your turn", 0).show();
            dismissAnimation();
        }
        if (aVar instanceof FreeCommand) {
            Toast.makeText(App.get(), "Machine is Available", 0).show();
            dismissAnimation();
            dismissDialog();
        }
        if (aVar instanceof MessageNotDelivered) {
            dismissAnimation();
            if (isOfflineConditionsMet() == 0) {
                this.mViewModel.resign();
            }
        }
        if (aVar instanceof MachineNotAvailable) {
            dismissAnimation();
            if (isOfflineConditionsMet() == 0) {
                this.mViewModel.resign();
            }
            Toast.makeText(this, "Machine not available", 0).show();
        }
        if (aVar instanceof ClosedCommand) {
            dismissAnimation();
            PaymentManager.get().refreshSilent(LocationStore.get().getRecentLocations().get(0).getId());
            PlowUtils.MachineInteractionHelper.trackBrwoseDoorEvent(this.mViewModel.getHookedMac(), d.g.CLOSED);
            Toast makeText = Toast.makeText(this, "Order Picked, continue shopping ", 0);
            makeText.setGravity(80, 0, 200);
            makeText.show();
        }
        if (aVar instanceof com.bigbasket.bbinstant.core.io.socket.command.b) {
            this.disposable.add(Observable.timer(1L, TimeUnit.SECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer() {
                public final void accept(Object obj) {
                    DiscoverActivity.this.lambda$onCommandReceived$10((Long) obj);
                }
            }));
        }
        boolean z = aVar instanceof com.bigbasket.bbinstant.core.io.socket.command.messages.c;
    }

    private void onPaymentSyncFailed() {
        com.bigbasket.bbinstant.ui.payments.errors.a aVar = new com.bigbasket.bbinstant.ui.payments.errors.a(this);
        aVar.setTitle("Payment Sync Failed");
        aVar.setDescription("Unable to fetch payment details, please retry.");
        final com.google.android.material.bottomsheet.a aVar2 = new com.google.android.material.bottomsheet.a(this);
        aVar2.setContentView(aVar.getView());
        aVar.cancelBtn().setVisibility(4);
        aVar.positiveBtn().setText("Retry");
        aVar.positiveBtn().setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                DiscoverActivity.lambda$onPaymentSyncFailed$12(aVar2, view);
            }
        });
        aVar2.show();
    }

    public void onTrayOpenFailed(Throwable th) {
        this.mViewModel.resign();
    }

    public void onTrayOpenResult(Boolean bool) {
    }

    private void onUnKnowErrors() {
        com.bigbasket.bbinstant.ui.payments.errors.a aVar = new com.bigbasket.bbinstant.ui.payments.errors.a(this);
        aVar.setTitle("Something went wrong");
        aVar.setDescription("Something went wrong, please try again.");
        final com.google.android.material.bottomsheet.a aVar2 = new com.google.android.material.bottomsheet.a(this);
        aVar2.setContentView(aVar.getView());
        aVar.cancelBtn().setVisibility(4);
        aVar.positiveBtn().setText("OK");
        aVar.positiveBtn().setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                aVar2.dismiss();
            }
        });
        aVar2.show();
    }

    private void onUnsupportedLocation() {
        UnSupportedPaymentLocation.INSTANCE.show(getSupportFragmentManager(), "onUnsupportedLocation");
    }

    private void opnenOfferBottomSheet(Bundle bundle, LinearLayout linearLayout) {
        BottomSheetDialogFragment minBalanceOfferSheet = MinBalanceOfferSheet.getInstance();
        if (minBalanceOfferSheet.isAdded() || getFragmentManager() == null) {
            return;
        }
        minBalanceOfferSheet.setArguments(bundle);
        minBalanceOfferSheet.show(getSupportFragmentManager(), "NA");
        linearLayout.setVisibility(8);
    }

    private void setCategoryTab(Map<String, List<CategoryModel>> map) {
        com.bigbasket.bbinstant.ui.discoverability.adapters.f fVar = new com.bigbasket.bbinstant.ui.discoverability.adapters.f(this, map);
        this.rclCategoryTab.setLayoutManager(new LinearLayoutManager(this, 0, false));
        this.rclCategoryTab.setAdapter(fVar);
    }

    private void setProductGrid(List<CategoryModel> list) {
        com.bigbasket.bbinstant.ui.discoverability.adapters.c cVar = this.itemAdapter;
        if (cVar != null) {
            cVar.refreshView(list);
            return;
        }
        this.rclItemGrid.addItemDecoration(new c.a(10));
        this.itemAdapter = new com.bigbasket.bbinstant.ui.discoverability.adapters.c(this, list);
        this.rclItemGrid.setLayoutManager(new GridLayoutManager(this, 3));
        this.rclItemGrid.setAdapter(this.itemAdapter);
    }

    private void setSelectedTray(List<TrayInfoList> list) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getQuantity().intValue() > 0) {
                TrayInfoList trayInfoList = list.get(i);
                Tray tray = new Tray();
                this.selectedTray = tray;
                tray.setName(trayInfoList.getTrayName());
                this.selectedTray.setContainerId(String.valueOf(trayInfoList.getContainerId()));
                this.selectedTray.setLockcode(trayInfoList.getLockCode());
                this.selectedTray.setQuantity(String.valueOf(trayInfoList.getQuantity()));
                this.selectedTray.setId(String.valueOf(trayInfoList.getId()));
                return;
            }
        }
    }

    private boolean shouldWeCelebrate() {
        return com.bigbasket.bbinstant.core.persistance.c.get().getDefaultsBoolean(Constants.Preference.SHOULD_SHOW_DMB_CELECREATION, true).booleanValue();
    }

    private boolean shoulshowDMB(MinBalanceOfferData minBalanceOfferData) {
        return minBalanceOfferData.getDmbEnabled().booleanValue() && minBalanceOfferData.getDmbDays().intValue() >= minBalanceOfferData.getUserTransactionDays().intValue();
    }

    private void showConfDialog() {
        new c.a(this, 2131951859).setTitle("Confirmation").setMessage(Html.fromHtml("Open <b>Tray" + this.selectedTray.getName().charAt(0) + " from " + this.scannedMachInfo.getFriendlyName() + "</b> to buy this product?")).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i) {
                DiscoverActivity.this.lambda$showConfDialog$8(dialogInterface, i);
            }
        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i) {
                dialogInterface.dismiss();
            }
        }).create().show();
    }

    public void showGifAnim() {
        if (this.mGifDialogFragment == null) {
            this.mGifDialogFragment = new GifDialogFragment();
        }
        this.mGifDialogFragment.show(getSupportFragmentManager(), this.TAG_GIF_DIALOG);
        attachTimer();
    }

    private void showOfflineError(int i) {
        Toast.makeText(this, "Offline error", 0).show();
    }

    private void showProductDetail(final CategoryModel categoryModel) {
        this.dialog = new Dialog(this);
        this.discovProdDialogView = new c(this);
        com.bigbasket.bbinstant.ui.discoverability.adapters.d dVar = new com.bigbasket.bbinstant.ui.discoverability.adapters.d(this, categoryModel);
        this.dialog.getWindow().setBackgroundDrawable(new ColorDrawable(App.get().getResources().getColor(R.color.transparent)));
        this.dialog.setContentView(this.discovProdDialogView.with(categoryModel, dVar));
        this.discovProdDialogView.getBuyButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                DiscoverActivity.this.lambda$showProductDetail$6(categoryModel, view);
            }
        });
        this.discovProdDialogView.getCloseView().setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                DiscoverActivity.this.lambda$showProductDetail$7(view);
            }
        });
        getWindowManager().getDefaultDisplay().getMetrics(new DisplayMetrics());
        this.dialog.getWindow().setLayout((int) (r6.widthPixels * 0.8d), -2);
        this.dialog.show();
        this.dialog.setCanceledOnTouchOutside(false);
    }

    private void showTimeoutSnackbar() {
        if (this.mGifDialogFragment.getState() == 2) {
            checkDMB(LocationStore.get().getRecentLocations().get(0).getId());
        }
    }

    @Override
    protected void onActivityResult(int i, int i2, Intent intent) {
        c cVar;
        super.onActivityResult(i, i2, intent);
        if (i == 49374 && i2 == -1 && intent != null) {
            String machineIdFromQR = getMachineIdFromQR(intent);
            if (machineIdFromQR == null || (cVar = this.discovProdDialogView) == null) {
                c cVar2 = this.discovProdDialogView;
                if (cVar2 != null) {
                    cVar2.updateErrorView();
                    return;
                }
                return;
            }
            MachineInfoList hasCorrectMacScaned = cVar.hasCorrectMacScaned(machineIdFromQR);
            this.scannedMachInfo = hasCorrectMacScaned;
            if (hasCorrectMacScaned == null) {
                this.discovProdDialogView.updateErrorView();
                return;
            }
            MachineEntity machineEntity = this.mViewModel.getMachineEntity(machineIdFromQR);
            setSelectedTray(this.scannedMachInfo.getTrayInfoList());
            this.discovProdDialogView.updateMachineList(this.scannedMachInfo);
            this.discovProdDialogView.updateProgressBar(0);
            this.discovProdDialogView.updateBuyBtn(c.b.CONNECTING);
            this.mViewModel.machinePredictionAndConnect(machineEntity);
        }
    }

    public void onCheckoutFailed(Throwable th) {
        dismissAnimation();
        if (th instanceof CheckoutException.PaymentNotInitialized) {
            onPaymentSyncFailed();
            return;
        }
        if (th instanceof CheckoutException.TransactionCancelled) {
            return;
        }
        if (th instanceof CheckoutException.LowBalance) {
            DialogFragment dialogFragment = (DialogFragment) getSupportFragmentManager().findFragmentByTag("lowBalanceAlert");
            if (dialogFragment != null) {
                dialogFragment.dismissAllowingStateLoss();
            }
            dismissAnimation();
            LowBalanceAlertSheet.getInstance().show(getSupportFragmentManager(), "lowBalanceAlert");
            return;
        }
        if ((th instanceof CheckoutException.UnRegisteredType) || (th instanceof CheckoutException.Authentication) || (th instanceof CheckoutException.DisabledWallet)) {
            return;
        }
        if (th instanceof CheckoutException.UnknownPaymentType) {
            onUnKnowErrors();
            return;
        }
        if (th instanceof CheckoutException.UnSupportedPaymentType) {
            return;
        }
        if (th instanceof CheckoutException.NotAnEmployerLocation) {
            onUnsupportedLocation();
        } else if (th instanceof CheckoutException.EmployerWalletBalanceExhausted) {
            EmployerWalletBalanceExhausted();
        } else if (th instanceof CheckoutException) {
            onUnKnowErrors();
        }
    }

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(2131558434);
        initView();
        this.machineEntity = (MachineEntity) getIntent().getSerializableExtra("mac_entity");
        this.disposable = new CompositeDisposable();
        this.mViewModel = (DiscoveryViewModel) ViewModelProviders.of(this).get(DiscoveryViewModel.class);
        MachineEntity machineEntity = this.machineEntity;
        if (machineEntity == null || machineEntity.getLocation_id() == null) {
            Toast.makeText(App.get(), getString(2131886468), 0).show();
            finish();
        }
        observerCategoryData();
        observeConectionMac();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        this.disposable.dispose();
    }

    @Override
    public void onGridItemSelect(CategoryModel categoryModel) {
        PlowUtils.ProductInteractionHelper.trackBrowseProductSelect(categoryModel);
        showProductDetail(categoryModel);
        this.selectedItem = categoryModel;
    }

    @Override
    protected void onResume() {
        super.onResume();
        initSocketObserver();
    }

    @Override
    protected void onStop() {
        super.onStop();
        RxUtils.dispose(this.disposable);
        RxUtils.dispose(this.socketConnectionObserver, this.socketMessageObserver, this.mPredicateDisposable);
        this.mViewModel.disconnectMachine();
        c cVar = this.discovProdDialogView;
        if (cVar != null) {
            cVar.updateBuyBtn(c.b.SCAN);
        }
        GifDialogFragment gifDialogFragment = this.mGifDialogFragment;
        if (gifDialogFragment != null) {
            gifDialogFragment.dismissAllowingStateLoss();
        }
    }

    @Override
    public void onTabSelected(String str) {
        PlowUtils.ScreenViewHelper.trackBrowseCateogryClick();
        setProductGrid(this.categoryItems.get(str));
    }

    public void openTray() {
        this.dialog.dismiss();
        if (!StringUtils.oneOf(this.mViewModel.getHookedMac().model().getPayment_type(), "All", com.bigbasket.bbinstant.core.payments.newiml.q.KWIK24CREDIT.value(), PaymentManager.get().getDefaultPayment().value())) {
            onCheckoutFailed(new CheckoutException.UnSupportedPaymentType());
            return;
        }
        if (!this.mViewModel.getHookedMac().type().isOffline()) {
            PaymentManager.get().canOpenDoor(StringUtils.toInt(this.selectedItem.getPrice()), new a());
        } else if (com.bigbasket.bbinstant.core.persistance.b.get().lastMinBalanceAvailable()) {
            if (!this.mViewModel.isEligibleOffline()) {
                Toast.makeText(this, getString(2131886406), 1).show();
            } else {
                showGifAnim();
                this.disposable.add(this.mViewModel.getHookedMac().openDoor(this.selectedTray).timeout(10L, TimeUnit.SECONDS).compose(RxUtils.applySingleSchedulers()).subscribe(new Consumer() {
                    public final void accept(Object obj) {
                        DiscoverActivity.this.onTrayOpenResult((Boolean) obj);
                    }
                }, new Consumer() {
                    public final void accept(Object obj) {
                        DiscoverActivity.this.onTrayOpenFailed((Throwable) obj);
                    }
                }));
            }
        }
    }

    public void requestQRScan() {
        com.google.zxing.integration.android.a aVar = new com.google.zxing.integration.android.a(this);
        aVar.setDesiredBarcodeFormats(new String[]{"QR_CODE"});
        aVar.setBeepEnabled(true);
        aVar.setOrientationLocked(true);
        aVar.setCameraId(0);
        aVar.setCaptureActivity(QRScanActivity.class);
        aVar.initiateScan();
    }
}