最右.apk(点击下载) / rf2.java


package defpackage;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.airbnb.epoxy.ControllerModelList;
import com.airbnb.epoxy.EpoxyControllerAdapter;
import com.airbnb.epoxy.EpoxyDiffLogger;
import com.airbnb.epoxy.EpoxyViewHolder;
import com.airbnb.epoxy.IllegalEpoxyUsage;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.CopyOnWriteArrayList;

/* renamed from: rf2  reason: default package */
public abstract class rf2 implements hg2 {
    private static final int DELAY_TO_CHECK_ADAPTER_COUNT_MS = 3000;
    private static final rg2 NO_OP_TIMER = new jg2();
    public static Handler defaultDiffingHandler;
    public static Handler defaultModelBuildingHandler;
    private static boolean filterDuplicatesDefault = false;
    private static boolean globalDebugLoggingEnabled = false;
    private static d globalExceptionHandler = new b();
    private final EpoxyControllerAdapter adapter;
    private final Runnable buildModelsRunnable;
    private EpoxyDiffLogger debugObserver;
    private volatile boolean filterDuplicates;
    private volatile boolean hasBuiltModelsEver;
    private final lf2 helper;
    private final List<e> interceptors;
    private final Handler modelBuildHandler;
    private List<f> modelInterceptorCallbacks;
    private ControllerModelList modelsBeingBuilt;
    private int recyclerViewAttachCount;
    private volatile int requestedModelBuildType;
    private tf2<?> stagedModel;
    private volatile Thread threadBuildingModels;
    private rg2 timer;

    /* renamed from: rf2$a */
    public class a implements Runnable {
        public a() {
        }

        public void run() {
            rf2.this.threadBuildingModels = Thread.currentThread();
            rf2.this.cancelPendingModelBuild();
            rf2.this.helper.resetAutoModels();
            rf2.this.modelsBeingBuilt = new ControllerModelList(rf2.this.getExpectedModelCount());
            rf2.this.timer.a("Models built");
            try {
                rf2.this.buildModels();
                rf2.this.addCurrentlyStagedModelIfExists();
                rf2.this.timer.stop();
                rf2.this.runInterceptors();
                rf2 rf2 = rf2.this;
                rf2.filterDuplicatesIfNeeded(rf2.modelsBeingBuilt);
                rf2.this.modelsBeingBuilt.freeze();
                rf2.this.timer.a("Models diffed");
                rf2.this.adapter.T(rf2.this.modelsBeingBuilt);
                rf2.this.timer.stop();
                rf2.this.modelsBeingBuilt = null;
                rf2.this.hasBuiltModelsEver = true;
                rf2.this.threadBuildingModels = null;
            } catch (Throwable th) {
                rf2.this.timer.stop();
                rf2.this.modelsBeingBuilt = null;
                rf2.this.hasBuiltModelsEver = true;
                rf2.this.threadBuildingModels = null;
                rf2.this.stagedModel = null;
                throw th;
            }
        }
    }

    /* renamed from: rf2$b */
    public static final class b implements d {
        @Override // defpackage.rf2.d
        public void a(@NonNull rf2 rf2, @NonNull RuntimeException runtimeException) {
        }
    }

    /* renamed from: rf2$c */
    public class c implements Runnable {
        public c() {
        }

        public void run() {
            if (rf2.this.recyclerViewAttachCount > 1) {
                rf2.this.onExceptionSwallowed(new IllegalStateException("This EpoxyController had its adapter added to more than one ReyclerView. Epoxy does not support attaching an adapter to multiple RecyclerViews because saved state will not work properly. If you did not intend to attach your adapter to multiple RecyclerViews you may be leaking a reference to a previous RecyclerView. Make sure to remove the adapter from any previous RecyclerViews (eg if the adapter is reused in a Fragment across multiple onCreateView/onDestroyView cycles). See https://github.com/airbnb/epoxy/wiki/Avoiding-Memory-Leaks for more information."));
            }
        }
    }

    /* renamed from: rf2$d */
    public interface d {
        void a(@NonNull rf2 rf2, @NonNull RuntimeException runtimeException);
    }

    /* renamed from: rf2$e */
    public interface e {
        void a(@NonNull List<tf2<?>> list);
    }

    /* renamed from: rf2$f */
    public interface f {
        void a(rf2 rf2);

        void b(rf2 rf2);
    }

    static {
        Handler handler = gg2.f27019b.f1678a;
        defaultModelBuildingHandler = handler;
        defaultDiffingHandler = handler;
    }

    public rf2() {
        this(defaultModelBuildingHandler, defaultDiffingHandler);
    }

    private void assertIsBuildingModels() {
        if (!isBuildingModels()) {
            throw new IllegalEpoxyUsage("Can only call this when inside the `buildModels` method");
        }
    }

    private void assertNotBuildingModels() {
        if (isBuildingModels()) {
            throw new IllegalEpoxyUsage("Cannot call this from inside `buildModels`");
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void filterDuplicatesIfNeeded(List<tf2<?>> list) {
        if (this.filterDuplicates) {
            this.timer.a("Duplicates filtered");
            HashSet hashSet = new HashSet(list.size());
            ListIterator<tf2<?>> listIterator = list.listIterator();
            while (listIterator.hasNext()) {
                tf2<?> next = listIterator.next();
                if (!hashSet.add(Long.valueOf(next.id()))) {
                    int previousIndex = listIterator.previousIndex();
                    listIterator.remove();
                    int findPositionOfDuplicate = findPositionOfDuplicate(list, next);
                    tf2<?> tf2 = list.get(findPositionOfDuplicate);
                    if (previousIndex <= findPositionOfDuplicate) {
                        findPositionOfDuplicate++;
                    }
                    onExceptionSwallowed(new IllegalEpoxyUsage("Two models have the same ID. ID's must be unique!\nOriginal has position " + findPositionOfDuplicate + ":\n" + tf2 + "\nDuplicate has position " + previousIndex + ":\n" + next));
                }
            }
            this.timer.stop();
        }
    }

    private int findPositionOfDuplicate(List<tf2<?>> list, tf2<?> tf2) {
        int size = list.size();
        for (int i = 0; i < size; i++) {
            if (list.get(i).id() == tf2.id()) {
                return i;
            }
        }
        throw new IllegalArgumentException("No duplicates in list");
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private int getExpectedModelCount() {
        int itemCount = this.adapter.getItemCount();
        if (itemCount != 0) {
            return itemCount;
        }
        return 25;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void runInterceptors() {
        if (!this.interceptors.isEmpty()) {
            List<f> list = this.modelInterceptorCallbacks;
            if (list != null) {
                for (f fVar : list) {
                    fVar.b(this);
                }
            }
            this.timer.a("Interceptors executed");
            for (e eVar : this.interceptors) {
                eVar.a(this.modelsBeingBuilt);
            }
            this.timer.stop();
            List<f> list2 = this.modelInterceptorCallbacks;
            if (list2 != null) {
                for (f fVar2 : list2) {
                    fVar2.a(this);
                }
            }
        }
        this.modelInterceptorCallbacks = null;
    }

    public static void setGlobalDebugLoggingEnabled(boolean z) {
        globalDebugLoggingEnabled = z;
    }

    public static void setGlobalDuplicateFilteringDefault(boolean z) {
        filterDuplicatesDefault = z;
    }

    public static void setGlobalExceptionHandler(@NonNull d dVar) {
        globalExceptionHandler = dVar;
    }

    @Override // defpackage.hg2
    public void add(@NonNull tf2<?> tf2) {
        tf2.addTo(this);
    }

    public void addAfterInterceptorCallback(f fVar) {
        assertIsBuildingModels();
        if (this.modelInterceptorCallbacks == null) {
            this.modelInterceptorCallbacks = new ArrayList();
        }
        this.modelInterceptorCallbacks.add(fVar);
    }

    public void addCurrentlyStagedModelIfExists() {
        tf2<?> tf2 = this.stagedModel;
        if (tf2 != null) {
            tf2.addTo(this);
        }
        this.stagedModel = null;
    }

    public void addInterceptor(@NonNull e eVar) {
        this.interceptors.add(eVar);
    }

    public void addInternal(tf2<?> tf2) {
        assertIsBuildingModels();
        if (tf2.e()) {
            throw new IllegalEpoxyUsage("You must set an id on a model before adding it. Use the @AutoModel annotation if you want an id to be automatically generated for you.");
        } else if (tf2.isShown()) {
            clearModelFromStaging(tf2);
            tf2.f = null;
            this.modelsBeingBuilt.add(tf2);
        } else {
            throw new IllegalEpoxyUsage("You cannot hide a model in an EpoxyController. Use `addIf` to conditionally add a model instead.");
        }
    }

    public void addModelBuildListener(lg2 lg2) {
        this.adapter.M(lg2);
    }

    public abstract void buildModels();

    public synchronized void cancelPendingModelBuild() {
        if (this.requestedModelBuildType != 0) {
            this.requestedModelBuildType = 0;
            this.modelBuildHandler.removeCallbacks(this.buildModelsRunnable);
        }
    }

    public void clearModelFromStaging(tf2<?> tf2) {
        if (this.stagedModel != tf2) {
            addCurrentlyStagedModelIfExists();
        }
        this.stagedModel = null;
    }

    @NonNull
    public EpoxyControllerAdapter getAdapter() {
        return this.adapter;
    }

    public int getFirstIndexOfModelInBuildingList(tf2<?> tf2) {
        assertIsBuildingModels();
        int size = this.modelsBeingBuilt.size();
        for (int i = 0; i < size; i++) {
            if (this.modelsBeingBuilt.get(i) == tf2) {
                return i;
            }
        }
        return -1;
    }

    public int getModelCountBuiltSoFar() {
        assertIsBuildingModels();
        return this.modelsBeingBuilt.size();
    }

    public int getSpanCount() {
        return this.adapter.r();
    }

    @NonNull
    public GridLayoutManager.SpanSizeLookup getSpanSizeLookup() {
        return this.adapter.s();
    }

    public boolean hasPendingModelBuild() {
        return (this.requestedModelBuildType == 0 && this.threadBuildingModels == null && !this.adapter.P()) ? false : true;
    }

    public boolean isBuildingModels() {
        return this.threadBuildingModels == Thread.currentThread();
    }

    public boolean isDebugLoggingEnabled() {
        return this.timer != NO_OP_TIMER;
    }

    public boolean isDuplicateFilteringEnabled() {
        return this.filterDuplicates;
    }

    public boolean isModelAddedMultipleTimes(tf2<?> tf2) {
        assertIsBuildingModels();
        int size = this.modelsBeingBuilt.size();
        int i = 0;
        for (int i2 = 0; i2 < size; i2++) {
            if (this.modelsBeingBuilt.get(i2) == tf2) {
                i++;
            }
        }
        if (i > 1) {
            return true;
        }
        return false;
    }

    public boolean isMultiSpan() {
        return this.adapter.t();
    }

    public boolean isStickyHeader(int i) {
        return false;
    }

    public void moveModel(int i, int i2) {
        assertNotBuildingModels();
        this.adapter.Q(i, i2);
        requestDelayedModelBuild(500);
    }

    public void notifyModelChanged(int i) {
        assertNotBuildingModels();
        this.adapter.R(i);
    }

    public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
    }

    public void onAttachedToRecyclerViewInternal(RecyclerView recyclerView) {
        int i = this.recyclerViewAttachCount + 1;
        this.recyclerViewAttachCount = i;
        if (i > 1) {
            gg2.f27019b.f1678a.postDelayed(new c(), 3000);
        }
        onAttachedToRecyclerView(recyclerView);
    }

    public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) {
    }

    public void onDetachedFromRecyclerViewInternal(RecyclerView recyclerView) {
        this.recyclerViewAttachCount--;
        onDetachedFromRecyclerView(recyclerView);
    }

    public void onExceptionSwallowed(@NonNull RuntimeException runtimeException) {
        globalExceptionHandler.a(this, runtimeException);
    }

    public void onModelBound(@NonNull EpoxyViewHolder epoxyViewHolder, @NonNull tf2<?> tf2, int i, @Nullable tf2<?> tf22) {
    }

    public void onModelUnbound(@NonNull EpoxyViewHolder epoxyViewHolder, @NonNull tf2<?> tf2) {
    }

    public void onRestoreInstanceState(@Nullable Bundle bundle) {
        this.adapter.E(bundle);
    }

    public void onSaveInstanceState(@NonNull Bundle bundle) {
        this.adapter.F(bundle);
    }

    public void onViewAttachedToWindow(@NonNull EpoxyViewHolder epoxyViewHolder, @NonNull tf2<?> tf2) {
    }

    public void onViewDetachedFromWindow(@NonNull EpoxyViewHolder epoxyViewHolder, @NonNull tf2<?> tf2) {
    }

    public void removeInterceptor(@NonNull e eVar) {
        this.interceptors.remove(eVar);
    }

    public void removeModelBuildListener(lg2 lg2) {
        this.adapter.S(lg2);
    }

    public synchronized void requestDelayedModelBuild(int i) {
        if (!isBuildingModels()) {
            int i2 = 1;
            if (this.requestedModelBuildType == 2) {
                cancelPendingModelBuild();
            } else if (this.requestedModelBuildType == 1) {
                return;
            }
            if (i != 0) {
                i2 = 2;
            }
            this.requestedModelBuildType = i2;
            this.modelBuildHandler.postDelayed(this.buildModelsRunnable, (long) i);
            return;
        }
        throw new IllegalEpoxyUsage("Cannot call `requestDelayedModelBuild` from inside `buildModels`");
    }

    public void requestModelBuild() {
        if (isBuildingModels()) {
            throw new IllegalEpoxyUsage("Cannot call `requestModelBuild` from inside `buildModels`");
        } else if (this.hasBuiltModelsEver) {
            requestDelayedModelBuild(0);
        } else {
            this.buildModelsRunnable.run();
        }
    }

    public void setDebugLoggingEnabled(boolean z) {
        assertNotBuildingModels();
        if (z) {
            this.timer = new nf2(getClass().getSimpleName());
            if (this.debugObserver == null) {
                this.debugObserver = new EpoxyDiffLogger(getClass().getSimpleName());
            }
            this.adapter.registerAdapterDataObserver(this.debugObserver);
            return;
        }
        this.timer = NO_OP_TIMER;
        EpoxyDiffLogger epoxyDiffLogger = this.debugObserver;
        if (epoxyDiffLogger != null) {
            this.adapter.unregisterAdapterDataObserver(epoxyDiffLogger);
        }
    }

    public void setFilterDuplicates(boolean z) {
        this.filterDuplicates = z;
    }

    public void setSpanCount(int i) {
        this.adapter.J(i);
    }

    public void setStagedModel(tf2<?> tf2) {
        if (tf2 != this.stagedModel) {
            addCurrentlyStagedModelIfExists();
        }
        this.stagedModel = tf2;
    }

    public void setupStickyHeaderView(View view) {
    }

    public void teardownStickyHeaderView(View view) {
    }

    public rf2(Handler handler, Handler handler2) {
        this.recyclerViewAttachCount = 0;
        this.interceptors = new CopyOnWriteArrayList();
        this.filterDuplicates = filterDuplicatesDefault;
        this.threadBuildingModels = null;
        this.timer = NO_OP_TIMER;
        this.helper = mf2.b(this);
        this.requestedModelBuildType = 0;
        this.buildModelsRunnable = new a();
        this.adapter = new EpoxyControllerAdapter(this, handler2);
        this.modelBuildHandler = handler;
        setDebugLoggingEnabled(globalDebugLoggingEnabled);
    }

    public void add(@NonNull tf2<?>... tf2Arr) {
        ControllerModelList controllerModelList = this.modelsBeingBuilt;
        controllerModelList.ensureCapacity(controllerModelList.size() + tf2Arr.length);
        for (tf2<?> tf2 : tf2Arr) {
            add(tf2);
        }
    }

    public void add(@NonNull List<? extends tf2<?>> list) {
        ControllerModelList controllerModelList = this.modelsBeingBuilt;
        controllerModelList.ensureCapacity(controllerModelList.size() + list.size());
        for (tf2<?> tf2 : list) {
            add(tf2);
        }
    }
}