package com.bytedance.android.livesdk.service.assets;

import X.053;
import X.07U;
import X.0HH;
import X.0UM;
import X.0UO;
import X.0aP;
import X.0b0;
import X.0c0;
import X.0cm;
import X.0yx;
import X.0z9;
import X.1Bn;
import X.2K7;
import X.2Ym;
import X.2sR;
import X.5Fn;
import X.7tg;
import X.86a;
import X.C1781GFy;
import X.C1832GHx;
import X.C1856GIv;
import X.C2205GWg;
import X.C2281GZe;
import X.C2675Gg0;
import X.C3304Gq9;
import X.C3502GtL;
import X.C4448HKn;
import X.C4492HMf;
import X.C4495HMi;
import X.C4524HNl;
import X.C4529HNq;
import X.C4545HOg;
import X.C4564HOz;
import X.C4593HQc;
import X.C4596HQf;
import X.C4617HRa;
import X.C4618HRb;
import X.C4619HRc;
import X.C4636HRt;
import X.C4641HRy;
import X.C4642HRz;
import X.C4649HSg;
import X.C4853Ha2;
import X.D4n;
import X.DEW;
import X.DEX;
import X.GWE;
import X.HEP;
import X.HPK;
import X.HPY;
import X.HQ2;
import X.HQO;
import X.HQU;
import X.HRW;
import X.HRZ;
import X.HS2;
import X.HT6;
import X.M12;
import X.Mk2;
import X.Mk3;
import X.PgU;
import X.PhE;
import X.PiN;
import X.Pj7;
import X.PlI;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.SparseArray;
import com.bytedance.android.live.base.model.ImageModel;
import com.bytedance.android.live.liveinteract.api.IInteractService;
import com.bytedance.android.livesdk.gift.model.FreqLimitGiftInfo;
import com.bytedance.android.livesdk.gift.model.FreqLimitGiftOption;
import com.bytedance.android.livesdk.gift.model.GiftGroupCount;
import com.bytedance.android.livesdk.gift.model.GiftIconInfo;
import com.bytedance.android.livesdk.gift.model.GiftListResult;
import com.bytedance.android.livesdk.gift.model.GiftPage;
import com.bytedance.android.livesdk.gift.model.GiftPollInfo;
import com.bytedance.android.livesdk.gift.model.GiftPollOption;
import com.bytedance.android.livesdk.gift.model.GiftsInfo;
import com.bytedance.android.livesdk.gift.model.LiveLimitedTimeDiscountGiftInfo;
import com.bytedance.android.livesdk.gift.model.RiskCtl;
import com.bytedance.android.livesdk.livesetting.gift.GiftUnlockExperiment;
import com.bytedance.android.livesdk.livesetting.gift.LiveGiftResourceDownloadSetting;
import com.bytedance.android.livesdk.model.Gift;
import com.bytedance.android.livesdk.service.model.GiftListExtra;
import com.bytedance.android.livesdk.service.network.GiftRetrofitApi;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.android.livesdkapi.host.IHostApp;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.ies.sdk.datachannel.DataChannelGlobal;
import com.google.gson.Gson;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import kotlin.h.b.n;

public class GiftManager {
    public static GiftManager sInst;
    public LinkedList<C4564HOz<? extends C4649HSg>> currentPanelList = new LinkedList<>();
    public FreqLimitGiftInfo freqLimitGiftInfo = null;
    public HashMap<Long, C4596HQf> freqLimitInfoList = null;
    public Gson gson = 0UO.LIZIZ;
    public Map<Integer, Set<Long>> lockedGiftsMap = new HashMap();
    public long lockedGiftsMapRoomId = -1;
    public final List<C4448HKn> mGiftListListeners = new CopyOnWriteArrayList();
    public GiftPollInfo mGiftPollInfo = null;
    public final SparseArray<GiftListResult> mGiftsMap = new SparseArray<>();
    public final SparseArray<053<Gift>> mGiftsMapByFind = new SparseArray<>();
    public List<GiftGroupCount> mGroupSendInfo;
    public 1Bn<Boolean> mHideBottomBar = new 1Bn<>();
    public ConcurrentHashMap<Long, Long> mRoomFastGiftIdMap = new ConcurrentHashMap<>(20);
    public ConcurrentHashMap<Long, GiftsInfo> mRoomGiftInfoMap = new ConcurrentHashMap<>(20);
    public final ConcurrentHashMap<Long, RiskCtl> mRoomRiskCtl = new ConcurrentHashMap<>(20);

    static {
        Covode.recordClassIndex(20643);
    }

    public List<GiftGroupCount> getGroupSendInfo() {
        return this.mGroupSendInfo;
    }

    public void clearGiftIconInfo() {
        this.mRoomFastGiftIdMap.clear();
    }

    public static synchronized GiftManager inst() {
        GiftManager giftManager;
        synchronized (GiftManager.class) {
            MethodCollector.i(3122);
            if (sInst == null) {
                sInst = new GiftManager();
            }
            giftManager = sInst;
            MethodCollector.o(3122);
        }
        return giftManager;
    }

    private void loadLocal() {
        PiN.LIZ(new C4641HRy(this), Pj7.BUFFER).LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZ(Mk2.LIZ(Mk3.LIZ)).LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZ(new C4642HRz(this), HS2.LIZ);
    }

    public List<GiftPage> getGiftPageList() {
        int i;
        Room room = (Room) DataChannelGlobal.LIZLLL.LIZIZ(HEP.class);
        if (room != null) {
            i = room.getOrientation();
        } else {
            i = 0;
        }
        GiftListResult giftListResult = this.mGiftsMap.get(i);
        if (giftListResult == null || 5Fn.LIZ(giftListResult.LJ)) {
            return new ArrayList();
        }
        return new ArrayList(giftListResult.LJ);
    }

    public List<Gift> getStickerGifts() {
        ArrayList arrayList = new ArrayList();
        ArrayList<Gift> arrayList2 = new ArrayList<>();
        List<GiftPage> giftPageList = getGiftPageList();
        if (giftPageList != null) {
            for (GiftPage giftPage : giftPageList) {
                arrayList2.addAll(giftPage.gifts);
            }
        }
        for (Gift gift : arrayList2) {
            if (gift.LJ == 4) {
                arrayList.add(gift);
            }
        }
        return arrayList;
    }

    public boolean hideBottomBar() {
        int i;
        Room room = (Room) DataChannelGlobal.LIZLLL.LIZIZ(HEP.class);
        if (room != null) {
            i = room.getOrientation();
        } else {
            i = 0;
        }
        GiftListResult giftListResult = this.mGiftsMap.get(i);
        if (giftListResult != null) {
            return giftListResult.LIZLLL.LIZJ;
        }
        return false;
    }

    public GiftManager() {
        0cm.LIZ(IHostApp.class).initImageLib();
        loadLocal();
    }

    public GWE getPollGifts() {
        GiftPollInfo giftPollInfo = this.mGiftPollInfo;
        if (giftPollInfo == null || giftPollInfo.LIZ == null || this.mGiftPollInfo.LIZ.size() != 2) {
            return null;
        }
        List<GiftPollOption> list = this.mGiftPollInfo.LIZ;
        GiftPollOption giftPollOption = list.get(0);
        GiftPollOption giftPollOption2 = list.get(1);
        if (giftPollOption == null || giftPollOption2 == null || giftPollOption.LIZ == null || giftPollOption2.LIZ == null) {
            return null;
        }
        return new GWE(findGiftById(giftPollOption.LIZ.longValue()), findGiftById(giftPollOption2.LIZ.longValue()), list.get(0).LIZIZ, list.get(1).LIZIZ);
    }

    public void updatePanelList(LinkedList<C4564HOz<? extends C4649HSg>> linkedList) {
        this.currentPanelList = linkedList;
    }

    public void registerGiftListListener(C4448HKn hKn) {
        this.mGiftListListeners.add(hKn);
    }

    public void unRegisterGiftListListener(C4448HKn hKn) {
        this.mGiftListListeners.remove(hKn);
    }

    public static boolean INVOKESTATIC_com_bytedance_android_livesdk_service_assets_GiftManager_com_ss_android_ugc_aweme_net_lancet_NetworkLancet_isNetworkAvailableTwo(Context context) {
        try {
            return 2K7.LIZ.LIZJ();
        } catch (Exception unused) {
            return false;
        }
    }

    public static final /* synthetic */ void lambda$syncGiftList$4$GiftManager(C4593HQc hQc) {
        if (hQc != null) {
            hQc.LIZ(1, "network unavailable");
        }
    }

    public RiskCtl getTargetRoomGiftRiskCtl(long j) {
        return this.mRoomRiskCtl.get(Long.valueOf(j));
    }

    public void syncGiftList(int i) {
        syncGiftList((C4593HQc) null, 0, i, false, "");
    }

    private 2sR<String> getPropertyByLiveType(int i) {
        return new 2sR<>("gift_list_response_".concat(String.valueOf(i)), "");
    }

    public void clearFastGift(long j) {
        this.mRoomFastGiftIdMap.remove(Long.valueOf(j));
        this.mRoomFastGiftIdMap.remove(0L);
    }

    public static void filterFirstAndCallbackGifts(Collection<? extends Gift> collection) {
        if (collection != null) {
            long LJIIIZ = C4495HMi.LJIIJJI.LJIIIZ();
            Iterator<? extends Gift> it = collection.iterator();
            while (it.hasNext()) {
                Gift gift = (Gift) it.next();
                if (gift.LIZLLL == LJIIIZ || gift.LIZLLL == 0) {
                    it.remove();
                }
            }
        }
    }

    public static void filterNotDisplayedOnPanel(Collection<? extends Gift> collection) {
        if (collection != null) {
            Iterator<? extends Gift> it = collection.iterator();
            boolean showLock = GiftUnlockExperiment.showLock();
            while (it.hasNext()) {
                Gift gift = (Gift) it.next();
                if (!gift.LJIIL) {
                    it.remove();
                }
                if (!showLock && gift.LJJJ != null && gift.LJJJ.LIZ == 2 && gift.LJJJ.LIZIZ) {
                    it.remove();
                }
            }
        }
    }

    public int checkTabCanDisplay(int i) {
        GiftListResult giftListResult = this.mGiftsMap.get(0);
        if (!(giftListResult == null || giftListResult.LJ == null)) {
            for (GiftPage next : giftListResult.LJ) {
                if (next.pageType == i && next.display) {
                    return i;
                }
            }
        }
        return 1;
    }

    public Gift findGiftById(long j) {
        int i;
        Room room = (Room) DataChannelGlobal.LIZLLL.LIZIZ(HEP.class);
        if (room != null) {
            i = room.getOrientation();
        } else {
            i = 0;
        }
        053 r1 = (053) this.mGiftsMapByFind.get(i);
        if (r1 == null) {
            return null;
        }
        return (Gift) r1.LIZ(j, (Object) null);
    }

    public Gift getFastGift(long j) {
        Long l;
        if (this.mRoomFastGiftIdMap.containsKey(Long.valueOf(j))) {
            l = this.mRoomFastGiftIdMap.get(Long.valueOf(j));
        } else {
            l = this.mRoomFastGiftIdMap.get(0L);
        }
        if (l != null) {
            return findGiftById(l.longValue());
        }
        return null;
    }

    public FreqLimitGiftOption getFreqLimitOption(Long l) {
        FreqLimitGiftInfo freqLimitGiftInfo2 = this.freqLimitGiftInfo;
        if (!(freqLimitGiftInfo2 == null || freqLimitGiftInfo2.LIZ == null)) {
            for (FreqLimitGiftOption next : this.freqLimitGiftInfo.LIZ) {
                if (l.longValue() == next.LIZ) {
                    return next;
                }
            }
        }
        return null;
    }

    public GiftsInfo getGiftIconInfo(long j) {
        if (this.mRoomGiftInfoMap.containsKey(Long.valueOf(j))) {
            return this.mRoomGiftInfoMap.get(Long.valueOf(j));
        }
        return this.mRoomGiftInfoMap.get(0L);
    }

    public int getGiftPosition(long j) {
        LinkedList<C4564HOz<? extends C4649HSg>> linkedList = this.currentPanelList;
        if (linkedList != null && !linkedList.isEmpty()) {
            int i = 0;
            Iterator it = this.currentPanelList.iterator();
            while (it.hasNext()) {
                C4564HOz hOz = (C4564HOz) it.next();
                i++;
                if (hOz != null && hOz.LIZLLL() == j) {
                    return i;
                }
            }
        }
        return -1;
    }

    public int getPollGiftIndex(long j) {
        long j2;
        if (this.mGiftPollInfo.LIZ == null) {
            return 0;
        }
        GiftPollOption giftPollOption = this.mGiftPollInfo.LIZ.get(0);
        if (giftPollOption.LIZ != null) {
            j2 = giftPollOption.LIZ.longValue();
        } else {
            j2 = 0;
        }
        if (j == j2) {
            return 0;
        }
        return 1;
    }

    public int getTabLocation(int i) {
        int i2 = 0;
        GiftListResult giftListResult = this.mGiftsMap.get(0);
        if (!(giftListResult == null || giftListResult.LJ == null)) {
            for (GiftPage giftPage : giftListResult.LJ) {
                i2++;
                if (giftPage.pageType == C4524HNl.LIZ.LJIIJ) {
                    return i2;
                }
            }
        }
        return -1;
    }

    public String getTabName(int i) {
        GiftListResult giftListResult = this.mGiftsMap.get(0);
        if (!(giftListResult == null || giftListResult.LJ == null)) {
            for (GiftPage next : giftListResult.LJ) {
                if (next.pageType == i) {
                    return next.pageName;
                }
            }
        }
        return "Gift";
    }

    public String getTabNameByIndex(int i) {
        GiftListResult giftListResult = this.mGiftsMap.get(0);
        if (giftListResult == null || giftListResult.LJ == null || i >= giftListResult.LJ.size()) {
            return "Gift";
        }
        return giftListResult.LJ.get(i).pageName;
    }

    public final /* synthetic */ void lambda$loadLocal$6$GiftManager(Map map) {
        if (map != null && !map.isEmpty()) {
            for (Integer num : map.keySet()) {
                GiftListResult giftListResult = (GiftListResult) map.get(num);
                if (giftListResult != null) {
                    addGiftMap(giftListResult, num.intValue());
                }
            }
            updateGiftsInfo(this.mGiftsMap.get(0), 0);
        }
    }

    public final /* synthetic */ D4n lambda$syncGiftList$1$GiftManager(0z9 r3) {
        if (r3 == null) {
            return PgU.LIZ(new Exception("response is empty"));
        }
        if (r3.data == null) {
            return PgU.LIZ(new Exception("response.data is empty"));
        }
        if (r3.extra != null) {
            C4529HNq.LIZIZ = ((GiftListExtra) r3.extra).LIZ;
        }
        return PgU.LIZ(new C4619HRc(this, r3));
    }

    public HPY getGiftType(Gift gift) {
        if (gift == null) {
            return HPY.UNKNOWN;
        }
        if (gift.LJ == 10) {
            return HPY.GOLDEN_BEAN_CELL;
        }
        if (gift.LJ == 9) {
            return HPY.FREE_CELL;
        }
        if (gift.LJ == 1) {
            return HPY.NORMAL_GIFT;
        }
        if (gift.LJ == 5) {
            return HPY.TASK_GIFT;
        }
        if (gift.LJ == 4) {
            return HPY.STICKER_GIFT;
        }
        if (gift.LJ == 8) {
            return HPY.MIDDLE_GIFT;
        }
        if (gift.LJ == 2) {
            return HPY.SPECIAL_GIFT;
        }
        if (gift.LJ == 11) {
            return HPY.GAME;
        }
        return HPY.UNKNOWN;
    }

    public int getTabByGiftId(long j) {
        GiftListResult giftListResult = this.mGiftsMap.get(0);
        if (giftListResult == null || giftListResult.LJ == null || giftListResult.LJ.size() == 0) {
            return -1;
        }
        if (C4495HMi.LJIIJJI.LJFF() || (!C4495HMi.LJIIJJI.LJFF() && C4495HMi.LJIIJJI.LJ())) {
            return giftListResult.LJ.get(0).pageType;
        }
        for (GiftPage next : giftListResult.LJ) {
            if (next.display) {
                for (Gift gift : next.gifts) {
                    if (gift.LIZLLL == j) {
                        return next.pageType;
                    }
                }
                continue;
            }
        }
        return -1;
    }

    public int getTabByGiftIdWithoutFirstRecharge(long j) {
        GiftListResult giftListResult = this.mGiftsMap.get(0);
        if (!(giftListResult == null || giftListResult.LJ == null || giftListResult.LJ.size() == 0)) {
            for (GiftPage next : giftListResult.LJ) {
                if (next.display) {
                    for (Gift gift : next.gifts) {
                        if (gift.LIZLLL == j) {
                            return next.pageType;
                        }
                    }
                    continue;
                }
            }
        }
        return -1;
    }

    public boolean isDynamicGift(long j) {
        GiftListResult giftListResult = this.mGiftsMap.get(0);
        if (giftListResult != null && giftListResult.LJ != null) {
            Iterator<GiftPage> it = giftListResult.LJ.iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                Iterator<Gift> it2 = it.next().gifts.iterator();
                while (true) {
                    if (it2.hasNext()) {
                        Gift next = it2.next();
                        if (next.LIZLLL == j) {
                            ImageModel imageModel = next.LJIILL;
                            if (imageModel == null || imageModel.mUrls == null || imageModel.mUrls.size() <= 0) {
                                return false;
                            }
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }

    public boolean isPollGift(long j) {
        long j2;
        GiftPollInfo giftPollInfo = this.mGiftPollInfo;
        if (giftPollInfo == null || giftPollInfo.LIZ == null || this.mGiftPollInfo.LIZ.get(0).LIZ == null || this.mGiftPollInfo.LIZ.get(1).LIZ == null) {
            return false;
        }
        GiftPollOption giftPollOption = this.mGiftPollInfo.LIZ.get(0);
        GiftPollOption giftPollOption2 = this.mGiftPollInfo.LIZ.get(1);
        long j3 = 0;
        if (giftPollOption == null || giftPollOption2 == null || giftPollOption.LIZ == null || giftPollOption2.LIZ == null) {
            j2 = 0;
        } else {
            j3 = giftPollOption.LIZ.longValue();
            j2 = giftPollOption2.LIZ.longValue();
        }
        if (j == j3 || j == j2) {
            return true;
        }
        return false;
    }

    public boolean isSubscribeGift(long j) {
        GiftListResult giftListResult = this.mGiftsMap.get(0);
        if (!(giftListResult == null || giftListResult.LJ == null || giftListResult.LJ.size() == 0)) {
            for (GiftPage next : giftListResult.LJ) {
                if (next.pageType == 15 && next.gifts != null) {
                    for (Gift gift : next.gifts) {
                        if (gift.LIZLLL == j) {
                            return true;
                        }
                    }
                    continue;
                }
            }
        }
        return false;
    }

    public final /* synthetic */ void lambda$loadLocal$5$GiftManager(DEX dex) {
        HashMap hashMap = new HashMap(4);
        for (String valueOf : (Set) C1781GFy.LIZJ.LIZ()) {
            int intValue = Integer.valueOf(valueOf).intValue();
            String str = (String) getPropertyByLiveType(intValue).LIZ();
            if (!86a.LIZ(str)) {
                hashMap.put(Integer.valueOf(intValue), this.gson.LIZ(str, GiftListResult.class));
            }
        }
        dex.onNext(hashMap);
        dex.onComplete();
    }

    public void updateFreqList(FreqLimitGiftInfo freqLimitGiftInfo2) {
        if (freqLimitGiftInfo2 != null && freqLimitGiftInfo2.LIZ != null) {
            if (this.freqLimitInfoList == null) {
                this.freqLimitInfoList = new HashMap<>();
            }
            for (FreqLimitGiftOption next : freqLimitGiftInfo2.LIZ) {
                if (this.freqLimitInfoList.get(Long.valueOf(next.LIZ)) != null) {
                    this.freqLimitInfoList.get(Long.valueOf(next.LIZ)).LIZJ = next.LIZLLL;
                } else {
                    C4596HQf hQf = new C4596HQf();
                    hQf.LIZ = next.LIZ;
                    hQf.LIZJ = next.LIZLLL;
                    hQf.LIZIZ = next.LJ;
                    this.freqLimitInfoList.put(Long.valueOf(next.LIZ), hQf);
                }
            }
        }
    }

    public static void filterInteractNotSupportGift(Collection<? extends Gift> collection, boolean z) {
        if (collection != null) {
            filterNotSupportGift(collection, z);
            Iterator<? extends Gift> it = collection.iterator();
            while (it.hasNext()) {
                if (!((Gift) it.next()).LJIIIIZZ) {
                    it.remove();
                }
            }
        }
    }

    public final /* synthetic */ void lambda$null$0$GiftManager(0z9 r5, DEW dew) {
        dew.onNext(new 07U(r5.data, this.gson.LIZIZ(r5.data)));
    }

    private void notifyFastGiftModule(long j, long j2) {
        this.mRoomFastGiftIdMap.put(Long.valueOf(j), Long.valueOf(j2));
        this.mRoomFastGiftIdMap.put(0L, Long.valueOf(j2));
        C2675Gg0.LIZ().LIZ((Object) new C2281GZe(j, j2));
    }

    private void updateGiftsInfo(GiftListResult giftListResult, long j) {
        if (giftListResult != null) {
            GiftsInfo giftsInfo = giftListResult.LIZLLL;
            if (giftsInfo == null) {
                C2675Gg0.LIZ().LIZ((Object) new C4853Ha2(0, (GiftsInfo) null));
                return;
            }
            notifyFastGiftModule(j, giftsInfo.LIZ);
            notifyGiftIconModule(j, giftsInfo.LIZLLL, giftsInfo);
        }
    }

    private void updateRiskCtlInfo(GiftListResult giftListResult, long j) {
        if (giftListResult != null) {
            GiftsInfo giftsInfo = giftListResult.LIZLLL;
            RiskCtl riskCtl = null;
            if (giftsInfo == null || (riskCtl = giftsInfo.LJIJ) == null) {
                this.mRoomRiskCtl.remove(Long.valueOf(j));
            } else {
                this.mRoomRiskCtl.put(Long.valueOf(j), riskCtl);
            }
            C2675Gg0.LIZ().LIZ((Object) new HQO(j, riskCtl));
        }
    }

    private void addGiftMap(GiftListResult giftListResult, int i) {
        List<GiftPage> list;
        if (giftListResult != null) {
            this.mGiftsMap.put(i, giftListResult);
            053 r4 = (053) this.mGiftsMapByFind.get(i);
            if (r4 != null) {
                r4.LIZJ();
            } else {
                r4 = new 053();
                this.mGiftsMapByFind.append(i, r4);
            }
            ArrayList<Gift> arrayList = new ArrayList<>();
            if (!5Fn.LIZ(giftListResult.LJ) && (list = giftListResult.LJ) != null) {
                for (GiftPage giftPage : list) {
                    arrayList.addAll(giftPage.gifts);
                }
            }
            for (Gift gift : arrayList) {
                r4.LIZJ(gift.LIZLLL, gift);
            }
        }
    }

    public static void filterNotSupportGift(Collection<? extends Gift> collection, boolean z) {
        IInteractService LIZ;
        if (collection != null) {
            Iterator<? extends Gift> it = collection.iterator();
            while (it.hasNext()) {
                Gift gift = (Gift) it.next();
                if (gift.LJIILLIIL && gift.LJ == 2 && (LIZ = 0cm.LIZ(IInteractService.class)) != null) {
                    if (LIZ.getMultiGuestOnlineGuestsViews() > 0 || LIZ.isMultiLiveLayout()) {
                        it.remove();
                    } else {
                        Room room = (Room) DataChannelGlobal.LIZLLL.LIZIZ(HEP.class);
                        if (!(room == null || room.getStreamType() == C1856GIv.VIDEO)) {
                            it.remove();
                        }
                    }
                }
            }
        }
    }

    private void updateGiftLock(GiftListResult giftListResult, long j) {
        List<GiftPage> list = giftListResult.LJ;
        if (j != this.lockedGiftsMapRoomId) {
            this.lockedGiftsMap.clear();
        }
        for (GiftPage next : list) {
            for (Gift next2 : next.gifts) {
                if (next2.LJJJ != null && next2.LJJJ.LIZ == 2 && next2.LJJJ.LIZIZ) {
                    if (!this.lockedGiftsMap.containsKey(Integer.valueOf(next.pageType))) {
                        this.lockedGiftsMap.put(Integer.valueOf(next.pageType), new HashSet());
                    }
                    this.lockedGiftsMap.get(Integer.valueOf(next.pageType)).add(Long.valueOf(next2.LIZLLL));
                }
            }
        }
        this.lockedGiftsMapRoomId = j;
    }

    public void updateFreqList(long j, int i, long j2) {
        C4596HQf hQf;
        if (this.freqLimitInfoList != null && getFreqLimitOption(Long.valueOf(j)) != null && (hQf = this.freqLimitInfoList.get(Long.valueOf(j))) != null) {
            if (!hQf.LIZJ) {
                hQf.LIZIZ = i;
            } else {
                hQf.LIZLLL.put(Long.valueOf(j2), Integer.valueOf(i));
            }
        }
    }

    public void notifyGiftIconModule(long j, GiftIconInfo giftIconInfo, GiftsInfo giftsInfo) {
        this.mRoomGiftInfoMap.put(Long.valueOf(j), giftsInfo);
        this.mRoomGiftInfoMap.put(0L, giftsInfo);
        if (giftIconInfo.LIZJ >= System.currentTimeMillis() / 1000 || giftIconInfo.LIZLLL <= System.currentTimeMillis() / 1000) {
            this.mRoomGiftInfoMap.remove(Long.valueOf(j));
            this.mRoomGiftInfoMap.remove(0L);
        }
        C2675Gg0.LIZ().LIZ((Object) new C4853Ha2(j, giftsInfo));
    }

    public static final /* synthetic */ void lambda$syncGiftList$3$GiftManager(boolean z, long j, int i, WeakReference weakReference, Throwable th) {
        Exception exc = new Exception(th);
        0HH.LIZ(exc);
        0aP.LIZ(6, "GIFT_MANAGER", "syncgiftlist error! " + exc.getStackTrace());
        if (z) {
            String message = exc.getMessage();
            HashMap hashMap = new HashMap();
            hashMap.put("error_msg", message);
            0c0.LIZIZ(C1832GHx.LIZ("ttlive_gift_list_status"), 1, 0, hashMap);
            0c0.LIZ(C1832GHx.LIZIZ("ttlive_gift_list_status"), 1, hashMap, 0);
            C3502GtL.LIZ().LIZ(C3304Gq9.Gift.info, "ttlive_gift_list_status", (Map) hashMap);
        }
        int i2 = -1;
        if (th instanceof 0UM) {
            i2 = ((0UM) th).getErrorCode();
        }
        HPK.LIZ(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - j), i2, i, exc.getMessage());
        if (weakReference.get() != null) {
            ((C4593HQc) weakReference.get()).LIZ(i2, exc.getMessage());
        }
    }

    public void syncGiftList(C4593HQc hQc, long j, int i, boolean z, String str) {
        boolean z2;
        C4593HQc hQc2 = hQc;
        if (hQc2 != null) {
            hQc2.LIZIZ();
        }
        if (INVOKESTATIC_com_bytedance_android_livesdk_service_assets_GiftManager_com_ss_android_ugc_aweme_net_lancet_NetworkLancet_isNetworkAvailableTwo(0b0.LJ())) {
            long j2 = j;
            int i2 = i;
            if (LiveGiftResourceDownloadSetting.INSTANCE.getValue() == 0) {
                HT6.LIZ(i2, j2);
            }
            WeakReference weakReference = new WeakReference(hQc2);
            if (j2 != 0) {
                z2 = true;
            } else {
                z2 = false;
            }
            long nanoTime = System.nanoTime();
            PgU LIZ = ((GiftRetrofitApi) 0yx.LIZ().LIZ(GiftRetrofitApi.class)).syncGiftList(String.valueOf(j2), i2, str, 2Ym.LIZ.LIZ()).LIZ(new HRZ(this), false).LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZ(Mk2.LIZ(Mk3.LIZ));
            C4617HRa hRa = r5;
            C4617HRa hRa2 = new C4617HRa(this, i2, z, j2, hQc2, nanoTime, z2);
            LIZ.LIZ(hRa, new C4618HRb(z2, nanoTime, i2, weakReference));
            return;
        }
        new Handler(Looper.getMainLooper()).postDelayed(new C4636HRt(hQc2), 250);
    }

    private void onSyncGiftListSuccess(GiftListResult giftListResult, String str, int i, boolean z, long j, C4593HQc hQc) {
        int i2;
        if (giftListResult != null) {
            C4545HOg.LIZ(giftListResult);
            for (C4448HKn LIZ : this.mGiftListListeners) {
                LIZ.LIZ(giftListResult, i);
            }
            Room room = (Room) DataChannelGlobal.LIZLLL.LIZIZ(HEP.class);
            if (room != null) {
                i2 = room.getOrientation();
            } else {
                i2 = 0;
            }
            addGiftMap(giftListResult, i2);
            List<GiftPage> list = giftListResult.LJ;
            getPropertyByLiveType(i2).LIZ(str);
            Set set = (Set) C1781GFy.LIZJ.LIZ();
            set.add(String.valueOf(i2));
            C1781GFy.LIZJ.LIZ(set);
            updateGiftsInfo(giftListResult, j);
            updateGiftLock(giftListResult, j);
            updateRiskCtlInfo(giftListResult, j);
            if (hQc != null) {
                hQc.LIZ(list, giftListResult.LIZIZ);
            }
        } else if (hQc != null) {
            hQc.LIZ(new ArrayList());
        }
    }

    public final /* synthetic */ void lambda$syncGiftList$2$GiftManager(int i, boolean z, long j, C4593HQc hQc, long j2, boolean z2, 07U r22) {
        long j3;
        long j4 = j;
        if (LiveGiftResourceDownloadSetting.INSTANCE.getValue() != 0) {
            HT6.LIZ(i, j4);
        }
        07U r4 = r22;
        this.mHideBottomBar.setValue(Boolean.valueOf(((GiftListResult) r4.LIZ).LIZLLL.LIZJ));
        GiftsInfo giftsInfo = ((GiftListResult) r4.LIZ).LIZLLL;
        this.mGroupSendInfo = giftsInfo.LJIILJJIL;
        this.mGiftPollInfo = giftsInfo.LJIILL;
        FreqLimitGiftInfo freqLimitGiftInfo2 = giftsInfo.LJIILLIIL;
        this.freqLimitGiftInfo = freqLimitGiftInfo2;
        updateFreqList(freqLimitGiftInfo2);
        C2675Gg0.LIZ().LIZ((Object) new C2205GWg(getPollGifts()));
        C4492HMf hMf = C4495HMi.LJIIJJI;
        hMf.LIZJ = giftsInfo;
        GiftsInfo giftsInfo2 = hMf.LIZJ;
        if (giftsInfo2 != null) {
            LiveLimitedTimeDiscountGiftInfo liveLimitedTimeDiscountGiftInfo = giftsInfo2.LIZIZ;
            if (liveLimitedTimeDiscountGiftInfo != null) {
                j3 = liveLimitedTimeDiscountGiftInfo.LIZJ;
            } else {
                j3 = 0;
            }
            hMf.LIZLLL = j3;
            if (0 > hMf.LIZLLL) {
                hMf.LIZLLL = 0;
            }
        }
        hMf.LJ = hMf.LJFF();
        onSyncGiftListSuccess((GiftListResult) r4.LIZ, (String) r4.LIZIZ, i, z, j4, hQc);
        long millis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - j2);
        if (z2) {
            String LIZ = C1832GHx.LIZ("ttlive_gift_list_status");
            if (!7tg.LIZ.LIZ(LIZ, 0)) {
                0c0.LIZ(LIZ, 0, millis);
            }
        }
        HPK.LIZ(millis, 0, i, "");
        if (i == 1) {
            GiftListResult giftListResult = (GiftListResult) r4.LIZ;
            String str = (String) r4.LIZIZ;
            M12.LIZ(giftListResult, str);
            List<GiftPage> list = giftListResult.LJ;
            n.LIZIZ(list, "");
            HQ2.LIZIZ = list;
            HRW.LIZ(new HQU(str));
        }
    }
}
