package com.ss.android.ugc.aweme.feed.model;

import X.2YN;
import X.4BB;
import X.4Bs;
import X.C4326EfC;
import X.CqM;
import android.os.Message;
import com.bytedance.covode.number.Covode;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import kotlin.h.b.n;
import kotlin.o.y;

public final class FollowingFeedListModel$loadList$1<T> implements 2YN {
    public final /* synthetic */ int $cursor;
    public final /* synthetic */ boolean $isBlueUser;
    public final /* synthetic */ int $refreshType;
    public final /* synthetic */ String $uid;
    public final /* synthetic */ FollowingFeedListModel this$0;

    static {
        Covode.recordClassIndex(78922);
    }

    public FollowingFeedListModel$loadList$1(FollowingFeedListModel followingFeedListModel, int i, String str, boolean z, int i2) {
        this.this$0 = followingFeedListModel;
        this.$refreshType = i;
        this.$uid = str;
        this.$isBlueUser = z;
        this.$cursor = i2;
    }

    public final void accept(C4326EfC efC) {
        boolean z = true;
        if (efC.getCode() != 0) {
            Message obtainMessage = this.this$0.mHandler.obtainMessage(0);
            n.LIZIZ(obtainMessage, "");
            obtainMessage.obj = new RuntimeException(efC.getMsg());
            this.this$0.mHandler.sendMessage(obtainMessage);
            this.this$0.mIsNewDataEmpty = true;
            return;
        }
        int i = this.$refreshType;
        int i2 = -1;
        if (i == 1) {
            Iterator<String> it = this.this$0.uidList.iterator();
            int i3 = 0;
            while (true) {
                if (!it.hasNext()) {
                    break;
                } else if (y.LIZ(it.next(), this.$uid, true)) {
                    i2 = i3;
                    break;
                } else {
                    i3++;
                }
            }
            this.this$0.hasMoreHeader = true;
            if (i2 == 0) {
                this.this$0.hasMoreHeader = false;
            } else {
                FollowingFeedListModel followingFeedListModel = this.this$0;
                followingFeedListModel.headerUid = followingFeedListModel.uidList.get(i2 - 1);
                this.this$0.headerNextCursor = 0;
            }
            this.this$0.hasMoreFooter = true;
            if (efC.getHasMore()) {
                this.this$0.footerUid = this.$uid;
                this.this$0.footerNextCursor = efC.getNextCursor();
            } else if (i2 == this.this$0.uidList.size() - 1) {
                this.this$0.hasMoreFooter = false;
            } else {
                FollowingFeedListModel followingFeedListModel2 = this.this$0;
                followingFeedListModel2.footerUid = followingFeedListModel2.uidList.get(i2 + 1);
                this.this$0.footerNextCursor = 0;
            }
            Map map = 4BB.LIZ;
            String str = this.$uid;
            String str2 = efC.getAwemeList().get(0).aid;
            n.LIZIZ(str2, "");
            map.put(str, str2);
            if (!efC.getHasMore()) {
                Map map2 = 4BB.LIZIZ;
                String str3 = this.$uid;
                String str4 = efC.getAwemeList().get(efC.getAwemeList().size() - 1).aid;
                n.LIZIZ(str4, "");
                map2.put(str3, str4);
            }
            if (this.$isBlueUser) {
                CqM.LIZ(new 4Bs(this.$uid));
            }
        } else if (i == 3) {
            if (efC.getHasMore()) {
                this.this$0.headerUid = this.$uid;
                this.this$0.headerNextCursor = efC.getNextCursor();
            } else {
                Iterator<String> it2 = this.this$0.uidList.iterator();
                int i4 = 0;
                while (true) {
                    if (!it2.hasNext()) {
                        break;
                    } else if (y.LIZ(it2.next(), this.$uid, true)) {
                        i2 = i4;
                        if (i2 == 0) {
                            this.this$0.hasMoreHeader = false;
                        }
                    } else {
                        i4++;
                    }
                }
                FollowingFeedListModel followingFeedListModel3 = this.this$0;
                followingFeedListModel3.headerUid = followingFeedListModel3.uidList.get(i2 - 1);
                this.this$0.headerNextCursor = 0;
            }
            if (this.$cursor == 0) {
                Map map3 = 4BB.LIZIZ;
                String str5 = this.$uid;
                String str6 = efC.getAwemeList().get(efC.getAwemeList().size() - 1).aid;
                n.LIZIZ(str6, "");
                map3.put(str5, str6);
            }
            if (!efC.getHasMore()) {
                Map map4 = 4BB.LIZ;
                String str7 = this.$uid;
                String str8 = efC.getAwemeList().get(0).aid;
                n.LIZIZ(str8, "");
                map4.put(str7, str8);
            }
        } else {
            if (efC.getHasMore()) {
                this.this$0.footerUid = this.$uid;
                this.this$0.footerNextCursor = efC.getNextCursor();
            } else {
                Iterator<String> it3 = this.this$0.uidList.iterator();
                int i5 = 0;
                while (true) {
                    if (!it3.hasNext()) {
                        break;
                    } else if (y.LIZ(it3.next(), this.$uid, true)) {
                        i2 = i5;
                        break;
                    } else {
                        i5++;
                    }
                }
                if (i2 == this.this$0.uidList.size() - 1) {
                    this.this$0.hasMoreFooter = false;
                } else {
                    FollowingFeedListModel followingFeedListModel4 = this.this$0;
                    followingFeedListModel4.footerUid = followingFeedListModel4.uidList.get(i2 + 1);
                    this.this$0.footerNextCursor = 0;
                }
            }
            if (this.$cursor == 0) {
                Map map5 = 4BB.LIZ;
                String str9 = this.$uid;
                String str10 = efC.getAwemeList().get(0).aid;
                n.LIZIZ(str10, "");
                map5.put(str9, str10);
            }
            if (!efC.getHasMore()) {
                Map map6 = 4BB.LIZIZ;
                String str11 = this.$uid;
                String str12 = efC.getAwemeList().get(efC.getAwemeList().size() - 1).aid;
                n.LIZIZ(str12, "");
                map6.put(str11, str12);
            }
        }
        FollowingFeedListModel followingFeedListModel5 = this.this$0;
        List<Aweme> awemeList = efC.getAwemeList();
        if (awemeList != null && !awemeList.isEmpty()) {
            z = false;
        }
        followingFeedListModel5.mIsNewDataEmpty = z;
        Message obtainMessage2 = this.this$0.mHandler.obtainMessage(0);
        n.LIZIZ(obtainMessage2, "");
        obtainMessage2.obj = efC;
        this.this$0.mHandler.sendMessage(obtainMessage2);
    }
}
