discord-jadx/app/src/main/java/com/discord/tooltips/TooltipManager.java

209 lines
7.6 KiB
Java

package com.discord.tooltips;
import android.content.SharedPreferences;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.MainThread;
import androidx.core.view.ViewCompat;
import c.a.j.a;
import c.a.j.c;
import c.a.j.d;
import c.a.j.f;
import c.a.v.e;
import com.discord.floating_view_manager.FloatingViewGravity;
import d0.g;
import d0.z.d.m;
import d0.z.d.o;
import java.lang.ref.WeakReference;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import kotlin.Lazy;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
/* compiled from: TooltipManager.kt */
public class TooltipManager {
public Map<String, Integer> a;
public final c.a.v.a b;
/* renamed from: c reason: collision with root package name */
public final Set<String> f2188c;
public final int d;
public final c.a.j.a e;
/* compiled from: TooltipManager.kt */
public static final class a {
public static WeakReference<TooltipManager> a;
public static final Lazy b = g.lazy(C0180a.i);
/* renamed from: c reason: collision with root package name */
public static final Lazy f2189c = g.lazy(b.i);
public static final a d = null;
/* compiled from: TooltipManager.kt */
/* renamed from: com.discord.tooltips.TooltipManager$a$a reason: collision with other inner class name */
public static final class C0180a extends o implements Function0<c.a.v.a> {
public static final C0180a i = new C0180a();
public C0180a() {
super(0);
}
/* Return type fixed from 'java.lang.Object' to match base method */
@Override // kotlin.jvm.functions.Function0
/* renamed from: invoke */
public c.a.v.a mo1invoke() {
return new c.a.v.a(null, 1);
}
}
/* compiled from: TooltipManager.kt */
public static final class b extends o implements Function0<Set<String>> {
public static final b i = new b();
public b() {
super(0);
}
/* Return type fixed from 'java.lang.Object' to match base method */
@Override // kotlin.jvm.functions.Function0
/* renamed from: invoke */
public Set<String> mo1invoke() {
return new LinkedHashSet();
}
}
}
/* compiled from: TooltipManager.kt */
public static class b {
private final String cacheKey;
private final String tooltipName;
public b(String str, String str2) {
m.checkNotNullParameter(str2, "tooltipName");
this.cacheKey = str;
this.tooltipName = str2;
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ b(String str, String str2, int i, DefaultConstructorMarker defaultConstructorMarker) {
this((i & 1) != 0 ? null : str, str2);
}
public final String getCacheKey() {
return this.cacheKey;
}
public final String getTooltipName() {
return this.tooltipName;
}
}
public TooltipManager(c.a.v.a aVar, Set set, int i, c.a.j.a aVar2, int i2) {
i = (i2 & 4) != 0 ? 1 : i;
m.checkNotNullParameter(aVar, "acknowledgedTooltipsCache");
m.checkNotNullParameter(set, "shownTooltipNames");
m.checkNotNullParameter(aVar2, "floatingViewManager");
this.b = aVar;
this.f2188c = set;
this.d = i;
this.e = aVar2;
aVar2.a = new e(this);
this.a = new LinkedHashMap();
}
@MainThread
public final void a(b bVar) {
m.checkNotNullParameter(bVar, "tooltip");
c(bVar);
String cacheKey = bVar.getCacheKey();
if (cacheKey != null) {
c.a.v.a aVar = this.b;
Objects.requireNonNull(aVar);
m.checkNotNullParameter(cacheKey, "tooltipCacheKey");
if (!aVar.a.getBoolean(cacheKey, false)) {
c.a.v.a aVar2 = this.b;
Objects.requireNonNull(aVar2);
m.checkNotNullParameter(cacheKey, "tooltipCacheKey");
SharedPreferences.Editor edit = aVar2.a.edit();
m.checkExpressionValueIsNotNull(edit, "editor");
edit.putBoolean(cacheKey, true);
edit.apply();
}
}
}
@MainThread
public final boolean b(b bVar, boolean z2) {
m.checkNotNullParameter(bVar, "tooltip");
String cacheKey = bVar.getCacheKey();
if (cacheKey != null) {
c.a.v.a aVar = this.b;
Objects.requireNonNull(aVar);
m.checkNotNullParameter(cacheKey, "tooltipCacheKey");
boolean z3 = aVar.a.getBoolean(cacheKey, false);
boolean contains = this.f2188c.contains(bVar.getTooltipName());
int size = this.f2188c.size();
if (z3) {
return false;
}
if (!contains && !z2 && size >= this.d) {
return false;
}
}
return true;
}
@MainThread
public final void c(b bVar) {
m.checkNotNullParameter(bVar, "tooltip");
Integer num = this.a.get(bVar.getTooltipName());
if (num != null) {
this.e.b(num.intValue());
}
}
@MainThread
public final void d(View view, View view2, b bVar, FloatingViewGravity floatingViewGravity, int i, int i2, boolean z2, Observable<Unit> observable) {
m.checkNotNullParameter(view, "anchorView");
m.checkNotNullParameter(view2, "tooltipView");
m.checkNotNullParameter(bVar, "tooltip");
m.checkNotNullParameter(floatingViewGravity, "tooltipGravity");
m.checkNotNullParameter(observable, "componentPausedObservable");
if (b(bVar, z2)) {
c(bVar);
this.f2188c.add(bVar.getTooltipName());
this.a.put(bVar.getTooltipName(), Integer.valueOf(view2.getId()));
c.a.j.a aVar = this.e;
Objects.requireNonNull(aVar);
m.checkNotNullParameter(view, "anchorView");
m.checkNotNullParameter(view2, "floatingView");
m.checkNotNullParameter(floatingViewGravity, "floatingViewGravity");
m.checkNotNullParameter(observable, "componentPausedObservable");
View rootView = view.getRootView();
Objects.requireNonNull(rootView, "null cannot be cast to non-null type android.view.ViewGroup");
ViewGroup viewGroup = (ViewGroup) rootView;
view2.setVisibility(4);
if (!aVar.b.containsKey(Integer.valueOf(view2.getId()))) {
viewGroup.addView(view2);
}
if (!ViewCompat.isLaidOut(view2) || view2.isLayoutRequested()) {
view2.addOnLayoutChangeListener(new c.a.j.b(aVar, view, view2, floatingViewGravity, i, i2));
} else if (!ViewCompat.isLaidOut(view) || view.isLayoutRequested()) {
view.addOnLayoutChangeListener(new c(aVar, view, view2, floatingViewGravity, i, i2));
} else {
c.a.j.a.a(aVar, view2, view, floatingViewGravity, i, i2);
view2.setVisibility(0);
}
f fVar = new f(aVar, view2, view, floatingViewGravity, i, i2);
viewGroup.getViewTreeObserver().addOnPreDrawListener(fVar);
aVar.b.put(Integer.valueOf(view2.getId()), new a.C0028a(view2, viewGroup, fVar));
observable.Y(1).V(new d(aVar, view2), new c.a.j.e(aVar));
}
}
}