CommodityListGoogleFragment.java 源代码


package activity.cloud1.fragment;

import activity.cloud.api.GoogleApiFactory;
import activity.cloud.bean.GoodsGroupRequ;
import activity.cloud.bean.GoodsGroupResp;
import activity.cloud.re.HttpThrowable;
import activity.cloud.re.MyCallBack;
import activity.cloud.utils.DateUtils;
import activity.cloud1.CloudInfoGoogleActivity;
import activity.cloud1.adapter.GoodsGroupGoogleItemAdapter;
import activity.cloud1.bean.CreateGoogleOrderBack;
import activity.cloud1.bean.CreateGoogleOrderReq;
import activity.cloud1.bean.GetAllPackageBack;
import activity.cloud1.bean.GetGoogleServiceBack;
import activity.cloud1.bean.GetGoogleServiceReq;
import activity.cloud1.bean.VerifyOrderBack;
import activity.cloud1.bean.VerifyOrderReq;
import activity.cloud1.fragment.CommodityListGoogleFragment;
import activity.cloud1.mannager.BillingClientManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import base.HiFragment;
import bean.MyCamera;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import com.android.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingClientStateListener;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.ConsumeResponseListener;
import com.android.billingclient.api.Purchase;
import com.android.billingclient.api.SkuDetails;
import com.android.billingclient.api.SkuDetailsResponseListener;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hichip.callback.ICameraIOSessionCallback;
import com.hichip.campro.R;
import com.hichip.control.HiCamera;
import com.meizu.cloud.pushsdk.constants.PushConstants;
import com.meizu.cloud.pushsdk.notification.model.AdvanceSetting;
import com.meizu.cloud.pushsdk.notification.model.AdvertisementOption;
import common.Constant;
import common.ConstantCommand;
import common.HiDataValue;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import utils.HiLogcatUtil;
import utils.RecyclerViewSpacesItemDecoration;
import utils.SharePreUtils;
import utils.TimeUtil;
import utils.ToastUtil;

public class CommodityListGoogleFragment extends HiFragment implements ICameraIOSessionCallback {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    public static boolean isRefreshInfo = false;

    private CloudInfoGoogleActivity f979activity;
    private BillingClientManager billingClientManager;
    private Purchase currentPurchase;
    List<GoodsGroupResp> data;
    private boolean getGoogleError;
    GetAllPackageBack.GoodsesBean goodsBean;
    GoodsGroupGoogleItemAdapter groupItemAdapter;
    private boolean isBoughtCloud;
    private boolean isSelectGoods;
    private View layoutView;
    LinearLayout llBottom;
    LinearLayout llCloudInfo;
    private MyCamera mCamera;
    private String mParam1;
    private String mParam2;
    private int purchaseId;
    RecyclerView recCategory;
    private Runnable runnable;
    NestedScrollView scrollView;
    TextView tvDesc;
    TextView tvGoPay;
    TextView tvInfoNo;
    TextView tvPrice;
    TextView tvTime;
    TextView tv_package_timeout;
    Unbinder unbinder;
    String uuid;
    private int videoSaveDaysBuy;
    int videoSaveDays = 0;
    List<GetAllPackageBack.GoodsesBean> listData = new ArrayList();
    private List<SkuDetails> skuList = new ArrayList();
    private String ecsIp = "8.209.77.99";
    private Handler handler = new Handler();
    private Handler mIOHandler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            MyCamera myCamera = (MyCamera) message.obj;
            int i = message.what;
            if (i == -1879048191) {
                CommodityListGoogleFragment.this.handSessionState(message, myCamera);
            } else {
                if (i != -1879048189) {
                    return;
                }
                if (message.arg2 == 0) {
                    CommodityListGoogleFragment.this.handIOCTRLSuccess(message, myCamera);
                } else {
                    CommodityListGoogleFragment.this.handIOCTRLFail(message, myCamera);
                }
            }
        }
    };

    public void handIOCTRLFail(Message message, MyCamera myCamera) {
    }

    public static CommodityListGoogleFragment newInstance(String str, CloudInfoGoogleActivity cloudInfoGoogleActivity) {
        CommodityListGoogleFragment commodityListGoogleFragment = new CommodityListGoogleFragment();
        Bundle bundle = new Bundle();
        bundle.putString(ARG_PARAM1, str);
        commodityListGoogleFragment.f979activity = cloudInfoGoogleActivity;
        commodityListGoogleFragment.setArguments(bundle);
        return commodityListGoogleFragment;
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (getArguments() != null) {
            this.mParam1 = getArguments().getString(ARG_PARAM1);
            this.mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.activity_commodity_list_google, viewGroup, false);
        this.layoutView = inflate;
        this.unbinder = ButterKnife.bind(this, inflate);
        initView();
        initData();
        setListener();
        return this.layoutView;
    }

    @Override
    public void setUserVisibleHint(boolean z) {
        super.setUserVisibleHint(z);
        if (z && this.listData.size() == 0) {
            showJuHuaDialog(false);
        }
        if (z && this.getGoogleError && getActivity() != null) {
            dismissJuHuaDialog();
            Toast.makeText(getActivity(), getString(R.string.netword_abnormal), 1).show();
            getActivity().finish();
        }
    }

    private void setListener() {
        this.tvGoPay.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                CommodityListGoogleFragment.this.lambda$setListener$0$CommodityListGoogleFragment(view);
            }
        });
    }

    public void lambda$setListener$0$CommodityListGoogleFragment(View view) {
        String trim = this.tvPrice.getText().toString().trim();
        if (trim.equals("0.00")) {
            ToastUtil.showShort(getActivity(), R.string.choose_product);
            return;
        }
        for (SkuDetails skuDetails : this.skuList) {
            if (skuDetails.getPrice().equals(trim)) {
                goBuy(skuDetails);
                return;
            }
        }
    }

    private void goBuy(SkuDetails skuDetails) {
        ArrayList<Purchase> arrayList = new ArrayList(this.billingClientManager.queryPurchases(BillingClient.SkuType.INAPP));
        if (arrayList.size() > 0) {
            HiLogcatUtil.iTag(HiLogcatUtil.TAG_Google, arrayList.toString());
            for (Purchase purchase : arrayList) {
                if (purchase.getPurchaseState() == 1) {
                    HiLogcatUtil.wTag(HiLogcatUtil.TAG_Google, "存在未处理订单: " + purchase.toString());
                    showJuHuaDialog(false);
                    this.currentPurchase = purchase;
                    if (TextUtils.isEmpty(this.mCamera.getCloudOrderSN())) {
                        checkFromService(purchase);
                        return;
                    } else {
                        checkFromServiceAgain(purchase);
                        return;
                    }
                }
            }
            CloudInfoGoogleActivity cloudInfoGoogleActivity = this.f979activity;
            if (cloudInfoGoogleActivity != null) {
                this.billingClientManager.launchBillingFlow(skuDetails, cloudInfoGoogleActivity, this.uuid);
                return;
            }
            return;
        }
        HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, "start buy");
        CloudInfoGoogleActivity cloudInfoGoogleActivity2 = this.f979activity;
        if (cloudInfoGoogleActivity2 != null) {
            this.billingClientManager.launchBillingFlow(skuDetails, cloudInfoGoogleActivity2, this.uuid);
        }
    }

    private void checkFromServiceAgain(Purchase purchase) {
        VerifyOrderReq verifyOrderReq = new VerifyOrderReq(this.mCamera.getCloudOrderSN(), DateUtils.getDate());
        HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, verifyOrderReq.toString());
        GoogleApiFactory.getApi().VerifyOrder(verifyOrderReq).enqueue(new AnonymousClass1(purchase));
    }

    public class AnonymousClass1 extends MyCallBack<VerifyOrderBack> {
        final Purchase val$purchase;

        AnonymousClass1(Purchase purchase) {
            this.val$purchase = purchase;
        }

        @Override
        public void onSuccess(VerifyOrderBack verifyOrderBack) {
            if (CommodityListGoogleFragment.this.f979activity == null || CommodityListGoogleFragment.this.getActivity() == null || CommodityListGoogleFragment.this.billingClientManager == null) {
                return;
            }
            HiLogcatUtil.wTag(HiLogcatUtil.TAG_Google, verifyOrderBack.toString());
            if (verifyOrderBack.getStatus() == 99) {
                CommodityListGoogleFragment.this.mCamera.setCloudOrderSN("");
                CommodityListGoogleFragment.this.openDevCloudSwitch();
                if (CommodityListGoogleFragment.this.handler != null) {
                    CommodityListGoogleFragment.this.handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            CommodityListGoogleFragment.this.videoSaveDays = CommodityListGoogleFragment.this.videoSaveDaysBuy;
                            CommodityListGoogleFragment.this.groupItemAdapter.setTimeout(false, true, CommodityListGoogleFragment.this.videoSaveDays);
                            CommodityListGoogleFragment.this.groupItemAdapter.notifyDataSetChanged();
                        }
                    }, 1000L);
                }
                CommodityListGoogleFragment.this.billingClientManager.consumeAsync(this.val$purchase, new ConsumeResponseListener() {
                    @Override
                    public void onConsumeResponse(BillingResult billingResult, String str) {
                        CloudGoogleFragment.isUpdatePackage = true;
                        if (CommodityListGoogleFragment.this.handler != null) {
                            CommodityListGoogleFragment.this.handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    CommodityListGoogleFragment.this.dismissJuHuaDialog();
                                    if (CommodityListGoogleFragment.this.f979activity == null || CommodityListGoogleFragment.this.f979activity.viewPager == null || CommodityListGoogleFragment.this.f979activity.viewPager.getCurrentItem() == 0) {
                                        return;
                                    }
                                    CommodityListGoogleFragment.this.f979activity.viewPager.setCurrentItem(0, true);
                                }
                            }, 1500L);
                        }
                    }
                });
                return;
            }
            CommodityListGoogleFragment.this.dismissJuHuaDialog();
            Toast.makeText(CommodityListGoogleFragment.this.f979activity, CommodityListGoogleFragment.this.getString(R.string.check_error), 0).show();
            CommodityListGoogleFragment.this.f979activity.finish();
        }

        @Override
        public void onError(Throwable th, String str) {
            if (CommodityListGoogleFragment.this.f979activity == null || CommodityListGoogleFragment.this.getActivity() == null || CommodityListGoogleFragment.this.billingClientManager == null) {
                return;
            }
            CommodityListGoogleFragment.this.dismissJuHuaDialog();
            HiLogcatUtil.eTag(HiLogcatUtil.TAG_Google, "errMsg: " + str);
            CommodityListGoogleFragment.this.f979activity.finish();
        }
    }

    private void initView() {
        if (!TextUtils.isEmpty(this.mParam1)) {
            this.uuid = this.mParam1;
        }
        if (!TextUtils.isEmpty(this.uuid)) {
            Iterator<MyCamera> it = HiDataValue.CameraList.iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                MyCamera next = it.next();
                if (this.uuid.equals(next.getUid())) {
                    this.mCamera = next;
                    next.registerIOSessionListener(this);
                    break;
                }
            }
        }
        BillingClientManager billingClientManager = BillingClientManager.getInstance();
        this.billingClientManager = billingClientManager;
        billingClientManager.initClient(this.f979activity, new AnonymousClass2());
    }

    public class AnonymousClass2 implements BillingClientManager.OnPurchaseCallBack {
        AnonymousClass2() {
        }

        @Override
        public void onPaySuccess(List<Purchase> list) {
            if (CommodityListGoogleFragment.this.f979activity == null) {
                return;
            }
            CommodityListGoogleFragment.this.showJuHuaDialog(false);
            CommodityListGoogleFragment.this.currentPurchase = list.get(0);
            HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, "onPaySuccess -> PurchaseState: " + CommodityListGoogleFragment.this.currentPurchase.getPurchaseState());
            if (CommodityListGoogleFragment.this.currentPurchase.getPurchaseState() != 1) {
                if (CommodityListGoogleFragment.this.handler != null) {
                    CommodityListGoogleFragment.this.handler.postDelayed(new Runnable() {
                        @Override
                        public final void run() {
                            CommodityListGoogleFragment.AnonymousClass2.this.lambda$onPaySuccess$0$CommodityListGoogleFragment$2();
                        }
                    }, 10000L);
                }
            } else {
                CommodityListGoogleFragment commodityListGoogleFragment = CommodityListGoogleFragment.this;
                commodityListGoogleFragment.checkFromService(commodityListGoogleFragment.currentPurchase);
            }
        }

        public void lambda$onPaySuccess$0$CommodityListGoogleFragment$2() {
            if (CommodityListGoogleFragment.this.f979activity != null) {
                CommodityListGoogleFragment.this.f979activity.finish();
            }
        }

        @Override
        public void onUserCancel() {
            if (CommodityListGoogleFragment.this.f979activity == null) {
                return;
            }
            Toast.makeText(CommodityListGoogleFragment.this.f979activity, CommodityListGoogleFragment.this.getString(R.string.user_cancel_buy), 0).show();
        }

        @Override
        public void onError(int i) {
            HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, "onError: " + i);
            if (CommodityListGoogleFragment.this.f979activity == null) {
                return;
            }
            CommodityListGoogleFragment.this.f979activity.finish();
            Toast.makeText(CommodityListGoogleFragment.this.f979activity, CommodityListGoogleFragment.this.getString(R.string.buy_error), 0).show();
        }
    }

    public void checkFromService(Purchase purchase) {
        if (purchase == null) {
            return;
        }
        Date date = new Date();
        date.setTime(purchase.getPurchaseTime());
        CreateGoogleOrderReq createGoogleOrderReq = new CreateGoogleOrderReq();
        createGoogleOrderReq.setToken("9527");
        createGoogleOrderReq.setUUID(this.mCamera.getUid());
        createGoogleOrderReq.setGoodsId(this.purchaseId);
        createGoogleOrderReq.setYunServerNo(HiDataValue.OSSFILEEn_HX);
        createGoogleOrderReq.setPaytype("googlePay");
        createGoogleOrderReq.setTransactionID(purchase.getOrderId());
        createGoogleOrderReq.setReceiptData(purchase.getPurchaseToken());
        createGoogleOrderReq.setSandboxFlag(PushConstants.PUSH_TYPE_NOTIFY);
        createGoogleOrderReq.setPurchaseKey("Bl1skLCcgrQXacnAPW0q06KK");
        createGoogleOrderReq.setPurchaseTime(DateUtils.getGMTDate(date));
        createGoogleOrderReq.setECSIP(this.mCamera.getEcsIp());
        createGoogleOrderReq.setDate(DateUtils.getDate());
        HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, createGoogleOrderReq.toString());
        GoogleApiFactory.getApi().CreateGoogleOrder(createGoogleOrderReq).enqueue(new AnonymousClass3(purchase));
    }

    public class AnonymousClass3 extends MyCallBack<CreateGoogleOrderBack> {
        final Purchase val$purchase;

        AnonymousClass3(Purchase purchase) {
            this.val$purchase = purchase;
        }

        @Override
        public void onSuccess(CreateGoogleOrderBack createGoogleOrderBack) {
            if (CommodityListGoogleFragment.this.f979activity == null || CommodityListGoogleFragment.this.getActivity() == null || CommodityListGoogleFragment.this.billingClientManager == null) {
                return;
            }
            HiLogcatUtil.wTag(HiLogcatUtil.TAG_Google, createGoogleOrderBack.toString());
            if (createGoogleOrderBack.getStatus() == 99) {
                CommodityListGoogleFragment.this.mCamera.setCloudOrderSN("");
                CommodityListGoogleFragment.this.openDevCloudSwitch();
                if (CommodityListGoogleFragment.this.handler != null) {
                    CommodityListGoogleFragment.this.handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            CommodityListGoogleFragment.this.videoSaveDays = CommodityListGoogleFragment.this.videoSaveDaysBuy;
                            CommodityListGoogleFragment.this.groupItemAdapter.setTimeout(false, true, CommodityListGoogleFragment.this.videoSaveDays);
                            CommodityListGoogleFragment.this.groupItemAdapter.notifyDataSetChanged();
                        }
                    }, 1000L);
                }
                CommodityListGoogleFragment.this.billingClientManager.consumeAsync(this.val$purchase, new ConsumeResponseListener() {
                    @Override
                    public void onConsumeResponse(BillingResult billingResult, String str) {
                        CloudGoogleFragment.isUpdatePackage = true;
                        if (CommodityListGoogleFragment.this.handler != null) {
                            CommodityListGoogleFragment.this.handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    CommodityListGoogleFragment.this.dismissJuHuaDialog();
                                    if (CommodityListGoogleFragment.this.f979activity == null || CommodityListGoogleFragment.this.f979activity.viewPager == null || CommodityListGoogleFragment.this.f979activity.viewPager.getCurrentItem() == 0) {
                                        return;
                                    }
                                    CommodityListGoogleFragment.this.f979activity.viewPager.setCurrentItem(0, true);
                                }
                            }, 1500L);
                        }
                    }
                });
                return;
            }
            CommodityListGoogleFragment.this.dismissJuHuaDialog();
            CommodityListGoogleFragment.this.mCamera.setCloudOrderSN(createGoogleOrderBack.getOrderSN());
            Toast.makeText(CommodityListGoogleFragment.this.f979activity, CommodityListGoogleFragment.this.getString(R.string.check_error), 0).show();
            CommodityListGoogleFragment.this.f979activity.finish();
        }

        @Override
        public void onError(Throwable th, String str) {
            if (CommodityListGoogleFragment.this.f979activity == null || CommodityListGoogleFragment.this.getActivity() == null || CommodityListGoogleFragment.this.billingClientManager == null) {
                return;
            }
            CommodityListGoogleFragment.this.dismissJuHuaDialog();
            HiLogcatUtil.eTag(HiLogcatUtil.TAG_Google, "errMsg: " + str);
            CommodityListGoogleFragment.this.f979activity.finish();
        }
    }

    public void openDevCloudSwitch() {
        SharePreUtils.putString(HiDataValue.CACHE, this.f979activity, this.uuid + Constant.NOT_SEND_CLOUD_STATUS, this.uuid);
        if (this.mCamera.getConnectState() == 4) {
            ConstantCommand.HI_P2P_SET_CLOUD_PARAM hi_p2p_set_cloud_param = new ConstantCommand.HI_P2P_SET_CLOUD_PARAM(new byte[8]);
            hi_p2p_set_cloud_param.u32CloudEnable = 1;
            hi_p2p_set_cloud_param.u32CloudUpdate = 1;
            this.mCamera.sendIOCtrl(ConstantCommand.HI_P2P_SET_CLOUD_PARAM, hi_p2p_set_cloud_param.parseContent());
        }
    }

    private void initData() {
        TextView textView = this.tvInfoNo;
        if (textView == null) {
            return;
        }
        textView.setVisibility(4);
        int i = 1000;
        if (Locale.getDefault().getLanguage().equals("zh")) {
            i = Locale.getDefault().getCountry().equals("CN") ? 1001 : 1003;
        } else if (Locale.getDefault().getLanguage().equals("de")) {
            i = 1002;
        } else if (Locale.getDefault().getLanguage().equals("fr")) {
            i = 1004;
        } else if (Locale.getDefault().getLanguage().equals("es")) {
            i = 1005;
        } else if (Locale.getDefault().getLanguage().equals(AdvertisementOption.PRIORITY_VALID_TIME)) {
            i = 1006;
        } else if (Locale.getDefault().getLanguage().equals("ko")) {
            i = 1007;
        } else if (Locale.getDefault().getLanguage().equals("ja")) {
            i = 1008;
        } else if (Locale.getDefault().getLanguage().equals(AdvanceSetting.NETWORK_TYPE)) {
            i = 1009;
        } else if (Locale.getDefault().getLanguage().equals("tr")) {
            i = 1010;
        } else if (Locale.getDefault().getLanguage().equals("vi")) {
            i = 1012;
        } else if (Locale.getDefault().getLanguage().equals("pl")) {
            i = 1013;
        } else if (Locale.getDefault().getLanguage().equals("ru")) {
            i = 1014;
        }
        GetGoogleServiceReq getGoogleServiceReq = new GetGoogleServiceReq(this.uuid, i, DateUtils.getDate());
        HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, getGoogleServiceReq.toString());
        GoogleApiFactory.getApi().GetGoogleService(getGoogleServiceReq).enqueue(new AnonymousClass4());
    }

    public class AnonymousClass4 extends MyCallBack<GetGoogleServiceBack> {
        AnonymousClass4() {
        }

        @Override
        public void onSuccess(GetGoogleServiceBack getGoogleServiceBack) {
            Date date;
            if (CommodityListGoogleFragment.this.f979activity == null || CommodityListGoogleFragment.this.getActivity() == null || CommodityListGoogleFragment.this.billingClientManager == null) {
                return;
            }
            HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, getGoogleServiceBack.toString());
            try {
                CommodityListGoogleFragment.isRefreshInfo = false;
                CommodityListGoogleFragment.this.tvTime.setText(getGoogleServiceBack.getStartDate() + "—" + getGoogleServiceBack.getEndDate());
                CommodityListGoogleFragment.this.tvDesc.setText(getGoogleServiceBack.getServiceDesc());
                CommodityListGoogleFragment.this.videoSaveDays = getGoogleServiceBack.getVideoSaveDays();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(TimeUtil.FORMAT_DATE_TIME_FULL, Locale.getDefault());
                Date date2 = null;
                try {
                    date = simpleDateFormat.parse(getGoogleServiceBack.getEndDate());
                } catch (ParseException e) {
                    e = e;
                    date = null;
                }
                try {
                    date2 = simpleDateFormat.parse(getGoogleServiceBack.getDate());
                } catch (ParseException e2) {
                    e = e2;
                    e.printStackTrace();
                    if (date == null) {
                        return;
                    }
                    if (date.getTime() > date2.getTime() + 28800000) {
                    }
                    CommodityListGoogleFragment.this.isBoughtCloud = true;
                    HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, " isBoughtCloud = true ");
                    long time = date.getTime() - (date2.getTime() + 28800000);
                    CommodityListGoogleFragment commodityListGoogleFragment = CommodityListGoogleFragment.this;
                    commodityListGoogleFragment.getListData(commodityListGoogleFragment.tv_package_timeout.getVisibility() == 0, true, time);
                }
                if (date == null && date2 != null) {
                    if (date.getTime() > date2.getTime() + 28800000) {
                        CommodityListGoogleFragment.this.tv_package_timeout.setVisibility(0);
                    } else {
                        CommodityListGoogleFragment.this.tv_package_timeout.setVisibility(8);
                    }
                    CommodityListGoogleFragment.this.isBoughtCloud = true;
                    HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, " isBoughtCloud = true ");
                    long time2 = date.getTime() - (date2.getTime() + 28800000);
                    CommodityListGoogleFragment commodityListGoogleFragment2 = CommodityListGoogleFragment.this;
                    commodityListGoogleFragment2.getListData(commodityListGoogleFragment2.tv_package_timeout.getVisibility() == 0, true, time2);
                }
            } catch (Exception e3) {
                e3.printStackTrace();
            }
        }

        @Override
        public void onError(Throwable th, String str) {
            if (CommodityListGoogleFragment.this.f979activity == null || CommodityListGoogleFragment.this.getActivity() == null || CommodityListGoogleFragment.this.billingClientManager == null) {
                return;
            }
            try {
                if (!(th instanceof HttpThrowable)) {
                    if (CommodityListGoogleFragment.this.handler != null) {
                        CommodityListGoogleFragment.this.handler.postDelayed(new Runnable() {
                            @Override
                            public final void run() {
                                CommodityListGoogleFragment.AnonymousClass4.this.lambda$onError$0$CommodityListGoogleFragment$4();
                            }
                        }, 2000L);
                    }
                } else {
                    if (CommodityListGoogleFragment.this.tvInfoNo != null) {
                        CommodityListGoogleFragment.this.tvInfoNo.setVisibility(0);
                    }
                    CommodityListGoogleFragment.this.isBoughtCloud = false;
                    HiLogcatUtil.wTag(HiLogcatUtil.TAG_Google, " isBoughtCloud = false ");
                    CommodityListGoogleFragment commodityListGoogleFragment = CommodityListGoogleFragment.this;
                    commodityListGoogleFragment.getListData(commodityListGoogleFragment.tv_package_timeout.getVisibility() == 0, false, 0L);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        public void lambda$onError$0$CommodityListGoogleFragment$4() {
            if (CommodityListGoogleFragment.this.f979activity == null) {
                return;
            }
            Toast.makeText(CommodityListGoogleFragment.this.f979activity, CommodityListGoogleFragment.this.getString(R.string.netword_abnormal), 1).show();
            CommodityListGoogleFragment.this.f979activity.finish();
        }
    }

    public void getListData(final boolean z, final boolean z2, final long j) {
        List<GetAllPackageBack.GoodsesBean> list = this.listData;
        if (list == null || this.recCategory == null) {
            return;
        }
        list.clear();
        GoodsGroupGoogleItemAdapter goodsGroupGoogleItemAdapter = new GoodsGroupGoogleItemAdapter(R.layout.item_goods_two, this.listData, this.videoSaveDays, j);
        this.groupItemAdapter = goodsGroupGoogleItemAdapter;
        goodsGroupGoogleItemAdapter.setTimeout(z, z2, this.videoSaveDays);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this.f979activity, 2);
        this.recCategory.setLayoutManager(gridLayoutManager);
        gridLayoutManager.setOrientation(1);
        HashMap hashMap = new HashMap();
        hashMap.put(RecyclerViewSpacesItemDecoration.BOTTOM_DECORATION, 30);
        this.recCategory.addItemDecoration(new RecyclerViewSpacesItemDecoration(hashMap));
        this.recCategory.setAdapter(this.groupItemAdapter);
        this.recCategory.setNestedScrollingEnabled(false);
        this.groupItemAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public final void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
                CommodityListGoogleFragment.this.lambda$getListData$1$CommodityListGoogleFragment(j, z2, z, baseQuickAdapter, view, i);
            }
        });
        GoodsGroupRequ goodsGroupRequ = new GoodsGroupRequ();
        goodsGroupRequ.setDate(DateUtils.getDate());
        if (Locale.getDefault().getLanguage().equals("zh")) {
            if (Locale.getDefault().getCountry().equals("CN")) {
                goodsGroupRequ.setLanguageId(1001);
            } else {
                goodsGroupRequ.setLanguageId(1003);
            }
        } else if (Locale.getDefault().getLanguage().equals("de")) {
            goodsGroupRequ.setLanguageId(1002);
        } else if (Locale.getDefault().getLanguage().equals("fr")) {
            goodsGroupRequ.setLanguageId(1004);
        } else if (Locale.getDefault().getLanguage().equals("es")) {
            goodsGroupRequ.setLanguageId(1005);
        } else if (Locale.getDefault().getLanguage().equals(AdvertisementOption.PRIORITY_VALID_TIME)) {
            goodsGroupRequ.setLanguageId(1006);
        } else if (Locale.getDefault().getLanguage().equals("ko")) {
            goodsGroupRequ.setLanguageId(1007);
        } else if (Locale.getDefault().getLanguage().equals("ja")) {
            goodsGroupRequ.setLanguageId(1008);
        } else if (Locale.getDefault().getLanguage().equals(AdvanceSetting.NETWORK_TYPE)) {
            goodsGroupRequ.setLanguageId(1009);
        } else if (Locale.getDefault().getLanguage().equals("tr")) {
            goodsGroupRequ.setLanguageId(1010);
        } else if (Locale.getDefault().getLanguage().equals("vi")) {
            goodsGroupRequ.setLanguageId(1012);
        } else if (Locale.getDefault().getLanguage().equals("pl")) {
            goodsGroupRequ.setLanguageId(1013);
        } else if (Locale.getDefault().getLanguage().equals("ru")) {
            goodsGroupRequ.setLanguageId(1014);
        } else {
            goodsGroupRequ.setLanguageId(1000);
        }
        HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, goodsGroupRequ.toString());
        GoogleApiFactory.getApi().GetAllPackage(goodsGroupRequ).enqueue(new MyCallBack<GetAllPackageBack>() {
            @Override
            public void onSuccess(GetAllPackageBack getAllPackageBack) {
                if (CommodityListGoogleFragment.this.f979activity == null || CommodityListGoogleFragment.this.getActivity() == null || CommodityListGoogleFragment.this.billingClientManager == null) {
                    return;
                }
                HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, getAllPackageBack.toString());
                CommodityListGoogleFragment.this.checkFromGoogle(getAllPackageBack);
            }

            @Override
            public void onError(Throwable th, String str) {
                if (CommodityListGoogleFragment.this.f979activity == null || CommodityListGoogleFragment.this.getActivity() == null || CommodityListGoogleFragment.this.billingClientManager == null) {
                    return;
                }
                CommodityListGoogleFragment.this.dismissJuHuaDialog();
                HiLogcatUtil.eTag(HiLogcatUtil.TAG_Google, "errMsg: " + str);
            }
        });
    }

    public void lambda$getListData$1$CommodityListGoogleFragment(long j, boolean z, boolean z2, BaseQuickAdapter baseQuickAdapter, View view, int i) {
        List data = baseQuickAdapter.getData();
        if (j < 7) {
            for (int i2 = 0; i2 < data.size(); i2++) {
                if (z) {
                    if (z2) {
                        if (i2 == i) {
                            ((GetAllPackageBack.GoodsesBean) data.get(i2)).setSelect(true);
                            this.isSelectGoods = true;
                            this.goodsBean = (GetAllPackageBack.GoodsesBean) data.get(i2);
                            setPrice(((GetAllPackageBack.GoodsesBean) data.get(i2)).getGoodsId(), ((GetAllPackageBack.GoodsesBean) data.get(i2)).getPrice(), ((GetAllPackageBack.GoodsesBean) data.get(i2)).getVideoSaveDays());
                        } else {
                            ((GetAllPackageBack.GoodsesBean) data.get(i2)).setSelect(false);
                        }
                    } else if (i2 == i) {
                        if (this.videoSaveDays > ((GetAllPackageBack.GoodsesBean) data.get(i2)).getVideoSaveDays()) {
                            return;
                        }
                        ((GetAllPackageBack.GoodsesBean) data.get(i2)).setSelect(true);
                        this.isSelectGoods = true;
                        this.goodsBean = (GetAllPackageBack.GoodsesBean) data.get(i2);
                        setPrice(((GetAllPackageBack.GoodsesBean) data.get(i2)).getGoodsId(), ((GetAllPackageBack.GoodsesBean) data.get(i2)).getPrice(), ((GetAllPackageBack.GoodsesBean) data.get(i2)).getVideoSaveDays());
                    } else {
                        ((GetAllPackageBack.GoodsesBean) data.get(i2)).setSelect(false);
                    }
                } else if (i2 == i) {
                    ((GetAllPackageBack.GoodsesBean) data.get(i2)).setSelect(true);
                    this.isSelectGoods = true;
                    this.goodsBean = (GetAllPackageBack.GoodsesBean) data.get(i2);
                    setPrice(((GetAllPackageBack.GoodsesBean) data.get(i2)).getGoodsId(), ((GetAllPackageBack.GoodsesBean) data.get(i2)).getPrice(), ((GetAllPackageBack.GoodsesBean) data.get(i2)).getVideoSaveDays());
                } else {
                    ((GetAllPackageBack.GoodsesBean) data.get(i2)).setSelect(false);
                }
            }
            this.groupItemAdapter.notifyDataSetChanged();
        }
    }

    public void checkFromGoogle(final GetAllPackageBack getAllPackageBack) {
        HiLogcatUtil.iTag(HiLogcatUtil.TAG_Google, " start connect google ");
        this.billingClientManager.billingClient.startConnection(new BillingClientStateListener() {
            @Override
            public void onBillingSetupFinished(BillingResult billingResult) {
                if (billingResult.getResponseCode() == 0) {
                    HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, "connect google success");
                    CommodityListGoogleFragment.this.querySku(getAllPackageBack);
                } else if (!CommodityListGoogleFragment.this.getUserVisibleHint()) {
                    CommodityListGoogleFragment.this.getGoogleError = true;
                } else if (CommodityListGoogleFragment.this.getActivity() != null) {
                    CommodityListGoogleFragment.this.dismissJuHuaDialog();
                    Toast.makeText(CommodityListGoogleFragment.this.getActivity(), CommodityListGoogleFragment.this.getString(R.string.netword_abnormal), 1).show();
                    CommodityListGoogleFragment.this.getActivity().finish();
                }
            }

            @Override
            public void onBillingServiceDisconnected() {
                CommodityListGoogleFragment.this.dismissJuHuaDialog();
                HiLogcatUtil.eTag(HiLogcatUtil.TAG_Google, "  connect google error ");
                Toast.makeText(CommodityListGoogleFragment.this.f979activity, "connect google error", 0).show();
            }
        });
    }

    public void querySku(final GetAllPackageBack getAllPackageBack) {
        int size = getAllPackageBack.getGoodses().size();
        String[] strArr = new String[size];
        for (int i = 0; i < getAllPackageBack.getGoodses().size(); i++) {
            strArr[i] = getAllPackageBack.getGoodses().get(i).getProductID();
        }
        for (int i2 = 0; i2 < size; i2++) {
            if (TextUtils.isEmpty(strArr[i2])) {
                return;
            }
        }
        this.billingClientManager.querySkuDetailsAsync(BillingClient.SkuType.INAPP, new SkuDetailsResponseListener() {
            @Override
            public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> list) {
                HiLogcatUtil.dTag(HiLogcatUtil.TAG_Google, list.toString());
                CommodityListGoogleFragment.this.skuList.clear();
                CommodityListGoogleFragment.this.skuList.addAll(list);
                for (SkuDetails skuDetails : list) {
                    for (GetAllPackageBack.GoodsesBean goodsesBean : getAllPackageBack.getGoodses()) {
                        if (skuDetails.getSku().equals(goodsesBean.getProductID())) {
                            goodsesBean.setPrice(skuDetails.getPrice());
                        }
                    }
                }
                CommodityListGoogleFragment.this.dismissJuHuaDialog();
                Collections.reverse(getAllPackageBack.getGoodses());
                CommodityListGoogleFragment.this.listData.clear();
                CommodityListGoogleFragment.this.listData.addAll(getAllPackageBack.getGoodses());
                CommodityListGoogleFragment.this.groupItemAdapter.setNewData(CommodityListGoogleFragment.this.listData);
                if (CommodityListGoogleFragment.this.scrollView != null) {
                    CommodityListGoogleFragment.this.scrollView.setVisibility(0);
                }
                CommodityListGoogleFragment.this.groupItemAdapter.notifyDataSetChanged();
            }
        }, strArr);
    }

    private void setPrice(int i, String str, int i2) {
        this.videoSaveDaysBuy = i2;
        this.purchaseId = i;
        this.tvPrice.setText(str);
    }

    @Override
    public void receiveSessionState(HiCamera hiCamera, int i) {
        Message obtainMessage = this.mIOHandler.obtainMessage();
        obtainMessage.what = HiDataValue.HANDLE_MESSAGE_SESSION_STATE;
        obtainMessage.arg1 = i;
        obtainMessage.obj = hiCamera;
        this.mIOHandler.sendMessage(obtainMessage);
    }

    @Override
    public void receiveIOCtrlData(HiCamera hiCamera, int i, byte[] bArr, int i2) {
        Bundle bundle = new Bundle();
        bundle.putByteArray("data", bArr);
        Message obtainMessage = this.mIOHandler.obtainMessage();
        obtainMessage.what = HiDataValue.HANDLE_MESSAGE_RECEIVE_IOCTRL;
        obtainMessage.obj = hiCamera;
        obtainMessage.arg1 = i;
        obtainMessage.arg2 = i2;
        obtainMessage.setData(bundle);
        this.mIOHandler.sendMessage(obtainMessage);
    }

    public void handIOCTRLSuccess(Message message, MyCamera myCamera) {
        CloudInfoGoogleActivity cloudInfoGoogleActivity;
        if (message.getData().getByteArray("data") == null || message.arg1 != 16823 || (cloudInfoGoogleActivity = this.f979activity) == null) {
            return;
        }
        SharePreUtils.putString(HiDataValue.CACHE, cloudInfoGoogleActivity, myCamera.getUid() + Constant.NOT_SEND_CLOUD_STATUS, "");
    }

    public void handSessionState(Message message, MyCamera myCamera) {
        if (message.arg1 != 0 || getActivity() == null) {
            return;
        }
        Toast.makeText(getActivity(), getString(R.string.disconnect), 0).show();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        HiLogcatUtil.iTag(HiLogcatUtil.TAG_Google, "CommodityListGoogleFragment onDestroyView ");
        BillingClientManager billingClientManager = this.billingClientManager;
        if (billingClientManager != null) {
            billingClientManager.billingClient.endConnection();
        }
        Handler handler = this.handler;
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
        }
    }
}