84 lines
3.8 KiB
Java
84 lines
3.8 KiB
Java
package com.discord.utilities.viewbinding;
|
|
|
|
import android.view.View;
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.lifecycle.Lifecycle;
|
|
import androidx.lifecycle.LifecycleOwner;
|
|
import androidx.viewbinding.ViewBinding;
|
|
import d0.z.d.m;
|
|
import kotlin.Unit;
|
|
import kotlin.jvm.functions.Function1;
|
|
import kotlin.reflect.KProperty;
|
|
/* compiled from: FragmentViewBindingDelegate.kt */
|
|
public final class FragmentViewBindingDelegate<T extends ViewBinding> {
|
|
private T binding;
|
|
private final Fragment fragment;
|
|
private final Function1<T, Unit> onViewBindingDestroy;
|
|
private final Function1<View, T> viewBindingFactory;
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r3v0, resolved type: kotlin.jvm.functions.Function1<? super android.view.View, ? extends T extends androidx.viewbinding.ViewBinding> */
|
|
/* JADX DEBUG: Multi-variable search result rejected for r4v0, resolved type: kotlin.jvm.functions.Function1<? super T extends androidx.viewbinding.ViewBinding, kotlin.Unit> */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public FragmentViewBindingDelegate(Fragment fragment, Function1<? super View, ? extends T> function1, Function1<? super T, Unit> function12) {
|
|
m.checkNotNullParameter(fragment, "fragment");
|
|
m.checkNotNullParameter(function1, "viewBindingFactory");
|
|
m.checkNotNullParameter(function12, "onViewBindingDestroy");
|
|
this.fragment = fragment;
|
|
this.viewBindingFactory = function1;
|
|
this.onViewBindingDestroy = function12;
|
|
addOnDestroyObserver();
|
|
}
|
|
|
|
public static final /* synthetic */ ViewBinding access$getBinding$p(FragmentViewBindingDelegate fragmentViewBindingDelegate) {
|
|
return fragmentViewBindingDelegate.binding;
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r1v0, resolved type: androidx.viewbinding.ViewBinding */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static final /* synthetic */ void access$setBinding$p(FragmentViewBindingDelegate fragmentViewBindingDelegate, ViewBinding viewBinding) {
|
|
fragmentViewBindingDelegate.binding = viewBinding;
|
|
}
|
|
|
|
private final void addOnDestroyObserver() {
|
|
this.fragment.getLifecycle().addObserver(new FragmentViewBindingDelegate$addOnDestroyObserver$1(this));
|
|
}
|
|
|
|
public final Fragment getFragment() {
|
|
return this.fragment;
|
|
}
|
|
|
|
public final Function1<T, Unit> getOnViewBindingDestroy() {
|
|
return this.onViewBindingDestroy;
|
|
}
|
|
|
|
public T getValue(Fragment fragment, KProperty<?> kProperty) {
|
|
m.checkNotNullParameter(fragment, "thisRef");
|
|
m.checkNotNullParameter(kProperty, "property");
|
|
T t = this.binding;
|
|
if (t != null) {
|
|
return t;
|
|
}
|
|
LifecycleOwner viewLifecycleOwner = this.fragment.getViewLifecycleOwner();
|
|
m.checkNotNullExpressionValue(viewLifecycleOwner, "fragment.viewLifecycleOwner");
|
|
Lifecycle lifecycle = viewLifecycleOwner.getLifecycle();
|
|
m.checkNotNullExpressionValue(lifecycle, "fragment.viewLifecycleOwner.lifecycle");
|
|
if (lifecycle.getCurrentState().isAtLeast(Lifecycle.State.INITIALIZED)) {
|
|
Function1<View, T> function1 = this.viewBindingFactory;
|
|
View requireView = fragment.requireView();
|
|
m.checkNotNullExpressionValue(requireView, "thisRef.requireView()");
|
|
T invoke = function1.invoke(requireView);
|
|
this.binding = invoke;
|
|
return invoke;
|
|
}
|
|
throw new IllegalStateException("Should not attempt to get bindings when Fragment views are destroyed.");
|
|
}
|
|
|
|
public /* bridge */ /* synthetic */ Object getValue(Object obj, KProperty kProperty) {
|
|
return getValue((Fragment) obj, (KProperty<?>) kProperty);
|
|
}
|
|
|
|
public final Function1<View, T> getViewBindingFactory() {
|
|
return this.viewBindingFactory;
|
|
}
|
|
}
|